• 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 AspectRatio from '../../../setting/settingitem/AspectRatio'
18import Resolution from '../../../setting/settingitem/Resolution'
19import Timer from '../../../setting/settingitem/Timer'
20import { CustomDialogView, CustomDialogDetails } from '../../customdialog/dialogComponent/CustomDialogView'
21import { Log } from '../../../utils/Log'
22import { getStore } from '../../../redux/store'
23import { SettingManager } from '../../../setting/SettingManager'
24import { BaseData }  from '../model/BaseData'
25import { SettingData }  from '../model/SettingData'
26
27let localState = (state) => {
28  return {
29    isCloseFlag: state.SettingReducer.isCloseFlag
30  }
31}
32
33let localDispatcher = (dispatch) => {
34  return {
35    closeDialog: (isCloseFlag: boolean) => {
36      dispatch(Action.closeDialog(isCloseFlag))
37    }
38  }
39}
40
41class StateStruct {
42  isCloseFlag
43  closeDialog: Function
44}
45
46@Component
47export struct TabletSetResolution {
48  private TAG: string = '[TabletSetResolution]:'
49  @Link settingsList: any[]
50  @Link @Watch('onCloseDialog') closeFlag: boolean
51  private itemValue: SettingData
52  private getCheckValue: Promise<string>
53  private WH_100_100: string = "100%"
54  private settingManager = SettingManager.getInstance()
55  private setAlias: string= undefined
56  @StorageLink("settingDialogFlag") settingDialogFlag: boolean = true
57
58  @State curCheckName: Resource = $r("app.string.default_value")
59
60  @State state: StateStruct = new StateStruct()
61
62  @Provide customDialogDetails: CustomDialogDetails = {
63    confirmCallback: null,
64    confirmItem: true,
65    height: 256,
66    width: 256,
67    setAlias: this.setAlias,
68    childrenList: [],
69    settingTitle: '',
70//    dialogCloseFlag:false
71  }
72  CustomDialogView: CustomDialogController = new CustomDialogController({
73    builder: CustomDialogView({ cancel: this.existView.bind(this) }),
74    autoCancel: true,
75    alignment: DialogAlignment.Center,
76    cancel: this.existView,
77    customStyle: true
78  })
79
80  existView() {
81    Log.info(`${this.TAG} existView E`)
82    if (this.settingManager.getSettingValue(this.itemValue.settingAlias) !== undefined) {
83      this.curCheckName = JSON.parse(JSON.stringify(this.settingManager.getSettingValue(this.itemValue.settingAlias)))
84      Log.info(`${this.TAG} existView curCheckName: ${this.curCheckName} X`)
85    }
86    this.state.closeDialog(false)
87  }
88
89  aboutToAppear(): void {
90    Log.info(`${this.TAG} aboutToAppear settingsList: ${JSON.stringify(this.settingsList)} E`)
91    getStore().connect(localState, localDispatcher)(this.state)
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.state.closeDialog(false)
103      this.CustomDialogView.close()
104    }
105    Log.info(`${this.TAG} onCloseDialog X`)
106  }
107
108  public formatCurCheckName(name) {
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): 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//    this.customDialogDetails.dialogCloseFlag = this.closeFlag
174    Log.info(`${this.TAG} childrenList: ${JSON.stringify(itemValue.radio)}`)
175    this.state.closeDialog(true)
176    this.CustomDialogView.open()
177    Log.info(`${this.TAG} openDetailsDialog end`)
178  }
179}
180