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