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