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.lifecycle.ExclusiveActivatable 20 import com.android.systemui.lifecycle.Hydrator 21 import com.android.systemui.qs.panels.domain.interactor.DynamicIconTilesInteractor 22 import dagger.assisted.AssistedFactory 23 import dagger.assisted.AssistedInject 24 import kotlinx.coroutines.awaitCancellation 25 import kotlinx.coroutines.coroutineScope 26 import kotlinx.coroutines.launch 27 28 /** View model to resize QS tiles down to icons when removed from the current tiles. */ 29 class DynamicIconTilesViewModel 30 @AssistedInject 31 constructor( 32 interactorFactory: DynamicIconTilesInteractor.Factory, 33 iconTilesViewModel: IconTilesViewModel, 34 ) : IconTilesViewModel by iconTilesViewModel, ExclusiveActivatable() { 35 private val hydrator = Hydrator("DynamicIconTilesViewModel") 36 private val interactor = interactorFactory.create() 37 38 val largeTilesState = 39 hydrator.hydratedStateOf(traceName = "largeTiles", source = iconTilesViewModel.largeTiles) 40 41 val largeTilesSpanState = 42 hydrator.hydratedStateOf( 43 traceName = "largeTilesSpan", 44 source = iconTilesViewModel.largeTilesSpan, 45 ) 46 onActivatednull47 override suspend fun onActivated(): Nothing { 48 coroutineScope { 49 launch { hydrator.activate() } 50 launch { interactor.activate() } 51 awaitCancellation() 52 } 53 } 54 55 @AssistedFactory 56 interface Factory { createnull57 fun create(): DynamicIconTilesViewModel 58 } 59 } 60