Skip to content

Commit

Permalink
fix: copyFileToCache NetworkOnMainThreadException (#15570)
Browse files Browse the repository at this point in the history
* fix: copyFileToCache NetworkOnMainThreadException

* fix: Moving showImportUnsuccessfulDialog execution to the Main thread
  • Loading branch information
AnisBak authored Feb 19, 2024
1 parent 89ab636 commit fb7417f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ open class DeckPicker :
ActivityResultContracts.StartActivityForResult(),
DeckPickerActivityResultCallback {
if (it.resultCode == RESULT_OK) {
onSelectedPackageToImport(it.data!!)
lifecycleScope.launch(Dispatchers.IO) {
onSelectedPackageToImport(it.data!!)
}
}
}
)
Expand Down
4 changes: 3 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/Import.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ fun interface ImportColpkgListener {
fun DeckPicker.onSelectedPackageToImport(data: Intent) {
val importResult = ImportUtils.handleFileImport(this, data)
if (!importResult.isSuccess) {
ImportUtils.showImportUnsuccessfulDialog(this, importResult.humanReadableMessage, false)
runOnUiThread {
ImportUtils.showImportUnsuccessfulDialog(this, importResult.humanReadableMessage, false)
}
}
}

Expand Down

0 comments on commit fb7417f

Please sign in to comment.