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