Clock widget: Keep settings of unselected watch faces
This commit is contained in:
+17
-2
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+13
-1
@@ -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
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
+33
-4
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user