Skip to content

Commit

Permalink
Allow to reorder the clock hands
Browse files Browse the repository at this point in the history
  • Loading branch information
AChep committed Jan 22, 2022
1 parent ed0b412 commit 6c17786
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 11 deletions.
3 changes: 3 additions & 0 deletions common/src/main/java/com/artemchep/essence/Cfg.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object Cfg : SharedPrefConfig("config") {
const val KEY_ACCENT_COLOR = "accent"
const val KEY_ACCENT_BG_ENABLED = "accent_bg_enabled"
const val KEY_DIGITAL_CLOCK_ENABLED = "digital_clock_enabled"
const val KEY_HANDS_REVERTED = "hands_reverted"
const val KEY_COMPLICATION_EDITOR = "complication_editor"

// Theme
Expand All @@ -25,6 +26,8 @@ object Cfg : SharedPrefConfig("config") {
const val THEME_DARK = "DARK"
const val THEME_LIGHT = "LIGHT"

var handsReverted: Boolean by configDelegate(KEY_HANDS_REVERTED, false)

var digitalClockEnabled: Boolean by configDelegate(KEY_DIGITAL_CLOCK_ENABLED, true)

var accentBgEnabled: Boolean by configDelegate(KEY_ACCENT_BG_ENABLED, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ class SettingsLiveData(
checked = isChecked,
)
},
SETTINGS_ITEM_HANDS_REVERTED to {
val isChecked = Cfg.handsReverted
ConfigItem(
id = SETTINGS_ITEM_HANDS_REVERTED,
icon = null,
title = context.getString(R.string.config_hands_reverted),
checked = isChecked,
)
},
SETTINGS_ITEM_ACCENT_TINT_BG to {
val isChecked = Cfg.accentBgEnabled
ConfigItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const val SETTINGS_ITEM_ACCENT = 3
const val SETTINGS_ITEM_ABOUT = 4
const val SETTINGS_ITEM_DIGITAL_CLOCK = 5
const val SETTINGS_ITEM_ACCENT_TINT_BG = 6
const val SETTINGS_ITEM_HANDS_REVERTED = 7

fun configKeyToSettingsKey(key: String) = when (key) {
Cfg.KEY_DIGITAL_CLOCK_ENABLED -> SETTINGS_ITEM_DIGITAL_CLOCK
Cfg.KEY_HANDS_REVERTED -> SETTINGS_ITEM_HANDS_REVERTED
Cfg.KEY_ACCENT_BG_ENABLED -> SETTINGS_ITEM_ACCENT_TINT_BG
Cfg.KEY_ACCENT_COLOR -> SETTINGS_ITEM_ACCENT
Cfg.KEY_THEME -> SETTINGS_ITEM_THEME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ class SettingsViewModel(
Cfg.digitalClockEnabled = !Cfg.digitalClockEnabled
}
}
SETTINGS_ITEM_HANDS_REVERTED -> {
Cfg.edit(context) {
Cfg.handsReverted = !Cfg.handsReverted
}
}
SETTINGS_ITEM_ACCENT_TINT_BG -> {
Cfg.edit(context) {
Cfg.accentBgEnabled = !Cfg.accentBgEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class AnalogClockDrawable(

var timeEnabled: Boolean = true

var handsReverted: Boolean = false

var backgroundTintEnabled: Boolean = false

var backgroundColor: Int = Color.BLACK
Expand Down Expand Up @@ -197,17 +199,31 @@ class AnalogClockDrawable(
handSubPaint.color = surfaceColor
handSubPaint.strokeWidth = blend(ambience, radius / 14f, 0f)

// Draw hour hand
handPaint.alpha = 115
drawClockHand(hourHandRotation, centerX, centerY, hourHandLength, handPaint)
if (ambience < 1f)
drawClockHand(hourHandRotation, centerX, centerY, hourHandLength / 1.5f, handSubPaint)

// Draw minute hand
handPaint.alpha = 255
drawClockHand(minuteHandRotation, centerX, centerY, minuteHandLength, handPaint)
if (ambience < 1f)
drawClockHand(minuteHandRotation, centerX, centerY, hourHandLength / 1.5f, handSubPaint)
if (handsReverted) {
// Draw minute hand
handPaint.alpha = 115
drawClockHand(minuteHandRotation, centerX, centerY, minuteHandLength, handPaint)
if (ambience < 1f)
drawClockHand(minuteHandRotation, centerX, centerY, hourHandLength / 1.5f, handSubPaint)

// Draw hour hand
handPaint.alpha = 255
drawClockHand(hourHandRotation, centerX, centerY, hourHandLength, handPaint)
if (ambience < 1f)
drawClockHand(hourHandRotation, centerX, centerY, hourHandLength / 1.5f, handSubPaint)
} else {
// Draw hour hand
handPaint.alpha = 115
drawClockHand(hourHandRotation, centerX, centerY, hourHandLength, handPaint)
if (ambience < 1f)
drawClockHand(hourHandRotation, centerX, centerY, hourHandLength / 1.5f, handSubPaint)

// Draw minute hand
handPaint.alpha = 255
drawClockHand(minuteHandRotation, centerX, centerY, minuteHandLength, handPaint)
if (ambience < 1f)
drawClockHand(minuteHandRotation, centerX, centerY, hourHandLength / 1.5f, handSubPaint)
}

if (timeEnabled) {
clockPaint.alpha = 70
Expand Down Expand Up @@ -358,6 +374,13 @@ fun AnalogClockDrawable.installCfgIn(scope: CoroutineScope, invalidate: () -> Un
invalidate()
}
.launchIn(scope)
Cfg
.asFlowOfProperty<Boolean>(Cfg.KEY_HANDS_REVERTED)
.onEach { enabled ->
handsReverted = enabled
invalidate()
}
.launchIn(scope)
Cfg
.asFlowOfProperty<Boolean>(Cfg.KEY_ACCENT_BG_ENABLED)
.onEach { enabled ->
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<string name="config_accent">Accent color</string>
<string name="config_about">About</string>
<string name="config_digital_clock">Digital clock</string>
<string name="config_hands_reverted">Reorder clock hands</string>
<string name="config_accent_bg">Tint background</string>

<string name="error_no_internet">IO error</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class MainActivity : ActivityBase(),
application, Cfg,
setOf(
SETTINGS_ITEM_DIGITAL_CLOCK,
SETTINGS_ITEM_HANDS_REVERTED,
SETTINGS_ITEM_THEME,
SETTINGS_ITEM_ACCENT,
SETTINGS_ITEM_ACCENT_TINT_BG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MainActivity : ActivityBase(), OnItemClickListener<ConfigItem> {
SETTINGS_ITEM_COMPLICATIONS
.takeIf { resources.configuration.isScreenRound },
SETTINGS_ITEM_DIGITAL_CLOCK,
SETTINGS_ITEM_HANDS_REVERTED,
SETTINGS_ITEM_THEME,
SETTINGS_ITEM_ACCENT,
SETTINGS_ITEM_ACCENT_TINT_BG,
Expand Down

0 comments on commit 6c17786

Please sign in to comment.