Loading src/com/android/customization/picker/clock/data/repository/ClockPickerRepository.kt +14 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ */ package com.android.customization.picker.clock.data.repository import androidx.annotation.ColorInt import androidx.annotation.IntRange import com.android.customization.picker.clock.shared.ClockSize import com.android.customization.picker.clock.shared.model.ClockMetadataModel import kotlinx.coroutines.flow.Flow Loading @@ -33,7 +35,18 @@ interface ClockPickerRepository { fun setSelectedClock(clockId: String) fun setClockColor(color: Int?) /** * Set clock color to the settings. * * @param selectedColor selected color in the color option list. * @param colorTone color tone from 0 to 100 to apply to the selected color * @param seedColor the actual clock color after blending the selected color and color tone */ fun setClockColor( @ColorInt selectedColor: Int?, @IntRange(from = 0, to = 100) colorTone: Int, @ColorInt seedColor: Int?, ) suspend fun setClockSize(size: ClockSize) } src/com/android/customization/picker/clock/data/repository/ClockPickerRepositoryImpl.kt +63 −10 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package com.android.customization.picker.clock.data.repository import android.provider.Settings import androidx.annotation.ColorInt import androidx.annotation.IntRange import com.android.customization.picker.clock.shared.ClockSize import com.android.customization.picker.clock.shared.model.ClockMetadataModel import com.android.systemui.plugins.ClockMetadata Loading @@ -34,6 +36,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.shareIn import org.json.JSONObject /** Implementation of [ClockPickerRepository], using [ClockRegistry]. */ class ClockPickerRepositoryImpl( Loading @@ -50,7 +53,7 @@ class ClockPickerRepositoryImpl( registry .getClocks() .filter { "NOT_IN_USE" !in it.clockId } .map { it.toModel(null) } .map { it.toModel() } trySend(allClocks) } Loading @@ -72,18 +75,22 @@ class ClockPickerRepositoryImpl( allClocks } /** The currently-selected clock. */ /** The currently-selected clock. This also emits the clock color information. */ override val selectedClock: Flow<ClockMetadataModel> = callbackFlow { fun send() { val currentClockId = registry.currentClockId // It is possible that the model can be null since the full clock list is not // initiated. val metadata = registry.settings?.metadata val model = registry .getClocks() .find { clockMetadata -> clockMetadata.clockId == currentClockId } ?.toModel(registry.seedColor) ?.toModel( selectedColor = metadata?.getSelectedColor(), colorTone = metadata?.getColorTone() ?: ClockMetadataModel.DEFAULT_COLOR_TONE, seedColor = registry.seedColor ) trySend(model) } Loading @@ -104,11 +111,26 @@ class ClockPickerRepositoryImpl( .mapNotNull { it } override fun setSelectedClock(clockId: String) { registry.currentClockId = clockId registry.mutateSetting { oldSettings -> val newSettings = oldSettings.copy(clockId = clockId) newSettings.metadata = oldSettings.metadata newSettings } } override fun setClockColor(color: Int?) { registry.seedColor = color override fun setClockColor( @ColorInt selectedColor: Int?, @IntRange(from = 0, to = 100) colorTone: Int, @ColorInt seedColor: Int?, ) { registry.mutateSetting { oldSettings -> val newSettings = oldSettings.copy(seedColor = seedColor) newSettings.metadata = oldSettings.metadata .put(KEY_METADATA_SELECTED_COLOR, selectedColor) .put(KEY_METADATA_COLOR_TONE, colorTone) newSettings } } override val selectedClockSize: SharedFlow<ClockSize> = Loading @@ -131,7 +153,38 @@ class ClockPickerRepositoryImpl( ) } private fun ClockMetadata.toModel(color: Int?): ClockMetadataModel { return ClockMetadataModel(clockId = clockId, name = name, color = color) private fun JSONObject.getSelectedColor(): Int? { return if (this.isNull(KEY_METADATA_SELECTED_COLOR)) { null } else { this.getInt(KEY_METADATA_SELECTED_COLOR) } } private fun JSONObject.getColorTone(): Int { return this.optInt(KEY_METADATA_COLOR_TONE, ClockMetadataModel.DEFAULT_COLOR_TONE) } /** By default, [ClockMetadataModel] has no color information unless specified. */ private fun ClockMetadata.toModel( @ColorInt selectedColor: Int? = null, @IntRange(from = 0, to = 100) colorTone: Int = 0, @ColorInt seedColor: Int? = null, ): ClockMetadataModel { return ClockMetadataModel( clockId = clockId, name = name, selectedColor = selectedColor, colorTone = colorTone, seedColor = seedColor, ) } companion object { // The selected color in the color option list private const val KEY_METADATA_SELECTED_COLOR = "metadataSelectedColor" // The color tone to apply to the selected color private const val KEY_METADATA_COLOR_TONE = "metadataColorTone" } } src/com/android/customization/picker/clock/domain/interactor/ClockPickerInteractor.kt +11 −4 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import com.android.customization.picker.clock.data.repository.ClockPickerReposit import com.android.customization.picker.clock.shared.ClockSize import com.android.customization.picker.clock.shared.model.ClockMetadataModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.map /** Loading @@ -31,9 +32,15 @@ class ClockPickerInteractor(private val repository: ClockPickerRepository) { val allClocks: Flow<List<ClockMetadataModel>> = repository.allClocks val selectedClock: Flow<ClockMetadataModel> = repository.selectedClock val selectedClockId: Flow<String> = repository.selectedClock.map { clock -> clock.clockId }.distinctUntilChanged() val selectedClockColor: Flow<Int?> = repository.selectedClock.map { clock -> clock.color } val selectedColor: Flow<Int?> = repository.selectedClock.map { clock -> clock.selectedColor }.distinctUntilChanged() val colorTone: Flow<Int> = repository.selectedClock.map { clock -> clock.colorTone } val seedColor: Flow<Int?> = repository.selectedClock.map { clock -> clock.seedColor } val selectedClockSize: Flow<ClockSize> = repository.selectedClockSize Loading @@ -41,8 +48,8 @@ class ClockPickerInteractor(private val repository: ClockPickerRepository) { repository.setSelectedClock(clockId) } fun setClockColor(color: Int?) { repository.setClockColor(color) fun setClockColor(selectedColor: Int?, colorTone: Int, seedColor: Int?) { repository.setClockColor(selectedColor, colorTone, seedColor) } suspend fun setClockSize(size: ClockSize) { Loading src/com/android/customization/picker/clock/shared/model/ClockMetadataModel.kt +11 −2 Original line number Diff line number Diff line Loading @@ -17,9 +17,18 @@ package com.android.customization.picker.clock.shared.model import androidx.annotation.ColorInt import androidx.annotation.IntRange /** Model for clock metadata. */ data class ClockMetadataModel( val clockId: String, val name: String, val color: Int?, ) @ColorInt val selectedColor: Int?, @IntRange(from = 0, to = 100) val colorTone: Int, @ColorInt val seedColor: Int?, ) { companion object { const val DEFAULT_COLOR_TONE = 50 } } src/com/android/customization/picker/clock/ui/binder/ClockSettingsBinder.kt +6 −6 Original line number Diff line number Diff line Loading @@ -63,8 +63,10 @@ object ClockSettingsBinder { } } override fun onStartTrackingTouch(p0: SeekBar?) = Unit override fun onStopTrackingTouch(p0: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { seekBar?.progress?.let { viewModel.onSliderProgressStop(it) } } } ) Loading Loading @@ -120,14 +122,12 @@ object ClockSettingsBinder { launch { viewModel.sliderProgress.collect { progress -> progress?.let { slider.setProgress(progress, false) } slider.setProgress(progress, true) } } launch { viewModel.isSliderEnabled.collect { isEnabled -> slider.isInvisible = !isEnabled } viewModel.isSliderEnabled.collect { isEnabled -> slider.isEnabled = isEnabled } } } } Loading Loading
src/com/android/customization/picker/clock/data/repository/ClockPickerRepository.kt +14 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ */ package com.android.customization.picker.clock.data.repository import androidx.annotation.ColorInt import androidx.annotation.IntRange import com.android.customization.picker.clock.shared.ClockSize import com.android.customization.picker.clock.shared.model.ClockMetadataModel import kotlinx.coroutines.flow.Flow Loading @@ -33,7 +35,18 @@ interface ClockPickerRepository { fun setSelectedClock(clockId: String) fun setClockColor(color: Int?) /** * Set clock color to the settings. * * @param selectedColor selected color in the color option list. * @param colorTone color tone from 0 to 100 to apply to the selected color * @param seedColor the actual clock color after blending the selected color and color tone */ fun setClockColor( @ColorInt selectedColor: Int?, @IntRange(from = 0, to = 100) colorTone: Int, @ColorInt seedColor: Int?, ) suspend fun setClockSize(size: ClockSize) }
src/com/android/customization/picker/clock/data/repository/ClockPickerRepositoryImpl.kt +63 −10 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package com.android.customization.picker.clock.data.repository import android.provider.Settings import androidx.annotation.ColorInt import androidx.annotation.IntRange import com.android.customization.picker.clock.shared.ClockSize import com.android.customization.picker.clock.shared.model.ClockMetadataModel import com.android.systemui.plugins.ClockMetadata Loading @@ -34,6 +36,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.shareIn import org.json.JSONObject /** Implementation of [ClockPickerRepository], using [ClockRegistry]. */ class ClockPickerRepositoryImpl( Loading @@ -50,7 +53,7 @@ class ClockPickerRepositoryImpl( registry .getClocks() .filter { "NOT_IN_USE" !in it.clockId } .map { it.toModel(null) } .map { it.toModel() } trySend(allClocks) } Loading @@ -72,18 +75,22 @@ class ClockPickerRepositoryImpl( allClocks } /** The currently-selected clock. */ /** The currently-selected clock. This also emits the clock color information. */ override val selectedClock: Flow<ClockMetadataModel> = callbackFlow { fun send() { val currentClockId = registry.currentClockId // It is possible that the model can be null since the full clock list is not // initiated. val metadata = registry.settings?.metadata val model = registry .getClocks() .find { clockMetadata -> clockMetadata.clockId == currentClockId } ?.toModel(registry.seedColor) ?.toModel( selectedColor = metadata?.getSelectedColor(), colorTone = metadata?.getColorTone() ?: ClockMetadataModel.DEFAULT_COLOR_TONE, seedColor = registry.seedColor ) trySend(model) } Loading @@ -104,11 +111,26 @@ class ClockPickerRepositoryImpl( .mapNotNull { it } override fun setSelectedClock(clockId: String) { registry.currentClockId = clockId registry.mutateSetting { oldSettings -> val newSettings = oldSettings.copy(clockId = clockId) newSettings.metadata = oldSettings.metadata newSettings } } override fun setClockColor(color: Int?) { registry.seedColor = color override fun setClockColor( @ColorInt selectedColor: Int?, @IntRange(from = 0, to = 100) colorTone: Int, @ColorInt seedColor: Int?, ) { registry.mutateSetting { oldSettings -> val newSettings = oldSettings.copy(seedColor = seedColor) newSettings.metadata = oldSettings.metadata .put(KEY_METADATA_SELECTED_COLOR, selectedColor) .put(KEY_METADATA_COLOR_TONE, colorTone) newSettings } } override val selectedClockSize: SharedFlow<ClockSize> = Loading @@ -131,7 +153,38 @@ class ClockPickerRepositoryImpl( ) } private fun ClockMetadata.toModel(color: Int?): ClockMetadataModel { return ClockMetadataModel(clockId = clockId, name = name, color = color) private fun JSONObject.getSelectedColor(): Int? { return if (this.isNull(KEY_METADATA_SELECTED_COLOR)) { null } else { this.getInt(KEY_METADATA_SELECTED_COLOR) } } private fun JSONObject.getColorTone(): Int { return this.optInt(KEY_METADATA_COLOR_TONE, ClockMetadataModel.DEFAULT_COLOR_TONE) } /** By default, [ClockMetadataModel] has no color information unless specified. */ private fun ClockMetadata.toModel( @ColorInt selectedColor: Int? = null, @IntRange(from = 0, to = 100) colorTone: Int = 0, @ColorInt seedColor: Int? = null, ): ClockMetadataModel { return ClockMetadataModel( clockId = clockId, name = name, selectedColor = selectedColor, colorTone = colorTone, seedColor = seedColor, ) } companion object { // The selected color in the color option list private const val KEY_METADATA_SELECTED_COLOR = "metadataSelectedColor" // The color tone to apply to the selected color private const val KEY_METADATA_COLOR_TONE = "metadataColorTone" } }
src/com/android/customization/picker/clock/domain/interactor/ClockPickerInteractor.kt +11 −4 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import com.android.customization.picker.clock.data.repository.ClockPickerReposit import com.android.customization.picker.clock.shared.ClockSize import com.android.customization.picker.clock.shared.model.ClockMetadataModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.map /** Loading @@ -31,9 +32,15 @@ class ClockPickerInteractor(private val repository: ClockPickerRepository) { val allClocks: Flow<List<ClockMetadataModel>> = repository.allClocks val selectedClock: Flow<ClockMetadataModel> = repository.selectedClock val selectedClockId: Flow<String> = repository.selectedClock.map { clock -> clock.clockId }.distinctUntilChanged() val selectedClockColor: Flow<Int?> = repository.selectedClock.map { clock -> clock.color } val selectedColor: Flow<Int?> = repository.selectedClock.map { clock -> clock.selectedColor }.distinctUntilChanged() val colorTone: Flow<Int> = repository.selectedClock.map { clock -> clock.colorTone } val seedColor: Flow<Int?> = repository.selectedClock.map { clock -> clock.seedColor } val selectedClockSize: Flow<ClockSize> = repository.selectedClockSize Loading @@ -41,8 +48,8 @@ class ClockPickerInteractor(private val repository: ClockPickerRepository) { repository.setSelectedClock(clockId) } fun setClockColor(color: Int?) { repository.setClockColor(color) fun setClockColor(selectedColor: Int?, colorTone: Int, seedColor: Int?) { repository.setClockColor(selectedColor, colorTone, seedColor) } suspend fun setClockSize(size: ClockSize) { Loading
src/com/android/customization/picker/clock/shared/model/ClockMetadataModel.kt +11 −2 Original line number Diff line number Diff line Loading @@ -17,9 +17,18 @@ package com.android.customization.picker.clock.shared.model import androidx.annotation.ColorInt import androidx.annotation.IntRange /** Model for clock metadata. */ data class ClockMetadataModel( val clockId: String, val name: String, val color: Int?, ) @ColorInt val selectedColor: Int?, @IntRange(from = 0, to = 100) val colorTone: Int, @ColorInt val seedColor: Int?, ) { companion object { const val DEFAULT_COLOR_TONE = 50 } }
src/com/android/customization/picker/clock/ui/binder/ClockSettingsBinder.kt +6 −6 Original line number Diff line number Diff line Loading @@ -63,8 +63,10 @@ object ClockSettingsBinder { } } override fun onStartTrackingTouch(p0: SeekBar?) = Unit override fun onStopTrackingTouch(p0: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { seekBar?.progress?.let { viewModel.onSliderProgressStop(it) } } } ) Loading Loading @@ -120,14 +122,12 @@ object ClockSettingsBinder { launch { viewModel.sliderProgress.collect { progress -> progress?.let { slider.setProgress(progress, false) } slider.setProgress(progress, true) } } launch { viewModel.isSliderEnabled.collect { isEnabled -> slider.isInvisible = !isEnabled } viewModel.isSliderEnabled.collect { isEnabled -> slider.isEnabled = isEnabled } } } } Loading