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