16e80583aSopenharmony_ci/** 26e80583aSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 36e80583aSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 46e80583aSopenharmony_ci * you may not use this file except in compliance with the License. 56e80583aSopenharmony_ci * You may obtain a copy of the License at 66e80583aSopenharmony_ci * 76e80583aSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 86e80583aSopenharmony_ci * 96e80583aSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 106e80583aSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 116e80583aSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 126e80583aSopenharmony_ci * See the License for the specific language governing permissions and 136e80583aSopenharmony_ci * limitations under the License. 146e80583aSopenharmony_ci */ 156e80583aSopenharmony_ci 166e80583aSopenharmony_ciimport { StyleConstants } from '../constants/StyleConstants'; 176e80583aSopenharmony_ciimport { CheckEmptyUtils } from '../utils/CheckEmptyUtils'; 186e80583aSopenharmony_ciimport { ResourceManager } from '../manager/ResourceManager'; 196e80583aSopenharmony_ciimport { LayoutViewModel } from '../viewmodel/LayoutViewModel'; 206e80583aSopenharmony_ciimport { AppItemInfo } from '../bean/AppItemInfo'; 216e80583aSopenharmony_ci 226e80583aSopenharmony_ci@CustomDialog 236e80583aSopenharmony_ciexport struct UninstallDialog { 246e80583aSopenharmony_ci @StorageLink('uninstallAppInfo') appInfo: AppItemInfo = new AppItemInfo(); 256e80583aSopenharmony_ci @StorageLink('isPad') isPad: boolean = false; 266e80583aSopenharmony_ci @StorageLink('NavigationBarStatusValue') navigationBarStatusValue: boolean = false; 276e80583aSopenharmony_ci controller?: CustomDialogController; 286e80583aSopenharmony_ci cancel = () => {}; 296e80583aSopenharmony_ci confirm = () => {}; 306e80583aSopenharmony_ci dialogName: string = ''; 316e80583aSopenharmony_ci dialogContent: string = ''; 326e80583aSopenharmony_ci @State icon: string = ''; 336e80583aSopenharmony_ci appIcon: number = 0; 346e80583aSopenharmony_ci bundleName: string = ''; 356e80583aSopenharmony_ci moduleName: string = ''; 366e80583aSopenharmony_ci mUninstallDialogWidth: string = ''; 376e80583aSopenharmony_ci private mLayoutViewModel?: LayoutViewModel; 386e80583aSopenharmony_ci private mResourceManager = ResourceManager.getInstance(); 396e80583aSopenharmony_ci private mDefaultAppIcon?: ResourceStr; 406e80583aSopenharmony_ci 416e80583aSopenharmony_ci private async updateScreenSize() { 426e80583aSopenharmony_ci if (this.mLayoutViewModel?.getCommonDialogWidth()) { 436e80583aSopenharmony_ci this.mUninstallDialogWidth = this.mLayoutViewModel?.getCommonDialogWidth(); 446e80583aSopenharmony_ci } 456e80583aSopenharmony_ci } 466e80583aSopenharmony_ci 476e80583aSopenharmony_ci aboutToAppear(): void { 486e80583aSopenharmony_ci this.mLayoutViewModel = LayoutViewModel.getInstance(); 496e80583aSopenharmony_ci this.updateScreenSize(); 506e80583aSopenharmony_ci this.mResourceManager = ResourceManager.getInstance(); 516e80583aSopenharmony_ci 526e80583aSopenharmony_ci this.appIcon = this.appInfo.appIconId as number; 536e80583aSopenharmony_ci this.bundleName = this.appInfo.bundleName as string; 546e80583aSopenharmony_ci this.moduleName = this.appInfo.moduleName as string; 556e80583aSopenharmony_ci 566e80583aSopenharmony_ci if (CheckEmptyUtils.isEmpty(this.icon)) { 576e80583aSopenharmony_ci this.updateIcon(); 586e80583aSopenharmony_ci } 596e80583aSopenharmony_ci } 606e80583aSopenharmony_ci 616e80583aSopenharmony_ci aboutToDisappear(): void { 626e80583aSopenharmony_ci } 636e80583aSopenharmony_ci 646e80583aSopenharmony_ci public iconLoadCallback = (image: string) => { 656e80583aSopenharmony_ci this.icon = image; 666e80583aSopenharmony_ci } 676e80583aSopenharmony_ci 686e80583aSopenharmony_ci public updateIcon() { 696e80583aSopenharmony_ci this.mResourceManager.getAppIconWithCache(this.appIcon, this.bundleName, this.moduleName, 706e80583aSopenharmony_ci this.iconLoadCallback, this.mDefaultAppIcon); 716e80583aSopenharmony_ci } 726e80583aSopenharmony_ci 736e80583aSopenharmony_ci build() { 746e80583aSopenharmony_ci Flex({ direction: FlexDirection.Column, justifyContent: this.isPad ? FlexAlign.Center : FlexAlign.End }) { 756e80583aSopenharmony_ci Column() { 766e80583aSopenharmony_ci Image(this.icon).width(StyleConstants.DEFAULT_APP_ITEM_HEIGHT).height(StyleConstants.DEFAULT_APP_ITEM_HEIGHT) 776e80583aSopenharmony_ci 786e80583aSopenharmony_ci Row() { 796e80583aSopenharmony_ci Text(this.dialogName) 806e80583aSopenharmony_ci .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 816e80583aSopenharmony_ci .fontColor(StyleConstants.TEXT_COLOR_PRIMARY) 826e80583aSopenharmony_ci Text(this.dialogContent) 836e80583aSopenharmony_ci .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 846e80583aSopenharmony_ci .fontColor(StyleConstants.TEXT_COLOR_PRIMARY) 856e80583aSopenharmony_ci }.margin({ top: StyleConstants.DEFAULT_DIALOG_RADIUS, bottom: StyleConstants.DEFAULT_DIALOG_BOTTOM_MARGIN }) 866e80583aSopenharmony_ci 876e80583aSopenharmony_ci Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceEvenly }) { 886e80583aSopenharmony_ci Button() { 896e80583aSopenharmony_ci Text($r('app.string.cancel')) 906e80583aSopenharmony_ci .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 916e80583aSopenharmony_ci .fontColor(StyleConstants.BUTTON_FONT_COLOR) 926e80583aSopenharmony_ci } 936e80583aSopenharmony_ci .backgroundColor(StyleConstants.DEFAULT_BG_COLOR) 946e80583aSopenharmony_ci .height(StyleConstants.DEFAULT_BUTTON_HEIGHT) 956e80583aSopenharmony_ci .width(StyleConstants.DEFAULT_BUTTON_WIDTH) 966e80583aSopenharmony_ci .onClick(() => { 976e80583aSopenharmony_ci this.controller?.close(); 986e80583aSopenharmony_ci this.cancel(); 996e80583aSopenharmony_ci }) 1006e80583aSopenharmony_ci 1016e80583aSopenharmony_ci Divider() 1026e80583aSopenharmony_ci .vertical(true) 1036e80583aSopenharmony_ci .color(StyleConstants.DEFAULT_DIVIDER_COLOR) 1046e80583aSopenharmony_ci .height(StyleConstants.DEFAULT_DIVIDER_HEIGHT) 1056e80583aSopenharmony_ci 1066e80583aSopenharmony_ci Button() { 1076e80583aSopenharmony_ci Text(this.isPad && this.dialogName == '是否卸载' ? $r('app.string.uninstall') : $r('app.string.submit')) 1086e80583aSopenharmony_ci .fontSize(StyleConstants.DEFAULT_BADGE_FONT_SIZE) 1096e80583aSopenharmony_ci .fontColor(StyleConstants.DEFAULT_COLOR_ERROR) 1106e80583aSopenharmony_ci } 1116e80583aSopenharmony_ci .backgroundColor(StyleConstants.DEFAULT_BG_COLOR) 1126e80583aSopenharmony_ci .height(StyleConstants.DEFAULT_BUTTON_HEIGHT) 1136e80583aSopenharmony_ci .width(StyleConstants.DEFAULT_BUTTON_WIDTH) 1146e80583aSopenharmony_ci .onClick(() => { 1156e80583aSopenharmony_ci this.controller?.close(); 1166e80583aSopenharmony_ci this.confirm(); 1176e80583aSopenharmony_ci }) 1186e80583aSopenharmony_ci } 1196e80583aSopenharmony_ci } 1206e80583aSopenharmony_ci .backgroundColor($r('app.color.default_dialog_background')) 1216e80583aSopenharmony_ci .backgroundBlurStyle(BlurStyle.Regular) 1226e80583aSopenharmony_ci .padding({ 1236e80583aSopenharmony_ci top: StyleConstants.DEFAULT_24, 1246e80583aSopenharmony_ci bottom: StyleConstants.DEFAULT_DIALOG_BOTTOM_MARGIN 1256e80583aSopenharmony_ci }) 1266e80583aSopenharmony_ci .border({ 1276e80583aSopenharmony_ci radius: StyleConstants.DEFAULT_DIALOG_RADIUS 1286e80583aSopenharmony_ci }) 1296e80583aSopenharmony_ci .width(this.mUninstallDialogWidth) 1306e80583aSopenharmony_ci } 1316e80583aSopenharmony_ci .margin({ bottom: this.navigationBarStatusValue ? StyleConstants.DEFAULT_12 : StyleConstants.DEFAULT_40 }) 1326e80583aSopenharmony_ci .padding({ left: StyleConstants.DEFAULT_12, right: StyleConstants.DEFAULT_12 }) 1336e80583aSopenharmony_ci } 1346e80583aSopenharmony_ci}