Skip to content
Snippets Groups Projects
Commit 4ffdb642 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Duncan McNamara
Browse files

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

parent fbb75dcf
No related branches found
No related tags found
1 merge request!1363New widgets
......@@ -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
......
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment