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 aboutToDisappear(): void { 61 this.controller = null; 62 this.cancel = null; 63 this.confirm = null; 64 } 65 66 public iconLoadCallback(image) { 67 this.icon = image; 68 } 69 70 public updateIcon() { 71 this.mResourceManager.getAppIconWithCache(this.appIcon, this.bundleName, this.moduleName, 72 this.iconLoadCallback.bind(this), this.mDefaultAppIcon); 73 } 74 75 build() { 76 Flex({ direction: FlexDirection.Column, justifyContent: this.isPad ? FlexAlign.Center : FlexAlign.End }) { 77 Column() { 78 Image(this.icon).width(StyleConstants.DEFAULT_APP_ITEM_HEIGHT).height(StyleConstants.DEFAULT_APP_ITEM_HEIGHT) 79 80 Row() { 81 Text(this.dialogName) 82 .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 83 .fontColor(StyleConstants.TEXT_COLOR_PRIMARY) 84 Text(this.dialogContent) 85 .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 86 .fontColor(StyleConstants.TEXT_COLOR_PRIMARY) 87 }.margin({ top: StyleConstants.DEFAULT_DIALOG_RADIUS, bottom: StyleConstants.DEFAULT_DIALOG_BOTTOM_MARGIN }) 88 89 Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceEvenly }) { 90 Button() { 91 Text($r('app.string.cancel')) 92 .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 93 .fontColor(StyleConstants.BUTTON_FONT_COLOR) 94 } 95 .backgroundColor(StyleConstants.DEFAULT_BG_COLOR) 96 .height(StyleConstants.DEFAULT_BUTTON_HEIGHT) 97 .width(StyleConstants.DEFAULT_BUTTON_WIDTH) 98 .onClick(() => { 99 this.controller.close(); 100 this.cancel() 101 }) 102 103 Divider() 104 .vertical(true) 105 .color(StyleConstants.DEFAULT_DIVIDER_COLOR) 106 .height(StyleConstants.DEFAULT_DIVIDER_HEIGHT) 107 108 Button() { 109 Text(this.isPad && this.dialogName == '是否卸载' ? $r('app.string.uninstall') : $r('app.string.submit')) 110 .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 111 .fontColor(StyleConstants.DEFAULT_COLOR_ERROR) 112 } 113 .backgroundColor(StyleConstants.DEFAULT_BG_COLOR) 114 .height(StyleConstants.DEFAULT_BUTTON_HEIGHT) 115 .width(StyleConstants.DEFAULT_BUTTON_WIDTH) 116 .onClick(() => { 117 this.controller.close(); 118 this.confirm() 119 }) 120 } 121 } 122 .backgroundColor($r("app.color.default_dialog_background")) 123 .backgroundBlurStyle(BlurStyle.Regular) 124 .padding({ 125 top: StyleConstants.DEFAULT_24, 126 bottom: StyleConstants.DEFAULT_DIALOG_BOTTOM_MARGIN 127 }) 128 .border({ 129 radius: StyleConstants.DEFAULT_DIALOG_RADIUS 130 }) 131 .width(this.mUninstallDialogWidth) 132 } 133 .margin({ bottom: this.navigationBarStatusValue ? StyleConstants.DEFAULT_12 : StyleConstants.DEFAULT_40 }) 134 .padding({ left: StyleConstants.DEFAULT_12, right: StyleConstants.DEFAULT_12 }) 135 } 136}