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

Commit 7c0a02a7 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Remove remaining references to the footer refactor.

- Remove TODO for isOnEmptySpace (this is only used when scene container
  is off, so it will be removed as part of that refactor)
- Update the way we inject the FooterViewModel to use the recommended
  factory
- Make sure we only create one instance of the viewModel and reuse it;
do the same for the empty shade view model while we're at it

Bug: 293167744
Test: builds
Flag: EXEMPT trivial dagger change
Change-Id: Iaa75b68a3d95d3d0a624f0e59d0d5faf95d5bdfd
parent af5b6ce5
Loading
Loading
Loading
Loading
+0 −2
Original line number Original line Diff line number Diff line
@@ -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.data.NotificationDataLayerModule;
import com.android.systemui.statusbar.notification.domain.NotificationDomainLayerModule;
import com.android.systemui.statusbar.notification.domain.NotificationDomainLayerModule;
import com.android.systemui.statusbar.notification.domain.interactor.NotificationLaunchAnimationInteractor;
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.headsup.HeadsUpManager;
import com.android.systemui.statusbar.notification.icon.ConversationIconManager;
import com.android.systemui.statusbar.notification.icon.ConversationIconManager;
import com.android.systemui.statusbar.notification.icon.IconManager;
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.
 * Dagger Module for classes found within the com.android.systemui.statusbar.notification package.
 */
 */
@Module(includes = {
@Module(includes = {
        FooterViewModelModule.class,
        KeyguardNotificationVisibilityProviderModule.class,
        KeyguardNotificationVisibilityProviderModule.class,
        NotificationDataLayerModule.class,
        NotificationDataLayerModule.class,
        NotificationDomainLayerModule.class,
        NotificationDomainLayerModule.class,
+2 −3
Original line number Original line Diff line number Diff line
@@ -40,6 +40,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.NonNull;


import com.android.systemui.res.R;
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.ColorUpdateLogger;
import com.android.systemui.statusbar.notification.footer.shared.NotifRedesignFooter;
import com.android.systemui.statusbar.notification.footer.shared.NotifRedesignFooter;
import com.android.systemui.statusbar.notification.row.FooterViewButton;
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.
     * 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) {
    public boolean isOnEmptySpace(float touchX, float touchY) {
        SceneContainerFlag.assertInLegacyMode();
        return touchX < mContent.getX()
        return touchX < mContent.getX()
                || touchX > mContent.getX() + mContent.getWidth()
                || touchX > mContent.getX() + mContent.getWidth()
                || touchY < mContent.getY()
                || touchY < mContent.getY()
+9 −26
Original line number Original line Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.statusbar.notification.footer.ui.viewmodel
import android.content.Intent
import android.content.Intent
import android.provider.Settings
import android.provider.Settings
import com.android.internal.jank.InteractionJankMonitor
import com.android.internal.jank.InteractionJankMonitor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.res.R
import com.android.systemui.res.R
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shared.notifications.domain.interactor.NotificationSettingsInteractor
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.AnimatableEvent
import com.android.systemui.util.ui.AnimatedValue
import com.android.systemui.util.ui.AnimatedValue
import com.android.systemui.util.ui.toAnimatedValueFlow
import com.android.systemui.util.ui.toAnimatedValueFlow
import dagger.Module
import dagger.assisted.AssistedFactory
import dagger.Provides
import dagger.assisted.AssistedInject
import java.util.Optional
import javax.inject.Provider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChanged
@@ -44,7 +41,9 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.onStart


/** ViewModel for [FooterView]. */
/** ViewModel for [FooterView]. */
class FooterViewModel(
class FooterViewModel
@AssistedInject
constructor(
    activeNotificationsInteractor: ActiveNotificationsInteractor,
    activeNotificationsInteractor: ActiveNotificationsInteractor,
    notificationSettingsInteractor: NotificationSettingsInteractor,
    notificationSettingsInteractor: NotificationSettingsInteractor,
    seenNotificationsInteractor: SeenNotificationsInteractor,
    seenNotificationsInteractor: SeenNotificationsInteractor,
@@ -141,25 +140,9 @@ class FooterViewModel(
                    AnimatedValue.NotAnimating(!messageVisible)
                    AnimatedValue.NotAnimating(!messageVisible)
                },
                },
        )
        )
}


// TODO: b/293167744 - remove this, use new viewmodel style
    @AssistedFactory
@Module
    interface Factory {
object FooterViewModelModule {
        fun create(): FooterViewModel
    @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(),
            )
        )
}
}
+37 −26
Original line number Original line Diff line number Diff line
@@ -99,6 +99,9 @@ constructor(
                .inflate(R.layout.status_bar_notification_shelf, view, false) as NotificationShelf
                .inflate(R.layout.status_bar_notification_shelf, view, false) as NotificationShelf
        view.setShelf(shelf)
        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 {
        view.repeatWhenAttached {
            lifecycleScope.launch {
            lifecycleScope.launch {
                if (SceneContainerFlag.isEnabled) {
                if (SceneContainerFlag.isEnabled) {
@@ -109,12 +112,18 @@ constructor(


                val hasNonClearableSilentNotifications: StateFlow<Boolean> =
                val hasNonClearableSilentNotifications: StateFlow<Boolean> =
                    viewModel.hasNonClearableSilentNotifications.stateIn(this)
                    viewModel.hasNonClearableSilentNotifications.stateIn(this)
                launch { reinflateAndBindFooter(view, hasNonClearableSilentNotifications) }
                launch {
                    reinflateAndBindFooter(
                        footerViewModel,
                        view,
                        hasNonClearableSilentNotifications,
                    )
                }
                launch {
                launch {
                    if (ModesEmptyShadeFix.isEnabled) {
                    if (ModesEmptyShadeFix.isEnabled) {
                        reinflateAndBindEmptyShade(view)
                        reinflateAndBindEmptyShade(emptyShadeViewModel, view)
                    } else {
                    } else {
                        bindEmptyShadeLegacy(viewModel.emptyShadeViewFactory.create(), view)
                        bindEmptyShadeLegacy(emptyShadeViewModel, view)
                    }
                    }
                }
                }
                launch { bindSilentHeaderClickListener(view, hasNonClearableSilentNotifications) }
                launch { bindSilentHeaderClickListener(view, hasNonClearableSilentNotifications) }
@@ -134,10 +143,10 @@ constructor(
    }
    }


    private suspend fun reinflateAndBindFooter(
    private suspend fun reinflateAndBindFooter(
        footerViewModel: FooterViewModel,
        parentView: NotificationStackScrollLayout,
        parentView: NotificationStackScrollLayout,
        hasNonClearableSilentNotifications: StateFlow<Boolean>,
        hasNonClearableSilentNotifications: StateFlow<Boolean>,
    ) {
    ) {
        viewModel.footer.getOrNull()?.let { footerViewModel ->
        // The footer needs to be re-inflated every time the theme or the font size changes.
        // The footer needs to be re-inflated every time the theme or the font size changes.
        configuration
        configuration
            .inflateLayout<FooterView>(
            .inflateLayout<FooterView>(
@@ -159,7 +168,6 @@ constructor(
                }
                }
            }
            }
    }
    }
    }


    /**
    /**
     * Binds the footer (including its visibility) and dispose of the [DisposableHandle] when done.
     * Binds the footer (including its visibility) and dispose of the [DisposableHandle] when done.
@@ -219,7 +227,10 @@ constructor(
        notificationActivityStarter.get().startHistoryIntent(view, /* showHistory= */ true)
        notificationActivityStarter.get().startHistoryIntent(view, /* showHistory= */ true)
    }
    }


    private suspend fun reinflateAndBindEmptyShade(parentView: NotificationStackScrollLayout) {
    private suspend fun reinflateAndBindEmptyShade(
        emptyShadeViewModel: EmptyShadeViewModel,
        parentView: NotificationStackScrollLayout,
    ) {
        ModesEmptyShadeFix.assertInNewMode()
        ModesEmptyShadeFix.assertInNewMode()
        // The empty shade needs to be re-inflated every time the theme or the font size
        // The empty shade needs to be re-inflated every time the theme or the font size
        // changes.
        // changes.
@@ -233,7 +244,7 @@ constructor(
            .collectLatest { emptyShadeView: EmptyShadeView ->
            .collectLatest { emptyShadeView: EmptyShadeView ->
                traceAsync("bind EmptyShadeView") {
                traceAsync("bind EmptyShadeView") {
                    parentView.setEmptyShadeView(emptyShadeView)
                    parentView.setEmptyShadeView(emptyShadeView)
                    bindEmptyShade(emptyShadeView, viewModel.emptyShadeViewFactory.create())
                    bindEmptyShade(emptyShadeView, emptyShadeViewModel)
                }
                }
            }
            }
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -56,8 +56,8 @@ class NotificationListViewModel
constructor(
constructor(
    val shelf: NotificationShelfViewModel,
    val shelf: NotificationShelfViewModel,
    val hideListViewModel: HideListViewModel,
    val hideListViewModel: HideListViewModel,
    val footer: Optional<FooterViewModel>,
    val footerViewModelFactory: FooterViewModel.Factory,
    val emptyShadeViewFactory: EmptyShadeViewModel.Factory,
    val emptyShadeViewModelFactory: EmptyShadeViewModel.Factory,
    val logger: Optional<NotificationLoggerViewModel>,
    val logger: Optional<NotificationLoggerViewModel>,
    activeNotificationsInteractor: ActiveNotificationsInteractor,
    activeNotificationsInteractor: ActiveNotificationsInteractor,
    notificationStackInteractor: NotificationStackInteractor,
    notificationStackInteractor: NotificationStackInteractor,
Loading