• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2023 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 AssistiveGrid from '../../../setting/settingitem/AssistiveGrid'
17import { Log } from '../../../utils/Log'
18import { SettingManager } from '../../../setting/SettingManager'
19import { SettingData }  from '../model/SettingData'
20import { getStore } from '../../../redux/store';
21
22let localState = (state) => {
23  return {
24    mode: state.ModeReducer.mode,
25  }
26}
27
28let localDispatcher = (dispatch) => {
29  return {}
30}
31
32class StateStruct {
33  mode
34}
35
36@Component
37export struct TabletSetToggle {
38  private TAG: string = '[TabletSetToggle]:'
39  @Link settingsList: any[]
40  @State isOn: boolean = false
41  private itemValue: SettingData
42  private getToggleStatus: Promise<string>
43  private WH_100_100: string = "100%"
44  private settingManager = SettingManager.getInstance()
45  @State generalStatusValue: boolean = false
46  @State state: StateStruct = new StateStruct()
47
48  aboutToAppear() {
49    Log.info(`${this.TAG} aboutToAppear start`)
50    getStore().connect(localState, localDispatcher)(this.state)
51    try {
52      if (this.settingManager.getSettingValue(this.itemValue.settingAlias) === "1") {
53        this.generalStatusValue = true
54      } else {
55        this.generalStatusValue = false
56      }
57    } catch {
58      Log.info(`${this.TAG} aboutToAppear settingsList ${JSON.stringify(this.settingsList)}`)
59      this.generalStatusValue = false
60    }
61    Log.info(`${this.TAG} aboutToAppear end`)
62  }
63
64  build() {
65    Row() {
66      Flex({
67        direction: FlexDirection.Row,
68        alignItems: ItemAlign.Center
69      }) {
70        Column() {
71          Row() {
72            Image(this.itemValue.imagePath)
73              .width(24)
74              .height(24)
75              .fillColor("#FFFFFF")
76            Text(this.itemValue.settingName)
77              .fontColor("#FFFFFF")
78              .fontSize($r("sys.float.ohos_id_text_size_sub_title2"))
79              .fontWeight(FontWeight.Regular)
80              .margin({ left: $r("sys.float.ohos_id_elements_margin_horizontal_l") })
81          }
82
83          if (this.itemValue?.description) {
84            Row() {
85              Text(this.itemValue.description)
86                .fontColor("#FFFFFF")
87                .fontSize($r("sys.float.ohos_id_text_size_body2"))
88                .fontWeight(FontWeight.Regular)
89                .opacity($r("sys.float.ohos_id_alpha_content_secondary"))
90            }.margin({
91              top: $r("sys.float.ohos_id_text_margin_vertical"),
92              left: 40 })
93          }
94        }
95        .layoutWeight(1)
96        .alignItems(HorizontalAlign.Start)
97
98        Row() {
99          Toggle({ type: ToggleType.Switch, isOn: this.generalStatusValue })
100            .width(36)
101            .height(20)
102            .onChange((isOn: boolean) => {
103              Log.info(this.TAG + ' SettingItemToggle onChange for Wlan Enable:' + isOn)
104              this.isOn = new Boolean(isOn).valueOf()
105              let setToggle: string = "0"
106              if (this.isOn) {
107                setToggle = "1"
108              } else {
109                setToggle = "0"
110              }
111              this.settingManager.setSettingValue(this.itemValue.settingAlias, setToggle, this.state.mode)
112            })
113        }
114        .margin({ left: $r("sys.float.ohos_id_card_margin_end") })
115      }
116      .padding({ left: 12, right: 12, top: 4, bottom: 4 })
117    }
118    .height(this.itemValue?.description ? 72 : 56)
119    .width(this.WH_100_100)
120  }
121}