[Android] Migrate app theme settings

Nicolas Pomepuy git at videolan.org
Mon Oct 7 15:05:31 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Fri Sep 20 13:26:11 2019 +0200| [096ae5bb27681665ed737914e48c9c0d6dc9b478] | committer: Geoffrey Métais

Migrate app theme settings

> https://code.videolan.org/videolan/vlc-android/commit/096ae5bb27681665ed737914e48c9c0d6dc9b478
---

 vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt    |  9 +--------
 vlc-android/src/org/videolan/vlc/util/SettingsMigration.kt | 11 +++++++++++
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
index d46907504..a7a7e32cf 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
@@ -674,12 +674,5 @@ fun BaseActivity.applyTheme() {
         setTheme(R.style.Theme_VLC_Black)
         return
     }
-    if (settings.contains(KEY_APP_THEME)) {
-        AppCompatDelegate.setDefaultNightMode(Integer.valueOf(settings.getString(KEY_APP_THEME, "-1")!!))
-    } else if (settings.contains(KEY_DAYNIGHT) || settings.contains(KEY_BLACK_THEME)) { // legacy support
-        val daynight = settings.getBoolean(KEY_DAYNIGHT, false)
-        val dark = settings.getBoolean(KEY_BLACK_THEME, false)
-        val mode = if (dark) AppCompatDelegate.MODE_NIGHT_YES else if (daynight) AppCompatDelegate.MODE_NIGHT_AUTO else AppCompatDelegate.MODE_NIGHT_NO
-        AppCompatDelegate.setDefaultNightMode(mode)
-    }
+    AppCompatDelegate.setDefaultNightMode(Integer.valueOf(settings.getString(KEY_APP_THEME, "-1")!!))
 }
diff --git a/vlc-android/src/org/videolan/vlc/util/SettingsMigration.kt b/vlc-android/src/org/videolan/vlc/util/SettingsMigration.kt
index 5d000c973..866293526 100644
--- a/vlc-android/src/org/videolan/vlc/util/SettingsMigration.kt
+++ b/vlc-android/src/org/videolan/vlc/util/SettingsMigration.kt
@@ -27,6 +27,7 @@ package org.videolan.vlc.util
 import android.content.Context
 import android.content.SharedPreferences
 import android.util.Log
+import androidx.appcompat.app.AppCompatDelegate
 import org.videolan.vlc.BuildConfig
 
 object SettingsMigration {
@@ -43,11 +44,21 @@ object SettingsMigration {
     private fun migrateToVersion3030000(settings: SharedPreferences) {
         Log.i(this::class.java.simpleName, "Migrating preferences to 3030000")
         val editor = settings.edit()
+        //Migrate video Resume confirmation
         val dialogConfirmResume = settings.getBoolean("dialog_confirm_resume", false)
         if (dialogConfirmResume) {
             editor.putString(KEY_VIDEO_CONFIRM_RESUME, "2")
         }
         editor.remove("dialog_confirm_resume")
+        //Migrate apptheme
+        if (!settings.contains(KEY_APP_THEME)) {
+            val daynight = settings.getBoolean("daynight", false)
+            val dark = settings.getBoolean("enable_black_theme", false)
+            val mode = if (dark) AppCompatDelegate.MODE_NIGHT_YES else if (daynight) AppCompatDelegate.MODE_NIGHT_AUTO else AppCompatDelegate.MODE_NIGHT_NO
+            editor.putString(KEY_APP_THEME, mode.toString())
+        }
+        editor.remove("daynight").remove("enable_black_theme")
+
         editor.apply()
     }
 }
\ No newline at end of file



More information about the Android mailing list