Color Picker Fragment Dark Mode Toggle (1/2)
Move dark mode toggle from the customization hub landing page into the
color picker page, gated by revamped UI flag. Currently the dark mode
section controller is kept and used in the color picker page, but this
can be refactored in the future.
Bug: 269449457
Test: Manual
Change-Id: I2669cee07fa81fcd8c436a30c511bae66aa50a29
diff --git a/res/layout/fragment_color_picker.xml b/res/layout/fragment_color_picker.xml
index 1e8fc15..a9d2adc 100644
--- a/res/layout/fragment_color_picker.xml
+++ b/res/layout/fragment_color_picker.xml
@@ -60,8 +60,7 @@
android:layout_marginHorizontal="24dp"
android:layout_marginBottom="28dp"
android:background="@drawable/picker_fragment_background"
- android:paddingTop="22dp"
- android:paddingBottom="62dp">
+ android:paddingTop="22dp">
<FrameLayout
android:layout_width="match_parent"
@@ -124,6 +123,11 @@
</FrameLayout>
+ <FrameLayout
+ android:id="@+id/dark_mode_toggle_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
</LinearLayout>
</LinearLayout>
diff --git a/src/com/android/customization/module/DefaultCustomizationSections.java b/src/com/android/customization/module/DefaultCustomizationSections.java
index 5fb23cf..18f2d37 100644
--- a/src/com/android/customization/module/DefaultCustomizationSections.java
+++ b/src/com/android/customization/module/DefaultCustomizationSections.java
@@ -174,12 +174,6 @@
break;
case HOME_SCREEN:
- // Dark/Light theme section.
- sectionControllers.add(new DarkModeSectionController(
- activity,
- lifecycleOwner.getLifecycle(),
- mDarkModeSnapshotRestorer));
-
// Themed app icon section.
sectionControllers.add(
new ThemedIconSectionController(
diff --git a/src/com/android/customization/module/ThemePickerInjector.kt b/src/com/android/customization/module/ThemePickerInjector.kt
index 2924135..b3756c1 100644
--- a/src/com/android/customization/module/ThemePickerInjector.kt
+++ b/src/com/android/customization/module/ThemePickerInjector.kt
@@ -374,7 +374,7 @@
.also { colorPickerViewModelFactory = it }
}
- protected fun getDarkModeSnapshotRestorer(
+ fun getDarkModeSnapshotRestorer(
context: Context,
): DarkModeSnapshotRestorer {
return darkModeSnapshotRestorer
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 0bc22f8..416faa6 100644
--- a/src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt
+++ b/src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt
@@ -19,9 +19,11 @@
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.FrameLayout
import androidx.cardview.widget.CardView
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.get
+import com.android.customization.model.mode.DarkModeSectionController
import com.android.customization.module.ThemePickerInjector
import com.android.customization.picker.color.ui.binder.ColorPickerBinder
import com.android.wallpaper.R
@@ -137,6 +139,17 @@
lifecycleOwner = this,
offsetToStart = displayUtils.isOnWallpaperDisplay(requireActivity()),
)
+ val darkModeToggleContainerView: FrameLayout =
+ view.requireViewById(R.id.dark_mode_toggle_container)
+ val darkModeSectionView =
+ DarkModeSectionController(
+ context,
+ lifecycle,
+ injector.getDarkModeSnapshotRestorer(requireContext())
+ )
+ .createView(requireContext())
+ darkModeSectionView.background = null
+ darkModeToggleContainerView.addView(darkModeSectionView)
return view
}