• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2022-2022 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 { BaseStartAppHandler } from '@ohos/common';
17import { CommonConstants } from '@ohos/common';
18import { AppItemInfo } from '@ohos/common';
19import { layoutConfigManager } from '@ohos/common';
20import { Log } from '@ohos/common';
21import { CheckEmptyUtils } from '@ohos/common';
22import { BigFolderConstants } from '../common/constants/BigFolderConstants';
23import { BigFolderStyleConfig } from './BigFolderStyleConfig';
24
25const TAG = 'BigFolderStartAppHandler';
26
27/**
28 * open big folder start app processing class
29 */
30export default class BigFolderStartAppHandler extends BaseStartAppHandler {
31    private mBigFolderStyleConfig;
32
33    private constructor() {
34        super();
35        this.mBigFolderStyleConfig = layoutConfigManager.getStyleConfig(BigFolderStyleConfig.APP_LIST_STYLE_CONFIG,
36            BigFolderConstants.FEATURE_NAME);
37    }
38
39    static getInstance(): BigFolderStartAppHandler {
40        Log.showInfo(TAG, `BigFolderStartAppHandler getInstance called!!`);
41        if (globalThis.BigFolderStartAppHandler == null) {
42            Log.showInfo(TAG, `BigFolderStartAppHandler constructor`);
43            globalThis.BigFolderStartAppHandler = new BigFolderStartAppHandler();
44        }
45        return globalThis.BigFolderStartAppHandler;
46    }
47
48    protected calculateAppIconPosition(): void {
49        Log.showInfo(TAG, `calculateAppIconPosition called`);
50        if (CheckEmptyUtils.isEmpty(this.mBigFolderStyleConfig)) {
51            Log.showError(TAG, `calculateAppIconPosition with invalid config`);
52            return;
53        }
54
55        const appItemInfo = AppStorage.Get('startAppItemInfo');
56        const screenWidth: number = AppStorage.Get('screenWidth');
57        const screenHeight: number = AppStorage.Get('screenHeight');
58        const appGridWidth: number = this.mBigFolderStyleConfig.mOpenFolderGridWidth;
59        const appGridHeight: number = this.mBigFolderStyleConfig.mOpenFolderGridHeight;
60        const swiperHeight: number = this.mBigFolderStyleConfig.mOpenFolderSwiperHeight;
61        const appGridPadding: number = this.mBigFolderStyleConfig.mOpenFolderGridPadding;
62        const titleHeight: number = this.mBigFolderStyleConfig.mFolderOpenMargin;
63        const titleTopMargin = this.mBigFolderStyleConfig.mFolderOpenTitle;
64        const appItemSize: number = this.mBigFolderStyleConfig.mOpenFolderAppSize;
65        const appIconSize: number = this.mBigFolderStyleConfig.mOpenFolderIconSize;
66        const bigFolderColumns: number = this.mBigFolderStyleConfig.mOpenFolderGridColumn;
67        const bigFolderRows: number = this.mBigFolderStyleConfig.mOpenFolderGridRow
68
69        let startPositionX: number = (screenWidth - appGridWidth) / 2;
70        let startPositionY: number = titleTopMargin + titleHeight + appGridPadding;
71        const index: number = this.getIndexInAppList(appItemInfo);
72        let row: number = Math.floor(index / bigFolderColumns);
73        let column: number = index % bigFolderColumns;
74        if (column != 0) {
75            row += 1;
76        } else {
77            column = bigFolderColumns;
78        }
79        Log.showInfo(TAG, `calculateAppIconPosition index ${index} row ${row} column ${column}`);
80        let columnsGap = this.mBigFolderStyleConfig.mOpenFolderGridGap;
81        let rowsGap = this.mBigFolderStyleConfig.mOpenFolderGridGap - this.mBigFolderStyleConfig.mOpenFolderGridIconTopPadding;
82        let appItemWidth = (appGridWidth - columnsGap * (bigFolderColumns - 1)) / bigFolderColumns;
83        let appItemHeight = (appGridHeight - rowsGap * (bigFolderRows - 1)) / bigFolderRows;
84        let itemLeftMargin = (appItemWidth - appIconSize) / 2;
85        this.mAppIconPositionX = startPositionX + (column - 1) * (appItemWidth + columnsGap) + itemLeftMargin;
86        this.mAppIconPositionY = startPositionY + (row - 1) * (appItemHeight + rowsGap)
87        + this.mBigFolderStyleConfig.mOpenFolderGridIconTopPadding;
88    }
89
90    private getIndexInAppList(appItemInfo): number {
91        let index: number = 0;
92        let folderInfo: {
93            layoutInfo: AppItemInfo[][],
94            enterEditing: boolean,
95            folderName: string,
96            folderId: string
97        } = AppStorage.Get('openFolderData');
98        for (var i = 0; i < folderInfo.layoutInfo.length; i++) {
99            for (var j = 0; j < folderInfo.layoutInfo[i].length; j++) {
100                if (appItemInfo.bundleName === folderInfo.layoutInfo[i][j]?.bundleName) {
101                    index = j;
102                    break;
103                }
104            }
105        }
106
107        return index + 1;
108    }
109}
110