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