• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2023-2023 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 BaseDataSource from './BaseDataSource';
17import FormConstants from '../common/constants/FormConstants';
18import AppFormWeightManager from '../manager/AppFormWeightManager';
19
20const TAG = 'HighFrequencyAppDataSource';
21
22/**
23 * 推荐卡片资源池数据源:高频应用对应的卡片
24 */
25export default class HighFrequencyAppDataSource extends BaseDataSource {
26  private mAppFormWeightManager: AppFormWeightManager = AppFormWeightManager.getInstance();
27
28  constructor() {
29    super();
30  }
31
32  /**
33  * getInstance
34   *
35   * @return Instance
36   */
37  static getInstance(): HighFrequencyAppDataSource {
38    if (globalThis.HighFrequencyAppDataSource == null) {
39      globalThis.HighFrequencyAppDataSource = new HighFrequencyAppDataSource();
40    }
41    return globalThis.HighFrequencyAppDataSource;
42  }
43
44  protected getSourceDataList(): string[] {
45    return this.mAppFormWeightManager.getSortedAppUsageWeight()?.map((weight) => {
46      return String(weight[0]);
47    });
48  }
49
50  /**
51   * 获取卡片资源池数据源名
52   *
53   * @return 卡片资源池数据源名
54   */
55  public getName(): string {
56    return FormConstants.FORM_DATA_SOURCE_POOL_NAME_HIGH_FREQUENCY;
57  }
58
59  /**
60   * 获取卡片资源池阈值
61   *
62   * @return 卡片资源池阈值
63   */
64  public getThreshold(): number {
65    return FormConstants.SERVICE_FORM_POOL_HIGH_FREQUENCY_APP_THRESHOLD;
66  }
67}
68