• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.shared.condition
18 
19 /**
20  * A higher order [Condition] which combines multiple conditions with a specified
21  * [Evaluator.ConditionOperand].
22  */
23 internal class CombinedCondition
24 constructor(
25     private val conditions: Collection<Condition>,
26     @Evaluator.ConditionOperand private val operand: Int
27 ) : Condition(null, false), Condition.Callback {
28 
29     override fun start() {
30         onConditionChanged(this)
31         conditions.forEach { it.addCallback(this) }
32     }
33 
34     override fun onConditionChanged(condition: Condition) {
35         Evaluator.evaluate(conditions, operand)?.also { value -> updateCondition(value) }
36             ?: clearCondition()
37     }
38 
39     override fun stop() {
40         conditions.forEach { it.removeCallback(this) }
41     }
42 }
43