Clock widget: Keep settings of unselected watch faces
This commit is contained in:
parent
494a18ac97
commit
6d15ab0e29
@ -352,9 +352,12 @@ fun ConfigureClockWidgetSheet(
|
||||
}
|
||||
}
|
||||
|
||||
if (color != null && compact != null) {
|
||||
val availableStyles by viewModel.availableClockStyles.collectAsState()
|
||||
|
||||
if (color != null && compact != null && availableStyles.isNotEmpty()) {
|
||||
ProvideClockTime {
|
||||
WatchFaceSelector(
|
||||
styles = availableStyles,
|
||||
compact = compact!!,
|
||||
colors = color!!,
|
||||
selected = style,
|
||||
|
||||
@ -20,6 +20,7 @@ import androidx.compose.material.icons.rounded.ChevronLeft
|
||||
import androidx.compose.material.icons.rounded.ChevronRight
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material.icons.rounded.Style
|
||||
import androidx.compose.material.icons.rounded.Tune
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
@ -55,6 +56,7 @@ import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun WatchFaceSelector(
|
||||
styles: List<ClockWidgetStyle>,
|
||||
compact: Boolean,
|
||||
colors: ClockWidgetColors,
|
||||
selected: ClockWidgetStyle?,
|
||||
@ -75,17 +77,6 @@ fun WatchFaceSelector(
|
||||
Column(
|
||||
modifier = Modifier,
|
||||
) {
|
||||
val styles = remember {
|
||||
listOf(
|
||||
ClockWidgetStyle.Digital1(),
|
||||
ClockWidgetStyle.Digital2,
|
||||
ClockWidgetStyle.Analog,
|
||||
ClockWidgetStyle.Orbit,
|
||||
ClockWidgetStyle.Segment,
|
||||
ClockWidgetStyle.Binary,
|
||||
ClockWidgetStyle.Empty,
|
||||
)
|
||||
}
|
||||
val pagerState = rememberPagerState(
|
||||
initialPage = styles.indexOfFirst { it.javaClass == selected?.javaClass }.coerceAtLeast(0),
|
||||
) {
|
||||
@ -115,23 +106,23 @@ fun WatchFaceSelector(
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
) {
|
||||
Icon(Icons.Rounded.Settings, null)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = showStyleSettings,
|
||||
onDismissRequest = { showStyleSettings = false }) {
|
||||
if (selected is ClockWidgetStyle.Digital1) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.clock_variant_outlined)) },
|
||||
leadingIcon = {
|
||||
if (selected.outlined) {
|
||||
Icon(Icons.Rounded.Check, null)
|
||||
Icon(Icons.Rounded.Tune, null)
|
||||
DropdownMenu(
|
||||
expanded = showStyleSettings,
|
||||
onDismissRequest = { showStyleSettings = false }) {
|
||||
if (selected is ClockWidgetStyle.Digital1) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.clock_variant_outlined)) },
|
||||
leadingIcon = {
|
||||
if (selected.outlined) {
|
||||
Icon(Icons.Rounded.Check, null)
|
||||
}
|
||||
},
|
||||
onClick = {
|
||||
onSelect(selected.copy(outlined = !selected.outlined))
|
||||
}
|
||||
},
|
||||
onClick = {
|
||||
onSelect(selected.copy(outlined = !selected.outlined))
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import de.mm20.launcher2.preferences.ClockWidgetColors
|
||||
import de.mm20.launcher2.preferences.ClockWidgetStyle
|
||||
import de.mm20.launcher2.preferences.ui.ClockWidgetSettings
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
@ -19,6 +20,18 @@ class ClockWidgetSettingsScreenVM : ViewModel(), KoinComponent {
|
||||
settings.setCompact(compact)
|
||||
}
|
||||
|
||||
val availableClockStyles = settings.digital1.map {digital1 ->
|
||||
listOf(
|
||||
digital1,
|
||||
ClockWidgetStyle.Digital2,
|
||||
ClockWidgetStyle.Analog,
|
||||
ClockWidgetStyle.Orbit,
|
||||
ClockWidgetStyle.Segment,
|
||||
ClockWidgetStyle.Binary,
|
||||
ClockWidgetStyle.Empty,
|
||||
)
|
||||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), emptyList())
|
||||
|
||||
val clockStyle = settings.clockStyle
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class LauncherSettingsData(
|
||||
data class LauncherSettingsData internal constructor(
|
||||
val schemaVersion: Int = 2,
|
||||
|
||||
val uiColorScheme: ColorScheme = ColorScheme.System,
|
||||
@ -24,7 +24,12 @@ data class LauncherSettingsData(
|
||||
val mediaDenyList: Set<String> = emptySet(),
|
||||
|
||||
val clockWidgetCompact: Boolean = false,
|
||||
val clockWidgetStyle: ClockWidgetStyle = ClockWidgetStyle.Digital1(),
|
||||
@Deprecated("")
|
||||
@SerialName("clockWidgetStyle")
|
||||
val _clockWidgetStyle: ClockWidgetStyle = ClockWidgetStyle.Digital1(),
|
||||
@SerialName("clockWidgetStyle2")
|
||||
internal val clockWidgetStyle: ClockWidgetStyleEnum = ClockWidgetStyleEnum.Digital1,
|
||||
val clockWidgetDigital1: ClockWidgetStyle.Digital1 = ClockWidgetStyle.Digital1(),
|
||||
val clockWidgetColors: ClockWidgetColors = ClockWidgetColors.Auto,
|
||||
val clockWidgetShowSeconds: Boolean = false,
|
||||
val clockWidgetUseThemeColor: Boolean = false,
|
||||
@ -179,6 +184,16 @@ sealed interface ThemeDescriptor {
|
||||
) : ThemeDescriptor
|
||||
}
|
||||
|
||||
internal enum class ClockWidgetStyleEnum {
|
||||
Digital1,
|
||||
Digital2,
|
||||
Orbit,
|
||||
Analog,
|
||||
Binary,
|
||||
Segment,
|
||||
Empty,
|
||||
}
|
||||
|
||||
@Serializable
|
||||
sealed interface ClockWidgetStyle {
|
||||
@Serializable
|
||||
|
||||
@ -68,7 +68,7 @@ class Migration1(
|
||||
clockWidgetFillHeight = legacyData.clockWidget.fillHeight,
|
||||
clockWidgetCompact = legacyData.clockWidget.layout == LegacySettings.ClockWidgetSettings.ClockWidgetLayout.Horizontal,
|
||||
clockWidgetMusicPart = legacyData.clockWidget.musicPart,
|
||||
clockWidgetStyle = when (legacyData.clockWidget.clockStyle) {
|
||||
_clockWidgetStyle = when (legacyData.clockWidget.clockStyle) {
|
||||
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock1 -> ClockWidgetStyle.Digital1()
|
||||
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock2 -> ClockWidgetStyle.Digital2
|
||||
LegacySettings.ClockWidgetSettings.ClockStyle.OrbitClock -> ClockWidgetStyle.Orbit
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package de.mm20.launcher2.preferences.migrations
|
||||
|
||||
import androidx.datastore.core.DataMigration
|
||||
import de.mm20.launcher2.preferences.ClockWidgetStyle
|
||||
import de.mm20.launcher2.preferences.ClockWidgetStyle.Digital1
|
||||
import de.mm20.launcher2.preferences.ClockWidgetStyleEnum
|
||||
import de.mm20.launcher2.preferences.LauncherSettingsData
|
||||
|
||||
class Migration2 : DataMigration<LauncherSettingsData> {
|
||||
@ -15,7 +17,17 @@ class Migration2 : DataMigration<LauncherSettingsData> {
|
||||
override suspend fun migrate(currentData: LauncherSettingsData): LauncherSettingsData {
|
||||
return currentData.copy(
|
||||
schemaVersion = 2,
|
||||
clockWidgetUseThemeColor = (currentData.clockWidgetStyle as? Digital1)?.variant == Digital1.Variant.MDY
|
||||
clockWidgetUseThemeColor = (currentData._clockWidgetStyle as? Digital1)?.variant == Digital1.Variant.MDY,
|
||||
clockWidgetDigital1 = currentData._clockWidgetStyle as? Digital1 ?: Digital1(),
|
||||
clockWidgetStyle = when (currentData._clockWidgetStyle) {
|
||||
is ClockWidgetStyle.Digital2 -> ClockWidgetStyleEnum.Digital2
|
||||
is ClockWidgetStyle.Orbit -> ClockWidgetStyleEnum.Orbit
|
||||
is ClockWidgetStyle.Analog -> ClockWidgetStyleEnum.Analog
|
||||
is ClockWidgetStyle.Binary -> ClockWidgetStyleEnum.Binary
|
||||
is ClockWidgetStyle.Segment -> ClockWidgetStyleEnum.Segment
|
||||
is ClockWidgetStyle.Empty -> ClockWidgetStyleEnum.Empty
|
||||
else -> ClockWidgetStyleEnum.Digital1
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,9 @@ package de.mm20.launcher2.preferences.ui
|
||||
import de.mm20.launcher2.preferences.ClockWidgetAlignment
|
||||
import de.mm20.launcher2.preferences.ClockWidgetColors
|
||||
import de.mm20.launcher2.preferences.ClockWidgetStyle
|
||||
import de.mm20.launcher2.preferences.ClockWidgetStyleEnum
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
@ -87,12 +89,28 @@ class ClockWidgetSettings internal constructor(
|
||||
}
|
||||
}
|
||||
|
||||
val clockStyle
|
||||
get() = launcherDataStore.data.map { it.clockWidgetStyle }
|
||||
val clockStyle: Flow<ClockWidgetStyle>
|
||||
get() = launcherDataStore.data.map {
|
||||
when (it.clockWidgetStyle) {
|
||||
ClockWidgetStyleEnum.Digital1 -> it.clockWidgetDigital1
|
||||
ClockWidgetStyleEnum.Digital2 -> ClockWidgetStyle.Digital2
|
||||
ClockWidgetStyleEnum.Orbit -> ClockWidgetStyle.Orbit
|
||||
ClockWidgetStyleEnum.Analog -> ClockWidgetStyle.Analog
|
||||
ClockWidgetStyleEnum.Binary -> ClockWidgetStyle.Binary
|
||||
ClockWidgetStyleEnum.Segment -> ClockWidgetStyle.Segment
|
||||
ClockWidgetStyleEnum.Empty -> ClockWidgetStyle.Empty
|
||||
}
|
||||
}
|
||||
|
||||
val digital1: Flow<ClockWidgetStyle.Digital1>
|
||||
get() = launcherDataStore.data.map { it.clockWidgetDigital1 }
|
||||
|
||||
fun setClockStyle(clockStyle: ClockWidgetStyle) {
|
||||
launcherDataStore.update {
|
||||
it.copy(clockWidgetStyle = clockStyle)
|
||||
it.copy(
|
||||
clockWidgetStyle = clockStyle.enumValue,
|
||||
clockWidgetDigital1 = if (clockStyle is ClockWidgetStyle.Digital1) clockStyle else it.clockWidgetDigital1,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,4 +140,15 @@ class ClockWidgetSettings internal constructor(
|
||||
it.copy(clockWidgetUseThemeColor = enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal val ClockWidgetStyle.enumValue
|
||||
get() = when (this) {
|
||||
is ClockWidgetStyle.Digital1 -> ClockWidgetStyleEnum.Digital1
|
||||
is ClockWidgetStyle.Digital2 -> ClockWidgetStyleEnum.Digital2
|
||||
is ClockWidgetStyle.Orbit -> ClockWidgetStyleEnum.Orbit
|
||||
is ClockWidgetStyle.Analog -> ClockWidgetStyleEnum.Analog
|
||||
is ClockWidgetStyle.Binary -> ClockWidgetStyleEnum.Binary
|
||||
is ClockWidgetStyle.Segment -> ClockWidgetStyleEnum.Segment
|
||||
is ClockWidgetStyle.Empty -> ClockWidgetStyleEnum.Empty
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user