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 {
|
ProvideClockTime {
|
||||||
WatchFaceSelector(
|
WatchFaceSelector(
|
||||||
|
styles = availableStyles,
|
||||||
compact = compact!!,
|
compact = compact!!,
|
||||||
colors = color!!,
|
colors = color!!,
|
||||||
selected = style,
|
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.ChevronRight
|
||||||
import androidx.compose.material.icons.rounded.Settings
|
import androidx.compose.material.icons.rounded.Settings
|
||||||
import androidx.compose.material.icons.rounded.Style
|
import androidx.compose.material.icons.rounded.Style
|
||||||
|
import androidx.compose.material.icons.rounded.Tune
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
@ -55,6 +56,7 @@ import kotlinx.coroutines.launch
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun WatchFaceSelector(
|
fun WatchFaceSelector(
|
||||||
|
styles: List<ClockWidgetStyle>,
|
||||||
compact: Boolean,
|
compact: Boolean,
|
||||||
colors: ClockWidgetColors,
|
colors: ClockWidgetColors,
|
||||||
selected: ClockWidgetStyle?,
|
selected: ClockWidgetStyle?,
|
||||||
@ -75,17 +77,6 @@ fun WatchFaceSelector(
|
|||||||
Column(
|
Column(
|
||||||
modifier = Modifier,
|
modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val styles = remember {
|
|
||||||
listOf(
|
|
||||||
ClockWidgetStyle.Digital1(),
|
|
||||||
ClockWidgetStyle.Digital2,
|
|
||||||
ClockWidgetStyle.Analog,
|
|
||||||
ClockWidgetStyle.Orbit,
|
|
||||||
ClockWidgetStyle.Segment,
|
|
||||||
ClockWidgetStyle.Binary,
|
|
||||||
ClockWidgetStyle.Empty,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
val pagerState = rememberPagerState(
|
val pagerState = rememberPagerState(
|
||||||
initialPage = styles.indexOfFirst { it.javaClass == selected?.javaClass }.coerceAtLeast(0),
|
initialPage = styles.indexOfFirst { it.javaClass == selected?.javaClass }.coerceAtLeast(0),
|
||||||
) {
|
) {
|
||||||
@ -115,23 +106,23 @@ fun WatchFaceSelector(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(4.dp)
|
.padding(4.dp)
|
||||||
) {
|
) {
|
||||||
Icon(Icons.Rounded.Settings, null)
|
Icon(Icons.Rounded.Tune, null)
|
||||||
}
|
DropdownMenu(
|
||||||
DropdownMenu(
|
expanded = showStyleSettings,
|
||||||
expanded = showStyleSettings,
|
onDismissRequest = { showStyleSettings = false }) {
|
||||||
onDismissRequest = { showStyleSettings = false }) {
|
if (selected is ClockWidgetStyle.Digital1) {
|
||||||
if (selected is ClockWidgetStyle.Digital1) {
|
DropdownMenuItem(
|
||||||
DropdownMenuItem(
|
text = { Text(stringResource(R.string.clock_variant_outlined)) },
|
||||||
text = { Text(stringResource(R.string.clock_variant_outlined)) },
|
leadingIcon = {
|
||||||
leadingIcon = {
|
if (selected.outlined) {
|
||||||
if (selected.outlined) {
|
Icon(Icons.Rounded.Check, null)
|
||||||
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.ClockWidgetStyle
|
||||||
import de.mm20.launcher2.preferences.ui.ClockWidgetSettings
|
import de.mm20.launcher2.preferences.ui.ClockWidgetSettings
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
@ -19,6 +20,18 @@ class ClockWidgetSettingsScreenVM : ViewModel(), KoinComponent {
|
|||||||
settings.setCompact(compact)
|
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
|
val clockStyle = settings.clockStyle
|
||||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import kotlinx.serialization.SerialName
|
|||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class LauncherSettingsData(
|
data class LauncherSettingsData internal constructor(
|
||||||
val schemaVersion: Int = 2,
|
val schemaVersion: Int = 2,
|
||||||
|
|
||||||
val uiColorScheme: ColorScheme = ColorScheme.System,
|
val uiColorScheme: ColorScheme = ColorScheme.System,
|
||||||
@ -24,7 +24,12 @@ data class LauncherSettingsData(
|
|||||||
val mediaDenyList: Set<String> = emptySet(),
|
val mediaDenyList: Set<String> = emptySet(),
|
||||||
|
|
||||||
val clockWidgetCompact: Boolean = false,
|
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 clockWidgetColors: ClockWidgetColors = ClockWidgetColors.Auto,
|
||||||
val clockWidgetShowSeconds: Boolean = false,
|
val clockWidgetShowSeconds: Boolean = false,
|
||||||
val clockWidgetUseThemeColor: Boolean = false,
|
val clockWidgetUseThemeColor: Boolean = false,
|
||||||
@ -179,6 +184,16 @@ sealed interface ThemeDescriptor {
|
|||||||
) : ThemeDescriptor
|
) : ThemeDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal enum class ClockWidgetStyleEnum {
|
||||||
|
Digital1,
|
||||||
|
Digital2,
|
||||||
|
Orbit,
|
||||||
|
Analog,
|
||||||
|
Binary,
|
||||||
|
Segment,
|
||||||
|
Empty,
|
||||||
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
sealed interface ClockWidgetStyle {
|
sealed interface ClockWidgetStyle {
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|||||||
@ -68,7 +68,7 @@ class Migration1(
|
|||||||
clockWidgetFillHeight = legacyData.clockWidget.fillHeight,
|
clockWidgetFillHeight = legacyData.clockWidget.fillHeight,
|
||||||
clockWidgetCompact = legacyData.clockWidget.layout == LegacySettings.ClockWidgetSettings.ClockWidgetLayout.Horizontal,
|
clockWidgetCompact = legacyData.clockWidget.layout == LegacySettings.ClockWidgetSettings.ClockWidgetLayout.Horizontal,
|
||||||
clockWidgetMusicPart = legacyData.clockWidget.musicPart,
|
clockWidgetMusicPart = legacyData.clockWidget.musicPart,
|
||||||
clockWidgetStyle = when (legacyData.clockWidget.clockStyle) {
|
_clockWidgetStyle = when (legacyData.clockWidget.clockStyle) {
|
||||||
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock1 -> ClockWidgetStyle.Digital1()
|
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock1 -> ClockWidgetStyle.Digital1()
|
||||||
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock2 -> ClockWidgetStyle.Digital2
|
LegacySettings.ClockWidgetSettings.ClockStyle.DigitalClock2 -> ClockWidgetStyle.Digital2
|
||||||
LegacySettings.ClockWidgetSettings.ClockStyle.OrbitClock -> ClockWidgetStyle.Orbit
|
LegacySettings.ClockWidgetSettings.ClockStyle.OrbitClock -> ClockWidgetStyle.Orbit
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package de.mm20.launcher2.preferences.migrations
|
package de.mm20.launcher2.preferences.migrations
|
||||||
|
|
||||||
import androidx.datastore.core.DataMigration
|
import androidx.datastore.core.DataMigration
|
||||||
|
import de.mm20.launcher2.preferences.ClockWidgetStyle
|
||||||
import de.mm20.launcher2.preferences.ClockWidgetStyle.Digital1
|
import de.mm20.launcher2.preferences.ClockWidgetStyle.Digital1
|
||||||
|
import de.mm20.launcher2.preferences.ClockWidgetStyleEnum
|
||||||
import de.mm20.launcher2.preferences.LauncherSettingsData
|
import de.mm20.launcher2.preferences.LauncherSettingsData
|
||||||
|
|
||||||
class Migration2 : DataMigration<LauncherSettingsData> {
|
class Migration2 : DataMigration<LauncherSettingsData> {
|
||||||
@ -15,7 +17,17 @@ class Migration2 : DataMigration<LauncherSettingsData> {
|
|||||||
override suspend fun migrate(currentData: LauncherSettingsData): LauncherSettingsData {
|
override suspend fun migrate(currentData: LauncherSettingsData): LauncherSettingsData {
|
||||||
return currentData.copy(
|
return currentData.copy(
|
||||||
schemaVersion = 2,
|
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.ClockWidgetAlignment
|
||||||
import de.mm20.launcher2.preferences.ClockWidgetColors
|
import de.mm20.launcher2.preferences.ClockWidgetColors
|
||||||
import de.mm20.launcher2.preferences.ClockWidgetStyle
|
import de.mm20.launcher2.preferences.ClockWidgetStyle
|
||||||
|
import de.mm20.launcher2.preferences.ClockWidgetStyleEnum
|
||||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
@ -87,12 +89,28 @@ class ClockWidgetSettings internal constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val clockStyle
|
val clockStyle: Flow<ClockWidgetStyle>
|
||||||
get() = launcherDataStore.data.map { it.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) {
|
fun setClockStyle(clockStyle: ClockWidgetStyle) {
|
||||||
launcherDataStore.update {
|
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)
|
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