• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { ResourceManager } from '@ohos/common';
17import { RecentsStyleConstants } from '../constants/RecentsStyleConstants';
18import { RecentMissionsViewModel } from '../../viewmodel/RecentMissionsViewModel';
19
20const TAG = 'Recent-RecentMissionAppIcon';
21
22/**
23 * App icon component for recent missions.
24 */
25@Component
26export default struct RecentMissionAppIcon {
27  @State iconSize: number = 0;
28  @State @Watch("updateIcon") appIcon: string = '';
29  @State bundleName: string = '';
30  @State moduleName: string = '';
31  @State labelId: string = '';
32  @State icon: string = ' ';
33  @State useCache: boolean = true;
34  private mIsSingleLayout: boolean = true;
35  private mResourceManager = ResourceManager.getInstance();
36  private mDefaultAppIcon;
37  private mRecentMissionsViewModel: RecentMissionsViewModel = RecentMissionsViewModel.getInstance();
38
39  aboutToAppear(): void  {
40    this.mDefaultAppIcon = RecentsStyleConstants.DEFAULT_APP_ICON_IMAGE;
41    this.icon = this.mDefaultAppIcon;
42    this.updateIcon();
43    this.mIsSingleLayout = this.mRecentMissionsViewModel.getRecentMissionsRowType() === 'single' ? true : false;
44  }
45
46  /**
47   * The callback of recent missions app icon.
48   *
49   * @param {string} image - the value get from ResourceManager
50   */
51  iconLoadCallback(image): void {
52    this.icon = image;
53  }
54
55  /**
56   * Update the app icon of recent missions.
57   */
58  updateIcon(): void {
59    this.mResourceManager.getAppIconWithCache(this.appIcon,
60      this.bundleName, this.moduleName, this.iconLoadCallback.bind(this), this.mDefaultAppIcon);
61  }
62
63  build() {
64    Column() {
65      Image(this.icon)
66    }
67    .width(this.iconSize)
68    .height(this.iconSize)
69  }
70}