Changed runCatching to try/catch block

This commit is contained in:
merkost 2023-07-02 10:13:07 +10:00
parent 22a2fbb331
commit 3892c5f5d5

View File

@ -304,7 +304,7 @@ class SettingsActivity : SimpleActivity() {
private fun importCallHistory(uri: Uri) { private fun importCallHistory(uri: Uri) {
runCatching { try {
val jsonString = contentResolver.openInputStream(uri)!!.use { inputStream -> val jsonString = contentResolver.openInputStream(uri)!!.use { inputStream ->
inputStream.bufferedReader().readText() inputStream.bufferedReader().readText()
} }
@ -315,8 +315,8 @@ class SettingsActivity : SimpleActivity() {
RecentsHelper(this).restoreRecentCalls(this, objects) { RecentsHelper(this).restoreRecentCalls(this, objects) {
toast(R.string.importing_successful) toast(R.string.importing_successful)
} }
}.onFailure { } catch (e: Exception) {
toast(R.string.importing_failed) showErrorToast(e)
} }
} }
@ -324,17 +324,16 @@ class SettingsActivity : SimpleActivity() {
if (recents.isEmpty()) { if (recents.isEmpty()) {
toast(R.string.no_entries_for_exporting) toast(R.string.no_entries_for_exporting)
} else { } else {
runCatching { try {
val outputStream = contentResolver.openOutputStream(uri)!! val outputStream = contentResolver.openOutputStream(uri)!!
val jsonString = Gson().toJson(recents) val jsonString = Gson().toJson(recents)
outputStream.use { outputStream.use {
it.write(jsonString.toByteArray()) it.write(jsonString.toByteArray())
} }
}.onSuccess {
toast(R.string.exporting_successful) toast(R.string.exporting_successful)
}.onFailure { } catch (e: Exception) {
toast(R.string.exporting_failed) showErrorToast(e)
} }
} }
} }