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 { Constants } from '../model/browser/photo/Constants';
17import { Log } from '../utils/Log';
18import { UiUtil } from '../utils/UiUtil';
19
20const TAG = 'BrowserController';
21
22@Observed
23export class BrowserController {
24  public geometryTransitionEnable: boolean = false;
25  public isAnimating: boolean = false;
26  public isBrowserShow: boolean = false;
27  public browserParam?: Object;
28  public browserBackFunc: Function = (): void => {};
29  public isSelectBrowserShow: boolean = false;
30  public selectBrowserParam?: Object;
31  public pageFrom: string = '';
32
33  constructor(isGeometryEnable: boolean) {
34    this.geometryTransitionEnable = isGeometryEnable;
35  }
36
37  showBrowserWithNoAnimation(param: Object) {
38    this.isBrowserShow = true;
39    this.browserParam = param;
40  }
41
42  showSelectBrowserWithNoAnimation(param: Object) {
43    this.isSelectBrowserShow = true;
44    this.selectBrowserParam = param;
45  }
46
47  showBrowser(geometryIndex: number, geometryString: string, name: string, param: Object) {
48    Log.debug(TAG, 'call show browser');
49    animateTo({
50      curve: Constants.PHOTO_TRANSITION_CURVE,
51      duration: Constants.SHARE_TRANSITION_DURATION,
52      onFinish: () => {
53        this.finishAnimation();
54      }
55    }, () => {
56      UiUtil.resetGeometryTransitionParams();
57      UiUtil.updateGeometryTapInfo(geometryIndex, geometryString);
58      this.isBrowserShow = true;
59      this.pageFrom = name;
60      this.browserParam = param;
61      this.isAnimating = true;
62    });
63  }
64
65  hideBrowser(): void {
66    Log.debug(TAG, 'call hide browser');
67    animateTo({
68      curve: Constants.SPRING_MOTION_CURVE, // 大图进出阻尼曲线参数
69      onFinish: () => {
70        AppStorage.setOrCreate<string>('geometryTransitionBrowserId', '');
71        UiUtil.resetGeometryTransitionParams();
72        this.finishAnimation();
73      }
74    }, () => {
75      this.isBrowserShow = false;
76      this.browserParam;
77      this.isAnimating = true;
78      AppStorage.setOrCreate<number>('placeholderIndex', -1);
79      Log.info(TAG, `placeholderIndex ${AppStorage.get<number>('placeholderIndex')}`);
80    });
81  }
82
83  showSelectBrowser(geometryIndex: number, geometryString: string, name: string, param: Object) {
84    Log.debug(TAG, 'call show select browser');
85    animateTo({
86      curve: Constants.PHOTO_TRANSITION_CURVE,
87      duration: Constants.SHARE_TRANSITION_DURATION,
88      onFinish: () => {
89        this.finishAnimation();
90      }
91    }, () => {
92      UiUtil.resetGeometryTransitionParams();
93      UiUtil.updateGeometryTapInfo(geometryIndex, geometryString);
94      this.isSelectBrowserShow = true;
95      this.pageFrom = name;
96      this.selectBrowserParam = param;
97      this.isAnimating = true;
98    });
99  }
100
101  hideSelectBrowser(): void {
102    Log.debug(TAG, 'call hide select browser');
103    animateTo({
104      curve: Constants.SPRING_MOTION_CURVE, // 大图进出阻尼曲线参数
105      onFinish: () => {
106        AppStorage.setOrCreate<string>('geometryTransitionBrowserId', '');
107        UiUtil.resetGeometryTransitionParams();
108        this.finishAnimation();
109      }
110    }, () => {
111      this.isSelectBrowserShow = false;
112      this.selectBrowserParam;
113      this.isAnimating = true;
114      AppStorage.setOrCreate<number>('placeholderIndex', -1);
115    });
116  }
117
118  finishAnimation() {
119    this.isAnimating = false;
120  }
121}