diff options
7 files changed, 57 insertions, 61 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java index ea48fb4ffd92..086c32cbae5d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java @@ -60,7 +60,6 @@ import com.android.systemui.statusbar.notification.collection.render.Notificatio import com.android.systemui.statusbar.notification.data.NotificationDataLayerModule; import com.android.systemui.statusbar.notification.domain.NotificationDomainLayerModule; import com.android.systemui.statusbar.notification.domain.interactor.NotificationLaunchAnimationInteractor; -import com.android.systemui.statusbar.notification.footer.ui.viewmodel.FooterViewModelModule; import com.android.systemui.statusbar.notification.headsup.HeadsUpManager; import com.android.systemui.statusbar.notification.icon.ConversationIconManager; import com.android.systemui.statusbar.notification.icon.IconManager; @@ -109,7 +108,6 @@ import javax.inject.Provider; * Dagger Module for classes found within the com.android.systemui.statusbar.notification package. */ @Module(includes = { - FooterViewModelModule.class, KeyguardNotificationVisibilityProviderModule.class, NotificationDataLayerModule.class, NotificationDomainLayerModule.class, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/view/FooterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/view/FooterView.java index a670f69df601..c88dd7af6b24 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/view/FooterView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/view/FooterView.java @@ -40,6 +40,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import com.android.systemui.res.R; +import com.android.systemui.scene.shared.flag.SceneContainerFlag; import com.android.systemui.statusbar.notification.ColorUpdateLogger; import com.android.systemui.statusbar.notification.footer.shared.NotifRedesignFooter; import com.android.systemui.statusbar.notification.row.FooterViewButton; @@ -333,11 +334,9 @@ public class FooterView extends StackScrollerDecorView { /** * Whether the touch is outside the Clear all button. - * - * TODO(b/293167744): This is an artifact from the time when we could press underneath the - * shade to dismiss it. Check if it's safe to remove. */ public boolean isOnEmptySpace(float touchX, float touchY) { + SceneContainerFlag.assertInLegacyMode(); return touchX < mContent.getX() || touchX > mContent.getX() + mContent.getWidth() || touchY < mContent.getY() diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModel.kt index 5696e9f0c5a2..c895c41960d4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModel.kt @@ -19,7 +19,6 @@ package com.android.systemui.statusbar.notification.footer.ui.viewmodel import android.content.Intent import android.provider.Settings import com.android.internal.jank.InteractionJankMonitor -import com.android.systemui.dagger.SysUISingleton import com.android.systemui.res.R import com.android.systemui.shade.domain.interactor.ShadeInteractor import com.android.systemui.shared.notifications.domain.interactor.NotificationSettingsInteractor @@ -32,10 +31,8 @@ import com.android.systemui.util.kotlin.sample import com.android.systemui.util.ui.AnimatableEvent import com.android.systemui.util.ui.AnimatedValue import com.android.systemui.util.ui.toAnimatedValueFlow -import dagger.Module -import dagger.Provides -import java.util.Optional -import javax.inject.Provider +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged @@ -44,7 +41,9 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart /** ViewModel for [FooterView]. */ -class FooterViewModel( +class FooterViewModel +@AssistedInject +constructor( activeNotificationsInteractor: ActiveNotificationsInteractor, notificationSettingsInteractor: NotificationSettingsInteractor, seenNotificationsInteractor: SeenNotificationsInteractor, @@ -141,25 +140,9 @@ class FooterViewModel( AnimatedValue.NotAnimating(!messageVisible) }, ) -} -// TODO: b/293167744 - remove this, use new viewmodel style -@Module -object FooterViewModelModule { - @Provides - @SysUISingleton - fun provideOptional( - activeNotificationsInteractor: Provider<ActiveNotificationsInteractor>, - notificationSettingsInteractor: Provider<NotificationSettingsInteractor>, - seenNotificationsInteractor: Provider<SeenNotificationsInteractor>, - shadeInteractor: Provider<ShadeInteractor>, - ): Optional<FooterViewModel> = - Optional.of( - FooterViewModel( - activeNotificationsInteractor.get(), - notificationSettingsInteractor.get(), - seenNotificationsInteractor.get(), - shadeInteractor.get(), - ) - ) + @AssistedFactory + interface Factory { + fun create(): FooterViewModel + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt index 1d7e658932ac..6385d53dbc8b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt @@ -99,6 +99,9 @@ constructor( .inflate(R.layout.status_bar_notification_shelf, view, false) as NotificationShelf view.setShelf(shelf) + // Create viewModels once, and only when needed. + val footerViewModel by lazy { viewModel.footerViewModelFactory.create() } + val emptyShadeViewModel by lazy { viewModel.emptyShadeViewModelFactory.create() } view.repeatWhenAttached { lifecycleScope.launch { if (SceneContainerFlag.isEnabled) { @@ -109,12 +112,18 @@ constructor( val hasNonClearableSilentNotifications: StateFlow<Boolean> = viewModel.hasNonClearableSilentNotifications.stateIn(this) - launch { reinflateAndBindFooter(view, hasNonClearableSilentNotifications) } + launch { + reinflateAndBindFooter( + footerViewModel, + view, + hasNonClearableSilentNotifications, + ) + } launch { if (ModesEmptyShadeFix.isEnabled) { - reinflateAndBindEmptyShade(view) + reinflateAndBindEmptyShade(emptyShadeViewModel, view) } else { - bindEmptyShadeLegacy(viewModel.emptyShadeViewFactory.create(), view) + bindEmptyShadeLegacy(emptyShadeViewModel, view) } } launch { bindSilentHeaderClickListener(view, hasNonClearableSilentNotifications) } @@ -134,31 +143,30 @@ constructor( } private suspend fun reinflateAndBindFooter( + footerViewModel: FooterViewModel, parentView: NotificationStackScrollLayout, hasNonClearableSilentNotifications: StateFlow<Boolean>, ) { - viewModel.footer.getOrNull()?.let { footerViewModel -> - // The footer needs to be re-inflated every time the theme or the font size changes. - configuration - .inflateLayout<FooterView>( - if (NotifRedesignFooter.isEnabled) R.layout.notification_2025_footer - else R.layout.status_bar_notification_footer, - parentView, - attachToRoot = false, - ) - .flowOn(backgroundDispatcher) - .collectLatest { footerView: FooterView -> - traceAsync("bind FooterView") { - parentView.setFooterView(footerView) - bindFooter( - footerView, - footerViewModel, - parentView, - hasNonClearableSilentNotifications, - ) - } + // The footer needs to be re-inflated every time the theme or the font size changes. + configuration + .inflateLayout<FooterView>( + if (NotifRedesignFooter.isEnabled) R.layout.notification_2025_footer + else R.layout.status_bar_notification_footer, + parentView, + attachToRoot = false, + ) + .flowOn(backgroundDispatcher) + .collectLatest { footerView: FooterView -> + traceAsync("bind FooterView") { + parentView.setFooterView(footerView) + bindFooter( + footerView, + footerViewModel, + parentView, + hasNonClearableSilentNotifications, + ) } - } + } } /** @@ -219,7 +227,10 @@ constructor( notificationActivityStarter.get().startHistoryIntent(view, /* showHistory= */ true) } - private suspend fun reinflateAndBindEmptyShade(parentView: NotificationStackScrollLayout) { + private suspend fun reinflateAndBindEmptyShade( + emptyShadeViewModel: EmptyShadeViewModel, + parentView: NotificationStackScrollLayout, + ) { ModesEmptyShadeFix.assertInNewMode() // The empty shade needs to be re-inflated every time the theme or the font size // changes. @@ -233,7 +244,7 @@ constructor( .collectLatest { emptyShadeView: EmptyShadeView -> traceAsync("bind EmptyShadeView") { parentView.setEmptyShadeView(emptyShadeView) - bindEmptyShade(emptyShadeView, viewModel.emptyShadeViewFactory.create()) + bindEmptyShade(emptyShadeView, emptyShadeViewModel) } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationListViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationListViewModel.kt index fcc671a5bae6..5ed1889de01e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationListViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationListViewModel.kt @@ -56,8 +56,8 @@ class NotificationListViewModel constructor( val shelf: NotificationShelfViewModel, val hideListViewModel: HideListViewModel, - val footer: Optional<FooterViewModel>, - val emptyShadeViewFactory: EmptyShadeViewModel.Factory, + val footerViewModelFactory: FooterViewModel.Factory, + val emptyShadeViewModelFactory: EmptyShadeViewModel.Factory, val logger: Optional<NotificationLoggerViewModel>, activeNotificationsInteractor: ActiveNotificationsInteractor, notificationStackInteractor: NotificationStackInteractor, diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModelKosmos.kt index 01cac4c1e030..99323dbd7cce 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModelKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/footer/ui/viewmodel/FooterViewModelKosmos.kt @@ -31,3 +31,8 @@ val Kosmos.footerViewModel by Fixture { shadeInteractor = shadeInteractor, ) } +val Kosmos.footerViewModelFactory: FooterViewModel.Factory by Fixture { + object : FooterViewModel.Factory { + override fun create() = footerViewModel + } +} diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationListViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationListViewModelKosmos.kt index c3bc744e09b0..fbc2a21b0888 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationListViewModelKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationListViewModelKosmos.kt @@ -24,7 +24,7 @@ import com.android.systemui.shade.domain.interactor.shadeInteractor import com.android.systemui.statusbar.domain.interactor.remoteInputInteractor import com.android.systemui.statusbar.notification.domain.interactor.activeNotificationsInteractor import com.android.systemui.statusbar.notification.emptyshade.ui.viewmodel.emptyShadeViewModelFactory -import com.android.systemui.statusbar.notification.footer.ui.viewmodel.footerViewModel +import com.android.systemui.statusbar.notification.footer.ui.viewmodel.footerViewModelFactory import com.android.systemui.statusbar.notification.shelf.ui.viewmodel.notificationShelfViewModel import com.android.systemui.statusbar.notification.stack.domain.interactor.headsUpNotificationInteractor import com.android.systemui.statusbar.notification.stack.domain.interactor.notificationStackInteractor @@ -35,7 +35,7 @@ val Kosmos.notificationListViewModel by Fixture { NotificationListViewModel( notificationShelfViewModel, hideListViewModel, - Optional.of(footerViewModel), + footerViewModelFactory, emptyShadeViewModelFactory, Optional.of(notificationListLoggerViewModel), activeNotificationsInteractor, |