Add the dark theme colors

This commit is contained in:
Tommaso Berlose 2020-10-02 17:36:39 +02:00
parent 72bf3b04a7
commit e8f3c110a8
9 changed files with 330 additions and 76 deletions

View File

@ -56,6 +56,20 @@ object Preferences : KotprefModel() {
var clockTextColor by stringPref(default = "#FFFFFF") var clockTextColor by stringPref(default = "#FFFFFF")
var clockTextAlpha by stringPref(default = "FF") 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 showAMPMIndicator by booleanPref(default = true)
var weatherIconPack by intPref(default = Constants.WeatherIconPack.DEFAULT.value) 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 clockAppName by stringPref(key = "PREF_CLOCK_APP_NAME", default = "")
var clockAppPackage by stringPref(key = "PREF_CLOCK_APP_PACKAGE", default = "") var clockAppPackage by stringPref(key = "PREF_CLOCK_APP_PACKAGE", default = "")
var textShadow by intPref(key = "PREF_TEXT_SHADOW", default = 1) 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 showDiffTime by booleanPref(key = "PREF_SHOW_DIFF_TIME", default = true)
var showDeclinedEvents by booleanPref(key = "PREF_SHOW_DECLINED_EVENTS", default = false) var showDeclinedEvents by booleanPref(key = "PREF_SHOW_DECLINED_EVENTS", default = false)
var showInvitedEvents by booleanPref(default = false) var showInvitedEvents by booleanPref(default = false)

View File

@ -7,97 +7,97 @@ import com.tommasoberlose.anotherwidget.global.Preferences
import kotlin.math.roundToInt import kotlin.math.roundToInt
object ColorHelper { object ColorHelper {
fun getFontColor(): Int { fun getFontColor(isDark: Boolean): Int {
return try { 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) { } catch (e: Exception) {
Color.parseColor("#FFFFFFFF") Color.parseColor("#FFFFFFFF")
} }
} }
fun getFontColorAlpha(): Int { fun getFontColorAlpha(isDark: Boolean): Int {
return try { return try {
Preferences.textGlobalAlpha.toIntValue().toDouble() * 255 / 100 (if (!isDark) Preferences.textGlobalAlpha else Preferences.textGlobalAlphaDark).toIntValue().toDouble() * 255 / 100
} catch (e: Exception) { } catch (e: Exception) {
"FF".toIntValue().toDouble() * 255 / 100 "FF".toIntValue().toDouble() * 255 / 100
}.roundToInt() }.roundToInt()
} }
fun getFontColorRgb(): Int { fun getFontColorRgb(isDark: Boolean): Int {
return try { return try {
Color.parseColor(Preferences.textGlobalColor) Color.parseColor((if (!isDark) Preferences.textGlobalColor else Preferences.textGlobalColorDark))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#000000") Color.parseColor("#000000")
} }
} }
fun getSecondaryFontColor(): Int { fun getSecondaryFontColor(isDark: Boolean): Int {
return try { 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) { } catch (e: Exception) {
Color.parseColor("#FFFFFFFF") Color.parseColor("#FFFFFFFF")
} }
} }
fun getSecondaryFontColorAlpha(): Int { fun getSecondaryFontColorAlpha(isDark: Boolean): Int {
return try { return try {
Preferences.textSecondaryAlpha.toIntValue().toDouble() * 255 / 100 (if (!isDark) Preferences.textSecondaryAlpha else Preferences.textSecondaryAlphaDark).toIntValue().toDouble() * 255 / 100
} catch (e: Exception) { } catch (e: Exception) {
"FF".toIntValue().toDouble() * 255 / 100 "FF".toIntValue().toDouble() * 255 / 100
}.roundToInt() }.roundToInt()
} }
fun getSecondaryFontColorRgb(): Int { fun getSecondaryFontColorRgb(isDark: Boolean): Int {
return try { return try {
Color.parseColor(Preferences.textSecondaryColor) Color.parseColor((if (!isDark) Preferences.textSecondaryColor else Preferences.textSecondaryColorDark))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#000000") Color.parseColor("#000000")
} }
} }
fun getClockFontColor(): Int { fun getClockFontColor(isDark: Boolean): Int {
return try { 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) { } catch (e: Exception) {
Color.parseColor("#FFFFFFFF") Color.parseColor("#FFFFFFFF")
} }
} }
fun getClockFontColorAlpha(): Int { fun getClockFontColorAlpha(isDark: Boolean): Int {
return try { return try {
Preferences.clockTextAlpha.toIntValue().toDouble() * 255 / 100 (if (!isDark) Preferences.clockTextAlpha else Preferences.clockTextAlphaDark).toIntValue().toDouble() * 255 / 100
} catch (e: Exception) { } catch (e: Exception) {
"FF".toIntValue().toDouble() * 255 / 100 "FF".toIntValue().toDouble() * 255 / 100
}.roundToInt() }.roundToInt()
} }
fun getClockFontColorRgb(): Int { fun getClockFontColorRgb(isDark: Boolean): Int {
return try { return try {
Color.parseColor(Preferences.clockTextColor) Color.parseColor((if (!isDark) Preferences.clockTextColor else Preferences.clockTextColorDark))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#000000") Color.parseColor("#000000")
} }
} }
fun getBackgroundColor(): Int { fun getBackgroundColor(isDark: Boolean): Int {
return try { 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) { } catch (e: Exception) {
Color.parseColor("#00000000") Color.parseColor("#00000000")
} }
} }
fun getBackgroundAlpha(): Int { fun getBackgroundAlpha(isDark: Boolean): Int {
return try { return try {
Preferences.backgroundCardAlpha.toIntValue().toDouble() * 255 / 100 (if (!isDark) Preferences.backgroundCardAlpha else Preferences.backgroundCardAlphaDark).toIntValue().toDouble() * 255 / 100
} catch (e: Exception) { } catch (e: Exception) {
"00".toIntValue().toDouble() * 255 / 100 "00".toIntValue().toDouble() * 255 / 100
}.roundToInt() }.roundToInt()
} }
fun getBackgroundColorRgb(): Int { fun getBackgroundColorRgb(isDark: Boolean): Int {
return try { return try {
Color.parseColor(Preferences.backgroundCardColor) Color.parseColor((if (!isDark) Preferences.backgroundCardColor else Preferences.backgroundCardColorDark))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#000000") Color.parseColor("#000000")
} }

View File

@ -36,6 +36,7 @@ import com.tommasoberlose.anotherwidget.helpers.IntentHelper
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import com.tommasoberlose.anotherwidget.utils.isDefaultSet import com.tommasoberlose.anotherwidget.utils.isDefaultSet
import kotlinx.android.synthetic.main.fragment_clock_settings.* import kotlinx.android.synthetic.main.fragment_clock_settings.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -127,7 +128,18 @@ class ClockTabFragment : Fragment() {
clock_text_color_label?.text = getString(R.string.transparent) clock_text_color_label?.text = getString(R.string.transparent)
} else { } else {
clock_text_color_label?.text = 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) clock_text_color_label?.text = getString(R.string.transparent)
} else { } else {
clock_text_color_label?.text = 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(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_font_color_title), header = getString(R.string.settings_font_color_title),
getSelected = ColorHelper::getClockFontColorRgb, getSelected = { ColorHelper.getClockFontColorRgb(activity?.isDarkTheme() == true) },
onColorSelected = { color: Int -> onColorSelected = { color: Int ->
val colorString = Integer.toHexString(color) val colorString = Integer.toHexString(color)
Preferences.clockTextColor = if (activity?.isDarkTheme() == true) {
"#" + if (colorString.length > 6) colorString.substring(2) else colorString 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, showAlphaSelector = true,
alpha = Preferences.clockTextAlpha.toIntValue(), alpha = if (activity?.isDarkTheme() == true) Preferences.clockTextAlphaDark.toIntValue() else Preferences.clockTextAlpha.toIntValue(),
onAlphaChangeListener = { alpha -> onAlphaChangeListener = { alpha ->
Preferences.clockTextAlpha = alpha.toHexValue() if (activity?.isDarkTheme() == true) {
Preferences.clockTextAlphaDark = alpha.toHexValue()
} else {
Preferences.clockTextAlpha = alpha.toHexValue()
}
} }
).show() ).show()
} }

View File

@ -28,6 +28,7 @@ import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel 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_clock_settings.*
import kotlinx.android.synthetic.main.fragment_general_settings.* import kotlinx.android.synthetic.main.fragment_general_settings.*
import kotlinx.android.synthetic.main.fragment_general_settings.scrollView import kotlinx.android.synthetic.main.fragment_general_settings.scrollView
@ -106,7 +107,18 @@ class GeneralTabFragment : Fragment() {
font_color_label?.text = getString(R.string.transparent) font_color_label?.text = getString(R.string.transparent)
} else { } else {
font_color_label?.text = 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) font_color_label?.text = getString(R.string.transparent)
} else { } else {
font_color_label?.text = 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) secondary_font_color_label?.text = getString(R.string.transparent)
} else { } else {
secondary_font_color_label?.text = 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) secondary_font_color_label?.text = getString(R.string.transparent)
} else { } else {
secondary_font_color_label?.text = 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) background_color_label?.text = getString(R.string.transparent)
} else { } else {
background_color_label?.text = 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) background_color_label?.text = getString(R.string.transparent)
} else { } else {
background_color_label?.text = 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 { viewModel.textShadow.observe(viewLifecycleOwner, Observer {
maintainScrollPosition { 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(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_font_color_title), header = getString(R.string.settings_font_color_title),
getSelected = ColorHelper::getFontColorRgb, getSelected = { ColorHelper.getFontColorRgb(activity?.isDarkTheme() == true) },
onColorSelected = { color: Int -> onColorSelected = { color: Int ->
val colorString = Integer.toHexString(color) 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, showAlphaSelector = true,
alpha = Preferences.textGlobalAlpha.toIntValue(), alpha = if (activity?.isDarkTheme() == true) Preferences.textGlobalAlphaDark.toIntValue() else Preferences.textGlobalAlpha.toIntValue(),
onAlphaChangeListener = { alpha -> onAlphaChangeListener = { alpha ->
Preferences.textGlobalAlpha = alpha.toHexValue() if (activity?.isDarkTheme() == true) {
Preferences.textGlobalAlphaDark = alpha.toHexValue()
} else {
Preferences.textGlobalAlpha = alpha.toHexValue()
}
} }
).show() ).show()
} }
@ -245,15 +332,25 @@ class GeneralTabFragment : Fragment() {
BottomSheetColorPicker(requireContext(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_secondary_font_color_title), header = getString(R.string.settings_secondary_font_color_title),
getSelected = ColorHelper::getSecondaryFontColorRgb, getSelected = { ColorHelper.getSecondaryFontColorRgb(activity?.isDarkTheme() == true) },
onColorSelected = { color: Int -> onColorSelected = { color: Int ->
val colorString = Integer.toHexString(color) 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, showAlphaSelector = true,
alpha = Preferences.textSecondaryAlpha.toIntValue(), alpha = if (activity?.isDarkTheme() == true) Preferences.textSecondaryAlphaDark.toIntValue() else Preferences.textSecondaryAlpha.toIntValue(),
onAlphaChangeListener = { alpha -> onAlphaChangeListener = { alpha ->
Preferences.textSecondaryAlpha = alpha.toHexValue() if (activity?.isDarkTheme() == true) {
Preferences.textSecondaryAlphaDark = alpha.toHexValue()
} else {
Preferences.textSecondaryAlpha = alpha.toHexValue()
}
} }
).show() ).show()
} }
@ -317,26 +414,40 @@ class GeneralTabFragment : Fragment() {
BottomSheetColorPicker(requireContext(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_background_color_title), header = getString(R.string.settings_background_color_title),
getSelected = { ColorHelper.getBackgroundColorRgb() }, getSelected = { ColorHelper.getBackgroundColorRgb(activity?.isDarkTheme() == true) },
onColorSelected = { color: Int -> onColorSelected = { color: Int ->
val colorString = Integer.toHexString(color) 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, showAlphaSelector = true,
alpha = Preferences.backgroundCardAlpha.toIntValue(), alpha = if (activity?.isDarkTheme() == true) Preferences.backgroundCardAlphaDark.toIntValue() else Preferences.backgroundCardAlpha.toIntValue(),
onAlphaChangeListener = { alpha -> onAlphaChangeListener = { alpha ->
Preferences.backgroundCardAlpha = alpha.toHexValue() if (activity?.isDarkTheme() == true) {
Preferences.backgroundCardAlphaDark = alpha.toHexValue()
} else {
Preferences.backgroundCardAlpha = alpha.toHexValue()
}
} }
).show() ).show()
} }
action_text_shadow.setOnClickListener { action_text_shadow.setOnClickListener {
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(Preferences.textShadow) val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(if (activity?.isDarkTheme() == true) Preferences.textShadowDark else Preferences.textShadow)
(2 downTo 0).forEach { (2 downTo 0).forEach {
dialog.addItem(getString(SettingsStringHelper.getTextShadowString(it)), it) dialog.addItem(getString(SettingsStringHelper.getTextShadowString(it)), it)
} }
dialog.addOnSelectItemListener { value -> dialog.addOnSelectItemListener { value ->
Preferences.textShadow = value if (activity?.isDarkTheme() == true) {
Preferences.textShadowDark = value
} else {
Preferences.textShadow = value
}
}.show() }.show()
} }

View File

@ -42,6 +42,7 @@ import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.getCurrentWallpaper import com.tommasoberlose.anotherwidget.utils.getCurrentWallpaper
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import com.tommasoberlose.anotherwidget.utils.toPixel import com.tommasoberlose.anotherwidget.utils.toPixel
import kotlinx.android.synthetic.main.fragment_app_main.* import kotlinx.android.synthetic.main.fragment_app_main.*
import kotlinx.android.synthetic.main.the_widget_sans.* import kotlinx.android.synthetic.main.the_widget_sans.*
@ -93,9 +94,9 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
}.attach() }.attach()
// Init clock // Init clock
time.setTextColor(ColorHelper.getClockFontColor()) time.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))
time.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext())) 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_am_pm.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2)
time_container.isVisible = Preferences.showClock time_container.isVisible = Preferences.showClock
@ -134,7 +135,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
preview?.setCardBackgroundColor( preview?.setCardBackgroundColor(
ContextCompat.getColor( ContextCompat.getColor(
requireContext(), requireContext(),
if (ColorHelper.getFontColor() if (ColorHelper.getFontColor(activity?.isDarkTheme() == true)
.isColorDark() .isColorDark()
) android.R.color.white else R.color.colorAccent ) android.R.color.white else R.color.colorAccent
) )
@ -143,7 +144,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
BitmapHelper.getTintedDrawable( BitmapHelper.getTintedDrawable(
requireContext(), requireContext(),
R.drawable.card_background, R.drawable.card_background,
ColorHelper.getBackgroundColor() ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true)
) )
) )
uiJob = lifecycleScope.launch(Dispatchers.IO) { uiJob = lifecycleScope.launch(Dispatchers.IO) {
@ -165,8 +166,8 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
// Clock // Clock
time?.setTextColor(ColorHelper.getClockFontColor()) time?.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))
time_am_pm?.setTextColor(ColorHelper.getClockFontColor()) time_am_pm?.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))
time?.setTextSize( time?.setTextSize(
TypedValue.COMPLEX_UNIT_SP, TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(requireContext()) Preferences.clockTextSize.toPixel(requireContext())

View File

@ -13,9 +13,16 @@ class MainViewModel : ViewModel() {
val textSecondaryAlpha = Preferences.asLiveData(Preferences::textSecondaryAlpha) val textSecondaryAlpha = Preferences.asLiveData(Preferences::textSecondaryAlpha)
val backgroundCardColor = Preferences.asLiveData(Preferences::backgroundCardColor) val backgroundCardColor = Preferences.asLiveData(Preferences::backgroundCardColor)
val backgroundCardAlpha = Preferences.asLiveData(Preferences::backgroundCardAlpha) 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 textMainSize = Preferences.asLiveData(Preferences::textMainSize)
val textSecondSize = Preferences.asLiveData(Preferences::textSecondSize) val textSecondSize = Preferences.asLiveData(Preferences::textSecondSize)
val textShadow = Preferences.asLiveData(Preferences::textShadow) val textShadow = Preferences.asLiveData(Preferences::textShadow)
val textShadowDark = Preferences.asLiveData(Preferences::textShadowDark)
val customFont = Preferences.asLiveData(Preferences::customFont) val customFont = Preferences.asLiveData(Preferences::customFont)
val secondRowInformation = Preferences.asLiveData(Preferences::secondRowInformation) val secondRowInformation = Preferences.asLiveData(Preferences::secondRowInformation)
val showDividers = Preferences.asLiveData(Preferences::showDividers) val showDividers = Preferences.asLiveData(Preferences::showDividers)
@ -38,6 +45,8 @@ class MainViewModel : ViewModel() {
val clockTextSize = Preferences.asLiveData(Preferences::clockTextSize) val clockTextSize = Preferences.asLiveData(Preferences::clockTextSize)
val clockTextColor = Preferences.asLiveData(Preferences::clockTextColor) val clockTextColor = Preferences.asLiveData(Preferences::clockTextColor)
val clockTextAlpha = Preferences.asLiveData(Preferences::clockTextAlpha) 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 showAMPMIndicator = Preferences.asLiveData(Preferences::showAMPMIndicator)
val clockAppName = Preferences.asLiveData(Preferences::clockAppName) val clockAppName = Preferences.asLiveData(Preferences::clockAppName)

View File

@ -24,9 +24,11 @@ import com.tommasoberlose.anotherwidget.global.Actions
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.* import com.tommasoberlose.anotherwidget.helpers.*
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue
import com.tommasoberlose.anotherwidget.receivers.* import com.tommasoberlose.anotherwidget.receivers.*
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.getCapWordString import com.tommasoberlose.anotherwidget.utils.getCapWordString
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import com.tommasoberlose.anotherwidget.utils.toPixel import com.tommasoberlose.anotherwidget.utils.toPixel
import kotlinx.android.synthetic.main.the_widget.view.* import kotlinx.android.synthetic.main.the_widget.view.*
import java.lang.Exception import java.lang.Exception
@ -99,12 +101,12 @@ class MainWidget : AppWidgetProvider() {
views.setInt( views.setInt(
R.id.widget_shape_background, R.id.widget_shape_background,
"setColorFilter", "setColorFilter",
ColorHelper.getBackgroundColorRgb() ColorHelper.getBackgroundColorRgb(context.isDarkTheme())
) )
views.setInt( views.setInt(
R.id.widget_shape_background, R.id.widget_shape_background,
"setImageAlpha", "setImageAlpha",
ColorHelper.getBackgroundAlpha() ColorHelper.getBackgroundAlpha(context.isDarkTheme())
) )
val refreshIntent = PendingIntent.getActivity( val refreshIntent = PendingIntent.getActivity(
context, 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_medium, View.GONE)
views.setViewVisibility(R.id.clock_bottom_margin_large, View.GONE) views.setViewVisibility(R.id.clock_bottom_margin_large, View.GONE)
} else { } else {
views.setTextColor(R.id.time, ColorHelper.getClockFontColor()) views.setTextColor(R.id.time, ColorHelper.getClockFontColor(context.isDarkTheme()))
views.setTextColor(R.id.time_am_pm, ColorHelper.getClockFontColor()) views.setTextColor(R.id.time_am_pm, ColorHelper.getClockFontColor(context.isDarkTheme()))
views.setTextViewTextSize( views.setTextViewTextSize(
R.id.time, R.id.time,
TypedValue.COMPLEX_UNIT_SP, TypedValue.COMPLEX_UNIT_SP,
@ -663,7 +665,7 @@ class MainWidget : AppWidgetProvider() {
// Color // Color
listOf<TextView>(v.empty_date, v.divider1, v.temp, v.next_event, v.next_event_difference_time, v.divider3, v.special_temp).forEach { listOf<TextView>(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) { if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) {
@ -671,11 +673,12 @@ class MainWidget : AppWidgetProvider() {
} else { } else {
listOf<ImageView>(v.action_next, v.action_previous, v.empty_weather_icon, v.special_weather_icon) listOf<ImageView>(v.action_next, v.action_previous, v.empty_weather_icon, v.special_weather_icon)
}.forEach { }.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<TextView>(v.next_event_date, v.divider2, v.calendar_temp).forEach { listOf<TextView>(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) { if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) {
@ -683,7 +686,8 @@ class MainWidget : AppWidgetProvider() {
} else { } else {
listOf<ImageView>(v.second_row_icon, v.weather_icon) listOf<ImageView>(v.second_row_icon, v.weather_icon)
}.forEach { }.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 // Text Size
@ -723,19 +727,19 @@ class MainWidget : AppWidgetProvider() {
// Shadows // Shadows
val shadowRadius = when (Preferences.textShadow) { val shadowRadius = when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
0 -> 0f 0 -> 0f
1 -> 5f 1 -> 5f
2 -> 5f 2 -> 5f
else -> 5f else -> 5f
} }
val shadowColor = when (Preferences.textShadow) { val shadowColor = when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
0 -> Color.TRANSPARENT 0 -> Color.TRANSPARENT
1 -> R.color.black_50 1 -> R.color.black_50
2 -> Color.BLACK 2 -> Color.BLACK
else -> R.color.black_50 else -> R.color.black_50
} }
val shadowDy = when (Preferences.textShadow) { val shadowDy = when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
0 -> 0f 0 -> 0f
1 -> 0f 1 -> 0f
2 -> 1f 2 -> 1f

View File

@ -172,7 +172,7 @@ fun String.isValidEmail(): Boolean
= this.isNotEmpty() && = this.isNotEmpty() &&
Patterns.EMAIL_ADDRESS.matcher(this).matches() 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 return resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
} }

View File

@ -87,7 +87,8 @@
android:src="@drawable/round_palette" android:src="@drawable/round_palette"
app:tint="@color/colorPrimaryText"/> app:tint="@color/colorPrimaryText"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingRight="8dp" android:paddingRight="8dp"
@ -103,6 +104,26 @@
android:id="@+id/font_color_label" android:id="@+id/font_color_label"
style="@style/AnotherWidget.Settings.Subtitle"/> style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout> </LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
android:layout_gravity="center_vertical"
app:cardBackgroundColor="@color/colorPrimary"
android:layout_marginEnd="8dp"
app:cardElevation="0dp">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryText"
android:textSize="12sp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Button"
android:text="@string/settings_subtitle_dark_theme_dark"/>
</androidx.cardview.widget.CardView>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -210,7 +231,8 @@
android:src="@drawable/round_palette" android:src="@drawable/round_palette"
app:tint="@color/colorPrimaryText"/> app:tint="@color/colorPrimaryText"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingRight="8dp" android:paddingRight="8dp"
@ -226,6 +248,26 @@
android:id="@+id/secondary_font_color_label" android:id="@+id/secondary_font_color_label"
style="@style/AnotherWidget.Settings.Subtitle"/> style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout> </LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
android:layout_gravity="center_vertical"
app:cardBackgroundColor="@color/colorPrimary"
android:layout_marginEnd="8dp"
app:cardElevation="0dp">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryText"
android:textSize="12sp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Button"
android:text="@string/settings_subtitle_dark_theme_dark"/>
</androidx.cardview.widget.CardView>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -296,7 +338,8 @@
android:src="@drawable/round_texture" android:src="@drawable/round_texture"
app:tint="@color/colorPrimaryText"/> app:tint="@color/colorPrimaryText"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingRight="8dp" android:paddingRight="8dp"
@ -312,6 +355,26 @@
android:id="@+id/text_shadow_label" android:id="@+id/text_shadow_label"
style="@style/AnotherWidget.Settings.Subtitle"/> style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout> </LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
android:layout_gravity="center_vertical"
app:cardBackgroundColor="@color/colorPrimary"
android:layout_marginEnd="8dp"
app:cardElevation="0dp">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryText"
android:textSize="12sp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Button"
android:text="@string/settings_subtitle_dark_theme_dark"/>
</androidx.cardview.widget.CardView>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -426,14 +489,13 @@
android:padding="12dp" android:padding="12dp"
android:src="@drawable/round_aspect_ratio" android:src="@drawable/round_aspect_ratio"
app:tint="@color/colorPrimaryText"/> app:tint="@color/colorPrimaryText"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingRight="8dp"> android:paddingRight="8dp">
<TextView <TextView
style="@style/AnotherWidget.Settings.Title" style="@style/AnotherWidget.Settings.Title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -446,6 +508,26 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
android:layout_gravity="center_vertical"
app:cardBackgroundColor="@color/colorPrimary"
android:layout_marginEnd="8dp"
app:cardElevation="0dp">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryText"
android:textSize="12sp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Button"
android:text="@string/settings_subtitle_dark_theme_dark"/>
</androidx.cardview.widget.CardView>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</com.tommasoberlose.anotherwidget.components.FixedFocusScrollView> </com.tommasoberlose.anotherwidget.components.FixedFocusScrollView>