Skip to content

Commit

Permalink
An option to always show complications
Browse files Browse the repository at this point in the history
  • Loading branch information
AChep committed Apr 10, 2022
1 parent 27c9207 commit 5a49819
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -18,6 +18,7 @@ object Cfg : SharedPrefConfig("config") {
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_ALWAYS_ON = "complication_always_on"
const val KEY_COMPLICATION_EDITOR = "complication_editor"

// Theme
Expand All @@ -34,6 +35,8 @@ object Cfg : SharedPrefConfig("config") {

var accentColor: Int by configDelegate(KEY_ACCENT_COLOR, PALETTE_MATERIAL_YOU)

var complicationAlwaysOn: Boolean by configDelegate(KEY_COMPLICATION_ALWAYS_ON, false)

var complicationEditor: ComplicationEditor by configDelegate(
key = KEY_COMPLICATION_EDITOR,
defaultValue = ComplicationEditor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ class SettingsLiveData(
checked = isChecked,
)
},
SETTINGS_ITEM_COMPLICATION_ALWAYS_ON to {
val isChecked = Cfg.complicationAlwaysOn
ConfigItem(
id = SETTINGS_ITEM_COMPLICATION_ALWAYS_ON,
icon = null,
title = context.getString(R.string.config_always_show_complications),
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 @@ -10,9 +10,11 @@ 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
const val SETTINGS_ITEM_COMPLICATION_ALWAYS_ON = 8

fun configKeyToSettingsKey(key: String) = when (key) {
Cfg.KEY_DIGITAL_CLOCK_ENABLED -> SETTINGS_ITEM_DIGITAL_CLOCK
Cfg.KEY_COMPLICATION_ALWAYS_ON -> SETTINGS_ITEM_COMPLICATION_ALWAYS_ON
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ class SettingsViewModel(
Cfg.handsReverted = !Cfg.handsReverted
}
}
SETTINGS_ITEM_COMPLICATION_ALWAYS_ON -> {
Cfg.edit(context) {
Cfg.complicationAlwaysOn = !Cfg.complicationAlwaysOn
}
}
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 @@ -51,6 +51,8 @@ class AnalogClockDrawable(

var handsReverted: Boolean = false

var complicationAlwaysOn: Boolean = false

var backgroundTintEnabled: Boolean = false

var backgroundColor: Int = Color.BLACK
Expand Down Expand Up @@ -143,6 +145,8 @@ class AnalogClockDrawable(
bounds.exactCenterY(),
)

val lAmbience = if (complicationAlwaysOn) 1f else ambience

// Draw tick marks
for (i in 0 until 60) {
val degrees = 360f / 60f * i
Expand All @@ -154,13 +158,13 @@ class AnalogClockDrawable(
val offsetY = calculateSquareScreenOffsetY(degrees, radius)
if (i.rem(5) == 0) {
tickPaint.alpha = 255
val length = blend(ambience, radius / 28f, 0f)
val length = blend(lAmbience, radius / 28f, 0f)
if (length > 0f) {
drawLine(centerX, offsetY, centerX, offsetY + length, tickPaint)
}
} else {
tickPaint.alpha = 122
val length = blend(ambience, radius / 42f, 0f)
val length = blend(lAmbience, radius / 42f, 0f)
if (length > 0f) {
drawLine(centerX, offsetY, centerX, offsetY + length, tickPaint)
}
Expand All @@ -171,11 +175,11 @@ class AnalogClockDrawable(
val strokeWidth = radius / 6f
val hourHandLengthMax = (radius - strokeWidth) * HAND_HOUR_MAX_FACTOR
val hourHandLengthMin = (radius - strokeWidth) * HAND_HOUR_MIN_FACTOR
val hourHandLength = blend(ambience, hourHandLengthMax, hourHandLengthMin)
val hourHandLength = blend(lAmbience, hourHandLengthMax, hourHandLengthMin)
val minuteHandLengthMax = (radius - strokeWidth) * HAND_MINUTE_MAX_FACTOR
val minuteHandLengthMin = (radius - strokeWidth) * HAND_MINUTE_MIN_FACTOR
val minuteHandLengthOffset = -calculateSquareScreenOffsetY(minuteHandRotation, radius) / 2f
val minuteHandLength = blend(ambience, minuteHandLengthMax, minuteHandLengthMin) +
val minuteHandLength = blend(lAmbience, minuteHandLengthMax, minuteHandLengthMin) +
minuteHandLengthOffset

textPaint.color = contentColor
Expand All @@ -195,7 +199,7 @@ class AnalogClockDrawable(
}

handPaint.color = accentColor
handPaint.strokeWidth = radius / blend(ambience, 8f, 5f)
handPaint.strokeWidth = radius / blend(lAmbience, 8f, 5f)
handSubPaint.color = surfaceColor
handSubPaint.strokeWidth = blend(ambience, radius / 14f, 0f)

Expand Down Expand Up @@ -234,7 +238,7 @@ class AnalogClockDrawable(
textPaint.textAlign = Paint.Align.CENTER
textPaint.textSize = (radius - minuteHandLengthMin) / 3.1f

val textArcRadius = blend(ambience, radius * 1.1f, radius)
val textArcRadius = blend(lAmbience, radius * 1.1f, radius)
WATCH_COMPLICATIONS.forEachIndexed { index, complicationId ->
val value = complicationDataSparse?.get(complicationId)
?: return@forEachIndexed
Expand Down Expand Up @@ -381,6 +385,13 @@ fun AnalogClockDrawable.installCfgIn(scope: CoroutineScope, invalidate: () -> Un
invalidate()
}
.launchIn(scope)
Cfg
.asFlowOfProperty<Boolean>(Cfg.KEY_COMPLICATION_ALWAYS_ON)
.onEach { enabled ->
complicationAlwaysOn = 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 @@ -20,6 +20,7 @@
<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_always_show_complications">Always show complications</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 @@ -103,6 +103,7 @@ class MainActivity : ActivityBase(),
setOf(
SETTINGS_ITEM_DIGITAL_CLOCK,
SETTINGS_ITEM_HANDS_REVERTED,
SETTINGS_ITEM_COMPLICATION_ALWAYS_ON,
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 @@ -58,6 +58,7 @@ class MainActivity : ActivityBase(), OnItemClickListener<ConfigItem> {
.takeIf { resources.configuration.isScreenRound },
SETTINGS_ITEM_DIGITAL_CLOCK,
SETTINGS_ITEM_HANDS_REVERTED,
SETTINGS_ITEM_COMPLICATION_ALWAYS_ON,
SETTINGS_ITEM_THEME,
SETTINGS_ITEM_ACCENT,
SETTINGS_ITEM_ACCENT_TINT_BG,
Expand Down

0 comments on commit 5a49819

Please sign in to comment.