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 { Action } from '../../../redux/actions/Action'; 17import Timer from '../../../setting/settingitem/Timer'; 18import { CustomDialogDetails } from '../../customdialog/dialogComponent/CustomDialogView'; 19import { CustomDialogView } from '../../customdialog/dialogComponent/CustomDialogView'; 20import { Log } from '../../../utils/Log'; 21import { Dispatch, OhCombinedState } from '../../../redux/store'; 22import { getStore } from '../../../redux/store'; 23import { SettingManager } from '../../../setting/SettingManager'; 24import { SettingData, SettingGroupItem } from '../model/SettingData'; 25 26class StateStruct { 27} 28 29class SetResolutionDispatcher { 30 private mDispatch: Dispatch = (data) => data; 31 32 public setDispatch(dispatch: Dispatch) { 33 this.mDispatch = dispatch; 34 } 35 36 public closeDialog(isCloseFlag: boolean): void { 37 this.mDispatch(Action.closeDialog(isCloseFlag)); 38 } 39} 40 41 42@Component 43export struct SetResolution { 44 private TAG: string = '[SetResolution]:'; 45 @Link settingsList: SettingGroupItem[]; 46 @Link @Watch('onCloseDialog') closeFlag: boolean; 47 private itemValue: SettingData = {}; 48 private WH_100_100: string = "100%"; 49 private settingManager = SettingManager.getInstance(); 50 private setAlias: string = ''; 51 @StorageLink('settingDialogFlag') settingDialogFlag: boolean = true; 52 @State curCheckName: Resource = $r('app.string.default_value'); 53 @State state: StateStruct = new StateStruct(); 54 private mAction: SetResolutionDispatcher = new SetResolutionDispatcher(); 55 @Provide customDialogDetails: CustomDialogDetails = { 56 confirmCallback: Function, 57 confirmItem: true, 58 height: 256, 59 width: 256, 60 setAlias: this.setAlias, 61 childrenList: [], 62 settingTitle: '' 63 }; 64 CustomDialogView: CustomDialogController = new CustomDialogController({ 65 builder: CustomDialogView({ cancel: () => this.existView() }), 66 autoCancel: true, 67 alignment: DialogAlignment.Bottom, 68 cancel: this.existView, 69 customStyle: true 70 }); 71 72 existView(): void { 73 Log.info(`${this.TAG} existView E`) 74 if (this.settingManager.getSettingValue(this.itemValue.settingAlias) !== undefined) { 75 this.curCheckName = JSON.parse(JSON.stringify(this.settingManager.getSettingValue(this.itemValue.settingAlias))) 76 Log.info(`${this.TAG} existView curCheckName: ${this.curCheckName} X`) 77 } 78 this.mAction.closeDialog(false) 79 } 80 81 aboutToAppear(): void { 82 Log.info(`${this.TAG} aboutToAppear settingsList: ${JSON.stringify(this.settingsList)} E`); 83 getStore().subscribe((state: OhCombinedState) => { 84 this.state = {}; 85 }, (dispatch: Dispatch) => { 86 this.mAction.setDispatch(dispatch); 87 }); 88 89 if (this.settingManager.getSettingValue(this.itemValue.settingAlias) !== undefined) { 90 this.curCheckName = JSON.parse(JSON.stringify(this.settingManager.getSettingValue(this.itemValue.settingAlias))) 91 Log.info(`${this.TAG} aboutToAppear curCheckName: ${this.curCheckName} X`) 92 } 93 } 94 95 public onCloseDialog(): void { 96 Log.info(`${this.TAG} onCloseDialog E`) 97 if (this.customDialogDetails.setAlias !== undefined) { 98 this.mAction.closeDialog(false) 99 this.CustomDialogView.close() 100 } 101 Log.info(`${this.TAG} onCloseDialog X`) 102 } 103 104 public formatCurCheckName(name: Resource): Resource { 105 if (name.id === Timer.DEFAULT_VALUE.id) { 106 name = Timer.RESOURCE_OFF_ALREADY 107 } 108 return name 109 } 110 111 build() { 112 Row() { 113 Flex({ 114 direction: FlexDirection.Row, 115 alignItems: ItemAlign.Center, 116 justifyContent: FlexAlign.SpaceBetween 117 }) { 118 Row() { 119 Image(this.itemValue.imagePath) 120 .width(24) 121 .height(24) 122 .fillColor('#FFFFFF') 123 Text(this.itemValue.settingName) 124 .margin({ left: $r('sys.float.ohos_id_elements_margin_horizontal_l') }) 125 .fontColor('#FFFFFF') 126 .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) 127 .fontWeight(FontWeight.Regular) 128 } 129 130 Row() { 131 Text(this.formatCurCheckName(this.curCheckName)) 132 .fontColor($r('app.color.font_color_FFFFFF')) 133 .fontSize($r('sys.float.ohos_id_text_size_body2')) 134 .opacity(0.6) 135 .fontWeight(FontWeight.Regular) 136 Image($r('app.media.ic_public_arrow_right')) 137 .width(12) 138 .height(24) 139 .fillColor('#33FFFFFF') 140 .opacity(0.4) 141 .opacity($r('app.float.opacity_4')) 142 .margin({ left: 4 }) 143 } 144 } 145 .height('100%') 146 } 147 .padding({ left: 12, right: 12 }) 148 .width(this.WH_100_100) 149 .height(56) 150 .onClick(() => { 151 if (this.settingDialogFlag) { 152 this.settingDialogFlag = false 153 setTimeout(() => { 154 this.settingDialogFlag = true 155 }, 200) 156 this.openDetailsDialog(this.itemValue) 157 } 158 }) 159 } 160 161 async openDetailsDialog(itemValue: SettingData): Promise<void> { 162 Log.info(`${this.TAG} openDetailsDialog start dataInfo ${JSON.stringify(itemValue)}`) 163 // 需要根据相机能力更新这个childrenList,目前是写死状态 164 // this.customDialogDetails.childrenList = itemValue.radio 165 // this.customDialogDetails.settingTitle = itemValue.settingName 166 // this.customDialogDetails.setAlias = itemValue.settingAlias 167 Log.info(`${this.TAG} childrenList: ${JSON.stringify(itemValue.radio)}`) 168 this.mAction.closeDialog(true) 169 this.CustomDialogView.open() 170 Log.info(`${this.TAG} openDetailsDialog end`) 171 } 172}