16e80583aSopenharmony_ci/**
26e80583aSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
36e80583aSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
46e80583aSopenharmony_ci * you may not use this file except in compliance with the License.
56e80583aSopenharmony_ci * You may obtain a copy of the License at
66e80583aSopenharmony_ci *
76e80583aSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
86e80583aSopenharmony_ci *
96e80583aSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
106e80583aSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
116e80583aSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126e80583aSopenharmony_ci * See the License for the specific language governing permissions and
136e80583aSopenharmony_ci * limitations under the License.
146e80583aSopenharmony_ci */
156e80583aSopenharmony_ciimport { ILayoutConfig } from './ILayoutConfig';
166e80583aSopenharmony_ciimport { CommonConstants } from '../constants/CommonConstants';
176e80583aSopenharmony_ciimport defaultLayoutConfig from '../configs/DefaultLayoutConfig';
186e80583aSopenharmony_ci
196e80583aSopenharmony_ci/**
206e80583aSopenharmony_ci * Recent missions layout mode configuration
216e80583aSopenharmony_ci */
226e80583aSopenharmony_ciexport class RecentsModeConfig extends ILayoutConfig {
236e80583aSopenharmony_ci  
246e80583aSopenharmony_ci  /**
256e80583aSopenharmony_ci   * The index of recent missions layout mode configuration
266e80583aSopenharmony_ci   */
276e80583aSopenharmony_ci  static RECENT_MISSIONS_MODE_CONFIG = 'RecentsModeConfig';
286e80583aSopenharmony_ci  protected mLoadConfig: any;
296e80583aSopenharmony_ci  private static readonly RECENT_MISSIONS_LIMIT = 'RecentMissionsLimit';
306e80583aSopenharmony_ci  protected mRecentMissionsLimit: number = defaultLayoutConfig.defaultRecentMissionsLimit;
316e80583aSopenharmony_ci  protected mRecentMissionsRowType: string = defaultLayoutConfig.defaultRecentMissionsRowConfig;
326e80583aSopenharmony_ci
336e80583aSopenharmony_ci  protected constructor() {
346e80583aSopenharmony_ci    super();
356e80583aSopenharmony_ci  }
366e80583aSopenharmony_ci
376e80583aSopenharmony_ci  protected getPersistConfigJson(): string {
386e80583aSopenharmony_ci    const persistConfig = {
396e80583aSopenharmony_ci      recentMissionsLimit: this.mRecentMissionsLimit,
406e80583aSopenharmony_ci      recentMissionsRowType: this.mRecentMissionsRowType
416e80583aSopenharmony_ci    };
426e80583aSopenharmony_ci    return JSON.stringify(persistConfig);
436e80583aSopenharmony_ci  }
446e80583aSopenharmony_ci
456e80583aSopenharmony_ci  /**
466e80583aSopenharmony_ci   * Get recent missions instance
476e80583aSopenharmony_ci   *
486e80583aSopenharmony_ci   * @return {RecentsModeConfig} RecentsModeConfig instance
496e80583aSopenharmony_ci   */
506e80583aSopenharmony_ci  static getInstance(): RecentsModeConfig {
516e80583aSopenharmony_ci    if (globalThis.RecentsModeConfigInstance == null) {
526e80583aSopenharmony_ci      globalThis.RecentsModeConfigInstance = new RecentsModeConfig();
536e80583aSopenharmony_ci      globalThis.RecentsModeConfigInstance.initConfig();
546e80583aSopenharmony_ci    }
556e80583aSopenharmony_ci    return globalThis.RecentsModeConfigInstance;
566e80583aSopenharmony_ci  }
576e80583aSopenharmony_ci
586e80583aSopenharmony_ci  initConfig(): void {
596e80583aSopenharmony_ci    this.mLoadConfig = this.loadPersistConfig();
606e80583aSopenharmony_ci    this.mRecentMissionsLimit = this.mLoadConfig.recentMissionsLimit;
616e80583aSopenharmony_ci    this.mRecentMissionsRowType = this.mLoadConfig.recentMissionsRowType;
626e80583aSopenharmony_ci  }
636e80583aSopenharmony_ci
646e80583aSopenharmony_ci  getConfigLevel(): string {
656e80583aSopenharmony_ci    return CommonConstants.LAYOUT_CONFIG_LEVEL_COMMON;
666e80583aSopenharmony_ci  }
676e80583aSopenharmony_ci
686e80583aSopenharmony_ci  getConfigType(): number {
696e80583aSopenharmony_ci    return CommonConstants.LAYOUT_CONFIG_TYPE_MODE;
706e80583aSopenharmony_ci  }
716e80583aSopenharmony_ci
726e80583aSopenharmony_ci  getConfigName(): string {
736e80583aSopenharmony_ci    return RecentsModeConfig.RECENT_MISSIONS_MODE_CONFIG;
746e80583aSopenharmony_ci  }
756e80583aSopenharmony_ci
766e80583aSopenharmony_ci  /**
776e80583aSopenharmony_ci   * Update recent missions limit
786e80583aSopenharmony_ci   *
796e80583aSopenharmony_ci   * @param {number} limit value
806e80583aSopenharmony_ci   */
816e80583aSopenharmony_ci  updateRecentMissionsLimit(limit: number): void {
826e80583aSopenharmony_ci    this.mRecentMissionsLimit = limit;
836e80583aSopenharmony_ci    super.persistConfig();
846e80583aSopenharmony_ci  }
856e80583aSopenharmony_ci
866e80583aSopenharmony_ci  /**
876e80583aSopenharmony_ci   * Get recent missions limit
886e80583aSopenharmony_ci   *
896e80583aSopenharmony_ci   * @return {number} limit value
906e80583aSopenharmony_ci   */
916e80583aSopenharmony_ci  getRecentMissionsLimit(): number {
926e80583aSopenharmony_ci    return this.mRecentMissionsLimit;
936e80583aSopenharmony_ci  }
946e80583aSopenharmony_ci
956e80583aSopenharmony_ci  /**
966e80583aSopenharmony_ci   * Get Recent row type
976e80583aSopenharmony_ci   *
986e80583aSopenharmony_ci   * @return {string} single / double
996e80583aSopenharmony_ci   */
1006e80583aSopenharmony_ci  getRecentMissionsRowType(): string {
1016e80583aSopenharmony_ci    return this.mRecentMissionsRowType;
1026e80583aSopenharmony_ci  }
1036e80583aSopenharmony_ci
1046e80583aSopenharmony_ci  /**
1056e80583aSopenharmony_ci   * load configuration
1066e80583aSopenharmony_ci   */
1076e80583aSopenharmony_ci  loadPersistConfig(): any {
1086e80583aSopenharmony_ci    let defaultConfig = super.loadPersistConfig();
1096e80583aSopenharmony_ci    const configFromFile = this.loadPersistConfigFromFile();
1106e80583aSopenharmony_ci    if (configFromFile) {
1116e80583aSopenharmony_ci      defaultConfig = JSON.parse(configFromFile);
1126e80583aSopenharmony_ci    }
1136e80583aSopenharmony_ci    return defaultConfig;
1146e80583aSopenharmony_ci  }
1156e80583aSopenharmony_ci}