1 /* 2 * Copyright (C) 2023 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.keyguard.data.repository 18 19 import com.android.keyguard.ClockEventController 20 import com.android.systemui.keyguard.shared.model.ClockSize 21 import com.android.systemui.keyguard.shared.model.ClockSizeSetting 22 import com.android.systemui.plugins.clocks.ClockController 23 import com.android.systemui.plugins.clocks.ClockId 24 import com.android.systemui.shared.clocks.DEFAULT_CLOCK_ID 25 import com.android.systemui.util.mockito.mock 26 import dagger.Binds 27 import dagger.Module 28 import kotlinx.coroutines.flow.Flow 29 import kotlinx.coroutines.flow.MutableStateFlow 30 import kotlinx.coroutines.flow.StateFlow 31 import org.mockito.Mockito 32 33 class FakeKeyguardClockRepository() : KeyguardClockRepository { 34 private val _clockSize = MutableStateFlow(ClockSize.LARGE) 35 override val clockSize: StateFlow<ClockSize> = _clockSize 36 37 private val _selectedClockSize = MutableStateFlow(ClockSizeSetting.DYNAMIC) 38 override val selectedClockSize = _selectedClockSize 39 40 private val _currentClockId = MutableStateFlow(DEFAULT_CLOCK_ID) 41 override val currentClockId: Flow<ClockId> = _currentClockId 42 43 private val _currentClock: MutableStateFlow<ClockController?> = MutableStateFlow(null) 44 override val currentClock = _currentClock 45 46 private val _previewClock = MutableStateFlow(Mockito.mock(ClockController::class.java)) 47 override val previewClock: Flow<ClockController> 48 get() = _previewClock 49 override val clockEventController: ClockEventController 50 get() = mock() 51 override val shouldForceSmallClock: Boolean 52 get() = _shouldForceSmallClock 53 private var _shouldForceSmallClock: Boolean = false 54 setClockSizenull55 override fun setClockSize(size: ClockSize) { 56 _clockSize.value = size 57 } 58 setSelectedClockSizenull59 fun setSelectedClockSize(size: ClockSizeSetting) { 60 _selectedClockSize.value = size 61 } 62 setCurrentClocknull63 fun setCurrentClock(clockController: ClockController) { 64 _currentClock.value = clockController 65 _currentClockId.value = clockController.config.id 66 } 67 setShouldForceSmallClocknull68 fun setShouldForceSmallClock(shouldForceSmallClock: Boolean) { 69 _shouldForceSmallClock = shouldForceSmallClock 70 } 71 } 72 73 @Module 74 interface FakeKeyguardClockRepositoryModule { bindFakenull75 @Binds fun bindFake(fake: FakeKeyguardClockRepository): KeyguardClockRepository 76 } 77