Add clock widget preference migration, remove OnePlus variant
This commit is contained in:
parent
2cd4097b1d
commit
4ce4812317
@ -77,7 +77,6 @@ fun WatchFaceSelector(
|
|||||||
mapOf(
|
mapOf(
|
||||||
ClockStyle.DigitalClock1 to 0,
|
ClockStyle.DigitalClock1 to 0,
|
||||||
ClockStyle.DigitalClock1_Outlined to 0,
|
ClockStyle.DigitalClock1_Outlined to 0,
|
||||||
ClockStyle.DigitalClock1_OnePlus to 0,
|
|
||||||
ClockStyle.DigitalClock2 to 1,
|
ClockStyle.DigitalClock2 to 1,
|
||||||
ClockStyle.AnalogClock to 2,
|
ClockStyle.AnalogClock to 2,
|
||||||
ClockStyle.OrbitClock to 3,
|
ClockStyle.OrbitClock to 3,
|
||||||
@ -258,7 +257,6 @@ fun getClockstyleName(context: Context, style: ClockWidgetStyle): String {
|
|||||||
return when (style) {
|
return when (style) {
|
||||||
ClockStyle.DigitalClock1,
|
ClockStyle.DigitalClock1,
|
||||||
ClockStyle.DigitalClock1_Outlined,
|
ClockStyle.DigitalClock1_Outlined,
|
||||||
ClockStyle.DigitalClock1_OnePlus -> context.getString(R.string.clock_style_digital1)
|
|
||||||
ClockStyle.DigitalClock2 -> context.getString(R.string.clock_style_digital2)
|
ClockStyle.DigitalClock2 -> context.getString(R.string.clock_style_digital2)
|
||||||
ClockStyle.OrbitClock -> context.getString(R.string.clock_style_orbit)
|
ClockStyle.OrbitClock -> context.getString(R.string.clock_style_orbit)
|
||||||
ClockStyle.BinaryClock -> context.getString(R.string.clock_style_binary)
|
ClockStyle.BinaryClock -> context.getString(R.string.clock_style_binary)
|
||||||
@ -279,7 +277,6 @@ fun getVariantName(context: Context, style: ClockWidgetStyle): String {
|
|||||||
ClockStyle.SegmentClock,
|
ClockStyle.SegmentClock,
|
||||||
ClockStyle.EmptyClock -> context.getString(R.string.clock_variant_standard)
|
ClockStyle.EmptyClock -> context.getString(R.string.clock_variant_standard)
|
||||||
ClockStyle.DigitalClock1_Outlined -> context.getString(R.string.clock_variant_outlined)
|
ClockStyle.DigitalClock1_Outlined -> context.getString(R.string.clock_variant_outlined)
|
||||||
ClockStyle.DigitalClock1_OnePlus -> "OnePlus"
|
|
||||||
else -> ""
|
else -> ""
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -289,7 +286,6 @@ fun getVariantName(context: Context, style: ClockWidgetStyle): String {
|
|||||||
object ClockStyle {
|
object ClockStyle {
|
||||||
val DigitalClock1 = ClockWidgetStyle.Digital1()
|
val DigitalClock1 = ClockWidgetStyle.Digital1()
|
||||||
val DigitalClock1_Outlined = ClockWidgetStyle.Digital1(outlined = true)
|
val DigitalClock1_Outlined = ClockWidgetStyle.Digital1(outlined = true)
|
||||||
val DigitalClock1_OnePlus = ClockWidgetStyle.Digital1(variant = ClockWidgetStyle.Digital1.Variant.OnePlus)
|
|
||||||
val DigitalClock2 = ClockWidgetStyle.Digital2
|
val DigitalClock2 = ClockWidgetStyle.Digital2
|
||||||
val OrbitClock = ClockWidgetStyle.Orbit
|
val OrbitClock = ClockWidgetStyle.Orbit
|
||||||
val AnalogClock = ClockWidgetStyle.Analog
|
val AnalogClock = ClockWidgetStyle.Analog
|
||||||
|
|||||||
@ -84,32 +84,11 @@ fun DigitalClock1(
|
|||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.Center
|
verticalArrangement = Arrangement.Center
|
||||||
) {
|
) {
|
||||||
if (style.variant == ClockWidgetStyle.Digital1.Variant.OnePlus) {
|
Text(
|
||||||
val hour = formattedString.substring(0, 2)
|
modifier = modifier,
|
||||||
Text(
|
text = formattedString,
|
||||||
modifier = modifier,
|
style = textStyle,
|
||||||
text = buildAnnotatedString {
|
)
|
||||||
hour.forEach {
|
|
||||||
if (it == '1') {
|
|
||||||
withStyle(style = SpanStyle(color = Color(0xFFC41442))) {
|
|
||||||
append(it)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
append(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
append(formattedString.substring(2))
|
|
||||||
},
|
|
||||||
style = textStyle
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Text(
|
|
||||||
modifier = modifier,
|
|
||||||
text = formattedString,
|
|
||||||
style = textStyle,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verticalLayout && showSeconds) {
|
if (verticalLayout && showSeconds) {
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package de.mm20.launcher2.preferences
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import de.mm20.launcher2.preferences.migrations.Migration1
|
import de.mm20.launcher2.preferences.migrations.Migration1
|
||||||
|
import de.mm20.launcher2.preferences.migrations.Migration2
|
||||||
import de.mm20.launcher2.settings.BaseSettings
|
import de.mm20.launcher2.settings.BaseSettings
|
||||||
|
|
||||||
internal class LauncherDataStore(
|
internal class LauncherDataStore(
|
||||||
@ -11,7 +12,10 @@ internal class LauncherDataStore(
|
|||||||
context,
|
context,
|
||||||
fileName = "settings.json",
|
fileName = "settings.json",
|
||||||
serializer = LauncherSettingsDataSerializer,
|
serializer = LauncherSettingsDataSerializer,
|
||||||
migrations = listOf(Migration1(legacyDataStore)),
|
migrations = listOf(
|
||||||
|
Migration1(legacyDataStore),
|
||||||
|
Migration2(),
|
||||||
|
),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val data
|
val data
|
||||||
|
|||||||
@ -4,11 +4,10 @@ import android.content.Context
|
|||||||
import de.mm20.launcher2.preferences.search.LocationSearchSettings
|
import de.mm20.launcher2.preferences.search.LocationSearchSettings
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import java.util.UUID
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class LauncherSettingsData(
|
data class LauncherSettingsData(
|
||||||
val schemaVersion: Int = 1,
|
val schemaVersion: Int = 2,
|
||||||
|
|
||||||
val uiColorScheme: ColorScheme = ColorScheme.System,
|
val uiColorScheme: ColorScheme = ColorScheme.System,
|
||||||
val uiTheme: ThemeDescriptor = ThemeDescriptor.Default,
|
val uiTheme: ThemeDescriptor = ThemeDescriptor.Default,
|
||||||
@ -186,12 +185,14 @@ sealed interface ClockWidgetStyle {
|
|||||||
@SerialName("digital1")
|
@SerialName("digital1")
|
||||||
data class Digital1(
|
data class Digital1(
|
||||||
val outlined: Boolean = false,
|
val outlined: Boolean = false,
|
||||||
|
@Deprecated("Variant.MDY has been replaced with LauncherSettingsData.clockWidgetUseThemeColor")
|
||||||
val variant: Variant = Variant.Default,
|
val variant: Variant = Variant.Default,
|
||||||
) : ClockWidgetStyle {
|
) : ClockWidgetStyle {
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@Deprecated("No longer in use")
|
||||||
enum class Variant {
|
enum class Variant {
|
||||||
Default,
|
Default,
|
||||||
OnePlus,
|
MDY,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -76,7 +76,7 @@ class Migration1(
|
|||||||
LegacySettings.ClockWidgetSettings.ClockStyle.AnalogClock -> ClockWidgetStyle.Analog
|
LegacySettings.ClockWidgetSettings.ClockStyle.AnalogClock -> ClockWidgetStyle.Analog
|
||||||
LegacySettings.ClockWidgetSettings.ClockStyle.EmptyClock -> ClockWidgetStyle.Empty
|
LegacySettings.ClockWidgetSettings.ClockStyle.EmptyClock -> ClockWidgetStyle.Empty
|
||||||
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock1_MDY -> ClockWidgetStyle.Digital1(
|
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock1_MDY -> ClockWidgetStyle.Digital1(
|
||||||
variant = ClockWidgetStyle.Digital1.Variant.Default
|
variant = ClockWidgetStyle.Digital1.Variant.MDY
|
||||||
)
|
)
|
||||||
|
|
||||||
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock1_Outlined -> ClockWidgetStyle.Digital1(
|
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock1_Outlined -> ClockWidgetStyle.Digital1(
|
||||||
@ -84,7 +84,7 @@ class Migration1(
|
|||||||
)
|
)
|
||||||
|
|
||||||
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock1_OnePlus -> ClockWidgetStyle.Digital1(
|
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock1_OnePlus -> ClockWidgetStyle.Digital1(
|
||||||
variant = ClockWidgetStyle.Digital1.Variant.OnePlus
|
variant = ClockWidgetStyle.Digital1.Variant.Default
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> ClockWidgetStyle.Digital1()
|
else -> ClockWidgetStyle.Digital1()
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
package de.mm20.launcher2.preferences.migrations
|
||||||
|
|
||||||
|
import androidx.datastore.core.DataMigration
|
||||||
|
import de.mm20.launcher2.preferences.ClockWidgetStyle.Digital1
|
||||||
|
import de.mm20.launcher2.preferences.LauncherSettingsData
|
||||||
|
|
||||||
|
class Migration2 : DataMigration<LauncherSettingsData> {
|
||||||
|
override suspend fun cleanUp() {
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun shouldMigrate(currentData: LauncherSettingsData): Boolean {
|
||||||
|
return currentData.schemaVersion < 2
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun migrate(currentData: LauncherSettingsData): LauncherSettingsData {
|
||||||
|
return currentData.copy(
|
||||||
|
schemaVersion = 2,
|
||||||
|
clockWidgetUseThemeColor = (currentData.clockWidgetStyle as? Digital1)?.variant == Digital1.Variant.MDY
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user