[Android] Widgets: use the user's colors when there is no palette

Nicolas Pomepuy git at videolan.org
Wed May 18 09:57:59 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu May 12 13:41:57 2022 +0200| [4ffdb642bb992ac905b668689093f67ecb40d568] | committer: Duncan McNamara

Widgets: use the user's colors when there is no palette

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

 .../videolan/vlc/gui/preferences/widgets/PreferencesWidgets.kt    | 4 ++--
 .../vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt  | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/widgets/PreferencesWidgets.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/widgets/PreferencesWidgets.kt
index d1bde4d02..e53fda7c0 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/widgets/PreferencesWidgets.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/widgets/PreferencesWidgets.kt
@@ -101,8 +101,8 @@ class PreferencesWidgets : BasePreferenceFragment(), SharedPreferences.OnSharedP
                 updateWidgetEntity()
             }
             themePreference.value = widget.theme.toString()
-            backgroundPreference.isVisible = widget.theme == 2
-            foregroundPreference.isVisible = widget.theme == 2
+            backgroundPreference.isVisible = widget.theme != 0
+            foregroundPreference.isVisible = widget.theme != 0
             backgroundPreference.saveValue(widget.backgroundColor)
             foregroundPreference.saveValue(widget.foregroundColor)
             findPreference<SeekBarPreference>("opacity")?.value = widget.opacity
diff --git a/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt b/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
index a862d3a25..52df6e317 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
@@ -51,7 +51,8 @@ fun Widget.getForegroundColor(context: Context, palette: Palette?): Int {
     val untreatedColor = when {
         theme == 0 && DynamicColors.isDynamicColorAvailable() -> ContextCompat.getColor(context, if (lightTheme) android.R.color.system_accent1_400 else android.R.color.system_accent1_200)
         theme == 2 -> foregroundColor
-        else -> (if (lightTheme) palette?.darkVibrantSwatch?.rgb ?: Color.BLACK else palette?.lightVibrantSwatch?.rgb ?: Color.WHITE)
+        else -> if (palette == null) foregroundColor else if (lightTheme) palette?.darkVibrantSwatch?.rgb
+                ?: Color.BLACK else palette?.lightVibrantSwatch?.rgb ?: Color.WHITE
     }
     return untreatedColor
 }
@@ -67,7 +68,8 @@ fun Widget.getBackgroundColor(context: Context, palette: Palette?): Int {
     val untreatedColor = when {
         theme == 0 && DynamicColors.isDynamicColorAvailable() -> ContextCompat.getColor(context, if (lightTheme) android.R.color.system_neutral2_50 else android.R.color.system_neutral2_800)
         theme == 2 -> backgroundColor
-        else -> (if (lightTheme) palette?.lightMutedSwatch?.rgb ?: Color.WHITE else palette?.darkMutedSwatch?.rgb ?: Color.BLACK)
+        else -> if (palette == null) backgroundColor else if (lightTheme) palette?.lightMutedSwatch?.rgb
+                ?: backgroundColor else palette?.darkMutedSwatch?.rgb ?: backgroundColor
     }
     return if (opacity.coerceAtLeast(0).coerceAtMost(100) != 100) ColorUtils.setAlphaComponent(untreatedColor, (opacity * 2.55F).toInt()) else untreatedColor
 }
@@ -83,7 +85,7 @@ fun Widget.getBackgroundSecondaryColor(context: Context, palette: Palette?): Int
     val untreatedColor = when {
         theme == 0 && DynamicColors.isDynamicColorAvailable() -> ContextCompat.getColor(context, if (lightTheme) android.R.color.system_accent1_100 else android.R.color.system_accent1_700)
         theme == 2 -> backgroundColor.lightenOrDarkenColor(0.1F)
-        else -> (if (lightTheme) palette?.lightMutedSwatch?.rgb ?: ContextCompat.getColor(context, R.color.grey300) else palette?.darkMutedSwatch?.rgb ?: ContextCompat.getColor(context, R.color.grey800))
+        else -> if (lightTheme) palette?.lightMutedSwatch?.rgb ?: ContextCompat.getColor(context, R.color.grey300) else palette?.darkMutedSwatch?.rgb ?: ContextCompat.getColor(context, R.color.grey800)
     }
     return if (opacity.coerceAtLeast(0).coerceAtMost(100) != 100) ColorUtils.setAlphaComponent(untreatedColor, (opacity * 2.55F).toInt()) else untreatedColor
 }



More information about the Android mailing list