Merge pull request #3954 from Bnyro/master

Show restart dialog after restoring backup
This commit is contained in:
Bnyro 2023-06-08 19:21:28 +02:00 committed by GitHub
commit b047c3c1a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 12 deletions

View File

@ -21,23 +21,20 @@ class AppearanceSettings : BasePreferenceFragment() {
val themeToggle = findPreference<ListPreference>(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<SwitchPreferenceCompat>(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<ListPreference>(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<ListPreference>(PreferenceKeys.LABEL_VISIBILITY)
labelVisibilityMode?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name)
RequireRestartDialog().show(childFragmentManager, RequireRestartDialog::class.java.name)
true
}

View File

@ -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<Preference>("backup")
advancesBackup?.setOnPreferenceClickListener {
val advancedBackup = findPreference<Preference>("backup")
advancedBackup?.setOnPreferenceClickListener {
BackupDialog {
backupFile = it
val timestamp = backupDateTimeFormatter.format(LocalDateTime.now())

View File

@ -20,8 +20,7 @@ class GeneralSettings : BasePreferenceFragment() {
val language = findPreference<ListPreference>("language")
language?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name)
RequireRestartDialog().show(childFragmentManager, RequireRestartDialog::class.java.name)
true
}