From e8f3c110a8fc846a19bc1bcc5b19c6ec983ad5d3 Mon Sep 17 00:00:00 2001 From: Tommaso Berlose Date: Fri, 2 Oct 2020 17:36:39 +0200 Subject: [PATCH] Add the dark theme colors --- .../anotherwidget/global/Preferences.kt | 15 ++ .../anotherwidget/helpers/ColorHelper.kt | 48 +++--- .../ui/fragments/ClockTabFragment.kt | 46 +++++- .../ui/fragments/GeneralTabFragment.kt | 153 +++++++++++++++--- .../ui/fragments/MainFragment.kt | 13 +- .../ui/viewmodels/MainViewModel.kt | 9 ++ .../anotherwidget/ui/widgets/MainWidget.kt | 26 +-- .../anotherwidget/utils/Extensions.kt | 2 +- .../res/layout/fragment_general_settings.xml | 94 ++++++++++- 9 files changed, 330 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt index 02548fb..f831e34 100755 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt @@ -56,6 +56,20 @@ object Preferences : KotprefModel() { var clockTextColor by stringPref(default = "#FFFFFF") var clockTextAlpha by stringPref(default = "FF") + + var textGlobalColorDark by stringPref(default = "#FFFFFF") + var textGlobalAlphaDark by stringPref(default = "FF") + + var textSecondaryColorDark by stringPref(default = "#FFFFFF") + var textSecondaryAlphaDark by stringPref(default = "FF") + + var backgroundCardColorDark by stringPref(default = "#000000") + var backgroundCardAlphaDark by stringPref(default = "00") + + var clockTextColorDark by stringPref(default = "#FFFFFF") + var clockTextAlphaDark by stringPref(default = "FF") + + var showAMPMIndicator by booleanPref(default = true) var weatherIconPack by intPref(default = Constants.WeatherIconPack.DEFAULT.value) @@ -70,6 +84,7 @@ object Preferences : KotprefModel() { var clockAppName by stringPref(key = "PREF_CLOCK_APP_NAME", default = "") var clockAppPackage by stringPref(key = "PREF_CLOCK_APP_PACKAGE", default = "") var textShadow by intPref(key = "PREF_TEXT_SHADOW", default = 1) + var textShadowDark by intPref(default = 1) var showDiffTime by booleanPref(key = "PREF_SHOW_DIFF_TIME", default = true) var showDeclinedEvents by booleanPref(key = "PREF_SHOW_DECLINED_EVENTS", default = false) var showInvitedEvents by booleanPref(default = false) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/ColorHelper.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/ColorHelper.kt index e8b9a54..439be80 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/ColorHelper.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/ColorHelper.kt @@ -7,97 +7,97 @@ import com.tommasoberlose.anotherwidget.global.Preferences import kotlin.math.roundToInt object ColorHelper { - fun getFontColor(): Int { + fun getFontColor(isDark: Boolean): Int { return try { - Color.parseColor("#%s%s".format(Preferences.textGlobalAlpha, Preferences.textGlobalColor.replace("#", ""))) + Color.parseColor("#%s%s".format(if (!isDark) Preferences.textGlobalAlpha else Preferences.textGlobalAlphaDark, (if (!isDark) Preferences.textGlobalColor else Preferences.textGlobalColorDark).replace("#", ""))) } catch (e: Exception) { Color.parseColor("#FFFFFFFF") } } - fun getFontColorAlpha(): Int { + fun getFontColorAlpha(isDark: Boolean): Int { return try { - Preferences.textGlobalAlpha.toIntValue().toDouble() * 255 / 100 + (if (!isDark) Preferences.textGlobalAlpha else Preferences.textGlobalAlphaDark).toIntValue().toDouble() * 255 / 100 } catch (e: Exception) { "FF".toIntValue().toDouble() * 255 / 100 }.roundToInt() } - fun getFontColorRgb(): Int { + fun getFontColorRgb(isDark: Boolean): Int { return try { - Color.parseColor(Preferences.textGlobalColor) + Color.parseColor((if (!isDark) Preferences.textGlobalColor else Preferences.textGlobalColorDark)) } catch (e: Exception) { Color.parseColor("#000000") } } - fun getSecondaryFontColor(): Int { + fun getSecondaryFontColor(isDark: Boolean): Int { return try { - Color.parseColor("#%s%s".format(Preferences.textSecondaryAlpha, Preferences.textSecondaryColor.replace("#", ""))) + Color.parseColor("#%s%s".format((if (!isDark) Preferences.textSecondaryAlpha else Preferences.textSecondaryAlphaDark), (if (!isDark) Preferences.textSecondaryColor else Preferences.textSecondaryColorDark).replace("#", ""))) } catch (e: Exception) { Color.parseColor("#FFFFFFFF") } } - fun getSecondaryFontColorAlpha(): Int { + fun getSecondaryFontColorAlpha(isDark: Boolean): Int { return try { - Preferences.textSecondaryAlpha.toIntValue().toDouble() * 255 / 100 + (if (!isDark) Preferences.textSecondaryAlpha else Preferences.textSecondaryAlphaDark).toIntValue().toDouble() * 255 / 100 } catch (e: Exception) { "FF".toIntValue().toDouble() * 255 / 100 }.roundToInt() } - fun getSecondaryFontColorRgb(): Int { + fun getSecondaryFontColorRgb(isDark: Boolean): Int { return try { - Color.parseColor(Preferences.textSecondaryColor) + Color.parseColor((if (!isDark) Preferences.textSecondaryColor else Preferences.textSecondaryColorDark)) } catch (e: Exception) { Color.parseColor("#000000") } } - fun getClockFontColor(): Int { + fun getClockFontColor(isDark: Boolean): Int { return try { - Color.parseColor("#%s%s".format(Preferences.clockTextAlpha, Preferences.clockTextColor.replace("#", ""))) + Color.parseColor("#%s%s".format((if (!isDark) Preferences.clockTextAlpha else Preferences.clockTextAlphaDark), (if (!isDark) Preferences.clockTextColor else Preferences.clockTextColorDark).replace("#", ""))) } catch (e: Exception) { Color.parseColor("#FFFFFFFF") } } - fun getClockFontColorAlpha(): Int { + fun getClockFontColorAlpha(isDark: Boolean): Int { return try { - Preferences.clockTextAlpha.toIntValue().toDouble() * 255 / 100 + (if (!isDark) Preferences.clockTextAlpha else Preferences.clockTextAlphaDark).toIntValue().toDouble() * 255 / 100 } catch (e: Exception) { "FF".toIntValue().toDouble() * 255 / 100 }.roundToInt() } - fun getClockFontColorRgb(): Int { + fun getClockFontColorRgb(isDark: Boolean): Int { return try { - Color.parseColor(Preferences.clockTextColor) + Color.parseColor((if (!isDark) Preferences.clockTextColor else Preferences.clockTextColorDark)) } catch (e: Exception) { Color.parseColor("#000000") } } - fun getBackgroundColor(): Int { + fun getBackgroundColor(isDark: Boolean): Int { return try { - Color.parseColor("#%s%s".format(Preferences.backgroundCardAlpha, Preferences.backgroundCardColor.replace("#", ""))) + Color.parseColor("#%s%s".format((if (!isDark) Preferences.backgroundCardAlpha else Preferences.backgroundCardAlphaDark), (if (!isDark) Preferences.backgroundCardColor else Preferences.backgroundCardColorDark).replace("#", ""))) } catch (e: Exception) { Color.parseColor("#00000000") } } - fun getBackgroundAlpha(): Int { + fun getBackgroundAlpha(isDark: Boolean): Int { return try { - Preferences.backgroundCardAlpha.toIntValue().toDouble() * 255 / 100 + (if (!isDark) Preferences.backgroundCardAlpha else Preferences.backgroundCardAlphaDark).toIntValue().toDouble() * 255 / 100 } catch (e: Exception) { "00".toIntValue().toDouble() * 255 / 100 }.roundToInt() } - fun getBackgroundColorRgb(): Int { + fun getBackgroundColorRgb(isDark: Boolean): Int { return try { - Color.parseColor(Preferences.backgroundCardColor) + Color.parseColor((if (!isDark) Preferences.backgroundCardColor else Preferences.backgroundCardColorDark)) } catch (e: Exception) { Color.parseColor("#000000") } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/ClockTabFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/ClockTabFragment.kt index 178d59f..fbd0e64 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/ClockTabFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/ClockTabFragment.kt @@ -36,6 +36,7 @@ import com.tommasoberlose.anotherwidget.helpers.IntentHelper import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel +import com.tommasoberlose.anotherwidget.utils.isDarkTheme import com.tommasoberlose.anotherwidget.utils.isDefaultSet import kotlinx.android.synthetic.main.fragment_clock_settings.* import kotlinx.coroutines.Dispatchers @@ -127,7 +128,18 @@ class ClockTabFragment : Fragment() { clock_text_color_label?.text = getString(R.string.transparent) } else { clock_text_color_label?.text = - "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor())).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase() + } + } + }) + + viewModel.clockTextColorDark.observe(viewLifecycleOwner, Observer { + maintainScrollPosition { + if (Preferences.clockTextAlphaDark == "00") { + clock_text_color_label?.text = getString(R.string.transparent) + } else { + clock_text_color_label?.text = + "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase() } } }) @@ -138,7 +150,18 @@ class ClockTabFragment : Fragment() { clock_text_color_label?.text = getString(R.string.transparent) } else { clock_text_color_label?.text = - "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor())).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase() + } + } + }) + + viewModel.clockTextAlphaDark.observe(viewLifecycleOwner, Observer { + maintainScrollPosition { + if (Preferences.clockTextAlphaDark == "00") { + clock_text_color_label?.text = getString(R.string.transparent) + } else { + clock_text_color_label?.text = + "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase() } } }) @@ -217,16 +240,25 @@ class ClockTabFragment : Fragment() { BottomSheetColorPicker(requireContext(), colors = colors, header = getString(R.string.settings_font_color_title), - getSelected = ColorHelper::getClockFontColorRgb, + getSelected = { ColorHelper.getClockFontColorRgb(activity?.isDarkTheme() == true) }, onColorSelected = { color: Int -> val colorString = Integer.toHexString(color) - Preferences.clockTextColor = - "#" + if (colorString.length > 6) colorString.substring(2) else colorString + if (activity?.isDarkTheme() == true) { + Preferences.clockTextColorDark = + "#" + if (colorString.length > 6) colorString.substring(2) else colorString + } else { + Preferences.clockTextColor = + "#" + if (colorString.length > 6) colorString.substring(2) else colorString + } }, showAlphaSelector = true, - alpha = Preferences.clockTextAlpha.toIntValue(), + alpha = if (activity?.isDarkTheme() == true) Preferences.clockTextAlphaDark.toIntValue() else Preferences.clockTextAlpha.toIntValue(), onAlphaChangeListener = { alpha -> - Preferences.clockTextAlpha = alpha.toHexValue() + if (activity?.isDarkTheme() == true) { + Preferences.clockTextAlphaDark = alpha.toHexValue() + } else { + Preferences.clockTextAlpha = alpha.toHexValue() + } } ).show() } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt index 0adc012..09b4026 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt @@ -28,6 +28,7 @@ import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel +import com.tommasoberlose.anotherwidget.utils.isDarkTheme import kotlinx.android.synthetic.main.fragment_clock_settings.* import kotlinx.android.synthetic.main.fragment_general_settings.* import kotlinx.android.synthetic.main.fragment_general_settings.scrollView @@ -106,7 +107,18 @@ class GeneralTabFragment : Fragment() { font_color_label?.text = getString(R.string.transparent) } else { font_color_label?.text = - "#%s".format(Integer.toHexString(ColorHelper.getFontColor())).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() + } + } + }) + + viewModel.textGlobalColorDark.observe(viewLifecycleOwner, Observer { + maintainScrollPosition { + if (Preferences.textGlobalAlphaDark == "00") { + font_color_label?.text = getString(R.string.transparent) + } else { + font_color_label?.text = + "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() } } }) @@ -117,7 +129,18 @@ class GeneralTabFragment : Fragment() { font_color_label?.text = getString(R.string.transparent) } else { font_color_label?.text = - "#%s".format(Integer.toHexString(ColorHelper.getFontColor())).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() + } + } + }) + + viewModel.textGlobalAlphaDark.observe(viewLifecycleOwner, Observer { + maintainScrollPosition { + if (Preferences.textGlobalAlphaDark == "00") { + font_color_label?.text = getString(R.string.transparent) + } else { + font_color_label?.text = + "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() } } }) @@ -128,7 +151,18 @@ class GeneralTabFragment : Fragment() { secondary_font_color_label?.text = getString(R.string.transparent) } else { secondary_font_color_label?.text = - "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor())).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() + } + } + }) + + viewModel.textSecondaryColorDark.observe(viewLifecycleOwner, Observer { + maintainScrollPosition { + if (Preferences.textSecondaryAlphaDark == "00") { + secondary_font_color_label?.text = getString(R.string.transparent) + } else { + secondary_font_color_label?.text = + "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() } } }) @@ -139,7 +173,18 @@ class GeneralTabFragment : Fragment() { secondary_font_color_label?.text = getString(R.string.transparent) } else { secondary_font_color_label?.text = - "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor())).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() + } + } + }) + + viewModel.textSecondaryAlphaDark.observe(viewLifecycleOwner, Observer { + maintainScrollPosition { + if (Preferences.textSecondaryAlphaDark == "00") { + secondary_font_color_label?.text = getString(R.string.transparent) + } else { + secondary_font_color_label?.text = + "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() } } }) @@ -161,7 +206,18 @@ class GeneralTabFragment : Fragment() { background_color_label?.text = getString(R.string.transparent) } else { background_color_label?.text = - "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor())).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() + } + } + }) + + viewModel.backgroundCardColorDark.observe(viewLifecycleOwner, Observer { + maintainScrollPosition { + if (Preferences.backgroundCardAlphaDark == "00") { + background_color_label?.text = getString(R.string.transparent) + } else { + background_color_label?.text = + "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() } } }) @@ -172,14 +228,37 @@ class GeneralTabFragment : Fragment() { background_color_label?.text = getString(R.string.transparent) } else { background_color_label?.text = - "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor())).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() + } + } + }) + + viewModel.backgroundCardAlphaDark.observe(viewLifecycleOwner, Observer { + maintainScrollPosition { + if (Preferences.backgroundCardAlphaDark == "00") { + background_color_label?.text = getString(R.string.transparent) + } else { + background_color_label?.text = + "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() } } }) viewModel.textShadow.observe(viewLifecycleOwner, Observer { maintainScrollPosition { - text_shadow_label?.text = getString(SettingsStringHelper.getTextShadowString(it)) + if (activity?.isDarkTheme() != true) { + text_shadow_label?.text = + getString(SettingsStringHelper.getTextShadowString(it)) + } + } + }) + + viewModel.textShadowDark.observe(viewLifecycleOwner, Observer { + maintainScrollPosition { + if (activity?.isDarkTheme() == true) { + text_shadow_label?.text = + getString(SettingsStringHelper.getTextShadowString(it)) + } } }) @@ -228,15 +307,23 @@ class GeneralTabFragment : Fragment() { BottomSheetColorPicker(requireContext(), colors = colors, header = getString(R.string.settings_font_color_title), - getSelected = ColorHelper::getFontColorRgb, + getSelected = { ColorHelper.getFontColorRgb(activity?.isDarkTheme() == true) }, onColorSelected = { color: Int -> val colorString = Integer.toHexString(color) - Preferences.textGlobalColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString + if (activity?.isDarkTheme() == true) { + Preferences.textGlobalColorDark = "#" + if (colorString.length > 6) colorString.substring(2) else colorString + } else { + Preferences.textGlobalColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString + } }, showAlphaSelector = true, - alpha = Preferences.textGlobalAlpha.toIntValue(), + alpha = if (activity?.isDarkTheme() == true) Preferences.textGlobalAlphaDark.toIntValue() else Preferences.textGlobalAlpha.toIntValue(), onAlphaChangeListener = { alpha -> - Preferences.textGlobalAlpha = alpha.toHexValue() + if (activity?.isDarkTheme() == true) { + Preferences.textGlobalAlphaDark = alpha.toHexValue() + } else { + Preferences.textGlobalAlpha = alpha.toHexValue() + } } ).show() } @@ -245,15 +332,25 @@ class GeneralTabFragment : Fragment() { BottomSheetColorPicker(requireContext(), colors = colors, header = getString(R.string.settings_secondary_font_color_title), - getSelected = ColorHelper::getSecondaryFontColorRgb, + getSelected = { ColorHelper.getSecondaryFontColorRgb(activity?.isDarkTheme() == true) }, onColorSelected = { color: Int -> val colorString = Integer.toHexString(color) - Preferences.textSecondaryColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString + if (activity?.isDarkTheme() == true) { + Preferences.textSecondaryColorDark = + "#" + if (colorString.length > 6) colorString.substring(2) else colorString + } else { + Preferences.textSecondaryColor = + "#" + if (colorString.length > 6) colorString.substring(2) else colorString + } }, showAlphaSelector = true, - alpha = Preferences.textSecondaryAlpha.toIntValue(), + alpha = if (activity?.isDarkTheme() == true) Preferences.textSecondaryAlphaDark.toIntValue() else Preferences.textSecondaryAlpha.toIntValue(), onAlphaChangeListener = { alpha -> - Preferences.textSecondaryAlpha = alpha.toHexValue() + if (activity?.isDarkTheme() == true) { + Preferences.textSecondaryAlphaDark = alpha.toHexValue() + } else { + Preferences.textSecondaryAlpha = alpha.toHexValue() + } } ).show() } @@ -317,26 +414,40 @@ class GeneralTabFragment : Fragment() { BottomSheetColorPicker(requireContext(), colors = colors, header = getString(R.string.settings_background_color_title), - getSelected = { ColorHelper.getBackgroundColorRgb() }, + getSelected = { ColorHelper.getBackgroundColorRgb(activity?.isDarkTheme() == true) }, onColorSelected = { color: Int -> val colorString = Integer.toHexString(color) - Preferences.backgroundCardColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString + if (activity?.isDarkTheme() == true) { + Preferences.backgroundCardColorDark = + "#" + if (colorString.length > 6) colorString.substring(2) else colorString + } else { + Preferences.backgroundCardColor = + "#" + if (colorString.length > 6) colorString.substring(2) else colorString + } }, showAlphaSelector = true, - alpha = Preferences.backgroundCardAlpha.toIntValue(), + alpha = if (activity?.isDarkTheme() == true) Preferences.backgroundCardAlphaDark.toIntValue() else Preferences.backgroundCardAlpha.toIntValue(), onAlphaChangeListener = { alpha -> - Preferences.backgroundCardAlpha = alpha.toHexValue() + if (activity?.isDarkTheme() == true) { + Preferences.backgroundCardAlphaDark = alpha.toHexValue() + } else { + Preferences.backgroundCardAlpha = alpha.toHexValue() + } } ).show() } action_text_shadow.setOnClickListener { - val dialog = BottomSheetMenu(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(Preferences.textShadow) + val dialog = BottomSheetMenu(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(if (activity?.isDarkTheme() == true) Preferences.textShadowDark else Preferences.textShadow) (2 downTo 0).forEach { dialog.addItem(getString(SettingsStringHelper.getTextShadowString(it)), it) } dialog.addOnSelectItemListener { value -> - Preferences.textShadow = value + if (activity?.isDarkTheme() == true) { + Preferences.textShadowDark = value + } else { + Preferences.textShadow = value + } }.show() } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt index 66b8fc8..b7168f0 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt @@ -42,6 +42,7 @@ import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.getCurrentWallpaper +import com.tommasoberlose.anotherwidget.utils.isDarkTheme import com.tommasoberlose.anotherwidget.utils.toPixel import kotlinx.android.synthetic.main.fragment_app_main.* import kotlinx.android.synthetic.main.the_widget_sans.* @@ -93,9 +94,9 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList }.attach() // Init clock - time.setTextColor(ColorHelper.getClockFontColor()) + time.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true)) time.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext())) - time_am_pm.setTextColor(ColorHelper.getClockFontColor()) + time_am_pm.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true)) time_am_pm.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2) time_container.isVisible = Preferences.showClock @@ -134,7 +135,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList preview?.setCardBackgroundColor( ContextCompat.getColor( requireContext(), - if (ColorHelper.getFontColor() + if (ColorHelper.getFontColor(activity?.isDarkTheme() == true) .isColorDark() ) android.R.color.white else R.color.colorAccent ) @@ -143,7 +144,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList BitmapHelper.getTintedDrawable( requireContext(), R.drawable.card_background, - ColorHelper.getBackgroundColor() + ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true) ) ) uiJob = lifecycleScope.launch(Dispatchers.IO) { @@ -165,8 +166,8 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList } withContext(Dispatchers.Main) { // Clock - time?.setTextColor(ColorHelper.getClockFontColor()) - time_am_pm?.setTextColor(ColorHelper.getClockFontColor()) + time?.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true)) + time_am_pm?.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true)) time?.setTextSize( TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext()) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/MainViewModel.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/MainViewModel.kt index 417c4f9..c6b7354 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/MainViewModel.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/MainViewModel.kt @@ -13,9 +13,16 @@ class MainViewModel : ViewModel() { val textSecondaryAlpha = Preferences.asLiveData(Preferences::textSecondaryAlpha) val backgroundCardColor = Preferences.asLiveData(Preferences::backgroundCardColor) val backgroundCardAlpha = Preferences.asLiveData(Preferences::backgroundCardAlpha) + val textGlobalColorDark = Preferences.asLiveData(Preferences::textGlobalColorDark) + val textGlobalAlphaDark = Preferences.asLiveData(Preferences::textGlobalAlphaDark) + val textSecondaryColorDark = Preferences.asLiveData(Preferences::textSecondaryColorDark) + val textSecondaryAlphaDark = Preferences.asLiveData(Preferences::textSecondaryAlphaDark) + val backgroundCardColorDark = Preferences.asLiveData(Preferences::backgroundCardColorDark) + val backgroundCardAlphaDark = Preferences.asLiveData(Preferences::backgroundCardAlphaDark) val textMainSize = Preferences.asLiveData(Preferences::textMainSize) val textSecondSize = Preferences.asLiveData(Preferences::textSecondSize) val textShadow = Preferences.asLiveData(Preferences::textShadow) + val textShadowDark = Preferences.asLiveData(Preferences::textShadowDark) val customFont = Preferences.asLiveData(Preferences::customFont) val secondRowInformation = Preferences.asLiveData(Preferences::secondRowInformation) val showDividers = Preferences.asLiveData(Preferences::showDividers) @@ -38,6 +45,8 @@ class MainViewModel : ViewModel() { val clockTextSize = Preferences.asLiveData(Preferences::clockTextSize) val clockTextColor = Preferences.asLiveData(Preferences::clockTextColor) val clockTextAlpha = Preferences.asLiveData(Preferences::clockTextAlpha) + val clockTextColorDark = Preferences.asLiveData(Preferences::clockTextColorDark) + val clockTextAlphaDark = Preferences.asLiveData(Preferences::clockTextAlphaDark) val showAMPMIndicator = Preferences.asLiveData(Preferences::showAMPMIndicator) val clockAppName = Preferences.asLiveData(Preferences::clockAppName) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt index 3cbbc86..bf3b540 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt @@ -24,9 +24,11 @@ import com.tommasoberlose.anotherwidget.global.Actions import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.helpers.* +import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue import com.tommasoberlose.anotherwidget.receivers.* import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.getCapWordString +import com.tommasoberlose.anotherwidget.utils.isDarkTheme import com.tommasoberlose.anotherwidget.utils.toPixel import kotlinx.android.synthetic.main.the_widget.view.* import java.lang.Exception @@ -99,12 +101,12 @@ class MainWidget : AppWidgetProvider() { views.setInt( R.id.widget_shape_background, "setColorFilter", - ColorHelper.getBackgroundColorRgb() + ColorHelper.getBackgroundColorRgb(context.isDarkTheme()) ) views.setInt( R.id.widget_shape_background, "setImageAlpha", - ColorHelper.getBackgroundAlpha() + ColorHelper.getBackgroundAlpha(context.isDarkTheme()) ) val refreshIntent = PendingIntent.getActivity( context, @@ -440,8 +442,8 @@ class MainWidget : AppWidgetProvider() { views.setViewVisibility(R.id.clock_bottom_margin_medium, View.GONE) views.setViewVisibility(R.id.clock_bottom_margin_large, View.GONE) } else { - views.setTextColor(R.id.time, ColorHelper.getClockFontColor()) - views.setTextColor(R.id.time_am_pm, ColorHelper.getClockFontColor()) + views.setTextColor(R.id.time, ColorHelper.getClockFontColor(context.isDarkTheme())) + views.setTextColor(R.id.time_am_pm, ColorHelper.getClockFontColor(context.isDarkTheme())) views.setTextViewTextSize( R.id.time, TypedValue.COMPLEX_UNIT_SP, @@ -663,7 +665,7 @@ class MainWidget : AppWidgetProvider() { // Color listOf(v.empty_date, v.divider1, v.temp, v.next_event, v.next_event_difference_time, v.divider3, v.special_temp).forEach { - it.setTextColor(ColorHelper.getFontColor()) + it.setTextColor(ColorHelper.getFontColor(context.applicationContext.isDarkTheme())) } if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) { @@ -671,11 +673,12 @@ class MainWidget : AppWidgetProvider() { } else { listOf(v.action_next, v.action_previous, v.empty_weather_icon, v.special_weather_icon) }.forEach { - it.setColorFilter(ColorHelper.getFontColor()) + it.setColorFilter(ColorHelper.getFontColorRgb(context.applicationContext.isDarkTheme())) + it.alpha = (if (context.isDarkTheme()) Preferences.textGlobalAlphaDark.toIntValue().toFloat() else Preferences.textGlobalAlpha.toIntValue().toFloat()) / 100 } listOf(v.next_event_date, v.divider2, v.calendar_temp).forEach { - it.setTextColor(ColorHelper.getSecondaryFontColor()) + it.setTextColor(ColorHelper.getSecondaryFontColor(context.applicationContext.isDarkTheme())) } if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) { @@ -683,7 +686,8 @@ class MainWidget : AppWidgetProvider() { } else { listOf(v.second_row_icon, v.weather_icon) }.forEach { - it.setColorFilter(ColorHelper.getSecondaryFontColor()) + it.setColorFilter(ColorHelper.getSecondaryFontColorRgb(context.applicationContext.isDarkTheme())) + it.alpha = (if (context.isDarkTheme()) Preferences.textSecondaryAlphaDark.toIntValue().toFloat() else Preferences.textSecondaryAlpha.toIntValue().toFloat()) / 100 } // Text Size @@ -723,19 +727,19 @@ class MainWidget : AppWidgetProvider() { // Shadows - val shadowRadius = when (Preferences.textShadow) { + val shadowRadius = when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) { 0 -> 0f 1 -> 5f 2 -> 5f else -> 5f } - val shadowColor = when (Preferences.textShadow) { + val shadowColor = when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) { 0 -> Color.TRANSPARENT 1 -> R.color.black_50 2 -> Color.BLACK else -> R.color.black_50 } - val shadowDy = when (Preferences.textShadow) { + val shadowDy = when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) { 0 -> 0f 1 -> 0f 2 -> 1f diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/utils/Extensions.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/utils/Extensions.kt index a7600b7..7b71399 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/utils/Extensions.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/utils/Extensions.kt @@ -172,7 +172,7 @@ fun String.isValidEmail(): Boolean = this.isNotEmpty() && Patterns.EMAIL_ADDRESS.matcher(this).matches() -fun Activity.isDarkTheme(): Boolean { +fun Context.isDarkTheme(): Boolean { return resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES } diff --git a/app/src/main/res/layout/fragment_general_settings.xml b/app/src/main/res/layout/fragment_general_settings.xml index 65526bc..bda407f 100644 --- a/app/src/main/res/layout/fragment_general_settings.xml +++ b/app/src/main/res/layout/fragment_general_settings.xml @@ -87,7 +87,8 @@ android:src="@drawable/round_palette" app:tint="@color/colorPrimaryText"/> + + + + + + + + + - - + + +