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 deviceInfo from '@ohos.deviceInfo' 17import { Action } from '@ohos/common/src/main/ets/default/redux/actions/Action' 18import { CameraSwitchButton } from '@ohos/common/src/main/ets/default/featurecommon/cameraswitcher/CameraSwitchButton' 19import { ComponentPosition } from '@ohos/common/src/main/ets/default/utils/ComponentPosition' 20import { EventBus } from '@ohos/common/src/main/ets/default/worker/eventbus/EventBus' 21import { EventBusManager } from '@ohos/common/src/main/ets/default/worker/eventbus/EventBusManager' 22import { OhCombinedState } from '@ohos/common/src/main/ets/default/redux/store' 23import { getStore } from '@ohos/common/src/main/ets/default/redux/store' 24import { Log } from '@ohos/common/src/main/ets/default/utils/Log' 25import { ShutterButtonLand } from '@ohos/common/src/main/ets/default/featurecommon/shutterbutton/ShutterButtonLand' 26import { ThumbnailView } from '@ohos/common/src/main/ets/default/featurecommon/thumbnail/ThumbnailView' 27import { ControlLand } from './ControlLand' 28import { CameraPlatformCapability } from '@ohos/common/src/main/ets/default/camera/CameraPlatformCapability' 29import { Dispatch } from '@ohos/common/src/main/ets/default/redux/core/redux/types/store' 30 31class StateStruct { 32 platformCapability: CameraPlatformCapability | undefined = undefined; 33 isThirdPartyCall: boolean = false; 34 videoState: string = ''; 35 showZoomLabelValue: boolean = true; 36 mode: string = ''; 37 xComponentHeight: number = 0; 38} 39 40class ScreenSizeType { 41 width: number = 0; 42 height: number = 0; 43} 44 45class FootBarDispatcher { 46 private mDispatch: Dispatch = (data) => data; 47 48 public setDispatch(dispatch: Dispatch) { 49 this.mDispatch = dispatch; 50 } 51} 52 53@Component 54export struct FootBarLand { 55 private TAG: string = '[FootBarLand]:'; 56 @State state: StateStruct = new StateStruct(); 57 @State isRecording: boolean = false; 58 @Link screenSize: ScreenSizeType; 59 private appEventBus: EventBus = EventBusManager.getInstance().getEventBus(); 60 private mAction: FootBarDispatcher = new FootBarDispatcher(); 61 62 private async onRecordStart() { 63 this.isRecording = true 64 Log.info(`${this.TAG} onRecordStart`) 65 } 66 67 private async onRecordStop() { 68 this.isRecording = false 69 Log.info(`${this.TAG} onRecordStop`) 70 } 71 72 aboutToAppear(): void { 73 Log.info(`${this.TAG} aboutToAppear E`) 74 getStore().subscribe((state: OhCombinedState) => { 75 this.state = { 76 platformCapability: state.CameraInitReducer.platformCapability, 77 isThirdPartyCall: state.ContextReducer.isThirdPartyCall, 78 videoState: state.RecordReducer.videoState, 79 showZoomLabelValue: state.ZoomReducer.showZoomLabelValue, 80 mode: state.ModeReducer.mode, 81 xComponentHeight: state.PreviewReducer.xComponentHeight 82 }; 83 }, (dispatch: Dispatch) => { 84 this.mAction.setDispatch(dispatch); 85 }); 86 this.isRecording = false 87 this.appEventBus.on(Action.ACTION_RECORD_START, () => this.onRecordStart()) 88 this.appEventBus.on(Action.ACTION_RECORD_STOP, () => this.onRecordStop()) 89 Log.info(`${this.TAG} aboutToAppear X`) 90 } 91 92 aboutToDisappear(): void { 93 Log.info(`${this.TAG} aboutToDisappear E`) 94 this.appEventBus.off(Action.ACTION_RECORD_START, () => this.onRecordStart()) 95 this.appEventBus.off(Action.ACTION_RECORD_STOP, () => this.onRecordStop()) 96 Log.info(`${this.TAG} aboutToDisappear X`) 97 } 98 99 private isThumbnailViewVisibility(): boolean { 100 return!this.isRecording && !this.state.isThirdPartyCall && 101 this.state.videoState !== "startTakeVideo" && this.state.videoState !== "pauseTakeVideo" 102 } 103 104 build() { 105 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 106 Column() { 107 }.width('100%').height(ComponentPosition.getControlHeight(this.screenSize.width, this.screenSize.height)) 108 109 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 110 if (this.state.platformCapability && this.state.platformCapability?.mCameraCount > 1 && 111 !this.isRecording && deviceInfo.deviceType !== "default") { 112 CameraSwitchButton() 113 } else { 114 Column() { 115 }.width('44').aspectRatio(1) 116 } 117 ShutterButtonLand({ screenSize: $screenSize }) 118 Column() { 119 ThumbnailView() 120 }.width(44).aspectRatio(1).visibility(this.isThumbnailViewVisibility() ? Visibility.Visible : Visibility.Hidden) 121 }.width('100%') 122 .height(ComponentPosition.getFootBarHeight(this.screenSize.width, this.screenSize.height, this.state.xComponentHeight)) 123 .margin({ 124 top: ComponentPosition.getFootBarMargin(this.screenSize.width, this.screenSize.height, this.state.xComponentHeight), 125 bottom: ComponentPosition.getFootBarMargin(this.screenSize.width, this.screenSize.height, this.state.xComponentHeight) 126 }) 127 .offset(ComponentPosition.getFootBarPosition(this.state.xComponentHeight)) 128 129 if (this.state.videoState === "beforeTakeVideo" && this.state.showZoomLabelValue) { 130 ControlLand({ screenSize: $screenSize }) 131 .offset({ x: 0, y: 0 }) 132 } else { 133 Column() { 134 }.width('100%').height(ComponentPosition.getControlHeight(this.screenSize.width, this.screenSize.height)) 135 } 136 }.width(98).height('100%') 137 } 138}