diff --git a/app/src/main/java/com/github/libretube/ui/preferences/AppearanceSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/AppearanceSettings.kt index 68d8a0f49..7801e521b 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/AppearanceSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/AppearanceSettings.kt @@ -21,23 +21,20 @@ class AppearanceSettings : BasePreferenceFragment() { val themeToggle = findPreference(PreferenceKeys.THEME_MODE) themeToggle?.setOnPreferenceChangeListener { _, _ -> - val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) + RequireRestartDialog().show(childFragmentManager, RequireRestartDialog::class.java.name) true } val pureTheme = findPreference(PreferenceKeys.PURE_THEME) pureTheme?.setOnPreferenceChangeListener { _, _ -> - val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) + RequireRestartDialog().show(childFragmentManager, RequireRestartDialog::class.java.name) true } val accentColor = findPreference(PreferenceKeys.ACCENT_COLOR) updateAccentColorValues(accentColor!!) accentColor.setOnPreferenceChangeListener { _, _ -> - val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) + RequireRestartDialog().show(childFragmentManager, RequireRestartDialog::class.java.name) true } @@ -56,8 +53,7 @@ class AppearanceSettings : BasePreferenceFragment() { val labelVisibilityMode = findPreference(PreferenceKeys.LABEL_VISIBILITY) labelVisibilityMode?.setOnPreferenceChangeListener { _, _ -> - val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) + RequireRestartDialog().show(childFragmentManager, RequireRestartDialog::class.java.name) true } diff --git a/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt index 048a78841..fa4d80398 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt @@ -13,12 +13,14 @@ import com.github.libretube.helpers.ImportHelper import com.github.libretube.obj.BackupFile import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.dialogs.BackupDialog +import com.github.libretube.ui.dialogs.RequireRestartDialog import com.google.android.material.dialog.MaterialAlertDialogBuilder import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import java.time.LocalDateTime import java.time.format.DateTimeFormatter +import kotlinx.coroutines.withContext class BackupRestoreSettings : BasePreferenceFragment() { private val backupDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH:mm:ss") @@ -50,6 +52,12 @@ class BackupRestoreSettings : BasePreferenceFragment() { it?.let { CoroutineScope(Dispatchers.IO).launch { BackupHelper.restoreAdvancedBackup(requireContext(), it) + withContext(Dispatchers.Main) { + // could fail if fragment is already closed + runCatching { + RequireRestartDialog().show(childFragmentManager, this::class.java.name) + } + } } } } @@ -162,8 +170,8 @@ class BackupRestoreSettings : BasePreferenceFragment() { true } - val advancesBackup = findPreference("backup") - advancesBackup?.setOnPreferenceClickListener { + val advancedBackup = findPreference("backup") + advancedBackup?.setOnPreferenceClickListener { BackupDialog { backupFile = it val timestamp = backupDateTimeFormatter.format(LocalDateTime.now()) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt index 58652af09..0899a65a5 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/GeneralSettings.kt @@ -20,8 +20,7 @@ class GeneralSettings : BasePreferenceFragment() { val language = findPreference("language") language?.setOnPreferenceChangeListener { _, _ -> - val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) + RequireRestartDialog().show(childFragmentManager, RequireRestartDialog::class.java.name) true }