1/* 2 * Copyright (c) 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 { MediaOperationType } from '../../model/common/MediaOperationType'; 17import { Log } from '../../utils/Log'; 18import { ColumnSize, ScreenManager } from '../../model/common/ScreenManager'; 19import { Constants } from '../../model/common/Constants'; 20 21const TAG: string = 'common_ProgressDialog'; 22 23@Observed 24export class ProgressParam { 25 public cancelFunc: Function = (): void => {}; 26 public operationType: string = ''; 27} 28 29@CustomDialog 30export struct ProgressDialog { 31 @StorageLink('isHorizontal') isHorizontal: boolean = ScreenManager.getInstance().isHorizontal(); 32 @StorageLink('isSidebar') isSidebar: boolean = ScreenManager.getInstance().isSidebar(); 33 @StorageLink('leftBlank') leftBlank: number[] = 34 [0, ScreenManager.getInstance().getStatusBarHeight(), 0, ScreenManager.getInstance().getNaviBarHeight()]; 35 controller?: CustomDialogController 36 @Consume progressMessage: Resource; 37 @Consume deleteProgress: number; 38 @Consume progressParam: ProgressParam; 39 40 /** 41 * 122 = Progress宽度(ScreenManager.getInstance().getColumnsWidth(ColumnSize.COLUMN_FOUR) - 88) - deleteProgress宽度(34) 42 */ 43 readonly progressMessageWidth: number = 122 44 45 /** 46 * 88 = 左右padding(24 * 2) + 关闭图片宽度(24) + 图片与Progress间距(16) 47 */ 48 readonly progressWidth: number = 88 49 50 build() { 51 Column() { 52 Row() { 53 Text(this.progressMessage) 54 .fontSize($r('sys.float.ohos_id_text_size_body2')) 55 .fontFamily($r('app.string.id_text_font_family_regular')) 56 .width(ScreenManager.getInstance().getColumnsWidth(ColumnSize.COLUMN_FOUR) - this.progressMessageWidth) 57 .fontColor($r('sys.color.ohos_id_color_text_primary')) 58 .maxLines(2) 59 .textOverflow({ overflow: TextOverflow.Ellipsis }) 60 Text(`${this.deleteProgress}%`) 61 .fontSize($r('sys.float.ohos_id_text_size_body2')) 62 .fontFamily($r('app.string.id_text_font_family_regular')) 63 .width($r('app.float.progress_percentage_text_width')) 64 .textAlign(TextAlign.End) 65 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 66 } 67 .width('100%') 68 .margin({ 69 top: $r('app.float.process_bar_text_margin_top'), 70 bottom: $r('app.float.process_bar_text_margin_bottom') 71 }) 72 73 Row() { 74 Progress({ value: 0, total: 100, style: ProgressStyle.Linear }) 75 .value(this.deleteProgress) 76 .color($r('app.color.color_control_highlight')) 77 .flexGrow(1) 78 .width(ScreenManager.getInstance().getColumnsWidth(ColumnSize.COLUMN_FOUR) - this.progressWidth) 79 .margin({ 80 right: $r('app.float.progress_image_right_margin') 81 }) 82 if (this.progressParam.operationType != MediaOperationType.Delete && 83 this.progressParam.operationType != MediaOperationType.Recover) { 84 Image($r('app.media.ic_progress_cancel')) 85 .width($r('app.float.icon_size')) 86 .height($r('app.float.icon_size')) 87 .onClick(() => { 88 this.progressParam.cancelFunc(); 89 }) 90 } 91 } 92 .width('100%') 93 .margin({ 94 top: $r('app.float.process_bar_progress_margin_top'), 95 bottom: $r('app.float.process_bar_progress_margin_bottom') 96 }) 97 } 98 .padding({ 99 left: $r('app.float.max_padding_start'), 100 right: $r('app.float.max_padding_end'), 101 top: $r('app.float.max_padding_start'), 102 bottom: $r('app.float.max_padding_end'), 103 }) 104 .border({ radius: $r('sys.float.ohos_id_corner_radius_default_l') }) 105 .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) 106 .width(ScreenManager.getInstance().getColumnsWidth(ColumnSize.COLUMN_FOUR)) 107 .margin({ 108 right: $r('app.float.dialog_content_margin'), 109 left: $r('app.float.dialog_content_margin'), 110 bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + this.leftBlank[3] 111 }) 112 .shadow({ 113 radius: $r('app.float.dialog_defult_shadow_m_radio'), 114 color: $r('app.color.dialog_defult_shadow_m_color'), 115 offsetX: $r('app.float.dialog_defult_shadow_m_offsetX'), 116 offsetY: $r('app.float.dialog_defult_shadow_m_offsetY') 117 }) 118 } 119} 120