Remove fontAxes from the ClockMetadataViewModel
This is to remove font axes since we can just use the axis config
Test: Manually tested
Bug: 395647577
Flag: com.android.systemui.shared.new_customization_picker_ui
Change-Id: I1d2e16e0c260c9f7ee53992e0a1ecf4c159710dd
diff --git a/src/com/android/customization/picker/clock/data/repository/ClockPickerRepository.kt b/src/com/android/customization/picker/clock/data/repository/ClockPickerRepository.kt
index fa71fc2..feebf43 100644
--- a/src/com/android/customization/picker/clock/data/repository/ClockPickerRepository.kt
+++ b/src/com/android/customization/picker/clock/data/repository/ClockPickerRepository.kt
@@ -52,7 +52,7 @@
suspend fun setClockSize(size: ClockSize)
- suspend fun setClockFontAxes(axisSettings: ClockAxisStyle)
+ suspend fun setClockAxisStyle(axisStyle: ClockAxisStyle)
fun isReactiveToTone(clockId: ClockId): Boolean?
}
diff --git a/src/com/android/customization/picker/clock/data/repository/ClockPickerRepositoryImpl.kt b/src/com/android/customization/picker/clock/data/repository/ClockPickerRepositoryImpl.kt
index 67926e1..fd0cd11 100644
--- a/src/com/android/customization/picker/clock/data/repository/ClockPickerRepositoryImpl.kt
+++ b/src/com/android/customization/picker/clock/data/repository/ClockPickerRepositoryImpl.kt
@@ -24,7 +24,6 @@
import com.android.customization.picker.clock.shared.model.ClockMetadataModel
import com.android.systemui.plugins.clocks.AxisPresetConfig
import com.android.systemui.plugins.clocks.ClockAxisStyle
-import com.android.systemui.plugins.clocks.ClockFontAxis
import com.android.systemui.plugins.clocks.ClockId
import com.android.systemui.plugins.clocks.ClockMetadata
import com.android.systemui.shared.clocks.ClockRegistry
@@ -74,7 +73,6 @@
description = clockConfig.description,
thumbnail = clockConfig.thumbnail,
isReactiveToTone = clockConfig.isReactiveToTone,
- fontAxes = clockConfig.axes,
axisPresetConfig = clockConfig.presetConfig,
)
} else {
@@ -125,7 +123,6 @@
description = it.description,
thumbnail = it.thumbnail,
isReactiveToTone = it.isReactiveToTone,
- fontAxes = it.axes,
axisPresetConfig = it.presetConfig,
selectedColorId = metadata?.getSelectedColorId(),
colorTone =
@@ -198,9 +195,9 @@
)
}
- override suspend fun setClockFontAxes(axisSettings: ClockAxisStyle) {
+ override suspend fun setClockAxisStyle(axisStyle: ClockAxisStyle) {
registry.mutateSetting { oldSettings ->
- val newSettings = oldSettings.copy(axes = axisSettings)
+ val newSettings = oldSettings.copy(axes = axisStyle)
newSettings.metadata = oldSettings.metadata
newSettings
}
@@ -231,7 +228,6 @@
description: String,
thumbnail: Drawable,
isReactiveToTone: Boolean,
- fontAxes: List<ClockFontAxis>,
axisPresetConfig: AxisPresetConfig?,
selectedColorId: String? = null,
@IntRange(from = 0, to = 100) colorTone: Int = 0,
@@ -243,7 +239,6 @@
description = description,
thumbnail = thumbnail,
isReactiveToTone = isReactiveToTone,
- fontAxes = fontAxes,
axisPresetConfig = axisPresetConfig,
selectedColorId = selectedColorId,
colorToneProgress = colorTone,
diff --git a/src/com/android/customization/picker/clock/domain/interactor/ClockPickerInteractor.kt b/src/com/android/customization/picker/clock/domain/interactor/ClockPickerInteractor.kt
index acff6e8..b962652 100644
--- a/src/com/android/customization/picker/clock/domain/interactor/ClockPickerInteractor.kt
+++ b/src/com/android/customization/picker/clock/domain/interactor/ClockPickerInteractor.kt
@@ -61,9 +61,7 @@
val seedColor: Flow<Int?> = repository.selectedClock.map { clock -> clock.seedColor }
val axisSettings: Flow<ClockAxisStyle?> =
- repository.selectedClock.map { clock ->
- if (clock.fontAxes.isEmpty()) null else ClockAxisStyle(clock.fontAxes)
- }
+ repository.selectedClock.map { it.axisPresetConfig?.current?.style }
val selectedClockSize: Flow<ClockSize> = repository.selectedClockSize
@@ -136,7 +134,7 @@
)
}
clockSnapshotModel.clockId?.let { repository.setSelectedClock(it) }
- clockSnapshotModel.axisSettings?.let { repository.setClockFontAxes(it) }
+ clockSnapshotModel.axisSettings?.let { repository.setClockAxisStyle(it) }
}
private suspend fun storeCurrentClockOption(clockSnapshotModel: ClockSnapshotModel) {
diff --git a/src/com/android/customization/picker/clock/domain/interactor/ClockPickerSnapshotRestorer.kt b/src/com/android/customization/picker/clock/domain/interactor/ClockPickerSnapshotRestorer.kt
index 41e82eb..62e6d16 100644
--- a/src/com/android/customization/picker/clock/domain/interactor/ClockPickerSnapshotRestorer.kt
+++ b/src/com/android/customization/picker/clock/domain/interactor/ClockPickerSnapshotRestorer.kt
@@ -60,7 +60,7 @@
seedColor = repository.selectedClock.map { clock -> clock.seedColor }.firstOrNull(),
axisSettings =
repository.selectedClock
- .map { clock -> ClockAxisStyle(clock.fontAxes) }
+ .map { clock -> clock.axisPresetConfig?.current?.style ?: ClockAxisStyle() }
.firstOrNull(),
)
return snapshot(originalOption)
@@ -97,7 +97,7 @@
)
}
optionToRestore.clockId?.let { repository.setSelectedClock(it) }
- optionToRestore.axisSettings?.let { repository.setClockFontAxes(it) }
+ optionToRestore.axisSettings?.let { repository.setClockAxisStyle(it) }
}
}
diff --git a/src/com/android/customization/picker/clock/shared/model/ClockMetadataModel.kt b/src/com/android/customization/picker/clock/shared/model/ClockMetadataModel.kt
index a839ffe..c2274a7 100644
--- a/src/com/android/customization/picker/clock/shared/model/ClockMetadataModel.kt
+++ b/src/com/android/customization/picker/clock/shared/model/ClockMetadataModel.kt
@@ -21,7 +21,6 @@
import androidx.annotation.ColorInt
import androidx.annotation.IntRange
import com.android.systemui.plugins.clocks.AxisPresetConfig
-import com.android.systemui.plugins.clocks.ClockFontAxis
/** Model for clock metadata. */
data class ClockMetadataModel(
@@ -30,7 +29,6 @@
val description: String,
val thumbnail: Drawable,
val isReactiveToTone: Boolean,
- val fontAxes: List<ClockFontAxis>,
val axisPresetConfig: AxisPresetConfig?, // Null indicates the preset list should be disabled.
val selectedColorId: String?,
@IntRange(from = 0, to = 100) val colorToneProgress: Int,
diff --git a/tests/robotests/src/com/android/customization/picker/clock/data/repository/FakeClockPickerRepository.kt b/tests/robotests/src/com/android/customization/picker/clock/data/repository/FakeClockPickerRepository.kt
index 83f49d6..3055f1f 100644
--- a/tests/robotests/src/com/android/customization/picker/clock/data/repository/FakeClockPickerRepository.kt
+++ b/tests/robotests/src/com/android/customization/picker/clock/data/repository/FakeClockPickerRepository.kt
@@ -22,10 +22,11 @@
import com.android.customization.picker.clock.data.repository.FakeClockPickerRepository.Companion.fakeClocks
import com.android.customization.picker.clock.shared.ClockSize
import com.android.customization.picker.clock.shared.model.ClockMetadataModel
+import com.android.systemui.plugins.clocks.AxisPresetConfig
+import com.android.systemui.plugins.clocks.AxisPresetConfig.Group
import com.android.systemui.plugins.clocks.AxisType
import com.android.systemui.plugins.clocks.ClockAxisStyle
import com.android.systemui.plugins.clocks.ClockFontAxis
-import com.android.systemui.plugins.clocks.ClockFontAxis.Companion.merge
import com.android.systemui.plugins.clocks.ClockId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
@@ -43,15 +44,14 @@
private val colorTone: MutableStateFlow<Int> =
MutableStateFlow(ClockMetadataModel.DEFAULT_COLOR_TONE_PROGRESS)
@ColorInt private val seedColor: MutableStateFlow<Int?> = MutableStateFlow(null)
- private val fontAxes: MutableStateFlow<List<ClockFontAxis>> =
- MutableStateFlow(listOf(buildFakeAxis(0)))
+ private val axisPresetConfig: MutableStateFlow<AxisPresetConfig?> = MutableStateFlow(null)
override val selectedClock: Flow<ClockMetadataModel> =
- combine(selectedClockId, selectedColorId, colorTone, seedColor, fontAxes) {
+ combine(selectedClockId, selectedColorId, colorTone, seedColor, axisPresetConfig) {
selectedClockId,
selectedColor,
colorTone,
seedColor,
- fontAxes ->
+ axisPresetConfig ->
val selectedClock = fakeClocks.find { clock -> clock.clockId == selectedClockId }
checkNotNull(selectedClock)
ClockMetadataModel(
@@ -60,8 +60,7 @@
description = "description",
thumbnail = ColorDrawable(0),
isReactiveToTone = selectedClock.isReactiveToTone,
- fontAxes = fontAxes,
- axisPresetConfig = null,
+ axisPresetConfig = axisPresetConfig,
selectedColorId = selectedColor,
colorToneProgress = colorTone,
seedColor = seedColor,
@@ -89,8 +88,22 @@
_selectedClockSize.value = size
}
- override suspend fun setClockFontAxes(axisSettings: ClockAxisStyle) {
- fontAxes.update { fontAxes -> fontAxes.merge(axisSettings) }
+ override suspend fun setClockAxisStyle(axisStyle: ClockAxisStyle) {
+ val config = axisPresetConfig.value
+ if (config == null) {
+ axisPresetConfig.value =
+ AxisPresetConfig(
+ groups =
+ listOf(
+ Group(presets = listOf(axisStyle), icon = ColorDrawable(Color.YELLOW))
+ ),
+ current = AxisPresetConfig.IndexedStyle(0, 0, axisStyle),
+ )
+ } else {
+ axisPresetConfig.update { axisPresetConfig ->
+ axisPresetConfig?.let { it.copy(current = it.findStyle(axisStyle)) }
+ }
+ }
}
override fun isReactiveToTone(clockId: ClockId): Boolean? = true
@@ -120,7 +133,6 @@
"description0",
ColorDrawable(0),
true,
- listOf(buildFakeAxis(0)),
null,
null,
50,
@@ -132,7 +144,6 @@
"description1",
ColorDrawable(0),
true,
- listOf(buildFakeAxis(1)),
null,
null,
50,
@@ -144,7 +155,6 @@
"description2",
ColorDrawable(0),
true,
- listOf(buildFakeAxis(2)),
null,
null,
50,
@@ -156,7 +166,6 @@
"description3",
ColorDrawable(0),
false,
- listOf(buildFakeAxis(3)),
null,
null,
50,
diff --git a/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModelTest.kt b/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModelTest.kt
index f8e6a94..07d7cbf 100644
--- a/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModelTest.kt
+++ b/tests/robotests/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModelTest.kt
@@ -60,7 +60,6 @@
description = "description",
thumbnail = ColorDrawable(0),
isReactiveToTone = true,
- fontAxes = listOf(),
axisPresetConfig = null,
selectedColorId = null,
colorToneProgress = ClockMetadataModel.DEFAULT_COLOR_TONE_PROGRESS,