• 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 settings from '@ohos.settings'
17
18import { Log } from '../../../utils/Log'
19import { SettingManager } from '../../../setting/SettingManager'
20import Timer from '../../../setting/settingitem/Timer'
21import AspectRatio from '../../../setting/settingitem/AspectRatio'
22import Resolution from '../../../setting/settingitem/Resolution'
23import { getStore } from '../../../redux/store';
24
25let localState = (state) => {
26  return {
27    mode: state.ModeReducer.mode,
28  }
29}
30
31let localDispatcher = (dispatch) => {
32  return {}
33}
34
35class StateStruct {
36  mode
37}
38
39@Component
40export default struct EntryComponent {
41  private TAG: string = '[EntryComponent]:'
42  @State itemValue: string = ''
43  @State checkedValue: string = ''
44  @State settingAlias: string = ''
45  private getValue: Resource
46  private onChange: Function
47  private settingManager = SettingManager.getInstance()
48  @State state: StateStruct = new StateStruct()
49
50  aboutToAppear(): void {
51    Log.info(`${this.TAG} aboutToAppear calle1d = ${this.settingAlias}`)
52    getStore().connect(localState, localDispatcher)(this.state)
53    try {
54      this.getValue = JSON.parse(JSON.stringify(this.settingManager.getSettingValue(this.settingAlias)))
55      Log.log(`${this.TAG} EntryComponent.getValue=${this.getValue}`)
56    } catch {
57      Log.log(`${this.TAG} catch this.settingAlias=${this.settingAlias}`)
58      if (this.settingAlias === Resolution.ALIAS) {
59        this.getValue = Resolution.DEFAULT_VALUE
60      } else if (this.settingAlias === Timer.ALIAS) {
61        this.getValue = Timer.DEFAULT_VALUE
62      } else {
63        this.getValue = AspectRatio.DEFAULT_VALUE
64      }
65      Log.error(`${this.TAG} catch this.getValue=${this.getValue}`)
66    }
67  }
68
69  build() {
70    Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
71      Text(this.itemValue)
72        .fontColor('#E6000000')
73        .fontSize($r("sys.float.ohos_id_text_size_body1"))
74        .fontWeight(FontWeight.Regular)
75
76      Radio({ group: 'settingChildren', value: this.itemValue.toString() })
77        .width(24)
78        .height(24)
79        .margin({ right: 14 })
80        .borderColor('#007DFF')
81        .checked(JSON.stringify(this.itemValue) === JSON.stringify(this.getValue))
82        .enabled(true)
83        .onClick(() => {
84          Log.info(`${this.TAG} onChange settingAlias:${this.settingAlias}  itemValue:${this.itemValue}`)
85          this.settingManager.setSettingValue(this.settingAlias, this.itemValue, this.state.mode)
86          this.onChange()
87        })
88    }
89    .width('100%')
90  }
91}