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 { Action } from '../redux/actions/Action'; 17import { CameraBasicFunction } from '../function/CameraBasicFunction'; 18import { CaptureFunction } from '../function/CaptureFunction'; 19import { Log } from '../utils/Log'; 20import { FunctionId } from './FunctionId'; 21import type { EventBus } from '../worker/eventbus/EventBus'; 22import { EventBusManager } from '../worker/eventbus/EventBusManager'; 23import { ModeAssembler } from './ModeAssembler'; 24import { RecordFunction } from '../function/RecordFunction'; 25import { ZoomFunction } from '../function/ZoomFunction'; 26import type { IModeMap } from './IModeMap'; 27 28const TAG = '[FeatureManager]:'; 29 30export class FeatureManager { 31 appEventBus: EventBus = EventBusManager.getInstance().getEventBus(); 32 private mModeAssembler: ModeAssembler; 33 private mPreMode: string = 'PHOTO'; 34 public mCurrentMode: string = this.mPreMode; 35 private mFunctionsMap = new Map(); 36 37 constructor(mode: string, modeMap: IModeMap) { 38 Log.info(`${TAG} constructor`); 39 this.initFunctionsMap(); 40 this.mModeAssembler = new ModeAssembler(this.mFunctionsMap, modeMap); 41 this.mPreMode = mode; 42 this.mCurrentMode = mode; 43 this.mFunctionsMap.get(FunctionId.CAMERA_BASIC_FUNCTION).load(); 44 this.mModeAssembler.assembler(null, this.mPreMode); 45 // 接收到modeChange的消息,调用changeMode做处理 46 this.appEventBus.on(Action.ACTION_CHANGE_MODE, this.changeMode.bind(this)); 47 } 48 49 public changeMode(data: any): void { 50 // 外部条件触发mode切换,传入下一个mode名称 51 Log.info(`${TAG} changeMode start data: ${JSON.stringify(data)}`); 52 this.mModeAssembler.assembler(this.mPreMode, data.mode); 53 this.mPreMode = data.mode; 54 } 55 56 private initFunctionsMap(): void { 57 Log.info(`${TAG} initFunctionsMap invoke E.`); 58 this.mFunctionsMap.set(FunctionId.CAMERA_BASIC_FUNCTION, CameraBasicFunction.getInstance()); 59 this.mFunctionsMap.set(FunctionId.CAPTURE_FUNCTION, new CaptureFunction()); 60 this.mFunctionsMap.set(FunctionId.RECORDING_FUNCTION, new RecordFunction()); 61 this.mFunctionsMap.set(FunctionId.ZOOM_FUNCTION, new ZoomFunction()); 62 Log.info(`${TAG} initFunctionsMap invoke X.`); 63 } 64}