• 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 { 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 { 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  closeDialog: Function = () => {
29  }
30}
31
32@Component
33export struct TabletSetResolution {
34  private TAG: string = '[TabletSetResolution]:';
35  @Link settingsList: SettingGroupItem[];
36  @Link @Watch('onCloseDialog') closeFlag: boolean;
37  private itemValue: SettingData = new SettingData();
38  private WH_100_100: string = "100%";
39  private settingManager: SettingManager = SettingManager.getInstance();
40  private setAlias: string = '';
41  @StorageLink("settingDialogFlag") settingDialogFlag: boolean = true;
42  @State curCheckName: Resource = $r("app.string.default_value");
43  @State state: StateStruct = new StateStruct();
44
45  @Provide customDialogDetails: CustomDialogDetails = {
46    confirmCallback: () => {},
47    confirmItem: true,
48    height: 256,
49    width: 256,
50    setAlias: this.setAlias,
51    childrenList: [],
52    settingTitle: '',
53    //    dialogCloseFlag:false
54  }
55  CustomDialogView: CustomDialogController = new CustomDialogController({
56    builder: CustomDialogView({ cancel: () => this.existView }),
57    autoCancel: true,
58    alignment: DialogAlignment.Center,
59    cancel: this.existView,
60    customStyle: true
61  })
62
63  existView() {
64    Log.info(`${this.TAG} existView E`)
65    if (this.settingManager.getSettingValue(this.itemValue.settingAlias) !== undefined) {
66      this.curCheckName = JSON.parse(JSON.stringify(this.settingManager.getSettingValue(this.itemValue.settingAlias)))
67      Log.info(`${this.TAG} existView curCheckName: ${this.curCheckName} X`)
68    }
69    this.state.closeDialog(false)
70  }
71
72  aboutToAppear(): void {
73    Log.info(`${this.TAG} aboutToAppear settingsList: ${JSON.stringify(this.settingsList)} E`)
74    getStore().connect((state: OhCombinedState) => {
75      return {
76        isCloseFlag: state.SettingReducer.isCloseFlag
77      }
78    }, (dispatch) => {
79      return {
80        closeDialog: (isCloseFlag: boolean): void => {
81          dispatch(Action.closeDialog(isCloseFlag))
82        }
83      }
84    })(this.state)
85
86    Log.info(`${this.TAG} aboutToAppear this.closeFlag ${this.closeFlag}`)
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() {
94    Log.info(`${this.TAG} onCloseDialog E`)
95    if (this.customDialogDetails.setAlias !== undefined) {
96      this.state.closeDialog(false)
97      this.CustomDialogView.close()
98    }
99    Log.info(`${this.TAG} onCloseDialog X`)
100  }
101
102  public formatCurCheckName(name: Resource): Resource | string {
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            .opacity($r('app.float.opacity_6'))
135          Image($r("app.media.ic_public_arrow_right"))
136            .width(12)
137            .height(24)
138            .fillColor('#33FFFFFF')
139            .opacity(0.4)
140            .opacity($r('app.float.opacity_4'))
141            .margin({ left: 4 })
142        }
143      }
144      .height(64)
145      .padding({ left: 12, right: 12 })
146    }
147    .width(this.WH_100_100)
148    .height(56)
149    .onClick(() => {
150      if (this.settingDialogFlag) {
151        this.settingDialogFlag = false
152        setTimeout(() => {
153          this.settingDialogFlag = true
154        }, 200)
155        this.openDetailsDialog(this.itemValue)
156      }
157    })
158  }
159
160  async openDetailsDialog(itemValue: SettingData): Promise<void> {
161    Log.info(`${this.TAG} openDetailsDialog start`)
162    Log.info(`${this.TAG} openDetailsDialog 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.state.closeDialog(true)
169    this.CustomDialogView.open()
170    Log.info(`${this.TAG} openDetailsDialog end`)
171  }
172}