Merge "Navigate to the color contrast settings activity (2/2)" into main
diff --git a/res/layout/customization_option_entry_color_contrast.xml b/res/layout/customization_option_entry_color_contrast.xml
new file mode 100644
index 0000000..4d005dc
--- /dev/null
+++ b/res/layout/customization_option_entry_color_contrast.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2024 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<androidx.constraintlayout.widget.ConstraintLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingHorizontal="@dimen/customization_option_entry_horizontal_padding"
+ android:paddingVertical="@dimen/customization_option_entry_vertical_padding"
+ android:clickable="true">
+
+ <TextView
+ android:id="@+id/option_entry_color_contrast_title"
+ style="@style/CustomizationOptionEntryTitleTextStyle"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:text="@string/color_contrast_section_title"
+ android:layout_marginEnd="@dimen/customization_option_entry_text_margin_end"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toStartOf="@+id/option_entry_color_contrast_icon_container"
+ app:layout_constraintBottom_toTopOf="@+id/option_entry_color_contrast_description"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintVertical_chainStyle="packed" />
+
+ <TextView
+ android:id="@+id/option_entry_color_contrast_description"
+ style="@style/CustomizationOptionEntrySubtitleTextStyle"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="@dimen/customization_option_entry_text_margin_end"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toStartOf="@+id/option_entry_color_contrast_icon_container"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/option_entry_color_contrast_title" />
+
+ <FrameLayout
+ android:id="@+id/option_entry_color_contrast_icon_container"
+ android:layout_width="@dimen/customization_option_entry_icon_size"
+ android:layout_height="@dimen/customization_option_entry_icon_size"
+ android:padding="@dimen/customization_option_entry_icon_padding"
+ android:background="@drawable/customization_option_entry_icon_background"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent">
+
+ <ImageView
+ android:id="@+id/option_entry_color_contrast_icon"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:contentDescription="@string/grid_preview_card_content_description" />
+ </FrameLayout>
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt b/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt
index f62471d..4c31618 100644
--- a/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt
+++ b/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt
@@ -55,6 +55,7 @@
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
@@ -74,6 +75,7 @@
lifecycleOwner: LifecycleOwner,
navigateToWallpaperCategoriesScreen: (screen: Screen) -> Unit,
navigateToMoreLockScreenSettingsActivity: () -> Unit,
+ navigateToColorContrastSettingsActivity: () -> Unit,
) {
defaultCustomizationOptionsBinder.bind(
view,
@@ -85,6 +87,7 @@
lifecycleOwner,
navigateToWallpaperCategoriesScreen,
navigateToMoreLockScreenSettingsActivity,
+ navigateToColorContrastSettingsActivity,
)
val optionClock =
@@ -134,6 +137,16 @@
val optionShapeGridIcon =
optionShapeGrid?.findViewById<ImageView>(R.id.option_entry_app_shape_grid_icon)
+ val optionColorContrast =
+ homeScreenCustomizationOptionEntries
+ .find { it.first == ThemePickerHomeCustomizationOption.COLOR_CONTRAST }
+ ?.second
+ optionColorContrast?.setOnClickListener { navigateToColorContrastSettingsActivity.invoke() }
+ val optionColorContrastDescription: TextView? =
+ optionColorContrast?.findViewById(R.id.option_entry_color_contrast_description)
+ val optionColorContrastIcon: ImageView? =
+ optionColorContrast?.findViewById(R.id.option_entry_color_contrast_icon)
+
val optionsViewModel =
viewModel.customizationOptionsViewModel as ThemePickerCustomizationOptionsViewModel
lifecycleOwner.lifecycleScope.launch {
@@ -210,6 +223,23 @@
}
launch {
+ optionsViewModel.colorContrastSectionViewModel.summary.collectLatest { summary
+ ->
+ optionColorContrastDescription?.let {
+ TextViewBinder.bind(view = it, viewModel = summary.description)
+ }
+
+ if (summary.icon != null && optionColorContrastIcon != null) {
+ IconViewBinder.bind(
+ view = optionColorContrastIcon,
+ viewModel = summary.icon,
+ )
+ }
+ optionColorContrastIcon?.isVisible = summary.icon != null
+ }
+ }
+
+ launch {
optionsViewModel.colorPickerViewModel2.selectedColorOption.collect { colorOption
->
(colorOption as? ColorOptionImpl)?.let {
diff --git a/src/com/android/wallpaper/customization/ui/util/ThemePickerCustomizationOptionUtil.kt b/src/com/android/wallpaper/customization/ui/util/ThemePickerCustomizationOptionUtil.kt
index 6006327..16d53f3 100644
--- a/src/com/android/wallpaper/customization/ui/util/ThemePickerCustomizationOptionUtil.kt
+++ b/src/com/android/wallpaper/customization/ui/util/ThemePickerCustomizationOptionUtil.kt
@@ -49,8 +49,9 @@
enum class ThemePickerHomeCustomizationOption : CustomizationOptionUtil.CustomizationOption {
COLORS,
- APP_SHAPE_GRID,
THEMED_ICONS,
+ APP_SHAPE_GRID,
+ COLOR_CONTRAST,
}
override fun getOptionEntries(
@@ -109,6 +110,14 @@
)
)
add(
+ ThemePickerHomeCustomizationOption.THEMED_ICONS to
+ layoutInflater.inflate(
+ R.layout.customization_option_entry_themed_icons,
+ optionContainer,
+ false,
+ )
+ )
+ add(
ThemePickerHomeCustomizationOption.APP_SHAPE_GRID to
layoutInflater.inflate(
R.layout.customization_option_entry_app_shape_grid,
@@ -117,9 +126,9 @@
)
)
add(
- ThemePickerHomeCustomizationOption.THEMED_ICONS to
+ ThemePickerHomeCustomizationOption.COLOR_CONTRAST to
layoutInflater.inflate(
- R.layout.customization_option_entry_themed_icons,
+ R.layout.customization_option_entry_color_contrast,
optionContainer,
false,
)
diff --git a/src/com/android/wallpaper/customization/ui/viewmodel/ColorContrastSectionViewModel2.kt b/src/com/android/wallpaper/customization/ui/viewmodel/ColorContrastSectionViewModel2.kt
new file mode 100644
index 0000000..7ac0053
--- /dev/null
+++ b/src/com/android/wallpaper/customization/ui/viewmodel/ColorContrastSectionViewModel2.kt
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wallpaper.customization.ui.viewmodel
+
+import android.app.UiModeManager.ContrastUtils.CONTRAST_LEVEL_HIGH
+import android.app.UiModeManager.ContrastUtils.CONTRAST_LEVEL_MEDIUM
+import android.app.UiModeManager.ContrastUtils.CONTRAST_LEVEL_STANDARD
+import android.util.Log
+import com.android.customization.picker.settings.domain.interactor.ColorContrastSectionInteractor
+import com.android.customization.picker.settings.ui.viewmodel.ColorContrastSectionDataViewModel
+import com.android.themepicker.R
+import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon
+import com.android.wallpaper.picker.common.text.ui.viewmodel.Text
+import dagger.hilt.android.scopes.ViewModelScoped
+import javax.inject.Inject
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.map
+
+@ViewModelScoped
+class ColorContrastSectionViewModel2
+@Inject
+constructor(colorContrastSectionInteractor: ColorContrastSectionInteractor) {
+
+ val summary: Flow<ColorContrastSectionDataViewModel> =
+ colorContrastSectionInteractor.contrast.map { contrastValue ->
+ when (contrastValue) {
+ CONTRAST_LEVEL_STANDARD ->
+ ColorContrastSectionDataViewModel(
+ Text.Resource(R.string.color_contrast_default_title),
+ Icon.Resource(
+ res = R.drawable.ic_contrast_standard,
+ contentDescription = null,
+ ),
+ )
+ CONTRAST_LEVEL_MEDIUM ->
+ ColorContrastSectionDataViewModel(
+ Text.Resource(R.string.color_contrast_medium_title),
+ Icon.Resource(
+ res = R.drawable.ic_contrast_medium,
+ contentDescription = null,
+ ),
+ )
+ CONTRAST_LEVEL_HIGH ->
+ ColorContrastSectionDataViewModel(
+ Text.Resource(R.string.color_contrast_high_title),
+ Icon.Resource(res = R.drawable.ic_contrast_high, contentDescription = null),
+ )
+ else -> {
+ Log.e(TAG, "Invalid contrast value: $contrastValue")
+ throw IllegalArgumentException("Invalid contrast value: $contrastValue")
+ }
+ }
+ }
+
+ companion object {
+ private const val TAG = "ColorContrastSectionViewModel2"
+ }
+}
diff --git a/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt b/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt
index f29be47..4832e1d 100644
--- a/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt
+++ b/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt
@@ -46,6 +46,7 @@
colorPickerViewModel2Factory: ColorPickerViewModel2.Factory,
clockPickerViewModelFactory: ClockPickerViewModel.Factory,
shapeGridPickerViewModelFactory: ShapeGridPickerViewModel.Factory,
+ val colorContrastSectionViewModel: ColorContrastSectionViewModel2,
val darkModeViewModel: DarkModeViewModel,
@Assisted private val viewModelScope: CoroutineScope,
) : CustomizationOptionsViewModel {