catch and show exceptions thrown at importing clips from a file

This commit is contained in:
tibbi 2022-02-02 11:26:53 +01:00
parent dd59e51bec
commit a20ab59df5
1 changed files with 15 additions and 11 deletions

View File

@ -175,19 +175,23 @@ class ManageClipboardItemsActivity : SimpleActivity(), RefreshRecyclerViewListen
var clipsImported = 0 var clipsImported = 0
ensureBackgroundThread { ensureBackgroundThread {
val token = object : TypeToken<List<String>>() {}.type try {
val clipValues = Gson().fromJson<ArrayList<String>>(inputStream.bufferedReader(), token) ?: ArrayList() val token = object : TypeToken<List<String>>() {}.type
clipValues.forEach { value -> val clipValues = Gson().fromJson<ArrayList<String>>(inputStream.bufferedReader(), token) ?: ArrayList()
val clip = Clip(null, value) clipValues.forEach { value ->
if (ClipsHelper(this).insertClip(clip) > 0) { val clip = Clip(null, value)
clipsImported++ if (ClipsHelper(this).insertClip(clip) > 0) {
clipsImported++
}
} }
}
runOnUiThread { runOnUiThread {
val msg = if (clipsImported > 0) R.string.importing_successful else R.string.no_new_entries_for_importing val msg = if (clipsImported > 0) R.string.importing_successful else R.string.no_new_entries_for_importing
toast(msg) toast(msg)
updateClips() updateClips()
}
} catch (e: Exception) {
showErrorToast(e)
} }
} }
} }