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.domain.model 18 19 import com.android.settingslib.graph.SignalDrawable 20 import com.android.systemui.log.table.Diffable 21 import com.android.systemui.log.table.TableRowLogger 22 23 /** A model that will be consumed by [SignalDrawable] to show the mobile triangle icon. */ 24 data class SignalIconModel( 25 val level: Int, 26 val numberOfLevels: Int, 27 val showExclamationMark: Boolean, 28 val carrierNetworkChange: Boolean, 29 ) : Diffable<SignalIconModel> { 30 // TODO(b/267767715): Can we implement [logDiffs] and [logFull] generically for data classes? 31 override fun logDiffs(prevVal: SignalIconModel, row: TableRowLogger) { 32 if (prevVal.level != level) { 33 row.logChange(COL_LEVEL, level) 34 } 35 if (prevVal.numberOfLevels != numberOfLevels) { 36 row.logChange(COL_NUM_LEVELS, numberOfLevels) 37 } 38 if (prevVal.showExclamationMark != showExclamationMark) { 39 row.logChange(COL_SHOW_EXCLAMATION, showExclamationMark) 40 } 41 if (prevVal.carrierNetworkChange != carrierNetworkChange) { 42 row.logChange(COL_CARRIER_NETWORK_CHANGE, carrierNetworkChange) 43 } 44 } 45 46 override fun logFull(row: TableRowLogger) { 47 row.logChange(COL_LEVEL, level) 48 row.logChange(COL_NUM_LEVELS, numberOfLevels) 49 row.logChange(COL_SHOW_EXCLAMATION, showExclamationMark) 50 row.logChange(COL_CARRIER_NETWORK_CHANGE, carrierNetworkChange) 51 } 52 53 /** Convert this model to an [Int] consumable by [SignalDrawable]. */ 54 fun toSignalDrawableState(): Int = 55 if (carrierNetworkChange) { 56 SignalDrawable.getCarrierChangeState(numberOfLevels) 57 } else { 58 SignalDrawable.getState(level, numberOfLevels, showExclamationMark) 59 } 60 61 companion object { 62 private const val COL_LEVEL = "level" 63 private const val COL_NUM_LEVELS = "numLevels" 64 private const val COL_SHOW_EXCLAMATION = "showExclamation" 65 private const val COL_CARRIER_NETWORK_CHANGE = "carrierNetworkChange" 66 } 67 } 68