100aff185Sopenharmony_ci/*
200aff185Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
300aff185Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
400aff185Sopenharmony_ci * you may not use this file except in compliance with the License.
500aff185Sopenharmony_ci * You may obtain a copy of the License at
600aff185Sopenharmony_ci *
700aff185Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
800aff185Sopenharmony_ci *
900aff185Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1000aff185Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1100aff185Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1200aff185Sopenharmony_ci * See the License for the specific language governing permissions and
1300aff185Sopenharmony_ci * limitations under the License.
1400aff185Sopenharmony_ci */
1500aff185Sopenharmony_ci
1600aff185Sopenharmony_ciimport { Constants } from '../model/browser/photo/Constants';
1700aff185Sopenharmony_ciimport { Log } from '../utils/Log';
1800aff185Sopenharmony_ciimport { UiUtil } from '../utils/UiUtil';
1900aff185Sopenharmony_ci
2000aff185Sopenharmony_ciconst TAG = 'BrowserController';
2100aff185Sopenharmony_ci
2200aff185Sopenharmony_ci@Observed
2300aff185Sopenharmony_ciexport class BrowserController {
2400aff185Sopenharmony_ci  public geometryTransitionEnable: boolean = false;
2500aff185Sopenharmony_ci  public isAnimating: boolean = false;
2600aff185Sopenharmony_ci  public isBrowserShow: boolean = false;
2700aff185Sopenharmony_ci  public browserParam?: Object;
2800aff185Sopenharmony_ci  public browserBackFunc: Function = (): void => {};
2900aff185Sopenharmony_ci  public isSelectBrowserShow: boolean = false;
3000aff185Sopenharmony_ci  public selectBrowserParam?: Object;
3100aff185Sopenharmony_ci  public pageFrom: string = '';
3200aff185Sopenharmony_ci
3300aff185Sopenharmony_ci  constructor(isGeometryEnable: boolean) {
3400aff185Sopenharmony_ci    this.geometryTransitionEnable = isGeometryEnable;
3500aff185Sopenharmony_ci  }
3600aff185Sopenharmony_ci
3700aff185Sopenharmony_ci  showBrowserWithNoAnimation(param: Object) {
3800aff185Sopenharmony_ci    this.isBrowserShow = true;
3900aff185Sopenharmony_ci    this.browserParam = param;
4000aff185Sopenharmony_ci  }
4100aff185Sopenharmony_ci
4200aff185Sopenharmony_ci  showSelectBrowserWithNoAnimation(param: Object) {
4300aff185Sopenharmony_ci    this.isSelectBrowserShow = true;
4400aff185Sopenharmony_ci    this.selectBrowserParam = param;
4500aff185Sopenharmony_ci  }
4600aff185Sopenharmony_ci
4700aff185Sopenharmony_ci  showBrowser(geometryIndex: number, geometryString: string, name: string, param: Object) {
4800aff185Sopenharmony_ci    Log.debug(TAG, 'call show browser');
4900aff185Sopenharmony_ci    animateTo({
5000aff185Sopenharmony_ci      curve: Constants.PHOTO_TRANSITION_CURVE,
5100aff185Sopenharmony_ci      duration: Constants.SHARE_TRANSITION_DURATION,
5200aff185Sopenharmony_ci      onFinish: () => {
5300aff185Sopenharmony_ci        this.finishAnimation();
5400aff185Sopenharmony_ci      }
5500aff185Sopenharmony_ci    }, () => {
5600aff185Sopenharmony_ci      UiUtil.resetGeometryTransitionParams();
5700aff185Sopenharmony_ci      UiUtil.updateGeometryTapInfo(geometryIndex, geometryString);
5800aff185Sopenharmony_ci      this.isBrowserShow = true;
5900aff185Sopenharmony_ci      this.pageFrom = name;
6000aff185Sopenharmony_ci      this.browserParam = param;
6100aff185Sopenharmony_ci      this.isAnimating = true;
6200aff185Sopenharmony_ci    });
6300aff185Sopenharmony_ci  }
6400aff185Sopenharmony_ci
6500aff185Sopenharmony_ci  hideBrowser(): void {
6600aff185Sopenharmony_ci    Log.debug(TAG, 'call hide browser');
6700aff185Sopenharmony_ci    animateTo({
6800aff185Sopenharmony_ci      curve: Constants.SPRING_MOTION_CURVE, // 大图进出阻尼曲线参数
6900aff185Sopenharmony_ci      onFinish: () => {
7000aff185Sopenharmony_ci        AppStorage.setOrCreate<string>('geometryTransitionBrowserId', '');
7100aff185Sopenharmony_ci        UiUtil.resetGeometryTransitionParams();
7200aff185Sopenharmony_ci        this.finishAnimation();
7300aff185Sopenharmony_ci      }
7400aff185Sopenharmony_ci    }, () => {
7500aff185Sopenharmony_ci      this.isBrowserShow = false;
7600aff185Sopenharmony_ci      this.browserParam;
7700aff185Sopenharmony_ci      this.isAnimating = true;
7800aff185Sopenharmony_ci      AppStorage.setOrCreate<number>('placeholderIndex', -1);
7900aff185Sopenharmony_ci      Log.info(TAG, `placeholderIndex ${AppStorage.get<number>('placeholderIndex')}`);
8000aff185Sopenharmony_ci    });
8100aff185Sopenharmony_ci  }
8200aff185Sopenharmony_ci
8300aff185Sopenharmony_ci  showSelectBrowser(geometryIndex: number, geometryString: string, name: string, param: Object) {
8400aff185Sopenharmony_ci    Log.debug(TAG, 'call show select browser');
8500aff185Sopenharmony_ci    animateTo({
8600aff185Sopenharmony_ci      curve: Constants.PHOTO_TRANSITION_CURVE,
8700aff185Sopenharmony_ci      duration: Constants.SHARE_TRANSITION_DURATION,
8800aff185Sopenharmony_ci      onFinish: () => {
8900aff185Sopenharmony_ci        this.finishAnimation();
9000aff185Sopenharmony_ci      }
9100aff185Sopenharmony_ci    }, () => {
9200aff185Sopenharmony_ci      UiUtil.resetGeometryTransitionParams();
9300aff185Sopenharmony_ci      UiUtil.updateGeometryTapInfo(geometryIndex, geometryString);
9400aff185Sopenharmony_ci      this.isSelectBrowserShow = true;
9500aff185Sopenharmony_ci      this.pageFrom = name;
9600aff185Sopenharmony_ci      this.selectBrowserParam = param;
9700aff185Sopenharmony_ci      this.isAnimating = true;
9800aff185Sopenharmony_ci    });
9900aff185Sopenharmony_ci  }
10000aff185Sopenharmony_ci
10100aff185Sopenharmony_ci  hideSelectBrowser(): void {
10200aff185Sopenharmony_ci    Log.debug(TAG, 'call hide select browser');
10300aff185Sopenharmony_ci    animateTo({
10400aff185Sopenharmony_ci      curve: Constants.SPRING_MOTION_CURVE, // 大图进出阻尼曲线参数
10500aff185Sopenharmony_ci      onFinish: () => {
10600aff185Sopenharmony_ci        AppStorage.setOrCreate<string>('geometryTransitionBrowserId', '');
10700aff185Sopenharmony_ci        UiUtil.resetGeometryTransitionParams();
10800aff185Sopenharmony_ci        this.finishAnimation();
10900aff185Sopenharmony_ci      }
11000aff185Sopenharmony_ci    }, () => {
11100aff185Sopenharmony_ci      this.isSelectBrowserShow = false;
11200aff185Sopenharmony_ci      this.selectBrowserParam;
11300aff185Sopenharmony_ci      this.isAnimating = true;
11400aff185Sopenharmony_ci      AppStorage.setOrCreate<number>('placeholderIndex', -1);
11500aff185Sopenharmony_ci    });
11600aff185Sopenharmony_ci  }
11700aff185Sopenharmony_ci
11800aff185Sopenharmony_ci  finishAnimation() {
11900aff185Sopenharmony_ci    this.isAnimating = false;
12000aff185Sopenharmony_ci  }
12100aff185Sopenharmony_ci}