1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.qs.panels.ui.viewmodel 18 19 import com.android.systemui.classifier.Classifier.QS_SWIPE_SIDE 20 import com.android.systemui.classifier.domain.interactor.FalsingInteractor 21 import com.android.systemui.development.ui.viewmodel.BuildNumberViewModel 22 import com.android.systemui.lifecycle.ExclusiveActivatable 23 import com.android.systemui.lifecycle.Hydrator 24 import com.android.systemui.media.controls.ui.controller.MediaHierarchyManager.Companion.LOCATION_QS 25 import com.android.systemui.qs.panels.ui.viewmodel.toolbar.EditModeButtonViewModel 26 import dagger.assisted.AssistedFactory 27 import dagger.assisted.AssistedInject 28 import kotlinx.coroutines.awaitCancellation 29 import kotlinx.coroutines.coroutineScope 30 import kotlinx.coroutines.launch 31 32 class PaginatedGridViewModel 33 @AssistedInject 34 constructor( 35 iconTilesViewModel: IconTilesViewModel, 36 columnsWithMediaViewModelFactory: QSColumnsViewModel.Factory, 37 inFirstPageViewModel: InFirstPageViewModel, 38 val buildNumberViewModelFactory: BuildNumberViewModel.Factory, 39 val editModeButtonViewModelFactory: EditModeButtonViewModel.Factory, 40 private val falsingInteractor: FalsingInteractor, 41 ) : IconTilesViewModel by iconTilesViewModel, ExclusiveActivatable() { 42 43 private val hydrator = Hydrator("PaginatedGridViewModel") 44 private val columnsWithMediaViewModel = columnsWithMediaViewModelFactory.create(LOCATION_QS) 45 46 var inFirstPage by inFirstPageViewModel::inFirstPage 47 48 val columns: Int 49 get() = columnsWithMediaViewModel.columns 50 registerSideSwipeGesturenull51 fun registerSideSwipeGesture() { 52 falsingInteractor.isFalseTouch(QS_SWIPE_SIDE) 53 } 54 onActivatednull55 override suspend fun onActivated(): Nothing { 56 coroutineScope { 57 launch { hydrator.activate() } 58 launch { columnsWithMediaViewModel.activate() } 59 awaitCancellation() 60 } 61 } 62 63 @AssistedFactory 64 interface Factory { createnull65 fun create(): PaginatedGridViewModel 66 } 67 } 68