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