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 { Log } from '@ohos/common'; 17import { EventConstants } from '@ohos/common'; 18import { CommonConstants } from '@ohos/common'; 19import { SettingsModel } from '@ohos/common'; 20import { FolderLayoutConfig } from '@ohos/common'; 21import { localEventManager } from '@ohos/common'; 22import { layoutConfigManager } from '@ohos/common'; 23 24const TAG = 'BigFolderModel'; 25 26/** 27 * Folder information data model 28 */ 29export class BigFolderModel { 30 private readonly mFolderLayoutConfig: FolderLayoutConfig; 31 private readonly mSettingsModel: SettingsModel; 32 mFolderInfoList = []; 33 34 private constructor() { 35 this.mSettingsModel = SettingsModel.getInstance(); 36 this.mFolderLayoutConfig = layoutConfigManager.getFunctionConfig(FolderLayoutConfig.FOLDER_GRID_LAYOUT_INFO); 37 } 38 39 /** 40 * Get folder model object 41 * 42 * @return Single instance of folder data model 43 */ 44 static getInstance(): BigFolderModel { 45 if (globalThis.BigFolderModelInstance == null) { 46 globalThis.BigFolderModelInstance = new BigFolderModel(); 47 } 48 return globalThis.BigFolderModelInstance; 49 } 50 51 getFolderLayout(): any { 52 return this.mFolderLayoutConfig.getFolderLayoutInfo().folderLayoutTable; 53 } 54 55 getFolderOpenLayout(): any { 56 return this.mFolderLayoutConfig.getFolderLayoutInfo().folderOpenLayoutTable; 57 } 58 59 getFolderAddAppLayout(): any { 60 return this.mFolderLayoutConfig.getFolderLayoutInfo().folderAddAppLayoutTable; 61 } 62 63 /** 64 * Get folder list 65 * 66 * @return folder list 67 */ 68 async getFolderList() { 69 Log.showDebug(TAG, 'getFolderList'); 70 this.mFolderInfoList = []; 71 let gridLayoutInfo = { 72 layoutInfo: [] 73 }; 74 gridLayoutInfo = this.mSettingsModel.getLayoutInfo(); 75 const layoutInfo = gridLayoutInfo.layoutInfo; 76 for (let i = 0; i < layoutInfo.length; i++) { 77 if (layoutInfo[i].typeId == CommonConstants.TYPE_FOLDER) { 78 this.mFolderInfoList.push(layoutInfo[i]); 79 } 80 } 81 return this.mFolderInfoList; 82 } 83 84 /** 85 * register folder update event. 86 * 87 * @param listener 88 */ 89 registerFolderUpdateEvent(listener): void { 90 localEventManager.registerEventListener(listener, [ 91 EventConstants.EVENT_BADGE_UPDATE, 92 EventConstants.EVENT_FOLDER_PACKAGE_REMOVED 93 ]); 94 } 95}