Fix color picker apply button
Fix how apply button text is binded. Also make sure apply button is
disabled when no new option is selected. In addition, disable apply
button text animation to ensure it is less distracting and has better
contrast when going from the disabled to enabled state.
Flag: com.android.systemui.shared.new_customization_picker_ui
Test: manually verified
Bug: 363018910
Bug: 350718581
Change-Id: Ifde133ada8ecac7a87bbab0faf10323f510a954f
diff --git a/src/com/android/wallpaper/customization/ui/binder/ThemePickerToolbarBinder.kt b/src/com/android/wallpaper/customization/ui/binder/ThemePickerToolbarBinder.kt
index 0ed5ff1..6cd553c 100644
--- a/src/com/android/wallpaper/customization/ui/binder/ThemePickerToolbarBinder.kt
+++ b/src/com/android/wallpaper/customization/ui/binder/ThemePickerToolbarBinder.kt
@@ -47,7 +47,6 @@
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filterNotNull
-import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
@Singleton
@@ -131,6 +130,24 @@
lifecycleOwner = lifecycleOwner,
)
+ ColorUpdateBinder.bind(
+ setColor = { color -> applyButton.setTextColor(color) },
+ color =
+ combine(
+ viewModel.isApplyButtonEnabled,
+ colorUpdateViewModel.colorOnPrimary,
+ colorUpdateViewModel.colorOnSurface,
+ ) { enabled, onPrimary, onSurface ->
+ if (enabled) {
+ onPrimary
+ } else {
+ ColorUtils.setAlphaComponent(onSurface, 97) // 97 for 38% transparent
+ }
+ },
+ shouldAnimate = { false },
+ lifecycleOwner = lifecycleOwner,
+ )
+
lifecycleOwner.lifecycleScope.launch {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
launch {
@@ -146,22 +163,6 @@
applyButton.isEnabled = it
applyButton.background.alpha =
if (it) 255 else 31 // 255 for 100%, 31 for 12% transparent
- ColorUpdateBinder.bind(
- setColor = { color -> applyButton.setTextColor(color) },
- color =
- if (it) {
- colorUpdateViewModel.colorOnPrimary
- } else {
- colorUpdateViewModel.colorOnSurface.map { color: Int ->
- ColorUtils.setAlphaComponent(
- color,
- 97,
- ) // 97 for 38% transparent
- }
- },
- shouldAnimate = { true },
- lifecycleOwner = lifecycleOwner,
- )
}
}
diff --git a/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt b/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt
index 4832e1d..45c84f4 100644
--- a/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt
+++ b/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt
@@ -158,9 +158,13 @@
combine(colorPickerViewModel2.onApply, darkModeViewModel.onApply) {
colorOnApply,
darkModeOnApply ->
- {
- colorOnApply?.invoke()
- darkModeOnApply?.invoke()
+ if (colorOnApply == null && darkModeOnApply == null) {
+ null
+ } else {
+ {
+ colorOnApply?.invoke()
+ darkModeOnApply?.invoke()
+ }
}
}
else -> flow { emit(null) }