1 /* <lambda>null2 * Copyright (C) 2022 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.statusbar.pipeline.airplane.ui.viewmodel 18 19 import com.android.systemui.dagger.SysUISingleton 20 import com.android.systemui.dagger.qualifiers.Application 21 import com.android.systemui.log.table.TableLogBuffer 22 import com.android.systemui.log.table.logDiffsForTable 23 import com.android.systemui.statusbar.pipeline.airplane.domain.interactor.AirplaneModeInteractor 24 import com.android.systemui.statusbar.pipeline.dagger.AirplaneTableLog 25 import javax.inject.Inject 26 import kotlinx.coroutines.CoroutineScope 27 import kotlinx.coroutines.flow.SharingStarted 28 import kotlinx.coroutines.flow.StateFlow 29 import kotlinx.coroutines.flow.combine 30 import kotlinx.coroutines.flow.distinctUntilChanged 31 import kotlinx.coroutines.flow.stateIn 32 33 /** 34 * Models the UI state for the status bar airplane mode icon. 35 * 36 * IMPORTANT: This is currently *not* used to render any airplane mode information anywhere. See 37 * [com.android.systemui.statusbar.pipeline.airplane.data.repository.AirplaneModeRepository] for 38 * more details. 39 */ 40 interface AirplaneModeViewModel { 41 /** True if the airplane mode icon is currently visible in the status bar. */ 42 val isAirplaneModeIconVisible: StateFlow<Boolean> 43 } 44 45 @SysUISingleton 46 class AirplaneModeViewModelImpl 47 @Inject 48 constructor( 49 interactor: AirplaneModeInteractor, 50 @AirplaneTableLog logger: TableLogBuffer, 51 @Application private val scope: CoroutineScope, 52 ) : AirplaneModeViewModel { 53 override val isAirplaneModeIconVisible: StateFlow<Boolean> = 54 combine(interactor.isAirplaneMode, interactor.isForceHidden) { isAirplaneModenull55 isAirplaneMode, 56 isAirplaneIconForceHidden -> 57 isAirplaneMode && !isAirplaneIconForceHidden 58 } 59 .distinctUntilChanged() 60 .logDiffsForTable( 61 logger, 62 columnPrefix = "", 63 columnName = "isAirplaneModeIconVisible", 64 initialValue = false, 65 ) 66 .stateIn(scope, started = SharingStarted.WhileSubscribed(), initialValue = false) 67 } 68