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 { ILayoutConfig } from './ILayoutConfig';
17import { CommonConstants } from '../constants/CommonConstants';
18import folderLayoutInfo from '../configs/FolderLayoutInfo';
19
20/**
21 * Folder layout configuration
22 */
23export class FolderLayoutConfig extends ILayoutConfig {
24
25  /**
26   *  The index of Folder layout configuration
27   */
28  static FOLDER_GRID_LAYOUT_INFO = 'FolderGridLayoutInfo';
29  protected mFolderLayoutInfo: any = folderLayoutInfo;
30
31  constructor() {
32    super();
33  }
34
35  /**
36   * Get folder layout configuration instance
37   */
38  static getInstance(): FolderLayoutConfig {
39    if (globalThis.FolderLayoutConfigInstance == null) {
40      globalThis.FolderLayoutConfigInstance = new FolderLayoutConfig();
41      globalThis.FolderLayoutConfigInstance.initConfig();
42    }
43    return globalThis.FolderLayoutConfigInstance;
44  }
45
46  initConfig(): void {
47    const config = this.loadPersistConfig();
48    this.mFolderLayoutInfo = config;
49  }
50
51  getConfigLevel(): string {
52    return CommonConstants.LAYOUT_CONFIG_LEVEL_COMMON;
53  }
54
55  getConfigType(): number {
56    return CommonConstants.LAYOUT_CONFIG_TYPE_FUNCTION;
57  }
58
59  getConfigName(): string {
60    return FolderLayoutConfig.FOLDER_GRID_LAYOUT_INFO;
61  }
62
63  getPersistConfigJson(): string {
64    return JSON.stringify(this.mFolderLayoutInfo);
65  }
66
67  /**
68   * Update folder layout data
69   *
70   * @params {gridLayoutInfo} folder layout data
71   */
72  updateFolderLayoutInfo(folderLayoutInfo: object): void {
73    this.mFolderLayoutInfo = folderLayoutInfo;
74    super.persistConfig();
75  }
76
77  /**
78   * Get folder layout data
79   *
80   * @return folder layout data
81   */
82  getFolderLayoutInfo(): any {
83    return this.mFolderLayoutInfo;
84  }
85}
86