wrap bookmark and progress import in try/catch

This commit is contained in:
Felix 2020-04-13 17:26:53 +02:00
parent ca82d78f20
commit 5de27c4965
2 changed files with 15 additions and 6 deletions

View file

@ -1,4 +1,5 @@
# 0.7.0
- [debug] im/export also for progess (not only bookmarks)
# 0.6.0
- Fahrplan-Import

View file

@ -100,13 +100,21 @@ class PreferencesViewModel(
if (favoritesJson == null && progressJson == null) {
mutableLiveData.postValue(LiveEvent(State.Done, null, null))
} else {
favoritesJson?.let {
val fromJson = gson.fromJson(it, Array<WatchlistItem>::class.java)
fromJson.map { watchlistItemDao.saveItem(it) }
try {
favoritesJson?.let {
val fromJson = gson.fromJson(it, Array<WatchlistItem>::class.java)
fromJson.map { watchlistItemDao.saveItem(it) }
}
} catch (ex: Exception) {
Log.e(TAG, "bookmark import failed", ex)
}
progressJson?.let {
val fromJson = gson.fromJson(it, Array<PlaybackProgress>::class.java)
fromJson.map { progressItemDao.saveProgress(it) }
try {
progressJson?.let {
val fromJson = gson.fromJson(it, Array<PlaybackProgress>::class.java)
fromJson.map { progressItemDao.saveProgress(it) }
}
} catch (ex: Exception) {
Log.e(TAG, "progress import failed", ex)
}
mutableLiveData.postValue(LiveEvent(State.Done, error = null))
}