Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5337343 authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge "Log UiEvents for widget reordering" into main

parents 156cc5b1 353cb9d2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ private fun BoxScope.CommunalHubLazyGrid(
        gridModifier =
            gridModifier
                .fillMaxSize()
                .dragContainer(dragDropState, beforeContentPadding(contentPadding))
                .dragContainer(dragDropState, beforeContentPadding(contentPadding), viewModel)
                .onGloballyPositioned { setGridCoordinates(it) }
        // for widgets dropped from other activities
        val dragAndDropTargetState =
+12 −3
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import androidx.compose.ui.unit.toOffset
import androidx.compose.ui.unit.toSize
import androidx.compose.ui.zIndex
import com.android.systemui.communal.ui.compose.extensions.plus
import com.android.systemui.communal.ui.viewmodel.BaseCommunalViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
@@ -207,7 +208,8 @@ internal constructor(

fun Modifier.dragContainer(
    dragDropState: GridDragDropState,
    beforeContentPadding: ContentPaddingInPx
    beforeContentPadding: ContentPaddingInPx,
    viewModel: BaseCommunalViewModel,
): Modifier {
    return pointerInput(dragDropState, beforeContentPadding) {
        detectDragGesturesAfterLongPress(
@@ -220,9 +222,16 @@ fun Modifier.dragContainer(
                    offset,
                    Offset(beforeContentPadding.startPadding, beforeContentPadding.topPadding)
                )
                viewModel.onReorderWidgetStart()
            },
            onDragEnd = { dragDropState.onDragInterrupted() },
            onDragCancel = { dragDropState.onDragInterrupted() }
            onDragEnd = {
                dragDropState.onDragInterrupted()
                viewModel.onReorderWidgetEnd()
            },
            onDragCancel = {
                dragDropState.onDragInterrupted()
                viewModel.onReorderWidgetCancel()
            }
        )
    }
}
+23 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.provider.Settings
import android.widget.RemoteViews
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.logging.UiEventLogger
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.data.repository.FakeCommunalMediaRepository
import com.android.systemui.communal.data.repository.FakeCommunalRepository
@@ -33,6 +34,7 @@ import com.android.systemui.communal.data.repository.FakeCommunalTutorialReposit
import com.android.systemui.communal.data.repository.FakeCommunalWidgetRepository
import com.android.systemui.communal.domain.interactor.CommunalInteractorFactory
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.shared.log.CommunalUiEvent
import com.android.systemui.communal.shared.model.CommunalWidgetContentModel
import com.android.systemui.communal.ui.viewmodel.CommunalEditModeViewModel
import com.android.systemui.coroutines.collectLastValue
@@ -54,6 +56,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations

@OptIn(ExperimentalCoroutinesApi::class)
@@ -64,6 +67,7 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {
    @Mock private lateinit var shadeViewController: ShadeViewController
    @Mock private lateinit var powerManager: PowerManager
    @Mock private lateinit var appWidgetHost: AppWidgetHost
    @Mock private lateinit var uiEventLogger: UiEventLogger

    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
@@ -96,6 +100,7 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {
                Provider { shadeViewController },
                powerManager,
                mediaHost,
                uiEventLogger,
            )
    }

@@ -203,4 +208,22 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {
            val providerTwo = ComponentName("pkg.test", "testWidget2")
            underTest.onAddWidget(componentName = providerTwo, priority = 0)
        }

    @Test
    fun reorderWidget_uiEventLogging_start() {
        underTest.onReorderWidgetStart()
        verify(uiEventLogger).log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_START)
    }

    @Test
    fun reorderWidget_uiEventLogging_end() {
        underTest.onReorderWidgetEnd()
        verify(uiEventLogger).log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_FINISH)
    }

    @Test
    fun reorderWidget_uiEventLogging_cancel() {
        underTest.onReorderWidgetCancel()
        verify(uiEventLogger).log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_CANCEL)
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -116,4 +116,13 @@ abstract class BaseCommunalViewModel(

    /** Gets the interaction handler used to handle taps on a remote view */
    abstract fun getInteractionHandler(): RemoteViews.InteractionHandler

    /** Called as the user starts dragging a widget to reorder. */
    open fun onReorderWidgetStart() {}

    /** Called as the user finishes dragging a widget to reorder. */
    open fun onReorderWidgetEnd() {}

    /** Called as the user cancels dragging a widget to reorder. */
    open fun onReorderWidgetCancel() {}
}
+15 −0
Original line number Diff line number Diff line
@@ -25,8 +25,10 @@ import android.content.ActivityNotFoundException
import android.content.ComponentName
import android.os.PowerManager
import android.widget.RemoteViews
import com.android.internal.logging.UiEventLogger
import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.shared.log.CommunalUiEvent
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.media.controls.ui.MediaHost
import com.android.systemui.media.dagger.MediaModule
@@ -50,6 +52,7 @@ constructor(
    shadeViewController: Provider<ShadeViewController>,
    powerManager: PowerManager,
    @Named(MediaModule.COMMUNAL_HUB) mediaHost: MediaHost,
    private val uiEventLogger: UiEventLogger,
) : BaseCommunalViewModel(communalInteractor, shadeViewController, powerManager, mediaHost) {

    private companion object {
@@ -135,4 +138,16 @@ constructor(
        pendingConfiguration?.complete(resultCode)
            ?: throw IllegalStateException("No widget pending configuration")
    }

    override fun onReorderWidgetStart() {
        uiEventLogger.log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_START)
    }

    override fun onReorderWidgetEnd() {
        uiEventLogger.log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_FINISH)
    }

    override fun onReorderWidgetCancel() {
        uiEventLogger.log(CommunalUiEvent.COMMUNAL_HUB_REORDER_WIDGET_CANCEL)
    }
}