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 { StyleConstants } from '../constants/StyleConstants'; 17import { CheckEmptyUtils } from '../utils/CheckEmptyUtils'; 18import { ResourceManager } from '../manager/ResourceManager'; 19import { LayoutViewModel } from '../viewmodel/LayoutViewModel'; 20 21 22@CustomDialog 23export struct UninstallDialog { 24 @StorageLink('uninstallAppInfo') appInfo: any = {}; 25 @StorageLink('isPad') isPad: boolean = false; 26 @StorageLink('NavigationBarStatusValue') navigationBarStatusValue: boolean = false; 27 controller: CustomDialogController; 28 cancel: () => void 29 confirm: () => void 30 dialogName: string 31 dialogContent: string 32 @State icon: string = ''; 33 appIcon: string; 34 bundleName: string; 35 moduleName: string; 36 mUninstallDialogWidth: string; 37 private mLayoutViewModel: LayoutViewModel; 38 39 private async updateScreenSize() { 40 this.mUninstallDialogWidth = this.mLayoutViewModel.getCommonDialogWidth(); 41 } 42 43 private mResourceManager; 44 private mDefaultAppIcon; 45 46 aboutToAppear(): void { 47 this.mLayoutViewModel = LayoutViewModel.getInstance(); 48 this.updateScreenSize(); 49 this.mResourceManager = ResourceManager.getInstance(); 50 51 this.appIcon = this.appInfo.appIconId; 52 this.bundleName = this.appInfo.bundleName; 53 this.moduleName = this.appInfo.moduleName; 54 55 if (CheckEmptyUtils.isEmpty(this.icon)) { 56 this.updateIcon(); 57 } 58 } 59 60 public iconLoadCallback(image) { 61 this.icon = image; 62 } 63 64 public updateIcon() { 65 this.mResourceManager.getAppIconWithCache(this.appIcon, this.bundleName, this.moduleName, 66 this.iconLoadCallback.bind(this), this.mDefaultAppIcon); 67 } 68 69 build() { 70 Flex({ direction: FlexDirection.Column, justifyContent: this.isPad ? FlexAlign.Center : FlexAlign.End }) { 71 Column() { 72 Image(this.icon).width(StyleConstants.DEFAULT_APP_ITEM_HEIGHT).height(StyleConstants.DEFAULT_APP_ITEM_HEIGHT) 73 74 Row() { 75 Text(this.dialogName) 76 .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 77 .fontColor(StyleConstants.TEXT_COLOR_PRIMARY) 78 Text(this.dialogContent) 79 .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 80 .fontColor(StyleConstants.TEXT_COLOR_PRIMARY) 81 }.margin({ top: StyleConstants.DEFAULT_DIALOG_RADIUS, bottom: StyleConstants.DEFAULT_DIALOG_BOTTOM_MARGIN }) 82 83 Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceEvenly }) { 84 Button() { 85 Text($r('app.string.cancel')) 86 .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 87 .fontColor(StyleConstants.BUTTON_FONT_COLOR) 88 } 89 .backgroundColor(StyleConstants.DEFAULT_BG_COLOR) 90 .height(StyleConstants.DEFAULT_BUTTON_HEIGHT) 91 .width(StyleConstants.DEFAULT_BUTTON_WIDTH) 92 .onClick(() => { 93 this.controller.close(); 94 this.cancel() 95 }) 96 97 Divider() 98 .vertical(true) 99 .color(StyleConstants.DEFAULT_DIVIDER_COLOR) 100 .height(StyleConstants.DEFAULT_DIVIDER_HEIGHT) 101 102 Button() { 103 Text(this.isPad && this.dialogName == '是否卸载' ? $r('app.string.uninstall') : $r('app.string.submit')) 104 .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 105 .fontColor(StyleConstants.DEFAULT_COLOR_ERROR) 106 } 107 .backgroundColor(StyleConstants.DEFAULT_BG_COLOR) 108 .height(StyleConstants.DEFAULT_BUTTON_HEIGHT) 109 .width(StyleConstants.DEFAULT_BUTTON_WIDTH) 110 .onClick(() => { 111 this.controller.close(); 112 this.confirm() 113 }) 114 } 115 } 116 .backgroundColor($r("app.color.default_dialog_background")) 117 .backgroundBlurStyle(BlurStyle.Regular) 118 .padding({ 119 top: StyleConstants.DEFAULT_24, 120 bottom: StyleConstants.DEFAULT_DIALOG_BOTTOM_MARGIN 121 }) 122 .border({ 123 radius: StyleConstants.DEFAULT_DIALOG_RADIUS 124 }) 125 .width(this.mUninstallDialogWidth) 126 } 127 .margin({ bottom: this.navigationBarStatusValue ? StyleConstants.DEFAULT_12 : StyleConstants.DEFAULT_40 }) 128 .padding({ left: StyleConstants.DEFAULT_12, right: StyleConstants.DEFAULT_12 }) 129 } 130}