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 */ 15import { ILayoutConfig } from './ILayoutConfig'; 16import { CommonConstants } from '../constants/CommonConstants'; 17import defaultLayoutConfig from '../configs/DefaultLayoutConfig'; 18 19/** 20 * Recent missions layout mode configuration 21 */ 22export class RecentsModeConfig extends ILayoutConfig { 23 24 /** 25 * The index of recent missions layout mode configuration 26 */ 27 static RECENT_MISSIONS_MODE_CONFIG = 'RecentsModeConfig'; 28 protected mLoadConfig: any; 29 private static readonly RECENT_MISSIONS_LIMIT = 'RecentMissionsLimit'; 30 protected mRecentMissionsLimit: number = defaultLayoutConfig.defaultRecentMissionsLimit; 31 protected mRecentMissionsRowType: string = defaultLayoutConfig.defaultRecentMissionsRowConfig; 32 33 protected constructor() { 34 super(); 35 } 36 37 protected getPersistConfigJson(): string { 38 const persistConfig = { 39 recentMissionsLimit: this.mRecentMissionsLimit, 40 recentMissionsRowType: this.mRecentMissionsRowType 41 }; 42 return JSON.stringify(persistConfig); 43 } 44 45 /** 46 * Get recent missions instance 47 * 48 * @return {RecentsModeConfig} RecentsModeConfig instance 49 */ 50 static getInstance(): RecentsModeConfig { 51 if (globalThis.RecentsModeConfigInstance == null) { 52 globalThis.RecentsModeConfigInstance = new RecentsModeConfig(); 53 globalThis.RecentsModeConfigInstance.initConfig(); 54 } 55 return globalThis.RecentsModeConfigInstance; 56 } 57 58 initConfig(): void { 59 this.mLoadConfig = this.loadPersistConfig(); 60 this.mRecentMissionsLimit = this.mLoadConfig.recentMissionsLimit; 61 this.mRecentMissionsRowType = this.mLoadConfig.recentMissionsRowType; 62 } 63 64 getConfigLevel(): string { 65 return CommonConstants.LAYOUT_CONFIG_LEVEL_COMMON; 66 } 67 68 getConfigType(): number { 69 return CommonConstants.LAYOUT_CONFIG_TYPE_MODE; 70 } 71 72 getConfigName(): string { 73 return RecentsModeConfig.RECENT_MISSIONS_MODE_CONFIG; 74 } 75 76 /** 77 * Update recent missions limit 78 * 79 * @param {number} limit value 80 */ 81 updateRecentMissionsLimit(limit: number): void { 82 this.mRecentMissionsLimit = limit; 83 super.persistConfig(); 84 } 85 86 /** 87 * Get recent missions limit 88 * 89 * @return {number} limit value 90 */ 91 getRecentMissionsLimit(): number { 92 return this.mRecentMissionsLimit; 93 } 94 95 /** 96 * Get Recent row type 97 * 98 * @return {string} single / double 99 */ 100 getRecentMissionsRowType(): string { 101 return this.mRecentMissionsRowType; 102 } 103 104 /** 105 * load configuration 106 */ 107 loadPersistConfig(): any { 108 let defaultConfig = super.loadPersistConfig(); 109 const configFromFile = this.loadPersistConfigFromFile(); 110 if (configFromFile) { 111 defaultConfig = JSON.parse(configFromFile); 112 } 113 return defaultConfig; 114 } 115}