Loading packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/ContentListState.kt +3 −2 Original line number Diff line number Diff line Loading @@ -57,7 +57,8 @@ class ContentListState internal constructor( communalContent: List<CommunalContentModel>, private val onAddWidget: (componentName: ComponentName, user: UserHandle, rank: Int) -> Unit, private val onDeleteWidget: (id: Int, componentName: ComponentName, rank: Int) -> Unit, private val onDeleteWidget: (id: Int, key: String, componentName: ComponentName, rank: Int) -> Unit, private val onReorderWidgets: (widgetIdToRankMap: Map<Int, Int>) -> Unit, private val onResizeWidget: ( Loading @@ -81,7 +82,7 @@ internal constructor( if (list[indexToRemove].isWidgetContent()) { val widget = list[indexToRemove] as CommunalContentModel.WidgetContent list.apply { removeAt(indexToRemove) } onDeleteWidget(widget.appWidgetId, widget.componentName, widget.rank) onDeleteWidget(widget.appWidgetId, widget.key, widget.componentName, widget.rank) } } Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt +19 −0 Original line number Diff line number Diff line Loading @@ -201,6 +201,7 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { underTest.onDeleteWidget( id = 0, key = "key_0", componentName = ComponentName("test_package", "test_class"), rank = 30, ) Loading @@ -213,6 +214,24 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { assertThat(appWidgetId).isEqualTo(1) } @Test fun deleteWidget_clearsSelectedKey() = kosmos.runTest { val selectedKey by collectLastValue(underTest.selectedKey) underTest.setSelectedKey("test_key") assertThat(selectedKey).isEqualTo("test_key") // Selected key is deleted. underTest.onDeleteWidget( id = 0, key = "test_key", componentName = ComponentName("test_package", "test_class"), rank = 30, ) assertThat(selectedKey).isNull() } @Test fun reorderWidget_uiEventLogging_start() = kosmos.runTest { Loading packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +1 −1 Original line number Diff line number Diff line Loading @@ -153,7 +153,7 @@ abstract class BaseCommunalViewModel( ) {} /** Called as the UI requests deleting a widget. */ open fun onDeleteWidget(id: Int, componentName: ComponentName, rank: Int) {} open fun onDeleteWidget(id: Int, key: String, componentName: ComponentName, rank: Int) {} /** Called as the UI detects a tap event on the widget. */ open fun onTapWidget(componentName: ComponentName, rank: Int) {} Loading packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt +4 −1 Original line number Diff line number Diff line Loading @@ -141,7 +141,10 @@ constructor( metricsLogger.logAddWidget(componentName.flattenToString(), rank) } override fun onDeleteWidget(id: Int, componentName: ComponentName, rank: Int) { override fun onDeleteWidget(id: Int, key: String, componentName: ComponentName, rank: Int) { if (selectedKey.value == key) { setSelectedKey(null) } communalInteractor.deleteWidget(id) metricsLogger.logRemoveWidget(componentName.flattenToString(), rank) } Loading Loading
packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/ContentListState.kt +3 −2 Original line number Diff line number Diff line Loading @@ -57,7 +57,8 @@ class ContentListState internal constructor( communalContent: List<CommunalContentModel>, private val onAddWidget: (componentName: ComponentName, user: UserHandle, rank: Int) -> Unit, private val onDeleteWidget: (id: Int, componentName: ComponentName, rank: Int) -> Unit, private val onDeleteWidget: (id: Int, key: String, componentName: ComponentName, rank: Int) -> Unit, private val onReorderWidgets: (widgetIdToRankMap: Map<Int, Int>) -> Unit, private val onResizeWidget: ( Loading @@ -81,7 +82,7 @@ internal constructor( if (list[indexToRemove].isWidgetContent()) { val widget = list[indexToRemove] as CommunalContentModel.WidgetContent list.apply { removeAt(indexToRemove) } onDeleteWidget(widget.appWidgetId, widget.componentName, widget.rank) onDeleteWidget(widget.appWidgetId, widget.key, widget.componentName, widget.rank) } } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt +19 −0 Original line number Diff line number Diff line Loading @@ -201,6 +201,7 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { underTest.onDeleteWidget( id = 0, key = "key_0", componentName = ComponentName("test_package", "test_class"), rank = 30, ) Loading @@ -213,6 +214,24 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { assertThat(appWidgetId).isEqualTo(1) } @Test fun deleteWidget_clearsSelectedKey() = kosmos.runTest { val selectedKey by collectLastValue(underTest.selectedKey) underTest.setSelectedKey("test_key") assertThat(selectedKey).isEqualTo("test_key") // Selected key is deleted. underTest.onDeleteWidget( id = 0, key = "test_key", componentName = ComponentName("test_package", "test_class"), rank = 30, ) assertThat(selectedKey).isNull() } @Test fun reorderWidget_uiEventLogging_start() = kosmos.runTest { Loading
packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +1 −1 Original line number Diff line number Diff line Loading @@ -153,7 +153,7 @@ abstract class BaseCommunalViewModel( ) {} /** Called as the UI requests deleting a widget. */ open fun onDeleteWidget(id: Int, componentName: ComponentName, rank: Int) {} open fun onDeleteWidget(id: Int, key: String, componentName: ComponentName, rank: Int) {} /** Called as the UI detects a tap event on the widget. */ open fun onTapWidget(componentName: ComponentName, rank: Int) {} Loading
packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt +4 −1 Original line number Diff line number Diff line Loading @@ -141,7 +141,10 @@ constructor( metricsLogger.logAddWidget(componentName.flattenToString(), rank) } override fun onDeleteWidget(id: Int, componentName: ComponentName, rank: Int) { override fun onDeleteWidget(id: Int, key: String, componentName: ComponentName, rank: Int) { if (selectedKey.value == key) { setSelectedKey(null) } communalInteractor.deleteWidget(id) metricsLogger.logRemoveWidget(componentName.flattenToString(), rank) } Loading