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 
17 package com.android.systemui.statusbar.pipeline.wifi.ui.viewmodel
18 
19 import android.graphics.Color
20 import com.android.systemui.statusbar.phone.StatusBarLocation
21 import java.lang.IllegalArgumentException
22 
23 /**
24  * A view model for a wifi icon in a specific location. This allows us to control parameters that
25  * are location-specific (for example, different tints of the icon in different locations).
26  *
27  * Must be subclassed for each distinct location.
28  */
29 abstract class LocationBasedWifiViewModel(
30     private val commonImpl: WifiViewModelCommon,
31 ) : WifiViewModelCommon by commonImpl {
32     val defaultColor: Int = Color.WHITE
33 
34     companion object {
35         /**
36          * Returns a new instance of [LocationBasedWifiViewModel] that's specific to the given
37          * [location].
38          */
viewModelForLocationnull39         fun viewModelForLocation(
40             commonImpl: WifiViewModelCommon,
41             location: StatusBarLocation,
42         ): LocationBasedWifiViewModel =
43             when (location) {
44                 StatusBarLocation.HOME -> HomeWifiViewModel(commonImpl)
45                 StatusBarLocation.KEYGUARD -> KeyguardWifiViewModel(commonImpl)
46                 StatusBarLocation.QS -> QsWifiViewModel(commonImpl)
47                 StatusBarLocation.SHADE_CARRIER_GROUP ->
48                     throw IllegalArgumentException("invalid location for WifiViewModel: $location")
49             }
50     }
51 }
52 
53 /**
54  * A view model for the wifi icon shown on the "home" page (aka, when the device is unlocked and not
55  * showing the shade, so the user is on the home-screen, or in an app).
56  */
57 class HomeWifiViewModel(
58     commonImpl: WifiViewModelCommon,
59 ) : WifiViewModelCommon, LocationBasedWifiViewModel(commonImpl)
60 
61 /** A view model for the wifi icon shown on keyguard (lockscreen). */
62 class KeyguardWifiViewModel(
63     commonImpl: WifiViewModelCommon,
64 ) : WifiViewModelCommon, LocationBasedWifiViewModel(commonImpl)
65 
66 /** A view model for the wifi icon shown in quick settings (when the shade is pulled down). */
67 class QsWifiViewModel(
68     commonImpl: WifiViewModelCommon,
69 ) : WifiViewModelCommon, LocationBasedWifiViewModel(commonImpl)
70 
71 /**
72  * A view model for the wifi icon in the shade carrier group (visible when quick settings is fully
73  * expanded, and in large screen shade). Currently unused.
74  */
75 class ShadeCarrierGroupWifiViewModel(
76     commonImpl: WifiViewModelCommon,
77 ) : WifiViewModelCommon, LocationBasedWifiViewModel(commonImpl)
78