1 /*
2 * 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 package com.android.systemui.keyguard.shared.model
17
18 import kotlinx.coroutines.flow.Flow
19 import kotlinx.coroutines.flow.filter
20
21 /** This information will flow from the [KeyguardTransitionRepository] to control the UI layer */
22 data class TransitionStep
23 @JvmOverloads
24 constructor(
25 val from: KeyguardState = KeyguardState.OFF,
26 val to: KeyguardState = KeyguardState.OFF,
27 val value: Float = 0f, // constrained [0.0, 1.0]
28 val transitionState: TransitionState = TransitionState.FINISHED,
29 val ownerName: String = "",
30 ) {
31 constructor(
32 info: TransitionInfo,
33 value: Float,
34 transitionState: TransitionState,
35 ) : this(info.from, info.to, value, transitionState, info.ownerName)
36
isTransitioningnull37 fun isTransitioning(from: KeyguardState? = null, to: KeyguardState? = null): Boolean {
38 return (from == null || this.from == from) && (to == null || this.to == to)
39 }
40
isFinishedInnull41 fun isFinishedIn(state: KeyguardState): Boolean {
42 return to == state && transitionState == TransitionState.FINISHED
43 }
44 }
45
filterStatenull46 fun Flow<TransitionStep>.filterState(transitionState: TransitionState) =
47 this.filter { it.transitionState == transitionState }
48