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 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.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,
+2 −3
Original line number Diff line number Diff line
@@ -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()
+9 −26
Original line number Diff line number Diff line
@@ -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
    }
}
+37 −26
Original line number Diff line number Diff line
@@ -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,10 +143,10 @@ 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>(
@@ -159,7 +168,6 @@ constructor(
                }
            }
    }
    }

    /**
     * Binds the footer (including its visibility) and dispose of the [DisposableHandle] when done.
@@ -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)
                }
            }
    }
+2 −2
Original line number Diff line number Diff line
@@ -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,
Loading