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 { StyleConstants } from '@ohos/common';
17import { CommonConstants } from '@ohos/common';
18import { LayoutViewModel } from '@ohos/common';
19import { AppListStyleConfig } from '@ohos/common';
20import { PresetStyleConstants } from '@ohos/common';
21import { BigFolderModel } from '../model/BigFolderModel';
22import { BigFolderConstants } from './constants/BigFolderConstants';
23import { BigFolderStyleConstants } from './constants/BigFolderStyleConstants';
24
25/**
26 * folder style config
27 */
28export class BigFolderStyleConfig extends AppListStyleConfig {
29  /**
30   * folder grid size
31   */
32  mGridSize = StyleConstants.DEFAULT_FOLDER_GRID_SIZE;
33
34  /**
35   * folder app size
36   */
37  mFolderAppSize = StyleConstants.DEFAULT_FOLDER_APP_SIZE;
38
39  /**
40   * folder grid margin side
41   */
42  mGridMargin = StyleConstants.DEFAULT_FOLDER_GRID_MARGIN;
43
44  /**
45   * folder grid gap
46   */
47  mFolderGridGap = StyleConstants.DEFAULT_FOLDER_GRID_GAP;
48
49  /**
50   * margin of folder open
51   */
52  mFolderOpenMargin = StyleConstants.DEFAULT_OPEN_FOLDER_TITLE_HEIGHT;
53  mFolderOpenTitle = StyleConstants.DEFAULT_OPEN_FOLDER_TITLE_TOP;
54
55  /**
56   * open folder grid row
57   */
58  mOpenFolderGridRow = StyleConstants.DEFAULT_OPEN_FOLDER_GRID_ROW;
59
60  /**
61   * open folder grid column
62   */
63  mOpenFolderGridColumn = StyleConstants.DEFAULT_OPEN_FOLDER_GRID_COLUMN;
64
65  /**
66   * open folder app size
67   */
68  mOpenFolderAppSize = StyleConstants.DEFAULT_OPEN_FOLDER_APP_SIZE;
69
70  /**
71   * icon size of open folder
72   */
73  mOpenFolderIconSize = StyleConstants.DEFAULT_OPEN_FOLDER_APP_SIZE;
74
75  /**
76   * add icon size of open folder
77   */
78  mOpenFolderAddIconSize = StyleConstants.DEFAULT_ADD_APP_SIZE;
79
80  /**
81   * open folder app size
82   */
83  mOpenFolderAppNameSize = StyleConstants.DEFAULT_OPEN_FOLDER_APP_NAME_SIZE;
84
85  /**
86   * open folder app name height
87   */
88  mOpenFolderAppNameHeight = StyleConstants.DEFAULT_OPEN_FOLDER_APP_NAME_HEIGHT;
89
90  /**
91   * open folder grid width
92   */
93  mOpenFolderGridWidth = StyleConstants.DEFAULT_OPEN_FOLDER_GRID_WIDTH;
94
95  /**
96   * open folder grid height
97   */
98  mOpenFolderGridHeight = StyleConstants.DEFAULT_OPEN_FOLDER_GRID_HEIGHT;
99
100  /**
101   * open folder swiper height
102   */
103  mOpenFolderSwiperHeight = StyleConstants.DEFAULT_OPEN_FOLDER_SWIPER_HEIGHT;
104
105  /**
106   * open folder grid gap
107   */
108  mOpenFolderGridGap = StyleConstants.DEFAULT_OPEN_FOLDER_GRID_GAP;
109
110  /**
111   * padding of open folder layout
112   */
113  mOpenFolderGridPadding = PresetStyleConstants.DEFAULT_OPEN_FOLDER_PADDING;
114
115  /**
116   * padding of open folder icon
117   */
118  mOpenFolderGridIconTopPadding = PresetStyleConstants.DEFAULT_ICON_PADDING_TOP;
119  /**
120   * width of add app dialog
121   */
122  mAddFolderDialogWidth: number = BigFolderStyleConstants.DEFAULT_APP_ADD_DIALOG_WIDTH;
123
124  /**
125   * height of add app dialog
126   */
127  mAddFolderDialogHeight: number = BigFolderStyleConstants.DEFAULT_APP_ADD_DIALOG_HEIGHT;
128
129  /**
130   * width of add app container
131   */
132  mAddFolderGridWidth: number = BigFolderStyleConstants.DEFAULT_FOLDER_APP_GRID_LIST;
133
134  /**
135   * gap of add app container
136   */
137  mAddFolderGridGap: number = PresetStyleConstants.DEFAULT_FOLDER_ADD_GAP;
138
139  /**
140   * margin of add app container
141   */
142  mAddFolderGridMargin: number = PresetStyleConstants.DEFAULT_FOLDER_ADD_MARGIN;
143
144  /**
145   * maxHeight of add app container
146   */
147  mAddFolderMaxHeight: number = PresetStyleConstants.DEFAULT_FOLDER_ADD_MAX_HEIGHT;
148
149  /**
150   * size of add app toggle
151   */
152  mFolderToggleSize: number = PresetStyleConstants.DEFAULT_APP_GRID_TOGGLE_SIZE;
153
154  /**
155   * title size of add app
156   */
157  mAddFolderTitleSize: number = PresetStyleConstants.DEFAULT_FOLDER_ADD_TITLE_TEXT_SIZE;
158
159  /**
160   * text size of add app item
161   */
162  mAddFolderTextSize: number = PresetStyleConstants.DEFAULT_FOLDER_ADD_GRID_TEXT_SIZE;
163
164  /**
165   * name lines of add app item
166   */
167  mAddFolderTextLines: number = PresetStyleConstants.DEFAULT_FOLDER_ADD_TEXT_LINES;
168
169  /**
170   * line height of add app item
171   */
172  mAddFolderLinesHeight: number = PresetStyleConstants.DEFAULT_TEXT_LINES;
173
174  /**
175   * icon size of add app
176   */
177  mAddFolderIconSize: number = PresetStyleConstants.DEFAULT_ICON_SIZE;
178
179  /**
180   * size of add app item
181   */
182  mAddFolderItemSize: number = PresetStyleConstants.DEFAULT_APP_LAYOUT_SIZE;
183
184  /**
185   * padding top of add app icon
186   */
187  mAddFolderIconPaddingTop: number = PresetStyleConstants.DEFAULT_ICON_PADDING_TOP;
188
189  /**
190   * button size of add app
191   */
192  mAddFolderButtonSize: number = PresetStyleConstants.DEFAULT_FOLDER_ADD_BUTTON_SIZE;
193
194  /**
195   * margin left of icon with add app item
196   */
197  mAddFolderIconMarginHorizontal = PresetStyleConstants.DEFAULT_ICON_PADDING_LEFT;
198  /**
199   * folder list blur
200   */
201  mBackdropBlur = 20;
202
203  private constructor() {
204    super();
205  }
206
207  /**
208   * get folder style config instance
209   */
210  static getInstance(): BigFolderStyleConfig {
211    if (globalThis.BigFolderStyleConfigInstance == null) {
212      globalThis.BigFolderStyleConfigInstance = new BigFolderStyleConfig();
213    }
214    globalThis.BigFolderStyleConfigInstance.initConfig();
215    return globalThis.BigFolderStyleConfigInstance;
216  }
217
218  initConfig(): void {
219    const layoutViewModel = LayoutViewModel.getInstance();
220    const desktopFolderLayoutInfo = BigFolderModel.getInstance().getFolderLayout();
221    const folderResult = layoutViewModel.calculateFolder(desktopFolderLayoutInfo);
222    const openFolderLayoutInfo = BigFolderModel.getInstance().getFolderOpenLayout();
223    const openResult = layoutViewModel.calculateOpenFolder(openFolderLayoutInfo);
224    const addAppLayoutInfo = BigFolderModel.getInstance().getFolderAddAppLayout();
225    const addResult = layoutViewModel.calculateFolderAddList(addAppLayoutInfo);
226
227    this.mGridSize = folderResult.mGridSize;
228    this.mFolderAppSize = folderResult.mFolderAppSize;
229    this.mFolderGridGap = folderResult.mFolderGridGap;
230    this.mGridMargin = folderResult.mGridMargin;
231    this.mNameHeight = folderResult.mNameHeight;
232    this.mNameLines = folderResult.mNameLines;
233    this.mIconNameMargin = folderResult.mIconNameMargin;
234    this.mOpenFolderGridRow = openResult.mOpenFolderGridRow;
235    this.mOpenFolderGridColumn = openResult.mOpenFolderGridColumn;
236    this.mOpenFolderGridWidth = openResult.mOpenFolderGridWidth;
237    this.mOpenFolderGridHeight = openResult.mOpenFolderGridHeight;
238    this.mOpenFolderSwiperHeight = openResult.mOpenFolderSwiperHeight;
239    this.mOpenFolderIconSize = openResult.mOpenFolderIconSize;
240    this.mOpenFolderAddIconSize = openResult.mOpenFolderAddIconSize;
241    this.mOpenFolderAppSize = openResult.mOpenFolderAppSize;
242    this.mOpenFolderAppNameSize = openResult.mOpenFolderAppNameSize;
243    this.mOpenFolderAppNameHeight = openResult.mOpenFolderAppNameHeight;
244    this.mOpenFolderGridGap = openResult.mOpenFolderGridGap;
245    this.mOpenFolderGridPadding = openResult.mOpenFolderGridPadding;
246    this.mFolderOpenMargin = openResult.mFolderOpenMargin;
247    this.mFolderOpenTitle = openResult.mFolderOpenTitle;
248    this.mOpenFolderGridIconTopPadding = openResult.mOpenFolderGridIconTopPadding;
249
250    this.mAddFolderGridWidth = addResult.mAddFolderGridWidth;
251    this.mAddFolderDialogWidth = addResult.mAddFolderDialogWidth;
252    this.mAddFolderDialogHeight = addResult.mAddFolderDialogHeight;
253    this.mAddFolderGridGap = addResult.mAddFolderGridGap;
254    this.mAddFolderGridMargin = addResult.mAddFolderGridMargin;
255    this.mAddFolderMaxHeight = addResult.mAddFolderMaxHeight;
256    this.mFolderToggleSize = addResult.mFolderToggleSize;
257    this.mAddFolderTextSize = addResult.mAddFolderTextSize;
258    this.mAddFolderTextLines = addResult.mAddFolderTextLines;
259    this.mAddFolderLinesHeight = addResult.mAddFolderLinesHeight;
260    this.mAddFolderItemSize = addResult.mAddFolderItemSize;
261    this.mAddFolderIconPaddingTop = addResult.mAddFolderIconPaddingTop;
262    this.mAddFolderIconMarginHorizontal = addResult.mAddFolderIconMarginHorizontal;
263    this.mAddFolderIconSize = addResult.mAddFolderIconSize;
264    this.mAddFolderTitleSize = addResult.mAddFolderTitleSize;
265    this.mAddFolderButtonSize = addResult.mAddFolderButtonSize;
266  }
267
268  getConfigLevel(): string {
269    return CommonConstants.LAYOUT_CONFIG_LEVEL_FEATURE;
270  }
271
272  getFeatureName(): string {
273    return BigFolderConstants.FEATURE_NAME;
274  }
275}
276