Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add style to BinaryClock for 24-hour time #1190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ fun Clock(

is ClockWidgetStyle.Binary -> BinaryClock(
time,
style,
compact,
showSeconds,
useThemeColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fun WatchFaceSelector(

Box {
androidx.compose.animation.AnimatedVisibility(
selected is ClockWidgetStyle.Digital1 || (selected is ClockWidgetStyle.Custom && selected.widgetId != null),
selected is ClockWidgetStyle.Digital1 || selected is ClockWidgetStyle.Binary || (selected is ClockWidgetStyle.Custom && selected.widgetId != null),
modifier = Modifier
.align(Alignment.TopEnd)
.zIndex(1f),
Expand Down Expand Up @@ -178,6 +178,21 @@ fun WatchFaceSelector(
}
)
}
if (selected is ClockWidgetStyle.Binary) {
DropdownMenuItem(
text = { Text(stringResource(R.string.clock_variant_twentyfourhour)) },
leadingIcon = {
Icon(
if (selected.twentyfourhour) Icons.Rounded.CheckCircle
else Icons.Rounded.RadioButtonUnchecked,
null
)
},
onClick = {
onSelect(selected.copy(twentyfourhour = !selected.twentyfourhour))
}
)
}
if (selected is ClockWidgetStyle.Custom) {
DropdownMenuItem(
text = { Text(stringResource(R.string.widget_pick_widget)) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import de.mm20.launcher2.preferences.ClockWidgetStyle
import de.mm20.launcher2.ui.locals.LocalDarkTheme
import java.util.Calendar

@Composable
fun BinaryClock(
time: Long,
style: ClockWidgetStyle.Binary = ClockWidgetStyle.Binary(),
compact: Boolean,
showSeconds: Boolean,
useThemeColor: Boolean,
Expand All @@ -30,8 +32,8 @@ fun BinaryClock(
date.timeInMillis = time
val second = date[Calendar.SECOND]
val minute = date[Calendar.MINUTE]
var hour = date[Calendar.HOUR]
if (hour == 0) hour = 12
var hour = date[if(!style.twentyfourhour) Calendar.HOUR else Calendar.HOUR_OF_DAY]
if (!style.twentyfourhour && hour == 0) hour = 12

val color = if (useThemeColor) {
if (!darkColors) {
Expand All @@ -56,11 +58,11 @@ fun BinaryClock(
Row(
modifier = Modifier.padding(start = 0.dp, top = 24.dp, end = 0.dp, bottom = 6.dp)
) {
for (i in 0 until 10) {
val active = if (i < 4) {
hour and (1 shl (3 - i)) != 0
for (i in 0 until if (style.twentyfourhour) 11 else 10) {
val active = if (i < if (style.twentyfourhour) 5 else 4) {
hour and (1 shl ((if (style.twentyfourhour) 4 else 3) - i)) != 0
} else {
minute and (1 shl (9 - i)) != 0
minute and (1 shl ((if (style.twentyfourhour) 10 else 9) - i)) != 0
}
Box(
modifier = Modifier
Expand All @@ -70,7 +72,7 @@ fun BinaryClock(
if (active) color else disabledColor
)
)
if (i == 3) {
if (i == if (style.twentyfourhour) 4 else 3) {
Box(Modifier.size(8.dp))
}
}
Expand Down Expand Up @@ -98,8 +100,8 @@ fun BinaryClock(
horizontalAlignment = Alignment.End
) {
Row {
for (i in 0 until 4) {
val active = hour and (1 shl (3 - i)) != 0
for (i in 0 until if (style.twentyfourhour) 5 else 4) {
val active = hour and (1 shl ((if (style.twentyfourhour) 4 else 3) - i)) != 0
Box(
modifier = Modifier
.padding( 4.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class ClockWidgetSettingsScreenVM : ViewModel(), KoinComponent {
settings.setCompact(compact)
}

val availableClockStyles = combine(settings.digital1, settings.custom) {digital1, custom ->
val availableClockStyles = combine(settings.digital1, settings.binary, settings.custom) {digital1, binary, custom ->
listOf(
digital1,
ClockWidgetStyle.Digital2,
ClockWidgetStyle.Analog,
ClockWidgetStyle.Orbit,
ClockWidgetStyle.Segment,
ClockWidgetStyle.Binary,
binary,
custom,
ClockWidgetStyle.Empty,
)
Expand Down
1 change: 1 addition & 0 deletions core/i18n/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@
<string name="clock_style_empty">No clock</string>
<string name="clock_style_custom">Custom widget</string>
<string name="clock_variant_outlined">Outlined</string>
<string name="clock_variant_twentyfourhour">24 Hour</string>
<string name="menu_show_filters">Show filters</string>
<string name="menu_hide_filters">Hide filters</string>
<string name="search_filter_tools">Tools</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ data class LauncherSettingsData internal constructor(
@SerialName("clockWidgetStyle2")
internal val clockWidgetStyle: ClockWidgetStyleEnum = ClockWidgetStyleEnum.Digital1,
val clockWidgetDigital1: ClockWidgetStyle.Digital1 = ClockWidgetStyle.Digital1(),
val clockWidgetBinary: ClockWidgetStyle.Binary = ClockWidgetStyle.Binary(),
val clockWidgetCustom: ClockWidgetStyle.Custom = ClockWidgetStyle.Custom(),
val clockWidgetColors: ClockWidgetColors = ClockWidgetColors.Auto,
val clockWidgetShowSeconds: Boolean = false,
Expand Down Expand Up @@ -250,7 +251,9 @@ sealed interface ClockWidgetStyle {

@Serializable
@SerialName("binary")
data object Binary : ClockWidgetStyle
data class Binary(
val twentyfourhour: Boolean = false,
) : ClockWidgetStyle

@Serializable
@SerialName("segment")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ClockWidgetSettings internal constructor(
ClockWidgetStyleEnum.Digital2 -> ClockWidgetStyle.Digital2
ClockWidgetStyleEnum.Orbit -> ClockWidgetStyle.Orbit
ClockWidgetStyleEnum.Analog -> ClockWidgetStyle.Analog
ClockWidgetStyleEnum.Binary -> ClockWidgetStyle.Binary
ClockWidgetStyleEnum.Binary -> it.clockWidgetBinary
ClockWidgetStyleEnum.Segment -> ClockWidgetStyle.Segment
ClockWidgetStyleEnum.Empty -> ClockWidgetStyle.Empty
ClockWidgetStyleEnum.Custom -> it.clockWidgetCustom
Expand All @@ -106,6 +106,9 @@ class ClockWidgetSettings internal constructor(
val digital1: Flow<ClockWidgetStyle.Digital1>
get() = launcherDataStore.data.map { it.clockWidgetDigital1 }

val binary: Flow<ClockWidgetStyle.Binary>
get() = launcherDataStore.data.map { it.clockWidgetBinary }

val custom: Flow<ClockWidgetStyle.Custom>
get() = launcherDataStore.data.map { it.clockWidgetCustom }

Expand All @@ -114,6 +117,7 @@ class ClockWidgetSettings internal constructor(
it.copy(
clockWidgetStyle = clockStyle.enumValue,
clockWidgetDigital1 = if (clockStyle is ClockWidgetStyle.Digital1) clockStyle else it.clockWidgetDigital1,
clockWidgetBinary = if (clockStyle is ClockWidgetStyle.Binary) clockStyle else it.clockWidgetBinary,
clockWidgetCustom = if (clockStyle is ClockWidgetStyle.Custom) clockStyle else it.clockWidgetCustom,
)
}
Expand Down