• 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 { CameraService } from '../../camera/CameraService';
17import { Dispatch, getStore, OhCombinedState } from '../../redux/store';
18import { Log } from '../../utils/Log';
19
20class StateStruct {
21  uiEnable: boolean = true;
22}
23
24class ComponentForMultiDispatcher {
25  public setDispatch(dispatch: Dispatch) {
26    this.mDispatch = dispatch;
27  }
28
29  private mDispatch: Dispatch = (data) => data;
30}
31
32
33@Component
34export default struct EntryComponentForMulti {
35  @State state: StateStruct = new StateStruct();
36  @State isLocalDevice: boolean = false;
37  @State switchCameraState: boolean = false;
38  @State recCameraState: boolean = true;
39  @State defaultChecked: boolean = false;
40  @State curCameraName: string = '';
41  private TAG: string = '[EntryComponentForMulti]:';
42  private localList: string = '';
43  private item: string = '';
44  private cameraService: CameraService = CameraService.getInstance();
45  private deviceName: string = '';
46  private cameraPositionRes: string | Resource = '';
47  private cameraPositionName: string = '';
48  private mAction: ComponentForMultiDispatcher = new ComponentForMultiDispatcher();
49
50  aboutToAppear() {
51    getStore().subscribe((state: OhCombinedState) => {
52      this.state = {
53        uiEnable: state.contextReducer.uiEnable
54      };
55    }, (dispatch: Dispatch) => {
56      this.mAction.setDispatch(dispatch);
57    });
58
59
60    this.getShowName(this.item)
61    this.curCameraName = this.cameraService.getCameraName()
62    if (this.localList.split(',').length === 1 && this.curCameraName === 'BACK') {
63      this.curCameraName = 'FRONT'
64    }
65  }
66
67  build() {
68    Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
69      Row() {
70        if (this.isLocalDevice) {
71          Text($r('app.string.local'))
72            .fontColor('#E6000000')
73            .fontSize($r('sys.float.ohos_id_text_size_body1'))
74            .fontWeight(FontWeight.Medium)
75        } else {
76          Text(this.deviceName)
77            .fontColor('#E6000000')
78            .fontSize($r('sys.float.ohos_id_text_size_body1'))
79            .fontWeight(FontWeight.Medium)
80        }
81        Text(this.cameraPositionRes)
82          .fontColor('#E6000000')
83          .fontSize($r('sys.float.ohos_id_text_size_body1'))
84          .fontWeight(FontWeight.Medium)
85      }
86
87      Radio({ group: 'settingChildren', value: this.item.toString() })
88        .width(24)
89        .height(24)
90        .borderColor('#1095E8')
91        .checked(this.defaultChecked ? true : this.item === this.curCameraName)
92        .enabled(this.state.uiEnable)
93        .onClick(() => {
94          Log.info(`${this.TAG} onChange item: ${this.item}`)
95          if (this.item === this.curCameraName) {
96            Log.info(`${this.TAG} no Change curCameraName: ${this.curCameraName}`)
97          } else {
98            this.onChange(this.item)
99          }
100        })
101    }
102    .height(48)
103    .width('100%')
104  }
105
106  private onChange: Function = () => {
107  };
108
109  private getShowName(item: string): void {
110    this.cameraPositionName = item.split('_').pop() as string;
111    switch (this.cameraPositionName) {
112      case 'FRONT':
113        this.cameraPositionRes = $r('app.string.front')
114        break
115      case 'BACK':
116        this.cameraPositionRes = $r('app.string.back')
117        break
118      default:
119        break
120    }
121    if (item.split('_').length == 1) {
122      this.isLocalDevice = true
123    } else {
124      const cameraItem = this.cameraService.getCameraMap().get(item)
125      if (cameraItem) {
126        this.deviceName = cameraItem.deviceName as string;
127        this.isLocalDevice = false
128      }
129    }
130  }
131}