1/**
2 * Copyright (c) 2021-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 { CommonConstants } from '@ohos/common';
17import { LayoutViewModel } from '@ohos/common';
18import { PageDesktopGridStyleConfig } from '@ohos/pagedesktop';
19import StyleConstants from './constants/StyleConstants';
20
21/**
22 * Phone grid style config class
23 */
24export default class PhonePageDesktopGridStyleConfig extends PageDesktopGridStyleConfig {
25  /**
26   * icon size
27   */
28  mIconSize = StyleConstants.DEFAULT_APP_ICON_SIZE_WIDTH;
29
30  /**
31   * name size
32   */
33  mNameSize = StyleConstants.DEFAULT_APP_NAME_SIZE;
34
35  /**
36   * name height
37   */
38  mNameHeight = StyleConstants.DEFAULT_APP_NAME_HEIGHT;
39
40  /**
41   * item padding
42   */
43  mPaddingTop = StyleConstants.DEFAULT_APP_TOP_RATIO;
44
45  protected constructor() {
46    super();
47  }
48
49  /**
50   * get PhonePageDesktopGridStyleConfig instance
51   */
52  static getInstance(): PhonePageDesktopGridStyleConfig {
53    if (globalThis.PhonePageDesktopGridStyleConfig === undefined) {
54      globalThis.PhonePageDesktopGridStyleConfig  = new PhonePageDesktopGridStyleConfig();
55    }
56    globalThis.PhonePageDesktopGridStyleConfig.initConfig();
57    return globalThis.PhonePageDesktopGridStyleConfig ;
58  }
59
60  initConfig(): void {
61    const result = LayoutViewModel.getInstance().calculateDesktop();
62    this.mMargin = result.mMargin;
63    this.mColumnsGap = result.mColumnsGap;
64    this.mRowsGap = result.mRowsGap;
65    this.mColumns = result.mColumns;
66    this.mRows = result.mRows;
67    this.mDesktopMarginTop = result.mDesktopMarginTop;
68    this.mGridWidth = result.mGridWidth;
69    this.mGridHeight = result.mGridHeight;
70    this.mAppItemSize = result.mAppItemSize;
71    this.mNameSize = result.mNameSize;
72    this.mNameHeight = result.mNameHeight;
73    this.mIconNameMargin = result.mIconNameMargin;
74    this.mIconSize = result.mIconSize;
75    this.mNameLines = result.mNameLines;
76    this.mIconMarginHorizontal = result.mIconMarginHorizontal;
77    this.mIconMarginVertical = result.mIconMarginVertical;
78  }
79
80  getConfigLevel(): string {
81    return CommonConstants.LAYOUT_CONFIG_LEVEL_PRODUCT;
82  }
83}
84