mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 05:52:47 +00:00
make all colors setting independent for day and night mode
This commit is contained in:
parent
b26ac87ece
commit
7dac19cec7
4 changed files with 23 additions and 12 deletions
|
@ -19,7 +19,6 @@ import helium314.keyboard.latin.common.DynamicColors
|
|||
import helium314.keyboard.latin.common.readAllColorsMap
|
||||
import helium314.keyboard.latin.settings.Settings
|
||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||
import helium314.keyboard.latin.utils.ResourceUtils
|
||||
|
||||
class KeyboardTheme // Note: The themeId should be aligned with "themeId" attribute of Keyboard style in values/themes-<style>.xml.
|
||||
private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
|
||||
|
@ -101,12 +100,12 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
|
|||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getThemeColors(themeColors: String, themeStyle: String, context: Context, prefs: SharedPreferences): Colors {
|
||||
fun getThemeColors(themeColors: String, themeStyle: String, context: Context, prefs: SharedPreferences, isNight: Boolean): Colors {
|
||||
val hasBorders = prefs.getBoolean(Settings.PREF_THEME_KEY_BORDERS, false)
|
||||
val useNightMode = Settings.readDayNightPref(prefs, context.resources) && ResourceUtils.isNight(context.resources)
|
||||
val backgroundImage = Settings.readUserBackgroundImage(context, useNightMode)
|
||||
val backgroundImage = Settings.readUserBackgroundImage(context, isNight)
|
||||
return when (themeColors) {
|
||||
THEME_USER -> if (prefs.getInt(Settings.PREF_SHOW_MORE_COLORS, 0) == 2) AllColors(readAllColorsMap(prefs, false), themeStyle, hasBorders, backgroundImage)
|
||||
THEME_USER -> if (prefs.getInt(Settings.getColorPref(Settings.PREF_SHOW_MORE_COLORS, isNight), 0) == 2)
|
||||
AllColors(readAllColorsMap(prefs, false), themeStyle, hasBorders, backgroundImage)
|
||||
else DefaultColors(
|
||||
themeStyle,
|
||||
hasBorders,
|
||||
|
@ -122,7 +121,8 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
|
|||
Settings.readUserColor(prefs, context, Settings.PREF_COLOR_GESTURE_SUFFIX, false),
|
||||
keyboardBackground = backgroundImage
|
||||
)
|
||||
THEME_USER_NIGHT -> if (prefs.getInt(Settings.PREF_SHOW_MORE_COLORS, 0) == 2) AllColors(readAllColorsMap(prefs, true), themeStyle, hasBorders, backgroundImage)
|
||||
THEME_USER_NIGHT -> if (prefs.getInt(Settings.getColorPref(Settings.PREF_SHOW_MORE_COLORS, isNight), 0) == 2)
|
||||
AllColors(readAllColorsMap(prefs, true), themeStyle, hasBorders, backgroundImage)
|
||||
else DefaultColors(
|
||||
themeStyle,
|
||||
hasBorders,
|
||||
|
@ -140,7 +140,7 @@ private constructor(val themeId: Int, @JvmField val mStyleId: Int) {
|
|||
)
|
||||
THEME_DYNAMIC -> {
|
||||
if (Build.VERSION.SDK_INT >= VERSION_CODES.S) DynamicColors(context, themeStyle, hasBorders, backgroundImage)
|
||||
else getThemeColors(THEME_LIGHT, themeStyle, context, prefs)
|
||||
else getThemeColors(THEME_LIGHT, themeStyle, context, prefs, isNight)
|
||||
}
|
||||
THEME_DARK -> DefaultColors(
|
||||
themeStyle,
|
||||
|
|
|
@ -93,6 +93,17 @@ fun checkVersionUpgrade(context: Context) {
|
|||
if (prefs.contains(Settings.PREF_LANGUAGE_SWITCH_KEY) && prefs.getString(Settings.PREF_LANGUAGE_SWITCH_KEY, "") != "off")
|
||||
prefs.edit { putBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, true) }
|
||||
}
|
||||
if (oldVersion <= 2100) {
|
||||
if (prefs.contains(Settings.PREF_SHOW_MORE_COLORS)) {
|
||||
val moreColors = prefs.getInt(Settings.PREF_SHOW_MORE_COLORS, 0)
|
||||
prefs.edit {
|
||||
putInt(Settings.getColorPref(Settings.PREF_SHOW_MORE_COLORS, false), moreColors)
|
||||
if (prefs.getBoolean(Settings.PREF_THEME_DAY_NIGHT, false))
|
||||
putInt(Settings.getColorPref(Settings.PREF_SHOW_MORE_COLORS, true), moreColors)
|
||||
remove(Settings.PREF_SHOW_MORE_COLORS)
|
||||
}
|
||||
}
|
||||
}
|
||||
upgradeToolbarPrefs(prefs)
|
||||
onCustomLayoutFileListChanged() // just to be sure
|
||||
prefs.edit { putInt(Settings.PREF_VERSION_CODE, BuildConfig.VERSION_CODE) }
|
||||
|
|
|
@ -42,8 +42,8 @@ open class ColorsSettingsFragment : Fragment(R.layout.color_settings), MenuProvi
|
|||
// 1 for more colors
|
||||
// 2 for all colors
|
||||
private var moreColors: Int
|
||||
get() = prefs.getInt(Settings.PREF_SHOW_MORE_COLORS, 0)
|
||||
set(value) { prefs.edit().putInt(Settings.PREF_SHOW_MORE_COLORS, value).apply() }
|
||||
get() = prefs.getInt(Settings.getColorPref(Settings.PREF_SHOW_MORE_COLORS, isNight), 0)
|
||||
set(value) { prefs.edit().putInt(Settings.getColorPref(Settings.PREF_SHOW_MORE_COLORS, isNight), value).apply() }
|
||||
|
||||
private val prefs by lazy { DeviceProtectedUtils.getSharedPreferences(requireContext()) }
|
||||
|
||||
|
|
|
@ -187,7 +187,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
add(PREF_LAST_SHOWN_EMOJI_CATEGORY_ID);
|
||||
add(PREF_EMOJI_RECENT_KEYS);
|
||||
add(PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG);
|
||||
add(PREF_SHOW_MORE_COLORS);
|
||||
add(PREF_SELECTED_SUBTYPE);
|
||||
}};
|
||||
|
||||
|
@ -566,12 +565,13 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
public static Colors getColorsForCurrentTheme(final Context context, final SharedPreferences prefs) {
|
||||
boolean isNight = ResourceUtils.isNight(context.getResources());
|
||||
if (ColorsSettingsFragment.Companion.getForceOppositeTheme()) isNight = !isNight;
|
||||
final String themeColors = (isNight && readDayNightPref(prefs, context.getResources()))
|
||||
else isNight = isNight && readDayNightPref(prefs, context.getResources());
|
||||
final String themeColors = (isNight)
|
||||
? prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, KeyboardTheme.THEME_DARK)
|
||||
: prefs.getString(Settings.PREF_THEME_COLORS, KeyboardTheme.THEME_LIGHT);
|
||||
final String themeStyle = prefs.getString(Settings.PREF_THEME_STYLE, KeyboardTheme.STYLE_MATERIAL);
|
||||
|
||||
return KeyboardTheme.getThemeColors(themeColors, themeStyle, context, prefs);
|
||||
return KeyboardTheme.getThemeColors(themeColors, themeStyle, context, prefs, isNight);
|
||||
}
|
||||
|
||||
public static int readUserColor(final SharedPreferences prefs, final Context context, final String colorName, final boolean isNight) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue