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