summaryrefslogtreecommitdiff
path: root/src/com/android/customization/picker/color/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/customization/picker/color/ui')
-rw-r--r--src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt36
-rw-r--r--src/com/android/customization/picker/color/ui/binder/ColorSectionViewBinder.kt28
-rw-r--r--src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt112
3 files changed, 95 insertions, 81 deletions
diff --git a/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt b/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt
index cd9dd540..0f82f494 100644
--- a/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt
+++ b/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt
@@ -93,29 +93,21 @@ object ColorPickerBinder {
launch {
viewModel.colorOptions.collect { colorOptions ->
- colorOptionAdapter.setItems(colorOptions)
- // the same recycler view is used for different color types tabs
- // the scroll state of each tab should be independent of others
- if (layoutManagerSavedState != null) {
- colorOptionContainerView.post {
+ // only set or restore instance state on a recycler view once data binding
+ // is complete to ensure scroll position is reflected correctly
+ colorOptionAdapter.setItems(colorOptions) {
+ // the same recycler view is used for different color types tabs
+ // the scroll state of each tab should be independent of others
+ if (layoutManagerSavedState != null) {
(colorOptionContainerView.layoutManager as LinearLayoutManager)
.onRestoreInstanceState(layoutManagerSavedState)
layoutManagerSavedState = null
+ } else {
+ var indexToFocus = colorOptions.indexOfFirst { it.isSelected.value }
+ indexToFocus = if (indexToFocus < 0) 0 else indexToFocus
+ (colorOptionContainerView.layoutManager as LinearLayoutManager)
+ .scrollToPositionWithOffset(indexToFocus, 0)
}
- } else {
- var indexToFocus = colorOptions.indexOfFirst { it.isSelected.value }
- indexToFocus = if (indexToFocus < 0) 0 else indexToFocus
- val linearLayoutManager =
- object : LinearLayoutManager(view.context, HORIZONTAL, false) {
- override fun onLayoutCompleted(state: RecyclerView.State?) {
- super.onLayoutCompleted(state)
- // scrollToPosition seems to be inconsistently moving
- // selected
- // color to different positions
- scrollToPositionWithOffset(indexToFocus, 0)
- }
- }
- colorOptionContainerView.layoutManager = linearLayoutManager
}
}
}
@@ -123,9 +115,13 @@ object ColorPickerBinder {
}
return object : Binding {
override fun saveInstanceState(savedState: Bundle) {
+ // as a workaround for the picker restarting twice after a config change, if the
+ // picker restarts before the saved state was applied and set to null,
+ // re-use the same saved state
savedState.putParcelable(
LAYOUT_MANAGER_SAVED_STATE,
- colorOptionContainerView.layoutManager?.onSaveInstanceState()
+ layoutManagerSavedState
+ ?: colorOptionContainerView.layoutManager?.onSaveInstanceState()
)
}
diff --git a/src/com/android/customization/picker/color/ui/binder/ColorSectionViewBinder.kt b/src/com/android/customization/picker/color/ui/binder/ColorSectionViewBinder.kt
index 2daefe47..ad816143 100644
--- a/src/com/android/customization/picker/color/ui/binder/ColorSectionViewBinder.kt
+++ b/src/com/android/customization/picker/color/ui/binder/ColorSectionViewBinder.kt
@@ -112,22 +112,20 @@ object ColorSectionViewBinder {
val optionSelectedView = itemView.requireViewById<ImageView>(R.id.option_selected)
lifecycleOwner.lifecycleScope.launch {
- lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
- launch {
- item.isSelected.collect { isSelected ->
- optionSelectedView.isVisible = isSelected
- }
+ launch {
+ item.isSelected.collect { isSelected ->
+ optionSelectedView.isVisible = isSelected
}
- launch {
- item.onClicked.collect { onClicked ->
- itemView.setOnClickListener(
- if (onClicked != null) {
- View.OnClickListener { onClicked.invoke() }
- } else {
- null
- }
- )
- }
+ }
+ launch {
+ item.onClicked.collect { onClicked ->
+ itemView.setOnClickListener(
+ if (onClicked != null) {
+ View.OnClickListener { onClicked.invoke() }
+ } else {
+ null
+ }
+ )
}
}
}
diff --git a/src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt b/src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt
index 78bfa43e..4ef29d6e 100644
--- a/src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt
+++ b/src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt
@@ -22,9 +22,13 @@ import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.cardview.widget.CardView
+import androidx.core.content.ContextCompat
+import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.get
import androidx.lifecycle.lifecycleScope
+import androidx.transition.Transition
+import androidx.transition.doOnStart
import com.android.customization.model.mode.DarkModeSectionController
import com.android.customization.module.ThemePickerInjector
import com.android.customization.picker.color.ui.binder.ColorPickerBinder
@@ -92,53 +96,58 @@ class ColorPickerFragment : AppbarFragment() {
savedInstanceState?.let { binding?.restoreInstanceState(it) }
- ScreenPreviewBinder.bind(
- activity = requireActivity(),
- previewView = lockScreenView,
- viewModel =
- ScreenPreviewViewModel(
- previewUtils =
- PreviewUtils(
- context = requireContext(),
- authority =
- requireContext()
- .getString(
- R.string.lock_screen_preview_provider_authority,
- ),
- ),
- wallpaperInfoProvider = { forceReload ->
- suspendCancellableCoroutine { continuation ->
- wallpaperInfoFactory.createCurrentWallpaperInfos(
- { homeWallpaper, lockWallpaper, _ ->
- lifecycleScope.launch {
- if (
- wcViewModel.lockWallpaperColors.value
- is WallpaperColorsModel.Loading
- ) {
- loadInitialColors(
- wallpaperManager,
- wcViewModel,
- CustomizationSections.Screen.LOCK_SCREEN
- )
+ val lockScreenPreviewBinder =
+ ScreenPreviewBinder.bind(
+ activity = requireActivity(),
+ previewView = lockScreenView,
+ viewModel =
+ ScreenPreviewViewModel(
+ previewUtils =
+ PreviewUtils(
+ context = requireContext(),
+ authority =
+ requireContext()
+ .getString(
+ R.string.lock_screen_preview_provider_authority,
+ ),
+ ),
+ wallpaperInfoProvider = { forceReload ->
+ suspendCancellableCoroutine { continuation ->
+ wallpaperInfoFactory.createCurrentWallpaperInfos(
+ { homeWallpaper, lockWallpaper, _ ->
+ lifecycleScope.launch {
+ if (
+ wcViewModel.lockWallpaperColors.value
+ is WallpaperColorsModel.Loading
+ ) {
+ loadInitialColors(
+ wallpaperManager,
+ wcViewModel,
+ CustomizationSections.Screen.LOCK_SCREEN
+ )
+ }
}
- }
- continuation.resume(lockWallpaper ?: homeWallpaper, null)
- },
- forceReload,
- )
- }
- },
- onWallpaperColorChanged = { colors ->
- wcViewModel.setLockWallpaperColors(colors)
- },
- wallpaperInteractor = injector.getWallpaperInteractor(requireContext()),
- screen = CustomizationSections.Screen.LOCK_SCREEN,
- ),
- lifecycleOwner = this,
- offsetToStart =
- displayUtils.isSingleDisplayOrUnfoldedHorizontalHinge(requireActivity()),
- onWallpaperPreviewDirty = { activity?.recreate() },
- )
+ continuation.resume(lockWallpaper ?: homeWallpaper, null)
+ },
+ forceReload,
+ )
+ }
+ },
+ onWallpaperColorChanged = { colors ->
+ wcViewModel.setLockWallpaperColors(colors)
+ },
+ wallpaperInteractor = injector.getWallpaperInteractor(requireContext()),
+ screen = CustomizationSections.Screen.LOCK_SCREEN,
+ ),
+ lifecycleOwner = this,
+ offsetToStart =
+ displayUtils.isSingleDisplayOrUnfoldedHorizontalHinge(requireActivity()),
+ onWallpaperPreviewDirty = { activity?.recreate() },
+ )
+ val shouldMirrorHomePreview =
+ wallpaperManager.getWallpaperInfo(WallpaperManager.FLAG_SYSTEM) != null &&
+ wallpaperManager.getWallpaperId(WallpaperManager.FLAG_LOCK) < 0
+ val mirrorSurface = if (shouldMirrorHomePreview) lockScreenPreviewBinder.surface() else null
ScreenPreviewBinder.bind(
activity = requireActivity(),
previewView = homeScreenView,
@@ -185,6 +194,7 @@ class ColorPickerFragment : AppbarFragment() {
offsetToStart =
displayUtils.isSingleDisplayOrUnfoldedHorizontalHinge(requireActivity()),
onWallpaperPreviewDirty = { activity?.recreate() },
+ mirrorSurface = mirrorSurface,
)
val darkModeToggleContainerView: FrameLayout =
view.requireViewById(R.id.dark_mode_toggle_container)
@@ -197,6 +207,12 @@ class ColorPickerFragment : AppbarFragment() {
.createView(requireContext())
darkModeSectionView.background = null
darkModeToggleContainerView.addView(darkModeSectionView)
+
+ (returnTransition as? Transition)?.doOnStart {
+ lockScreenView.isVisible = false
+ homeScreenView.isVisible = false
+ }
+
return view
}
@@ -236,4 +252,8 @@ class ColorPickerFragment : AppbarFragment() {
override fun getToolbarColorId(): Int {
return android.R.color.transparent
}
+
+ override fun getToolbarTextColor(): Int {
+ return ContextCompat.getColor(requireContext(), R.color.system_on_surface)
+ }
}