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: number = 0; 29 @State bundleName: string = ''; 30 @State moduleName: string = ''; 31 @State labelId: number = 0; 32 @State icon: string = ''; 33 @State useCache: boolean = true; 34 private mIsSingleLayout: boolean = true; 35 private mResourceManager = ResourceManager.getInstance(); 36 private mDefaultAppIcon?: ResourceStr; 37 private mRecentMissionsViewModel: RecentMissionsViewModel = RecentMissionsViewModel.getInstance(); 38 39 aboutToAppear(): void { 40 this.mDefaultAppIcon = RecentsStyleConstants.DEFAULT_APP_ICON_IMAGE; 41 this.updateIcon(); 42 this.mIsSingleLayout = this.mRecentMissionsViewModel.getRecentMissionsRowType() === 'single' ? true : false; 43 } 44 45 /** 46 * The callback of recent missions app icon. 47 * 48 * @param {string} image - the value get from ResourceManager 49 */ 50 iconLoadCallback = (image: string): void => { 51 this.icon = image; 52 } 53 54 /** 55 * Update the app icon of recent missions. 56 */ 57 updateIcon(): void { 58 this.mResourceManager.getAppIconWithCache(this.appIcon, 59 this.bundleName, this.moduleName, this.iconLoadCallback, ''); 60 } 61 62 build() { 63 Column() { 64 if (this.icon) { 65 Image(this.icon) 66 } else { 67 Image(this.mDefaultAppIcon) 68 } 69 70 } 71 .width(this.iconSize) 72 .height(this.iconSize) 73 } 74}