Skip to content

Commit 428cbef

Browse files
committed
Add import try & catch
1 parent c40cc66 commit 428cbef

File tree

1 file changed

+10
-6
lines changed
  • app/src/main/java/com/vladshurakov/jetnotesapp/feature_settings/presenter/screen

1 file changed

+10
-6
lines changed

app/src/main/java/com/vladshurakov/jetnotesapp/feature_settings/presenter/screen/SettingsScreen.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,20 @@ fun SettingsScreen(
7676
val json = navController.context.contentResolver.openInputStream(uri).use {
7777
it?.bufferedReader()?.readText() ?: "[]"
7878
}
79-
val type: Type = object : TypeToken<List<Note>>() {}.type
80-
val notes = Gson().fromJson<List<Note>>(json, type).toMutableList()
81-
/*
79+
try {
80+
val type: Type = object : TypeToken<List<Note>>() {}.type
81+
val notes = Gson().fromJson<List<Note>>(json, type).toMutableList()
82+
/*
8283
* It changes id to null to auto-generate new id
8384
* (will be duplicated without it)
8485
*/
85-
notes.onEachIndexed { index, note ->
86-
notes[index] = note.copy(id = null)
86+
notes.onEachIndexed { index, note ->
87+
notes[index] = note.copy(id = null)
88+
}
89+
settingsViewModel.onEvent(SettingsEvent.InsertNotes(notes))
90+
}catch (e: java.lang.Exception){
91+
return@rememberLauncherForActivityResult
8792
}
88-
settingsViewModel.onEvent(SettingsEvent.InsertNotes(notes))
8993
}
9094

9195
val isStyleDialogOpen = remember {

0 commit comments

Comments
 (0)