From 88417b283e59fd637673177f062a9ff955290759 Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Mon, 24 Oct 2022 18:17:13 +0200 Subject: [PATCH] fix: Fixed file library crash --- .../fragment/FileLibraryDialogFragment.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/fragment/FileLibraryDialogFragment.kt b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/fragment/FileLibraryDialogFragment.kt index 82faa74c7..f1b6a7b84 100755 --- a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/fragment/FileLibraryDialogFragment.kt +++ b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/fragment/FileLibraryDialogFragment.kt @@ -119,11 +119,17 @@ class FileLibraryDialogFragment : ListPreferenceDialogFragmentCompat() { ) withContext(Dispatchers.Main) { - if (newName == "Invalid") - showMessage(getString(R.string.filelibrary_resample_failed)) - else - showMessage(getString(R.string.filelibrary_resample_complete, targetRate)) - refresh() + try { + if (newName == "Invalid") + showMessage(getString(R.string.filelibrary_resample_failed)) + else + showMessage(getString(R.string.filelibrary_resample_complete, + targetRate)) + refresh() + } + catch (_: IllegalStateException) { + // Context may not be attached to fragment at this point + } } } } @@ -225,7 +231,10 @@ class FileLibraryDialogFragment : ListPreferenceDialogFragmentCompat() { else { // TODO refresh without closing this.dismiss() - fileLibPreference.showDialog() + CoroutineScope(Dispatchers.Main).launch { + delay(50L) + fileLibPreference.showDialog() + } } }