[Android] Migrate the subtitles color setting

Nicolas Pomepuy git at videolan.org
Thu Sep 22 12:59:12 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Sep 22 08:53:08 2022 +0200| [1ae09c4ca420240e6dd1a3157462ca4591396809] | committer: Nicolas Pomepuy

Migrate the subtitles color setting

Fixes #2691

> https://code.videolan.org/videolan/vlc-android/commit/1ae09c4ca420240e6dd1a3157462ca4591396809
---

 .../src/org/videolan/vlc/util/VersionMigration.kt  | 26 +++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt b/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
index 4933bda57..a5dcf6502 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/VersionMigration.kt
@@ -26,6 +26,7 @@ package org.videolan.vlc.util
 
 import android.content.Context
 import android.content.SharedPreferences
+import android.graphics.Color
 import android.util.Log
 import androidx.appcompat.app.AppCompatDelegate
 import androidx.core.content.edit
@@ -39,7 +40,7 @@ import org.videolan.vlc.gui.onboarding.ONBOARDING_DONE_KEY
 import java.io.File
 import java.io.IOException
 
-private const val CURRENT_VERSION = 9
+private const val CURRENT_VERSION = 10
 
 object VersionMigration {
 
@@ -75,6 +76,10 @@ object VersionMigration {
             migrateToVersion9(settings)
         }
 
+        if (lastVersion < 10) {
+            migrateToVersion10(settings)
+        }
+
         settings.putSingle(KEY_CURRENT_SETTINGS_VERSION, CURRENT_VERSION)
     }
 
@@ -216,4 +221,23 @@ object VersionMigration {
                 remove("enable_screenshot_gesture")
             }
     }
+
+    /**
+     * Migrate the subtitle color setting
+     */
+    private fun migrateToVersion10(settings: SharedPreferences) {
+        Log.i(this::class.java.simpleName, "Migration to Version 10: Migrate the subtitle color setting")
+        if (settings.contains("subtitles_color"))
+            settings.edit(true) {
+                settings.getString("subtitles_color", "16777215")?.let {oldSetting ->
+                    try {
+                        val oldColor = oldSetting.toInt()
+                        val newColor = Color.argb(255, Color.red(oldColor), Color.green(oldColor), Color.blue(oldColor))
+                        putInt("subtitles_color", newColor)
+                    } catch (e: Exception) {
+                        remove("subtitles_color")
+                    }
+                }
+            }
+    }
 }
\ No newline at end of file



More information about the Android mailing list