1 /* <lambda>null2 * 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.keyboard.stickykeys.ui.viewmodel 18 19 import com.android.systemui.dagger.qualifiers.Application 20 import com.android.systemui.keyboard.data.repository.KeyboardRepository 21 import com.android.systemui.keyboard.stickykeys.data.repository.StickyKeysRepository 22 import com.android.systemui.keyboard.stickykeys.shared.model.Locked 23 import com.android.systemui.keyboard.stickykeys.shared.model.ModifierKey 24 import kotlinx.coroutines.CoroutineScope 25 import kotlinx.coroutines.ExperimentalCoroutinesApi 26 import kotlinx.coroutines.flow.Flow 27 import kotlinx.coroutines.flow.SharingStarted 28 import kotlinx.coroutines.flow.flatMapLatest 29 import kotlinx.coroutines.flow.flowOf 30 import kotlinx.coroutines.flow.stateIn 31 import javax.inject.Inject 32 33 class StickyKeysIndicatorViewModel 34 @Inject 35 constructor( 36 stickyKeysRepository: StickyKeysRepository, 37 keyboardRepository: KeyboardRepository, 38 @Application applicationScope: CoroutineScope, 39 ) { 40 41 @OptIn(ExperimentalCoroutinesApi::class) 42 val indicatorContent: Flow<Map<ModifierKey, Locked>> = 43 keyboardRepository.isAnyKeyboardConnected 44 .flatMapLatest { keyboardPresent -> 45 if (keyboardPresent) stickyKeysRepository.settingEnabled else flowOf(false) 46 } 47 .flatMapLatest { enabled -> 48 if (enabled) stickyKeysRepository.stickyKeys else flowOf(emptyMap()) 49 } 50 .stateIn(applicationScope, SharingStarted.Lazily, emptyMap()) 51 } 52