1 package com.android.systemui.bouncer.ui.binder 2 3 import android.view.ViewGroup 4 import com.android.keyguard.KeyguardMessageAreaController 5 import com.android.keyguard.ViewMediatorCallback 6 import com.android.keyguard.dagger.KeyguardBouncerComponent 7 import com.android.systemui.authentication.domain.interactor.AuthenticationInteractor 8 import com.android.systemui.bouncer.domain.interactor.BouncerMessageInteractor 9 import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor 10 import com.android.systemui.bouncer.shared.flag.ComposeBouncerFlags 11 import com.android.systemui.bouncer.ui.BouncerDialogFactory 12 import com.android.systemui.bouncer.ui.viewmodel.BouncerViewModel 13 import com.android.systemui.bouncer.ui.viewmodel.KeyguardBouncerViewModel 14 import com.android.systemui.dagger.SysUISingleton 15 import com.android.systemui.keyguard.ui.viewmodel.PrimaryBouncerToGoneTransitionViewModel 16 import com.android.systemui.log.BouncerLogger 17 import com.android.systemui.user.domain.interactor.SelectedUserInteractor 18 import dagger.Lazy 19 import javax.inject.Inject 20 import kotlinx.coroutines.ExperimentalCoroutinesApi 21 22 /** Helper data class that allows to lazy load all the dependencies of the legacy bouncer. */ 23 @OptIn(ExperimentalCoroutinesApi::class) 24 @SysUISingleton 25 data class LegacyBouncerDependencies 26 @Inject 27 constructor( 28 val viewModel: KeyguardBouncerViewModel, 29 val primaryBouncerToGoneTransitionViewModel: PrimaryBouncerToGoneTransitionViewModel, 30 val componentFactory: KeyguardBouncerComponent.Factory, 31 val messageAreaControllerFactory: KeyguardMessageAreaController.Factory, 32 val bouncerMessageInteractor: BouncerMessageInteractor, 33 val bouncerLogger: BouncerLogger, 34 val selectedUserInteractor: SelectedUserInteractor, 35 ) 36 37 /** Helper data class that allows to lazy load all the dependencies of the compose based bouncer. */ 38 @SysUISingleton 39 data class ComposeBouncerDependencies 40 @Inject 41 constructor( 42 val legacyInteractor: PrimaryBouncerInteractor, 43 val viewModel: BouncerViewModel, 44 val dialogFactory: BouncerDialogFactory, 45 val authenticationInteractor: AuthenticationInteractor, 46 val viewMediatorCallback: ViewMediatorCallback?, 47 val selectedUserInteractor: SelectedUserInteractor, 48 ) 49 50 /** 51 * Toggles between the compose and non compose version of the bouncer, instantiating only the 52 * dependencies required for each. 53 */ 54 @SysUISingleton 55 class BouncerViewBinder 56 @Inject 57 constructor( 58 private val composeBouncerFlags: ComposeBouncerFlags, 59 private val legacyBouncerDependencies: Lazy<LegacyBouncerDependencies>, 60 private val composeBouncerDependencies: Lazy<ComposeBouncerDependencies>, 61 ) { bindnull62 fun bind(view: ViewGroup) { 63 if (composeBouncerFlags.isOnlyComposeBouncerEnabled()) { 64 val deps = composeBouncerDependencies.get() 65 ComposeBouncerViewBinder.bind( 66 view, 67 deps.legacyInteractor, 68 deps.viewModel, 69 deps.dialogFactory, 70 deps.authenticationInteractor, 71 deps.selectedUserInteractor, 72 deps.viewMediatorCallback, 73 ) 74 } else { 75 val deps = legacyBouncerDependencies.get() 76 KeyguardBouncerViewBinder.bind( 77 view, 78 deps.viewModel, 79 deps.primaryBouncerToGoneTransitionViewModel, 80 deps.componentFactory, 81 deps.messageAreaControllerFactory, 82 deps.bouncerMessageInteractor, 83 deps.bouncerLogger, 84 deps.selectedUserInteractor, 85 ) 86 } 87 } 88 } 89