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