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