• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.statusbar.pipeline.mobile.ui.model
18 
19 import com.android.systemui.log.table.Diffable
20 import com.android.systemui.log.table.TableRowLogger
21 
22 /** A model that will be consumed by [SignalDrawable] to show the mobile triangle icon. */
23 data class SignalIconModel(
24     val level: Int,
25     val numberOfLevels: Int,
26     val showExclamationMark: Boolean,
27 ) : Diffable<SignalIconModel> {
28     // TODO(b/267767715): Can we implement [logDiffs] and [logFull] generically for data classes?
logDiffsnull29     override fun logDiffs(prevVal: SignalIconModel, row: TableRowLogger) {
30         if (prevVal.level != level) {
31             row.logChange(COL_LEVEL, level)
32         }
33         if (prevVal.numberOfLevels != numberOfLevels) {
34             row.logChange(COL_NUM_LEVELS, numberOfLevels)
35         }
36         if (prevVal.showExclamationMark != showExclamationMark) {
37             row.logChange(COL_SHOW_EXCLAMATION, showExclamationMark)
38         }
39     }
40 
logFullnull41     override fun logFull(row: TableRowLogger) {
42         row.logChange(COL_LEVEL, level)
43         row.logChange(COL_NUM_LEVELS, numberOfLevels)
44         row.logChange(COL_SHOW_EXCLAMATION, showExclamationMark)
45     }
46 
47     companion object {
48         /** Creates a [SignalIconModel] representing an empty and invalidated state. */
createEmptyStatenull49         fun createEmptyState(numberOfLevels: Int) =
50             SignalIconModel(level = 0, numberOfLevels, showExclamationMark = true)
51 
52         private const val COL_LEVEL = "level"
53         private const val COL_NUM_LEVELS = "numLevels"
54         private const val COL_SHOW_EXCLAMATION = "showExclamation"
55     }
56 }
57