Loading src/com/android/customization/model/grid/DefaultShapeGridManager.kt +8 −0 Original line number Diff line number Diff line Loading @@ -157,6 +157,14 @@ constructor( ) } override fun applyShapeOption(shapeKey: String) = context.contentResolver.update( previewUtils.getUri(SET_SHAPE), ContentValues().apply { put(COL_SHAPE_KEY, shapeKey) }, null, null, ) override fun getGridOptionDrawable(iconId: Int): Drawable? { val launcherPackageName = context.getString(com.android.themepicker.R.string.launcher_overlayable_package) Loading src/com/android/customization/model/grid/ShapeGridManager.kt +6 −0 Original line number Diff line number Diff line Loading @@ -30,5 +30,11 @@ interface ShapeGridManager { fun applyGridOption(gridKey: String) /** * @return an integer representing whether the operation was successful, 1 for success and 0 for * failure */ fun applyShapeOption(shapeKey: String): Int fun getGridOptionDrawable(iconId: Int): Drawable? } src/com/android/customization/picker/grid/data/repository/ShapeRepository.kt +2 −10 Original line number Diff line number Diff line Loading @@ -17,10 +17,7 @@ package com.android.customization.picker.grid.data.repository import android.content.ContentValues import android.content.Context import com.android.customization.model.grid.DefaultShapeGridManager.Companion.COL_SHAPE_KEY import com.android.customization.model.grid.DefaultShapeGridManager.Companion.SET_SHAPE import com.android.customization.model.grid.ShapeGridManager import com.android.customization.model.grid.ShapeOptionModel import com.android.wallpaper.R Loading Loading @@ -67,13 +64,8 @@ constructor( suspend fun applyShape(shapeKey: String) = withContext(bgDispatcher) { context.contentResolver.update( previewUtils.getUri(SET_SHAPE), ContentValues().apply { put(COL_SHAPE_KEY, shapeKey) }, null, null, ) // After applying, we should query and update shape and grid options again. shapeGridManager.applyShapeOption(shapeKey) // After applying, we should query and update shape options again. _shapeOptions.value = shapeGridManager.getShapeOptions() } } tests/common/src/com/android/customization/model/grid/FakeShapeGridManager.kt +11 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,11 @@ class FakeShapeGridManager @Inject constructor() : ShapeGridManager { gridOptions = gridOptions.map { it.copy(isCurrent = it.key == gridKey) } } override fun applyShapeOption(shapeKey: String): Int { shapeOptions = shapeOptions?.map { it.copy(isCurrent = it.key == shapeKey) } return 0 } override fun getGridOptionDrawable(iconId: Int): Drawable? { return when (iconId) { 0 -> gridOptionDrawable0 Loading Loading @@ -107,5 +112,11 @@ class FakeShapeGridManager @Inject constructor() : ShapeGridManager { isCurrent = false, ), ) const val FOUR_SIDED_COOKIE_IDX = 1 private val FOUR_SIDED_COOKIE_MODEL = DEFAULT_SHAPE_OPTION_LIST[FOUR_SIDED_COOKIE_IDX] val FOUR_SIDED_COOKIE_KEY = FOUR_SIDED_COOKIE_MODEL.key val FOUR_SIDED_COOKIE_TITLE = FOUR_SIDED_COOKIE_MODEL.title val FOUR_SIDED_COOKIE_PATH = FOUR_SIDED_COOKIE_MODEL.path } } tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/AppIconPickerViewModelTest.kt +86 −0 Original line number Diff line number Diff line Loading @@ -184,6 +184,92 @@ class AppIconPickerViewModelTest { assertThat(onApply()).isNotNull() } @Test fun selectedShapeOption_shouldUpdate_afterOnApply() = testScope.runTest { val selectedShapeOption = collectLastValue(underTest.selectedShape) val optionItems = collectLastValue(underTest.shapeOptions) val onApply = collectLastValue(underTest.onApply) val on4SidedCookieOptionClick = optionItems()?.get(FakeShapeGridManager.FOUR_SIDED_COOKIE_IDX)?.onClicked?.let { collectLastValue(it) } checkNotNull(on4SidedCookieOptionClick) on4SidedCookieOptionClick()?.invoke() onApply()?.invoke() assertShapeItem( optionItem = selectedShapeOption(), key = FakeShapeGridManager.FOUR_SIDED_COOKIE_KEY, payload = ShapeIconViewModel( FakeShapeGridManager.FOUR_SIDED_COOKIE_KEY, FakeShapeGridManager.FOUR_SIDED_COOKIE_PATH, ), text = Text.Loaded(FakeShapeGridManager.FOUR_SIDED_COOKIE_TITLE), isTextUserVisible = true, isSelected = true, isEnabled = true, ) } @Test fun isThemedIconEnabled_shouldUpdate_afterOnApply() { testScope.runTest { val isEnabled = collectLastValue(underTest.isThemedIconEnabled) val toggleThemedIcon = collectLastValue(underTest.toggleThemedIcon) val onApply = collectLastValue(underTest.onApply) assertThat(isEnabled()).isFalse() toggleThemedIcon()?.invoke() onApply()?.invoke() assertThat(isEnabled()).isTrue() toggleThemedIcon()?.invoke() onApply()?.invoke() assertThat(isEnabled()).isFalse() } } @Test fun shapeAndThemedIcon_shouldUpdate_afterOnApply() { testScope.runTest { val selectedShapeOption = collectLastValue(underTest.selectedShape) val optionItems = collectLastValue(underTest.shapeOptions) val onApply = collectLastValue(underTest.onApply) val on4SidedCookieOptionClick = optionItems()?.get(FakeShapeGridManager.FOUR_SIDED_COOKIE_IDX)?.onClicked?.let { collectLastValue(it) } checkNotNull(on4SidedCookieOptionClick) val isEnabled = collectLastValue(underTest.isThemedIconEnabled) val toggleThemedIcon = collectLastValue(underTest.toggleThemedIcon) assertThat(isEnabled()).isFalse() on4SidedCookieOptionClick()?.invoke() toggleThemedIcon()?.invoke() onApply()?.invoke() assertShapeItem( optionItem = selectedShapeOption(), key = FakeShapeGridManager.FOUR_SIDED_COOKIE_KEY, payload = ShapeIconViewModel( FakeShapeGridManager.FOUR_SIDED_COOKIE_KEY, FakeShapeGridManager.FOUR_SIDED_COOKIE_PATH, ), text = Text.Loaded(FakeShapeGridManager.FOUR_SIDED_COOKIE_TITLE), isTextUserVisible = true, isSelected = true, isEnabled = true, ) assertThat(isEnabled()).isTrue() } } private fun TestScope.assertShapeItem( optionItem: OptionItemViewModel2<ShapeIconViewModel>?, key: String, Loading Loading
src/com/android/customization/model/grid/DefaultShapeGridManager.kt +8 −0 Original line number Diff line number Diff line Loading @@ -157,6 +157,14 @@ constructor( ) } override fun applyShapeOption(shapeKey: String) = context.contentResolver.update( previewUtils.getUri(SET_SHAPE), ContentValues().apply { put(COL_SHAPE_KEY, shapeKey) }, null, null, ) override fun getGridOptionDrawable(iconId: Int): Drawable? { val launcherPackageName = context.getString(com.android.themepicker.R.string.launcher_overlayable_package) Loading
src/com/android/customization/model/grid/ShapeGridManager.kt +6 −0 Original line number Diff line number Diff line Loading @@ -30,5 +30,11 @@ interface ShapeGridManager { fun applyGridOption(gridKey: String) /** * @return an integer representing whether the operation was successful, 1 for success and 0 for * failure */ fun applyShapeOption(shapeKey: String): Int fun getGridOptionDrawable(iconId: Int): Drawable? }
src/com/android/customization/picker/grid/data/repository/ShapeRepository.kt +2 −10 Original line number Diff line number Diff line Loading @@ -17,10 +17,7 @@ package com.android.customization.picker.grid.data.repository import android.content.ContentValues import android.content.Context import com.android.customization.model.grid.DefaultShapeGridManager.Companion.COL_SHAPE_KEY import com.android.customization.model.grid.DefaultShapeGridManager.Companion.SET_SHAPE import com.android.customization.model.grid.ShapeGridManager import com.android.customization.model.grid.ShapeOptionModel import com.android.wallpaper.R Loading Loading @@ -67,13 +64,8 @@ constructor( suspend fun applyShape(shapeKey: String) = withContext(bgDispatcher) { context.contentResolver.update( previewUtils.getUri(SET_SHAPE), ContentValues().apply { put(COL_SHAPE_KEY, shapeKey) }, null, null, ) // After applying, we should query and update shape and grid options again. shapeGridManager.applyShapeOption(shapeKey) // After applying, we should query and update shape options again. _shapeOptions.value = shapeGridManager.getShapeOptions() } }
tests/common/src/com/android/customization/model/grid/FakeShapeGridManager.kt +11 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,11 @@ class FakeShapeGridManager @Inject constructor() : ShapeGridManager { gridOptions = gridOptions.map { it.copy(isCurrent = it.key == gridKey) } } override fun applyShapeOption(shapeKey: String): Int { shapeOptions = shapeOptions?.map { it.copy(isCurrent = it.key == shapeKey) } return 0 } override fun getGridOptionDrawable(iconId: Int): Drawable? { return when (iconId) { 0 -> gridOptionDrawable0 Loading Loading @@ -107,5 +112,11 @@ class FakeShapeGridManager @Inject constructor() : ShapeGridManager { isCurrent = false, ), ) const val FOUR_SIDED_COOKIE_IDX = 1 private val FOUR_SIDED_COOKIE_MODEL = DEFAULT_SHAPE_OPTION_LIST[FOUR_SIDED_COOKIE_IDX] val FOUR_SIDED_COOKIE_KEY = FOUR_SIDED_COOKIE_MODEL.key val FOUR_SIDED_COOKIE_TITLE = FOUR_SIDED_COOKIE_MODEL.title val FOUR_SIDED_COOKIE_PATH = FOUR_SIDED_COOKIE_MODEL.path } }
tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/AppIconPickerViewModelTest.kt +86 −0 Original line number Diff line number Diff line Loading @@ -184,6 +184,92 @@ class AppIconPickerViewModelTest { assertThat(onApply()).isNotNull() } @Test fun selectedShapeOption_shouldUpdate_afterOnApply() = testScope.runTest { val selectedShapeOption = collectLastValue(underTest.selectedShape) val optionItems = collectLastValue(underTest.shapeOptions) val onApply = collectLastValue(underTest.onApply) val on4SidedCookieOptionClick = optionItems()?.get(FakeShapeGridManager.FOUR_SIDED_COOKIE_IDX)?.onClicked?.let { collectLastValue(it) } checkNotNull(on4SidedCookieOptionClick) on4SidedCookieOptionClick()?.invoke() onApply()?.invoke() assertShapeItem( optionItem = selectedShapeOption(), key = FakeShapeGridManager.FOUR_SIDED_COOKIE_KEY, payload = ShapeIconViewModel( FakeShapeGridManager.FOUR_SIDED_COOKIE_KEY, FakeShapeGridManager.FOUR_SIDED_COOKIE_PATH, ), text = Text.Loaded(FakeShapeGridManager.FOUR_SIDED_COOKIE_TITLE), isTextUserVisible = true, isSelected = true, isEnabled = true, ) } @Test fun isThemedIconEnabled_shouldUpdate_afterOnApply() { testScope.runTest { val isEnabled = collectLastValue(underTest.isThemedIconEnabled) val toggleThemedIcon = collectLastValue(underTest.toggleThemedIcon) val onApply = collectLastValue(underTest.onApply) assertThat(isEnabled()).isFalse() toggleThemedIcon()?.invoke() onApply()?.invoke() assertThat(isEnabled()).isTrue() toggleThemedIcon()?.invoke() onApply()?.invoke() assertThat(isEnabled()).isFalse() } } @Test fun shapeAndThemedIcon_shouldUpdate_afterOnApply() { testScope.runTest { val selectedShapeOption = collectLastValue(underTest.selectedShape) val optionItems = collectLastValue(underTest.shapeOptions) val onApply = collectLastValue(underTest.onApply) val on4SidedCookieOptionClick = optionItems()?.get(FakeShapeGridManager.FOUR_SIDED_COOKIE_IDX)?.onClicked?.let { collectLastValue(it) } checkNotNull(on4SidedCookieOptionClick) val isEnabled = collectLastValue(underTest.isThemedIconEnabled) val toggleThemedIcon = collectLastValue(underTest.toggleThemedIcon) assertThat(isEnabled()).isFalse() on4SidedCookieOptionClick()?.invoke() toggleThemedIcon()?.invoke() onApply()?.invoke() assertShapeItem( optionItem = selectedShapeOption(), key = FakeShapeGridManager.FOUR_SIDED_COOKIE_KEY, payload = ShapeIconViewModel( FakeShapeGridManager.FOUR_SIDED_COOKIE_KEY, FakeShapeGridManager.FOUR_SIDED_COOKIE_PATH, ), text = Text.Loaded(FakeShapeGridManager.FOUR_SIDED_COOKIE_TITLE), isTextUserVisible = true, isSelected = true, isEnabled = true, ) assertThat(isEnabled()).isTrue() } } private fun TestScope.assertShapeItem( optionItem: OptionItemViewModel2<ShapeIconViewModel>?, key: String, Loading