Snap for 12524026 from f38448fc3357746c328ee309754c181273a859ad to 25Q1-release
Change-Id: I8ad5daacd0d8194bac064e119b7d65510d0b56e3
diff --git a/res/layout/shape_option.xml b/res/layout/shape_option.xml
index 78201d8..d2eb2f2 100644
--- a/res/layout/shape_option.xml
+++ b/res/layout/shape_option.xml
@@ -22,6 +22,14 @@
android:clipChildren="false">
<ImageView
+ android:id="@id/selection_border"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/option_item_border"
+ android:alpha="0"
+ android:importantForAccessibility="no" />
+
+ <ImageView
android:id="@id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/src/com/android/customization/model/grid/DefaultGridOptionsManager.kt b/src/com/android/customization/model/grid/DefaultShapeGridManager.kt
similarity index 96%
rename from src/com/android/customization/model/grid/DefaultGridOptionsManager.kt
rename to src/com/android/customization/model/grid/DefaultShapeGridManager.kt
index bc862fd..8de5ff2 100644
--- a/src/com/android/customization/model/grid/DefaultGridOptionsManager.kt
+++ b/src/com/android/customization/model/grid/DefaultShapeGridManager.kt
@@ -28,12 +28,12 @@
import kotlinx.coroutines.withContext
@Singleton
-class DefaultGridOptionsManager
+class DefaultShapeGridManager
@Inject
constructor(
@ApplicationContext private val context: Context,
@BackgroundDispatcher private val bgDispatcher: CoroutineDispatcher,
-) : GridOptionsManager2 {
+) : ShapeGridManager {
private val authorityMetadataKey: String =
context.getString(R.string.grid_control_metadata_name)
@@ -59,7 +59,7 @@
context.getString(
com.android.themepicker.R.string.grid_title_pattern,
cols,
- rows
+ rows,
),
isCurrent =
cursor
diff --git a/src/com/android/customization/model/grid/GridOptionsManager2.kt b/src/com/android/customization/model/grid/ShapeGridManager.kt
similarity index 95%
rename from src/com/android/customization/model/grid/GridOptionsManager2.kt
rename to src/com/android/customization/model/grid/ShapeGridManager.kt
index ce8500a..1603ed9 100644
--- a/src/com/android/customization/model/grid/GridOptionsManager2.kt
+++ b/src/com/android/customization/model/grid/ShapeGridManager.kt
@@ -16,7 +16,7 @@
package com.android.customization.model.grid
-interface GridOptionsManager2 {
+interface ShapeGridManager {
suspend fun isGridOptionAvailable(): Boolean
diff --git a/src/com/android/customization/picker/grid/data/repository/GridRepository2.kt b/src/com/android/customization/picker/grid/data/repository/ShapeGridRepository.kt
similarity index 94%
rename from src/com/android/customization/picker/grid/data/repository/GridRepository2.kt
rename to src/com/android/customization/picker/grid/data/repository/ShapeGridRepository.kt
index 8ce4374..9ae4d18 100644
--- a/src/com/android/customization/picker/grid/data/repository/GridRepository2.kt
+++ b/src/com/android/customization/picker/grid/data/repository/ShapeGridRepository.kt
@@ -18,7 +18,7 @@
package com.android.customization.picker.grid.data.repository
import com.android.customization.model.grid.GridOptionModel
-import com.android.customization.model.grid.GridOptionsManager2
+import com.android.customization.model.grid.ShapeGridManager
import com.android.wallpaper.picker.di.modules.BackgroundDispatcher
import javax.inject.Inject
import javax.inject.Singleton
@@ -33,10 +33,10 @@
import kotlinx.coroutines.withContext
@Singleton
-class GridRepository2
+class ShapeGridRepository
@Inject
constructor(
- private val manager: GridOptionsManager2,
+ private val manager: ShapeGridManager,
@BackgroundDispatcher private val bgScope: CoroutineScope,
@BackgroundDispatcher private val bgDispatcher: CoroutineDispatcher,
) {
diff --git a/src/com/android/customization/picker/grid/domain/interactor/GridInteractor2.kt b/src/com/android/customization/picker/grid/domain/interactor/ShapeGridInteractor.kt
similarity index 85%
rename from src/com/android/customization/picker/grid/domain/interactor/GridInteractor2.kt
rename to src/com/android/customization/picker/grid/domain/interactor/ShapeGridInteractor.kt
index 30c87d8..c9c2b0c 100644
--- a/src/com/android/customization/picker/grid/domain/interactor/GridInteractor2.kt
+++ b/src/com/android/customization/picker/grid/domain/interactor/ShapeGridInteractor.kt
@@ -17,16 +17,12 @@
package com.android.customization.picker.grid.domain.interactor
-import com.android.customization.picker.grid.data.repository.GridRepository2
+import com.android.customization.picker.grid.data.repository.ShapeGridRepository
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
-class GridInteractor2
-@Inject
-constructor(
- private val repository: GridRepository2,
-) {
+class ShapeGridInteractor @Inject constructor(private val repository: ShapeGridRepository) {
suspend fun isGridOptionAvailable(): Boolean = repository.isGridOptionAvailable()
val gridOptions = repository.gridOptions
diff --git a/src/com/android/customization/model/grid/GridOptionsManager2.kt b/src/com/android/customization/picker/grid/ui/viewmodel/ShapeIconViewModel.kt
similarity index 72%
copy from src/com/android/customization/model/grid/GridOptionsManager2.kt
copy to src/com/android/customization/picker/grid/ui/viewmodel/ShapeIconViewModel.kt
index ce8500a..1283603 100644
--- a/src/com/android/customization/model/grid/GridOptionsManager2.kt
+++ b/src/com/android/customization/picker/grid/ui/viewmodel/ShapeIconViewModel.kt
@@ -14,13 +14,6 @@
* limitations under the License.
*/
-package com.android.customization.model.grid
+package com.android.customization.picker.grid.ui.viewmodel
-interface GridOptionsManager2 {
-
- suspend fun isGridOptionAvailable(): Boolean
-
- suspend fun getGridOptions(): List<GridOptionModel>?
-
- fun applyGridOption(gridName: String): Int
-}
+data class ShapeIconViewModel(val key: String, val path: String)
diff --git a/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt b/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
index 4f199f8..8a59c60 100644
--- a/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
+++ b/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
@@ -32,6 +32,7 @@
import com.android.customization.picker.common.ui.view.SingleRowListItemSpacing
import com.android.customization.picker.grid.ui.binder.GridIconViewBinder
import com.android.customization.picker.grid.ui.viewmodel.GridIconViewModel
+import com.android.customization.picker.grid.ui.viewmodel.ShapeIconViewModel
import com.android.themepicker.R
import com.android.wallpaper.customization.ui.util.ThemePickerCustomizationOptionUtil.ThemePickerHomeCustomizationOption.APP_SHAPE_GRID
import com.android.wallpaper.customization.ui.viewmodel.ShapeGridFloatingSheetHeightsViewModel
@@ -82,16 +83,24 @@
shouldAnimateColor = { optionsViewModel.selectedOption.value == APP_SHAPE_GRID },
)
.also { tabs.setAdapter(it) }
+
val floatingSheetContainer =
view.requireViewById<ViewGroup>(R.id.shape_grid_floating_sheet_content_container)
val shapeContent = view.requireViewById<View>(R.id.app_shape_container)
+ val shapeOptionListAdapter =
+ createShapeOptionItemAdapter(view.context, lifecycleOwner, backgroundDispatcher)
+ val shapeOptionList =
+ view.requireViewById<RecyclerView>(R.id.shape_options).also {
+ it.initShapeOptionList(view.context, shapeOptionListAdapter)
+ }
val gridContent = view.requireViewById<View>(R.id.app_grid_container)
- val adapter = createOptionItemAdapter(view.context, lifecycleOwner, backgroundDispatcher)
+ val gridOptionListAdapter =
+ createGridOptionItemAdapter(view.context, lifecycleOwner, backgroundDispatcher)
val gridOptionList =
view.requireViewById<RecyclerView>(R.id.grid_options).also {
- it.initGridOptionList(view.context, adapter)
+ it.initGridOptionList(view.context, gridOptionListAdapter)
}
// Get the shape content height when it is ready
@@ -168,8 +177,8 @@
}
launch {
- viewModel.optionItems.collect { options ->
- adapter.setItems(options) {
+ viewModel.gridOptions.collect { options ->
+ gridOptionListAdapter.setItems(options) {
val indexToFocus =
options.indexOfFirst { it.isSelected.value }.coerceAtLeast(0)
(gridOptionList.layoutManager as LinearLayoutManager).scrollToPosition(
@@ -178,11 +187,68 @@
}
}
}
+
+ launch {
+ viewModel.shapeOptions.collect { options ->
+ shapeOptionListAdapter.setItems(options) {
+ val indexToFocus =
+ options.indexOfFirst { it.isSelected.value }.coerceAtLeast(0)
+ (shapeOptionList.layoutManager as LinearLayoutManager).scrollToPosition(
+ indexToFocus
+ )
+ }
+ }
+ }
}
}
}
- private fun createOptionItemAdapter(
+ private fun createShapeOptionItemAdapter(
+ context: Context,
+ lifecycleOwner: LifecycleOwner,
+ backgroundDispatcher: CoroutineDispatcher,
+ ): OptionItemAdapter<ShapeIconViewModel> =
+ OptionItemAdapter(
+ layoutResourceId = R.layout.shape_option,
+ lifecycleOwner = lifecycleOwner,
+ backgroundDispatcher = backgroundDispatcher,
+ foregroundTintSpec =
+ OptionItemBinder.TintSpec(
+ selectedColor =
+ context.getColor(com.android.wallpaper.R.color.system_on_surface),
+ unselectedColor =
+ context.getColor(com.android.wallpaper.R.color.system_on_surface),
+ ),
+ bindIcon = { foregroundView: View, shapeIcon: ShapeIconViewModel ->
+ val imageView = foregroundView as? ImageView
+ imageView?.let { ShapeIconViewBinder.bind(imageView, shapeIcon) }
+ },
+ )
+
+ private fun RecyclerView.initShapeOptionList(
+ context: Context,
+ adapter: OptionItemAdapter<ShapeIconViewModel>,
+ ) {
+ apply {
+ this.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
+ addItemDecoration(
+ SingleRowListItemSpacing(
+ edgeItemSpacePx =
+ context.resources.getDimensionPixelSize(
+ R.dimen.floating_sheet_content_horizontal_padding
+ ),
+ itemHorizontalSpacePx =
+ context.resources.getDimensionPixelSize(
+ com.android.themepicker.R.dimen
+ .floating_sheet_list_item_horizontal_space
+ ),
+ )
+ )
+ this.adapter = adapter
+ }
+ }
+
+ private fun createGridOptionItemAdapter(
context: Context,
lifecycleOwner: LifecycleOwner,
backgroundDispatcher: CoroutineDispatcher,
@@ -214,8 +280,7 @@
SingleRowListItemSpacing(
edgeItemSpacePx =
context.resources.getDimensionPixelSize(
- com.android.themepicker.R.dimen
- .floating_sheet_content_horizontal_padding
+ R.dimen.floating_sheet_content_horizontal_padding
),
itemHorizontalSpacePx =
context.resources.getDimensionPixelSize(
diff --git a/src/com/android/customization/model/grid/GridOptionsManager2.kt b/src/com/android/wallpaper/customization/ui/binder/ShapeIconViewBinder.kt
similarity index 60%
copy from src/com/android/customization/model/grid/GridOptionsManager2.kt
copy to src/com/android/wallpaper/customization/ui/binder/ShapeIconViewBinder.kt
index ce8500a..550038d 100644
--- a/src/com/android/customization/model/grid/GridOptionsManager2.kt
+++ b/src/com/android/wallpaper/customization/ui/binder/ShapeIconViewBinder.kt
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-package com.android.customization.model.grid
+package com.android.wallpaper.customization.ui.binder
-interface GridOptionsManager2 {
+import android.widget.ImageView
+import com.android.customization.picker.grid.ui.viewmodel.ShapeIconViewModel
+import com.android.wallpaper.customization.ui.view.ShapeTileDrawable
- suspend fun isGridOptionAvailable(): Boolean
-
- suspend fun getGridOptions(): List<GridOptionModel>?
-
- fun applyGridOption(gridName: String): Int
+object ShapeIconViewBinder {
+ fun bind(view: ImageView, shapeIcon: ShapeIconViewModel) {
+ view.setImageDrawable(ShapeTileDrawable(shapeIcon.path))
+ }
}
diff --git a/src/com/android/wallpaper/customization/ui/view/ShapeTileDrawable.kt b/src/com/android/wallpaper/customization/ui/view/ShapeTileDrawable.kt
new file mode 100644
index 0000000..3b492f4
--- /dev/null
+++ b/src/com/android/wallpaper/customization/ui/view/ShapeTileDrawable.kt
@@ -0,0 +1,71 @@
+/*
+ * 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.view
+
+import android.graphics.Canvas
+import android.graphics.ColorFilter
+import android.graphics.Matrix
+import android.graphics.Paint
+import android.graphics.Path
+import android.graphics.PixelFormat
+import android.graphics.Rect
+import android.graphics.drawable.Drawable
+import androidx.core.graphics.PathParser
+
+/**
+ * Drawable that draws a shape tile with a given path.
+ *
+ * @param path Path of the shape assuming drawing on a 100x100 canvas.
+ */
+class ShapeTileDrawable(path: String) : Drawable() {
+
+ private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
+ private val path = PathParser.createPathFromPathData(path)
+ // The path scaled with regard to the update of drawable bounds
+ private val scaledPath = Path(this.path)
+ private val scaleMatrix = Matrix()
+
+ override fun onBoundsChange(bounds: Rect) {
+ super.onBoundsChange(bounds)
+ scaleMatrix.setScale(bounds.width() / PATH_SIZE, bounds.height() / PATH_SIZE)
+ path.transform(scaleMatrix, scaledPath)
+ }
+
+ override fun draw(canvas: Canvas) {
+ canvas.drawPath(scaledPath, paint)
+ }
+
+ override fun setAlpha(alpha: Int) {
+ paint.alpha = alpha
+ }
+
+ override fun setColorFilter(colorFilter: ColorFilter?) {
+ paint.setColorFilter(colorFilter)
+ }
+
+ @Deprecated(
+ "getOpacity() is deprecated",
+ ReplaceWith("setAlpha(int)", "android.graphics.drawable.Drawable"),
+ )
+ override fun getOpacity(): Int {
+ return PixelFormat.TRANSLUCENT
+ }
+
+ companion object {
+ const val PATH_SIZE = 100f
+ }
+}
diff --git a/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt b/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt
index b6f48a1..7be934d 100644
--- a/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt
+++ b/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt
@@ -20,10 +20,10 @@
import android.content.res.Resources
import com.android.customization.model.ResourceConstants
import com.android.customization.model.grid.GridOptionModel
-import com.android.customization.picker.grid.domain.interactor.GridInteractor2
+import com.android.customization.picker.grid.domain.interactor.ShapeGridInteractor
import com.android.customization.picker.grid.ui.viewmodel.GridIconViewModel
+import com.android.customization.picker.grid.ui.viewmodel.ShapeIconViewModel
import com.android.themepicker.R
-import com.android.wallpaper.customization.ui.viewmodel.ClockPickerViewModel.Tab
import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon
import com.android.wallpaper.picker.common.text.ui.viewmodel.Text
import com.android.wallpaper.picker.customization.ui.viewmodel.FloatingToolbarTabViewModel
@@ -41,6 +41,7 @@
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filterNotNull
+import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.stateIn
@@ -49,7 +50,7 @@
@AssistedInject
constructor(
@ApplicationContext private val context: Context,
- interactor: GridInteractor2,
+ interactor: ShapeGridInteractor,
@Assisted private val viewModelScope: CoroutineScope,
) {
@@ -58,6 +59,35 @@
GRID,
}
+ // TODO (b/362237825): Get the shape options from the Launcher
+ val shapePaths =
+ listOf(
+ Pair(
+ "arch",
+ "M100 83.46C100 85.471 100 86.476 99.9 87.321 99.116 93.916 93.916 99.116 87.321 99.9 86.476 100 85.471 100 83.46 100H16.54C14.529 100 13.524 100 12.679 99.9 6.084 99.116.884 93.916.1 87.321 0 86.476 0 85.471 0 83.46L0 50C0 22.386 22.386 0 50 0 77.614 0 100 22.386 100 50V83.46Z",
+ ),
+ Pair(
+ "4-sided-cookie",
+ "M63.605 3C84.733-6.176 106.176 15.268 97 36.395L95.483 39.888C92.681 46.338 92.681 53.662 95.483 60.112L97 63.605C106.176 84.732 84.733 106.176 63.605 97L60.112 95.483C53.662 92.681 46.338 92.681 39.888 95.483L36.395 97C15.267 106.176-6.176 84.732 3 63.605L4.517 60.112C7.319 53.662 7.319 46.338 4.517 39.888L3 36.395C-6.176 15.268 15.267-6.176 36.395 3L39.888 4.517C46.338 7.319 53.662 7.319 60.112 4.517L63.605 3Z",
+ ),
+ Pair(
+ "7-sided-cookie",
+ "M35.209 4.878C36.326 3.895 36.884 3.404 37.397 3.006 44.82-2.742 55.18-2.742 62.603 3.006 63.116 3.404 63.674 3.895 64.791 4.878 65.164 5.207 65.351 5.371 65.539 5.529 68.167 7.734 71.303 9.248 74.663 9.932 74.902 9.981 75.147 10.025 75.637 10.113 77.1 10.375 77.831 10.506 78.461 10.66 87.573 12.893 94.032 21.011 94.176 30.412 94.186 31.062 94.151 31.805 94.08 33.293 94.057 33.791 94.045 34.04 94.039 34.285 93.958 37.72 94.732 41.121 96.293 44.18 96.404 44.399 96.522 44.618 96.759 45.056 97.467 46.366 97.821 47.021 98.093 47.611 102.032 56.143 99.727 66.266 92.484 72.24 91.983 72.653 91.381 73.089 90.177 73.961 89.774 74.254 89.572 74.4 89.377 74.548 86.647 76.626 84.477 79.353 83.063 82.483 82.962 82.707 82.865 82.936 82.671 83.395 82.091 84.766 81.8 85.451 81.51 86.033 77.31 94.44 67.977 98.945 58.801 96.994 58.166 96.859 57.451 96.659 56.019 96.259 55.54 96.125 55.3 96.058 55.063 95.998 51.74 95.154 48.26 95.154 44.937 95.998 44.699 96.058 44.46 96.125 43.981 96.259 42.549 96.659 41.834 96.859 41.199 96.994 32.023 98.945 22.69 94.44 18.49 86.033 18.2 85.451 17.909 84.766 17.329 83.395 17.135 82.936 17.038 82.707 16.937 82.483 15.523 79.353 13.353 76.626 10.623 74.548 10.428 74.4 10.226 74.254 9.823 73.961 8.619 73.089 8.017 72.653 7.516 72.24.273 66.266-2.032 56.143 1.907 47.611 2.179 47.021 2.533 46.366 3.241 45.056 3.478 44.618 3.596 44.399 3.707 44.18 5.268 41.121 6.042 37.72 5.961 34.285 5.955 34.04 5.943 33.791 5.92 33.293 5.849 31.805 5.814 31.062 5.824 30.412 5.968 21.011 12.427 12.893 21.539 10.66 22.169 10.506 22.9 10.375 24.363 10.113 24.853 10.025 25.098 9.981 25.337 9.932 28.697 9.248 31.833 7.734 34.461 5.529 34.649 5.371 34.836 5.207 35.209 4.878Z",
+ ),
+ Pair(
+ "sunny",
+ "M42.846 4.873C46.084-.531 53.916-.531 57.154 4.873L60.796 10.951C62.685 14.103 66.414 15.647 69.978 14.754L76.851 13.032C82.962 11.5 88.5 17.038 86.968 23.149L85.246 30.022C84.353 33.586 85.897 37.315 89.049 39.204L95.127 42.846C100.531 46.084 100.531 53.916 95.127 57.154L89.049 60.796C85.897 62.685 84.353 66.414 85.246 69.978L86.968 76.851C88.5 82.962 82.962 88.5 76.851 86.968L69.978 85.246C66.414 84.353 62.685 85.898 60.796 89.049L57.154 95.127C53.916 100.531 46.084 100.531 42.846 95.127L39.204 89.049C37.315 85.898 33.586 84.353 30.022 85.246L23.149 86.968C17.038 88.5 11.5 82.962 13.032 76.851L14.754 69.978C15.647 66.414 14.103 62.685 10.951 60.796L4.873 57.154C-.531 53.916-.531 46.084 4.873 42.846L10.951 39.204C14.103 37.315 15.647 33.586 14.754 30.022L13.032 23.149C11.5 17.038 17.038 11.5 23.149 13.032L30.022 14.754C33.586 15.647 37.315 14.103 39.204 10.951L42.846 4.873Z",
+ ),
+ Pair(
+ "circle",
+ "M99.18 50C99.18 77.162 77.162 99.18 50 99.18 22.838 99.18.82 77.162.82 50 .82 22.839 22.838.82 50 .82 77.162.82 99.18 22.839 99.18 50Z",
+ ),
+ Pair(
+ "square",
+ "M99.18 53.689C99.18 67.434 99.18 74.306 97.022 79.758 93.897 87.649 87.649 93.897 79.758 97.022 74.306 99.18 67.434 99.18 53.689 99.18H46.311C32.566 99.18 25.694 99.18 20.242 97.022 12.351 93.897 6.103 87.649 2.978 79.758.82 74.306.82 67.434.82 53.689L.82 46.311C.82 32.566.82 25.694 2.978 20.242 6.103 12.351 12.351 6.103 20.242 2.978 25.694.82 32.566.82 46.311.82L53.689.82C67.434.82 74.306.82 79.758 2.978 87.649 6.103 93.897 12.351 97.022 20.242 99.18 25.694 99.18 32.566 99.18 46.311V53.689Z",
+ ),
+ )
+
// Tabs
private val _selectedTab = MutableStateFlow(Tab.SHAPE)
val selectedTab: StateFlow<Tab> = _selectedTab.asStateFlow()
@@ -87,14 +117,28 @@
)
}
+ // The currently-set system shape option
+ val selectedShapeKey = flowOf(shapePaths[0].first)
+ private val overridingShapeKey = MutableStateFlow<String?>(null)
+ // If the overriding key is null, use the currently-set system shape option
+ val previewingShapeKey =
+ combine(overridingShapeKey, selectedShapeKey) { overridingShapeOptionKey, selectedShapeKey
+ ->
+ overridingShapeOptionKey ?: selectedShapeKey
+ }
+
+ val shapeOptions: Flow<List<OptionItemViewModel<ShapeIconViewModel>>> =
+ MutableStateFlow(shapePaths.map { toShapeOptionItemViewModel(it.first, it.second) })
+ .shareIn(scope = viewModelScope, started = SharingStarted.Lazily, replay = 1)
+
// The currently-set system grid option
val selectedGridOption =
interactor.selectedGridOption
.filterNotNull()
- .map { toOptionItemViewModel(it) }
+ .map { toGridOptionItemViewModel(it) }
.shareIn(scope = viewModelScope, started = SharingStarted.Lazily, replay = 1)
private val overridingGridOptionKey = MutableStateFlow<String?>(null)
- // If the previewing key is null, use the currently-set system grid option
+ // If the overriding key is null, use the currently-set system grid option
val previewingGridOptionKey =
combine(overridingGridOptionKey, selectedGridOption) {
overridingGridOptionKey,
@@ -102,15 +146,10 @@
overridingGridOptionKey ?: selectedGridOption.key.value
}
- fun resetPreview() {
- overridingGridOptionKey.value = null
- _selectedTab.value = Tab.SHAPE
- }
-
- val optionItems: Flow<List<OptionItemViewModel<GridIconViewModel>>> =
+ val gridOptions: Flow<List<OptionItemViewModel<GridIconViewModel>>> =
interactor.gridOptions
.filterNotNull()
- .map { gridOptions -> gridOptions.map { toOptionItemViewModel(it) } }
+ .map { gridOptions -> gridOptions.map { toGridOptionItemViewModel(it) } }
.shareIn(scope = viewModelScope, started = SharingStarted.Lazily, replay = 1)
val onApply: Flow<(suspend () -> Unit)?> =
@@ -124,7 +163,42 @@
}
}
- private fun toOptionItemViewModel(
+ fun resetPreview() {
+ overridingShapeKey.value = null
+ overridingGridOptionKey.value = null
+ _selectedTab.value = Tab.SHAPE
+ }
+
+ private fun toShapeOptionItemViewModel(
+ key: String,
+ path: String,
+ ): OptionItemViewModel<ShapeIconViewModel> {
+ val isSelected =
+ previewingShapeKey
+ .map { it == key }
+ .stateIn(
+ scope = viewModelScope,
+ started = SharingStarted.Lazily,
+ initialValue = false,
+ )
+
+ return OptionItemViewModel(
+ key = MutableStateFlow(key),
+ payload = ShapeIconViewModel(key, path),
+ text = Text.Loaded(key),
+ isSelected = isSelected,
+ onClicked =
+ isSelected.map {
+ if (!it) {
+ { overridingShapeKey.value = key }
+ } else {
+ null
+ }
+ },
+ )
+ }
+
+ private fun toGridOptionItemViewModel(
option: GridOptionModel
): OptionItemViewModel<GridIconViewModel> {
val iconShapePath =
diff --git a/src/com/android/wallpaper/picker/di/modules/ThemePickerSharedAppModule.kt b/src/com/android/wallpaper/picker/di/modules/ThemePickerSharedAppModule.kt
index 22e5fe5..98c881f 100644
--- a/src/com/android/wallpaper/picker/di/modules/ThemePickerSharedAppModule.kt
+++ b/src/com/android/wallpaper/picker/di/modules/ThemePickerSharedAppModule.kt
@@ -16,8 +16,8 @@
package com.android.wallpaper.picker.di.modules
-import com.android.customization.model.grid.DefaultGridOptionsManager
-import com.android.customization.model.grid.GridOptionsManager2
+import com.android.customization.model.grid.DefaultShapeGridManager
+import com.android.customization.model.grid.ShapeGridManager
import com.android.customization.picker.mode.shared.util.DarkModeUtil
import com.android.customization.picker.mode.shared.util.DarkModeUtilImpl
import dagger.Binds
@@ -32,7 +32,7 @@
@Binds
@Singleton
- abstract fun bindGridOptionsManager2(impl: DefaultGridOptionsManager): GridOptionsManager2
+ abstract fun bindGridOptionsManager2(impl: DefaultShapeGridManager): ShapeGridManager
@Binds @Singleton abstract fun bindDarkModeUtil(impl: DarkModeUtilImpl): DarkModeUtil
}
diff --git a/tests/common/src/com/android/customization/model/grid/FakeGridOptionsManager.kt b/tests/common/src/com/android/customization/model/grid/FakeShapeGridManager.kt
similarity index 95%
rename from tests/common/src/com/android/customization/model/grid/FakeGridOptionsManager.kt
rename to tests/common/src/com/android/customization/model/grid/FakeShapeGridManager.kt
index cc23981..a5a94c3 100644
--- a/tests/common/src/com/android/customization/model/grid/FakeGridOptionsManager.kt
+++ b/tests/common/src/com/android/customization/model/grid/FakeShapeGridManager.kt
@@ -20,7 +20,7 @@
import javax.inject.Singleton
@Singleton
-class FakeGridOptionsManager @Inject constructor() : GridOptionsManager2 {
+class FakeShapeGridManager @Inject constructor() : ShapeGridManager {
var isGridOptionAvailable: Boolean = true
diff --git a/tests/common/src/com/android/wallpaper/di/modules/ThemePickerSharedAppTestModule.kt b/tests/common/src/com/android/wallpaper/di/modules/ThemePickerSharedAppTestModule.kt
index 3112f75..4969db4 100644
--- a/tests/common/src/com/android/wallpaper/di/modules/ThemePickerSharedAppTestModule.kt
+++ b/tests/common/src/com/android/wallpaper/di/modules/ThemePickerSharedAppTestModule.kt
@@ -16,8 +16,8 @@
package com.android.wallpaper.di.modules
-import com.android.customization.model.grid.FakeGridOptionsManager
-import com.android.customization.model.grid.GridOptionsManager2
+import com.android.customization.model.grid.FakeShapeGridManager
+import com.android.customization.model.grid.ShapeGridManager
import com.android.customization.picker.mode.shared.util.DarkModeUtil
import com.android.customization.picker.mode.shared.util.FakeDarkModeUtil
import com.android.wallpaper.picker.di.modules.ThemePickerSharedAppModule
@@ -36,7 +36,7 @@
@Binds
@Singleton
- abstract fun bindGridOptionsManager2(impl: FakeGridOptionsManager): GridOptionsManager2
+ abstract fun bindGridOptionsManager2(impl: FakeShapeGridManager): ShapeGridManager
@Binds @Singleton abstract fun bindDarkModeUtil(impl: FakeDarkModeUtil): DarkModeUtil
}
diff --git a/tests/robotests/src/com/android/customization/picker/grid/data/repository/GridRepository2Test.kt b/tests/robotests/src/com/android/customization/picker/grid/data/repository/ShapeGridRepositoryTest.kt
similarity index 84%
rename from tests/robotests/src/com/android/customization/picker/grid/data/repository/GridRepository2Test.kt
rename to tests/robotests/src/com/android/customization/picker/grid/data/repository/ShapeGridRepositoryTest.kt
index 404f08b..61f8743 100644
--- a/tests/robotests/src/com/android/customization/picker/grid/data/repository/GridRepository2Test.kt
+++ b/tests/robotests/src/com/android/customization/picker/grid/data/repository/ShapeGridRepositoryTest.kt
@@ -17,7 +17,7 @@
package com.android.customization.picker.grid.data.repository
import androidx.test.filters.SmallTest
-import com.android.customization.model.grid.FakeGridOptionsManager
+import com.android.customization.model.grid.FakeShapeGridManager
import com.android.wallpaper.picker.di.modules.BackgroundDispatcher
import com.android.wallpaper.testing.collectLastValue
import com.google.common.truth.Truth.assertThat
@@ -42,21 +42,21 @@
@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(RobolectricTestRunner::class)
-class GridRepository2Test {
+class ShapeGridRepositoryTest {
@get:Rule var hiltRule = HiltAndroidRule(this)
- @Inject lateinit var gridOptionsManager: FakeGridOptionsManager
+ @Inject lateinit var gridOptionsManager: FakeShapeGridManager
@Inject lateinit var testScope: TestScope
@BackgroundDispatcher @Inject lateinit var bgScope: CoroutineScope
@BackgroundDispatcher @Inject lateinit var bgDispatcher: CoroutineDispatcher
- private lateinit var underTest: GridRepository2
+ private lateinit var underTest: ShapeGridRepository
@Before
fun setUp() {
hiltRule.inject()
underTest =
- GridRepository2(
+ ShapeGridRepository(
manager = gridOptionsManager,
bgScope = bgScope,
bgDispatcher = bgDispatcher,
@@ -86,7 +86,7 @@
fun gridOptions_default() =
testScope.runTest {
val gridOptions = collectLastValue(underTest.gridOptions)
- assertThat(gridOptions()).isEqualTo(FakeGridOptionsManager.DEFAULT_GRID_OPTION_LIST)
+ assertThat(gridOptions()).isEqualTo(FakeShapeGridManager.DEFAULT_GRID_OPTION_LIST)
}
@Test
@@ -94,7 +94,7 @@
testScope.runTest {
val selectedGridOption = collectLastValue(underTest.selectedGridOption)
assertThat(selectedGridOption())
- .isEqualTo(FakeGridOptionsManager.DEFAULT_GRID_OPTION_LIST[0])
+ .isEqualTo(FakeShapeGridManager.DEFAULT_GRID_OPTION_LIST[0])
}
@Test
@@ -104,7 +104,7 @@
underTest.applySelectedOption("practical")
assertThat(gridOptions())
.isEqualTo(
- FakeGridOptionsManager.DEFAULT_GRID_OPTION_LIST.map {
+ FakeShapeGridManager.DEFAULT_GRID_OPTION_LIST.map {
it.copy(isCurrent = it.key == "practical")
}
)
@@ -116,8 +116,6 @@
val selectedGridOption = collectLastValue(underTest.selectedGridOption)
underTest.applySelectedOption("practical")
assertThat(selectedGridOption())
- .isEqualTo(
- FakeGridOptionsManager.DEFAULT_GRID_OPTION_LIST[1].copy(isCurrent = true)
- )
+ .isEqualTo(FakeShapeGridManager.DEFAULT_GRID_OPTION_LIST[1].copy(isCurrent = true))
}
}
diff --git a/tests/robotests/src/com/android/customization/picker/grid/domain/interactor/GridInteractor2Test.kt b/tests/robotests/src/com/android/customization/picker/grid/domain/interactor/ShapeGridInteractorTest.kt
similarity index 80%
rename from tests/robotests/src/com/android/customization/picker/grid/domain/interactor/GridInteractor2Test.kt
rename to tests/robotests/src/com/android/customization/picker/grid/domain/interactor/ShapeGridInteractorTest.kt
index bfbe282..51642cb 100644
--- a/tests/robotests/src/com/android/customization/picker/grid/domain/interactor/GridInteractor2Test.kt
+++ b/tests/robotests/src/com/android/customization/picker/grid/domain/interactor/ShapeGridInteractorTest.kt
@@ -17,8 +17,8 @@
package com.android.customization.picker.grid.domain.interactor
import androidx.test.filters.SmallTest
-import com.android.customization.model.grid.FakeGridOptionsManager
-import com.android.customization.picker.grid.data.repository.GridRepository2
+import com.android.customization.model.grid.FakeShapeGridManager
+import com.android.customization.picker.grid.data.repository.ShapeGridRepository
import com.android.wallpaper.testing.collectLastValue
import com.google.common.truth.Truth.assertThat
import dagger.hilt.android.testing.HiltAndroidRule
@@ -40,19 +40,19 @@
@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(RobolectricTestRunner::class)
-class GridInteractor2Test {
+class ShapeGridInteractorTest {
@get:Rule var hiltRule = HiltAndroidRule(this)
- @Inject lateinit var gridOptionsManager: FakeGridOptionsManager
- @Inject lateinit var repository: GridRepository2
+ @Inject lateinit var gridOptionsManager: FakeShapeGridManager
+ @Inject lateinit var repository: ShapeGridRepository
@Inject lateinit var testScope: TestScope
- private lateinit var underTest: GridInteractor2
+ private lateinit var underTest: ShapeGridInteractor
@Before
fun setUp() {
hiltRule.inject()
- underTest = GridInteractor2(repository)
+ underTest = ShapeGridInteractor(repository)
}
@After
@@ -78,7 +78,7 @@
fun gridOptions_default() =
testScope.runTest {
val gridOptions = collectLastValue(underTest.gridOptions)
- assertThat(gridOptions()).isEqualTo(FakeGridOptionsManager.DEFAULT_GRID_OPTION_LIST)
+ assertThat(gridOptions()).isEqualTo(FakeShapeGridManager.DEFAULT_GRID_OPTION_LIST)
}
@Test
@@ -86,7 +86,7 @@
testScope.runTest {
val selectedGridOption = collectLastValue(underTest.selectedGridOption)
assertThat(selectedGridOption())
- .isEqualTo(FakeGridOptionsManager.DEFAULT_GRID_OPTION_LIST[0])
+ .isEqualTo(FakeShapeGridManager.DEFAULT_GRID_OPTION_LIST[0])
}
@Test
@@ -96,7 +96,7 @@
underTest.applySelectedOption("practical")
assertThat(gridOptions())
.isEqualTo(
- FakeGridOptionsManager.DEFAULT_GRID_OPTION_LIST.map {
+ FakeShapeGridManager.DEFAULT_GRID_OPTION_LIST.map {
it.copy(isCurrent = it.key == "practical")
}
)
@@ -108,8 +108,6 @@
val selectedGridOption = collectLastValue(underTest.selectedGridOption)
underTest.applySelectedOption("practical")
assertThat(selectedGridOption())
- .isEqualTo(
- FakeGridOptionsManager.DEFAULT_GRID_OPTION_LIST[1].copy(isCurrent = true)
- )
+ .isEqualTo(FakeShapeGridManager.DEFAULT_GRID_OPTION_LIST[1].copy(isCurrent = true))
}
}
diff --git a/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModelTest.kt b/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModelTest.kt
index dd88134..dcf658e 100644
--- a/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModelTest.kt
+++ b/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModelTest.kt
@@ -21,9 +21,10 @@
import androidx.test.core.app.ApplicationProvider
import androidx.test.filters.SmallTest
import com.android.customization.model.ResourceConstants
-import com.android.customization.model.grid.FakeGridOptionsManager
-import com.android.customization.picker.grid.domain.interactor.GridInteractor2
+import com.android.customization.model.grid.FakeShapeGridManager
+import com.android.customization.picker.grid.domain.interactor.ShapeGridInteractor
import com.android.customization.picker.grid.ui.viewmodel.GridIconViewModel
+import com.android.customization.picker.grid.ui.viewmodel.ShapeIconViewModel
import com.android.wallpaper.picker.common.text.ui.viewmodel.Text
import com.android.wallpaper.picker.option.ui.viewmodel.OptionItemViewModel
import com.android.wallpaper.testing.collectLastValue
@@ -52,8 +53,8 @@
@get:Rule var hiltRule = HiltAndroidRule(this)
@Inject lateinit var testScope: TestScope
- @Inject lateinit var gridOptionsManager: FakeGridOptionsManager
- @Inject lateinit var interactor: GridInteractor2
+ @Inject lateinit var gridOptionsManager: FakeShapeGridManager
+ @Inject lateinit var interactor: ShapeGridInteractor
@Inject @ApplicationContext lateinit var appContext: Context
private val iconShapePath =
@@ -82,6 +83,75 @@
}
@Test
+ fun selectedTabUpdates_whenClickOnGridTab() =
+ testScope.runTest {
+ val selectedTab = collectLastValue(underTest.selectedTab)
+ val tabs = collectLastValue(underTest.tabs)
+ val onGridTabClicked = tabs()?.get(1)?.onClick
+
+ assertThat(selectedTab()).isEqualTo(ShapeGridPickerViewModel.Tab.SHAPE)
+
+ onGridTabClicked?.invoke()
+
+ assertThat(selectedTab()).isEqualTo(ShapeGridPickerViewModel.Tab.GRID)
+ }
+
+ @Test
+ fun selectedShapeKey() =
+ testScope.runTest {
+ val selectedShapeKey = collectLastValue(underTest.selectedShapeKey)
+
+ assertThat(selectedShapeKey()).isEqualTo("arch")
+ }
+
+ @Test
+ fun shapeOptions() =
+ testScope.runTest {
+ val shapeOptions = collectLastValue(underTest.shapeOptions)
+
+ for (i in 0 until underTest.shapePaths.size) {
+ val expectedKey = underTest.shapePaths[i].first
+ val expectedPath = underTest.shapePaths[i].second
+ assertShapeItem(
+ optionItem = shapeOptions()?.get(i),
+ key = expectedKey,
+ payload = ShapeIconViewModel(expectedKey, expectedPath),
+ text = Text.Loaded(expectedKey),
+ isTextUserVisible = true,
+ isSelected = expectedKey == "arch",
+ isEnabled = true,
+ )
+ }
+ }
+
+ @Test
+ fun shapeOptions_whenClickOnCircleOption() =
+ testScope.runTest {
+ val shapeOptions = collectLastValue(underTest.shapeOptions)
+ val previewingShapeKey = collectLastValue(underTest.previewingShapeKey)
+ val onCircleOptionClicked =
+ shapeOptions()?.get(4)?.onClicked?.let { collectLastValue(it) }
+ checkNotNull(onCircleOptionClicked)
+
+ onCircleOptionClicked()?.invoke()
+
+ assertThat(previewingShapeKey()).isEqualTo("circle")
+ for (i in 0 until underTest.shapePaths.size) {
+ val expectedKey = underTest.shapePaths[i].first
+ val expectedPath = underTest.shapePaths[i].second
+ assertShapeItem(
+ optionItem = shapeOptions()?.get(i),
+ key = expectedKey,
+ payload = ShapeIconViewModel(expectedKey, expectedPath),
+ text = Text.Loaded(expectedKey),
+ isTextUserVisible = true,
+ isSelected = expectedKey == "circle",
+ isEnabled = true,
+ )
+ }
+ }
+
+ @Test
fun selectedGridOption() =
testScope.runTest {
val selectedGridOption = collectLastValue(underTest.selectedGridOption)
@@ -101,7 +171,7 @@
fun selectedGridOption_shouldUpdate_afterOnApply() =
testScope.runTest {
val selectedGridOption = collectLastValue(underTest.selectedGridOption)
- val optionItems = collectLastValue(underTest.optionItems)
+ val optionItems = collectLastValue(underTest.gridOptions)
val onApply = collectLastValue(underTest.onApply)
val onPracticalOptionClick =
optionItems()?.get(1)?.onClicked?.let { collectLastValue(it) }
@@ -124,7 +194,7 @@
@Test
fun optionItems() =
testScope.runTest {
- val optionItems = collectLastValue(underTest.optionItems)
+ val optionItems = collectLastValue(underTest.gridOptions)
assertOptionItem(
optionItem = optionItems()?.get(0),
@@ -149,7 +219,7 @@
@Test
fun optionItems_whenClickOnPracticalOption() =
testScope.runTest {
- val optionItems = collectLastValue(underTest.optionItems)
+ val optionItems = collectLastValue(underTest.gridOptions)
val onPracticalOptionClick =
optionItems()?.get(1)?.onClicked?.let { collectLastValue(it) }
checkNotNull(onPracticalOptionClick)
@@ -176,6 +246,24 @@
)
}
+ private fun TestScope.assertShapeItem(
+ optionItem: OptionItemViewModel<ShapeIconViewModel>?,
+ key: String,
+ payload: ShapeIconViewModel?,
+ text: Text,
+ isTextUserVisible: Boolean,
+ isSelected: Boolean,
+ isEnabled: Boolean,
+ ) {
+ checkNotNull(optionItem)
+ assertThat(collectLastValue(optionItem.key)()).isEqualTo(key)
+ assertThat(optionItem.text).isEqualTo(text)
+ assertThat(optionItem.payload).isEqualTo(payload)
+ assertThat(optionItem.isTextUserVisible).isEqualTo(isTextUserVisible)
+ assertThat(collectLastValue(optionItem.isSelected)()).isEqualTo(isSelected)
+ assertThat(optionItem.isEnabled).isEqualTo(isEnabled)
+ }
+
private fun TestScope.assertOptionItem(
optionItem: OptionItemViewModel<GridIconViewModel>?,
key: String,