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