1/* 2 * Copyright (c) 2022-2023 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 */ 15import type { DialogCallback } from '../../model/common/DialogUtil'; 16import { Log } from '../../utils/Log'; 17import { ColumnSize, ScreenManager } from '../../model/common/ScreenManager'; 18import { Constants } from '../../model/common/Constants'; 19import data_preferences from '@ohos.data.preferences'; 20 21const TAG: string = 'common_DeleteDialog'; 22 23@CustomDialog 24export struct DeleteDialog { 25 @StorageLink('isHorizontal') isHorizontal: boolean = ScreenManager.getInstance().isHorizontal(); 26 @StorageLink('isSidebar') isSidebar: boolean = ScreenManager.getInstance().isSidebar(); 27 @StorageLink('leftBlank') leftBlank: [number, number, number, number] 28 = [0, ScreenManager.getInstance().getStatusBarHeight(), 0, ScreenManager.getInstance().getNaviBarHeight()]; 29 @Consume dialogCallback: DialogCallback; 30 @Consume dialogMessage: Resource; 31 controller: CustomDialogController; 32 @StorageLink('isFirstTimeDelete') isFirstTimeDelete: boolean = false; 33 @StorageLink('confirmText') confirmText: Resource = $r('app.string.dialog_delete'); 34 private isPcDevice: boolean = AppStorage.Get('deviceType') === Constants.PC_DEVICE_TYPE; 35 36 aboutToDisappear() { 37 if (this.isFirstTimeDelete) { 38 AppStorage.SetOrCreate(Constants.IS_FIRST_TIME_DELETE, false); 39 let pref: data_preferences.Preferences = AppStorage.Get(Constants.PHOTOS_STORE_KEY); 40 pref.put(Constants.IS_FIRST_TIME_DELETE, false).then(() => { 41 Log.debug(TAG, `Succeeded in putting the value of '${Constants.IS_FIRST_TIME_DELETE}'.`); 42 pref.flush(); 43 }).catch((err) => { 44 Log.error(TAG, `Failed to put the value of '${Constants.IS_FIRST_TIME_DELETE}'. Cause: ${err}`); 45 }); 46 } 47 } 48 49 build() { 50 Column() { 51 Column() { 52 if (this.isFirstTimeDelete) { 53 Image($r('app.media.first_delete_dialog_ico')) 54 .objectFit(ImageFit.Cover) 55 .height($r('app.float.first_delete_dialog_ico_height')) 56 .width($r('app.float.first_delete_dialog_ico_width')) 57 .margin({ 58 bottom: $r('app.float.first_delete_dialog_ico_margin_bottom') 59 }) 60 } 61 62 Text(this.dialogMessage) 63 .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) 64 .fontWeight(FontWeight.Medium) 65 .fontColor($r('sys.color.ohos_id_color_text_primary')) 66 .textAlign(TextAlign.Center) 67 68 if (this.isFirstTimeDelete) { 69 Text($r('app.plural.first_delete_message', Constants.RECYCLE_DAYS_MAX, Constants.RECYCLE_DAYS_MAX)) 70 .textAlign(TextAlign.Center) 71 .fontSize($r('sys.float.ohos_id_text_size_body1')) 72 .fontWeight(FontWeight.Regular) 73 .fontColor($r('sys.color.ohos_id_color_text_primary')) 74 .margin({ top: $r('app.float.first_delete_message_margin_top') }) 75 } 76 } 77 .alignItems(HorizontalAlign.Center) 78 .width('100%') 79 .margin({ 80 top: $r('app.float.dialog_content_margin'), 81 bottom: $r('app.float.dialog_button_and_text_margin') 82 }) 83 84 85 Stack({ alignContent: Alignment.Top }) { 86 Row() { 87 Column() { 88 Button() { 89 Text($r('app.string.dialog_cancel')) 90 .fontSize($r('sys.float.ohos_id_text_size_button1')) 91 .fontColor($r('app.color.color_control_highlight')) 92 .fontWeight(FontWeight.Medium) 93 .width('100%') 94 .textAlign(TextAlign.Center) 95 } 96 .key('DeleteDialogCancelButton') 97 .margin({ 98 right: $r('app.float.dialog_double_buttons_margin_right') 99 }) 100 .backgroundColor(this.isPcDevice ? $r('sys.color.ohos_id_color_button_normal') : $r('app.color.transparent')) 101 .borderRadius($r('sys.float.ohos_id_corner_radius_button')) 102 .height($r('app.float.details_dialog_button_height')) 103 .onClick(() => { 104 Log.debug(TAG, `cancelCallback`); 105 this.controller.close(); 106 this.dialogCallback && this.dialogCallback.cancelCallback(); 107 }) 108 }.width('50%') 109 110 if (!this.isPcDevice) { 111 Divider() 112 .vertical(true) 113 .color(Constants.DEFAULT_DIVIDER_COLOR) 114 .height(Constants.DEFAULT_DIVIDER_HEIGHT) 115 } 116 117 Column() { 118 Button() { 119 Text(this.confirmText) 120 .fontSize($r('sys.float.ohos_id_text_size_button1')) 121 .fontColor($r('sys.color.ohos_id_color_warning')) 122 .fontWeight(FontWeight.Medium) 123 .width('100%') 124 .textAlign(TextAlign.Center) 125 } 126 .key('DeleteDialogConfirmButton') 127 .margin({ 128 left: $r('app.float.dialog_double_buttons_margin_left') 129 }) 130 .backgroundColor(this.isPcDevice ? $r('sys.color.ohos_id_color_button_normal') : $r('app.color.transparent')) 131 .borderRadius($r('sys.float.ohos_id_corner_radius_button')) 132 .height($r('app.float.details_dialog_button_height')) 133 .onClick(() => { 134 Log.debug(TAG, `confirmCallback`); 135 this.controller.close(); 136 this.dialogCallback && this.dialogCallback.confirmCallback(); 137 }) 138 }.width('50%') 139 } 140 } 141 .width('100%') 142 .height($r('app.float.details_dialog_button_area_height')) 143 } 144 .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) 145 .width(this.isPcDevice ? $r('app.float.pc_dialog_width') : ScreenManager.getInstance() 146 .getColumnsWidth(ColumnSize.COLUMN_FOUR)) 147 .backgroundColor($r('app.color.white')) 148 .margin({ 149 right: $r('app.float.dialog_content_margin'), 150 left: $r('app.float.dialog_content_margin'), 151 bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + this.leftBlank[3] 152 }) 153 .padding({ 154 left: $r('app.float.dialog_double_buttons_padding'), 155 right: $r('app.float.dialog_double_buttons_padding') 156 }) 157 .alignItems(HorizontalAlign.Center) 158 .shadow({ 159 radius: $r('app.float.dialog_defult_shadow_m_radio'), 160 color: $r('app.color.dialog_defult_shadow_m_color'), 161 offsetX: $r('app.float.dialog_defult_shadow_m_offsetX'), 162 offsetY: $r('app.float.dialog_defult_shadow_m_offsetY') 163 }) 164 } 165} 166