[Android] Migrate the subtitles color setting

Nicolas Pomepuy git at videolan.org
Thu Sep 22 14:01:21 UTC 2022


vlc-android | branch: 3.5.x | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Sep 22 08:53:08 2022 +0200| [cb163b804063669b966f22f261830f503d0156c0] | committer: Duncan McNamara

Migrate the subtitles color setting

Fixes #2691

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

 .../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