Loading packages/SystemUI/multivalentTests/src/com/android/systemui/media/controls/ui/viewmodel/MediaCarouselViewModelTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ class MediaCarouselViewModelTest : SysuiTestCase() { assertThat(mediaControl2.instanceId).isEqualTo(instanceId2) assertThat(mediaControl1.instanceId).isEqualTo(instanceId1) underTest.onAttached() underTest.onReorderingAllowed() mediaControl1 = sortedMedia?.get(0) as MediaCommonViewModel.MediaControl mediaControl2 = sortedMedia?.get(1) as MediaCommonViewModel.MediaControl Loading packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt +21 −9 Original line number Diff line number Diff line Loading @@ -308,7 +308,11 @@ constructor( * It will be called when the container is out of view. */ lateinit var updateUserVisibility: () -> Unit lateinit var updateHostVisibility: () -> Unit var updateHostVisibility: () -> Unit = {} set(value) { field = value mediaCarouselViewModel.updateHostVisibility = value } private val isReorderingAllowed: Boolean get() = visualStabilityProvider.isReorderingAllowed Loading Loading @@ -345,6 +349,20 @@ constructor( configurationController.addCallback(configListener) if (!mediaFlags.isMediaControlsRefactorEnabled()) { setUpListeners() } else { val visualStabilityCallback = OnReorderingAllowedListener { mediaCarouselViewModel.onReorderingAllowed() // Update user visibility so that no extra impression will be logged when // activeMediaIndex resets to 0 if (this::updateUserVisibility.isInitialized) { updateUserVisibility() } // Let's reset our scroll position mediaCarouselScrollHandler.scrollToStart() } visualStabilityProvider.addPersistentReorderingAllowedListener(visualStabilityCallback) } mediaFrame.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> // The pageIndicator is not laid out yet when we get the current state update, Loading @@ -366,10 +384,6 @@ constructor( ) keyguardUpdateMonitor.registerCallback(keyguardUpdateMonitorCallback) mediaCarousel.repeatWhenAttached { if (mediaFlags.isMediaControlsRefactorEnabled()) { mediaCarouselViewModel.onAttached() mediaCarouselScrollHandler.scrollToStart() } repeatOnLifecycle(Lifecycle.State.STARTED) { listenForAnyStateToGoneKeyguardTransition(this) listenForAnyStateToLockscreenTransition(this) Loading Loading @@ -592,10 +606,8 @@ constructor( if (!immediately) { // Although it wasn't requested, we were able to process the removal // immediately since reordering is allowed. So, notify hosts to update if (this@MediaCarouselController::updateHostVisibility.isInitialized) { updateHostVisibility() } } } else { keysNeedRemoval.add(key) } Loading Loading @@ -751,6 +763,7 @@ constructor( } } viewController.setListening(mediaCarouselScrollHandler.visibleToUser && currentlyExpanded) controllerByViewModel[commonViewModel] = viewController updateViewControllerToState(viewController, noAnimation = true) updatePageIndicator() if ( Loading @@ -764,7 +777,6 @@ constructor( mediaCarouselScrollHandler.onPlayersChanged() mediaFrame.requiresRemeasuring = true commonViewModel.onAdded(commonViewModel) controllerByViewModel[commonViewModel] = viewController } private fun onUpdated(commonViewModel: MediaCommonViewModel) { Loading packages/SystemUI/src/com/android/systemui/media/controls/ui/viewmodel/MediaCarouselViewModel.kt +20 −9 Original line number Diff line number Diff line Loading @@ -57,12 +57,12 @@ constructor( val mediaItems: StateFlow<List<MediaCommonViewModel>> = interactor.currentMedia .map { sortedItems -> buildList { val mediaList = buildList { sortedItems.forEach { commonModel -> // When view is started we should make sure to clean models that are pending // removal. // This action should only be triggered once. if (!isAttached || !modelsPendingRemoval.contains(commonModel)) { if (!allowReorder || !modelsPendingRemoval.contains(commonModel)) { when (commonModel) { is MediaCommonModel.MediaControl -> add(toViewModel(commonModel)) is MediaCommonModel.MediaRecommendations -> Loading @@ -70,11 +70,16 @@ constructor( } } } if (isAttached) { modelsPendingRemoval.clear() } isAttached = false if (allowReorder) { if (modelsPendingRemoval.size > 0) { updateHostVisibility() } modelsPendingRemoval.clear() } allowReorder = false mediaList } .stateIn( scope = applicationScope, Loading @@ -82,6 +87,8 @@ constructor( initialValue = emptyList(), ) var updateHostVisibility: () -> Unit = {} private val mediaControlByInstanceId = mutableMapOf<InstanceId, MediaCommonViewModel.MediaControl>() Loading @@ -89,15 +96,15 @@ constructor( private var modelsPendingRemoval: MutableSet<MediaCommonModel> = mutableSetOf() private var isAttached = false private var allowReorder = false fun onSwipeToDismiss() { logger.logSwipeDismiss() interactor.onSwipeToDismiss() } fun onAttached() { isAttached = true fun onReorderingAllowed() { allowReorder = true interactor.reorderMedia() } Loading Loading @@ -194,7 +201,11 @@ constructor( ) { if (immediatelyRemove || isReorderingAllowed()) { interactor.dismissSmartspaceRecommendation(commonModel.recsLoadingModel.key, 0L) // TODO if not immediate remove update host visibility if (!immediatelyRemove) { // Although it wasn't requested, we were able to process the removal // immediately since reordering is allowed. So, notify hosts to update updateHostVisibility() } } else { modelsPendingRemoval.add(commonModel) } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/media/controls/ui/viewmodel/MediaCarouselViewModelTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ class MediaCarouselViewModelTest : SysuiTestCase() { assertThat(mediaControl2.instanceId).isEqualTo(instanceId2) assertThat(mediaControl1.instanceId).isEqualTo(instanceId1) underTest.onAttached() underTest.onReorderingAllowed() mediaControl1 = sortedMedia?.get(0) as MediaCommonViewModel.MediaControl mediaControl2 = sortedMedia?.get(1) as MediaCommonViewModel.MediaControl Loading
packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaCarouselController.kt +21 −9 Original line number Diff line number Diff line Loading @@ -308,7 +308,11 @@ constructor( * It will be called when the container is out of view. */ lateinit var updateUserVisibility: () -> Unit lateinit var updateHostVisibility: () -> Unit var updateHostVisibility: () -> Unit = {} set(value) { field = value mediaCarouselViewModel.updateHostVisibility = value } private val isReorderingAllowed: Boolean get() = visualStabilityProvider.isReorderingAllowed Loading Loading @@ -345,6 +349,20 @@ constructor( configurationController.addCallback(configListener) if (!mediaFlags.isMediaControlsRefactorEnabled()) { setUpListeners() } else { val visualStabilityCallback = OnReorderingAllowedListener { mediaCarouselViewModel.onReorderingAllowed() // Update user visibility so that no extra impression will be logged when // activeMediaIndex resets to 0 if (this::updateUserVisibility.isInitialized) { updateUserVisibility() } // Let's reset our scroll position mediaCarouselScrollHandler.scrollToStart() } visualStabilityProvider.addPersistentReorderingAllowedListener(visualStabilityCallback) } mediaFrame.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> // The pageIndicator is not laid out yet when we get the current state update, Loading @@ -366,10 +384,6 @@ constructor( ) keyguardUpdateMonitor.registerCallback(keyguardUpdateMonitorCallback) mediaCarousel.repeatWhenAttached { if (mediaFlags.isMediaControlsRefactorEnabled()) { mediaCarouselViewModel.onAttached() mediaCarouselScrollHandler.scrollToStart() } repeatOnLifecycle(Lifecycle.State.STARTED) { listenForAnyStateToGoneKeyguardTransition(this) listenForAnyStateToLockscreenTransition(this) Loading Loading @@ -592,10 +606,8 @@ constructor( if (!immediately) { // Although it wasn't requested, we were able to process the removal // immediately since reordering is allowed. So, notify hosts to update if (this@MediaCarouselController::updateHostVisibility.isInitialized) { updateHostVisibility() } } } else { keysNeedRemoval.add(key) } Loading Loading @@ -751,6 +763,7 @@ constructor( } } viewController.setListening(mediaCarouselScrollHandler.visibleToUser && currentlyExpanded) controllerByViewModel[commonViewModel] = viewController updateViewControllerToState(viewController, noAnimation = true) updatePageIndicator() if ( Loading @@ -764,7 +777,6 @@ constructor( mediaCarouselScrollHandler.onPlayersChanged() mediaFrame.requiresRemeasuring = true commonViewModel.onAdded(commonViewModel) controllerByViewModel[commonViewModel] = viewController } private fun onUpdated(commonViewModel: MediaCommonViewModel) { Loading
packages/SystemUI/src/com/android/systemui/media/controls/ui/viewmodel/MediaCarouselViewModel.kt +20 −9 Original line number Diff line number Diff line Loading @@ -57,12 +57,12 @@ constructor( val mediaItems: StateFlow<List<MediaCommonViewModel>> = interactor.currentMedia .map { sortedItems -> buildList { val mediaList = buildList { sortedItems.forEach { commonModel -> // When view is started we should make sure to clean models that are pending // removal. // This action should only be triggered once. if (!isAttached || !modelsPendingRemoval.contains(commonModel)) { if (!allowReorder || !modelsPendingRemoval.contains(commonModel)) { when (commonModel) { is MediaCommonModel.MediaControl -> add(toViewModel(commonModel)) is MediaCommonModel.MediaRecommendations -> Loading @@ -70,11 +70,16 @@ constructor( } } } if (isAttached) { modelsPendingRemoval.clear() } isAttached = false if (allowReorder) { if (modelsPendingRemoval.size > 0) { updateHostVisibility() } modelsPendingRemoval.clear() } allowReorder = false mediaList } .stateIn( scope = applicationScope, Loading @@ -82,6 +87,8 @@ constructor( initialValue = emptyList(), ) var updateHostVisibility: () -> Unit = {} private val mediaControlByInstanceId = mutableMapOf<InstanceId, MediaCommonViewModel.MediaControl>() Loading @@ -89,15 +96,15 @@ constructor( private var modelsPendingRemoval: MutableSet<MediaCommonModel> = mutableSetOf() private var isAttached = false private var allowReorder = false fun onSwipeToDismiss() { logger.logSwipeDismiss() interactor.onSwipeToDismiss() } fun onAttached() { isAttached = true fun onReorderingAllowed() { allowReorder = true interactor.reorderMedia() } Loading Loading @@ -194,7 +201,11 @@ constructor( ) { if (immediatelyRemove || isReorderingAllowed()) { interactor.dismissSmartspaceRecommendation(commonModel.recsLoadingModel.key, 0L) // TODO if not immediate remove update host visibility if (!immediatelyRemove) { // Although it wasn't requested, we were able to process the removal // immediately since reordering is allowed. So, notify hosts to update updateHostVisibility() } } else { modelsPendingRemoval.add(commonModel) } Loading