1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import Constants from '../common/constants'
17import mWifiModel from '../wifiModel'
18import Log from '../../../../../../../common/src/main/ets/default/Log'
19import { TintContentInfo } from '../../../../../../../common/src/main/ets/default/TintStateManager'
20import StyleConfigurationCommon, { CommonStyle
21} from '../../../../../../../common/src/main/ets/default/StyleConfiguration'
22import StyleConfiguration, { StartsBarWifiComponentStyle } from '../common/StyleConfiguration'
23import ViewModel from '../viewmodel/WifiVM'
24
25const TAG = 'WifiComponent-WifiIcon'
26
27@Component
28export default struct WifiIcon {
29  @StorageLink('wifiInfo') wifiInfo: number = Constants.DEFAULT_WIFI_INFO
30  @StorageLink('wifiStatus') wifiStatus: boolean = Constants.DEFAULT_WIFI_STATUS
31  @State mTintContentInfo: TintContentInfo = ViewModel.getTintContentInfo()
32  @State styleCommon: CommonStyle = StyleConfigurationCommon.getCommonStyle()
33  @State style: StartsBarWifiComponentStyle = StyleConfiguration.getStartsBarWifiComponentStyle()
34
35  aboutToAppear() {
36    Log.showDebug(TAG, `aboutToAppear`);
37    mWifiModel.initWifiModel();
38  }
39
40  aboutToDisappear() {
41    Log.showDebug(TAG, `aboutToDisappear`);
42  }
43
44  build() {
45    Row() {
46      if (this.wifiStatus) {
47        Row().width(this.styleCommon.statusBarMarginLeftRight).height('100%')
48        Image(this.getImage(this.wifiInfo))
49          .objectFit(ImageFit.Contain)
50          .width(this.style.statusBarWifiWidth)
51          .height(this.style.statusBarWifiHeight)
52          .fillColor(this.mTintContentInfo.contentColor)
53          .opacity($r("app.float.icon_component_opacity"))
54        Row().width(this.styleCommon.statusBarMarginLeftRight).height('100%')
55      }
56    }
57    .height('100%')
58  }
59
60  private getImage(wifiInfo: number) {
61    Log.showInfo(TAG, `getImage`);
62    let wifiImage;
63    switch (wifiInfo) {
64      case Constants.WIFI_SIGNAL_NO:
65        wifiImage = $r('app.media.ic_statusbar_wifi_no');
66        break;
67      case Constants.WIFI_SIGNAL_LOW:
68        wifiImage = $r('app.media.ic_statusbar_wifi_1');
69        break;
70      case Constants.WIFI_SIGNAL_MID:
71        wifiImage = $r('app.media.ic_statusbar_wifi_2');
72        break;
73      case Constants.WIFI_SIGNAL_HIGH:
74        wifiImage = $r('app.media.ic_statusbar_wifi_3');
75        break;
76      case Constants.WIFI_SIGNAL_FULL:
77        wifiImage = $r('app.media.ic_statusbar_wifi_full');
78        break;
79      default:
80        wifiImage = $r('app.media.ic_statusbar_wifi_no');
81        break;
82    }
83    return wifiImage;
84  }
85}
86