• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 '@ohos/base/src/main/ets/data/MediaOperationType'
17import  screenManager  from '@ohos/base/src/main/ets/manager/ScreenManager';
18import { Constants } from '../../model/common/Constants';
19
20@Observed
21export class ProgressParam {
22    cancelFunc: Function
23    operationType: string
24}
25
26@CustomDialog
27export struct ProgressDialog {
28    @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal();
29    @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar();
30    @StorageLink('leftBlank') leftBlank: [number, number, number, number] = [0, 0, 0, 0];
31    controller: CustomDialogController
32    @Consume progressMessage: Resource;
33    @Consume deleteProgress: number;
34    @Consume progressParam: ProgressParam;
35
36    build() {
37        Column() {
38            Row() {
39                Text(this.progressMessage)
40                    .fontSize($r('sys.float.ohos_id_text_size_body2'))
41                    .fontFamily($r('app.string.id_text_font_family_regular'))
42                    .flexGrow(1)
43                    .fontColor($r('sys.color.ohos_id_color_text_primary'))
44                    .maxLines(2)
45                    .textOverflow({ overflow: TextOverflow.Ellipsis })
46                Text(`${this.deleteProgress}%`)
47                    .fontSize($r('sys.float.ohos_id_text_size_body2'))
48                    .fontFamily($r('app.string.id_text_font_family_regular'))
49                    .fontColor($r('sys.color.ohos_id_color_text_secondary'))
50                    .margin({
51                        left: $r('app.float.process_bar_margin_left'),
52                        right: $r('app.float.process_bar_margin_right'),
53                    })
54            }
55            .width('100%')
56
57            Row() {
58                Progress({ value: 0, total: Constants.PROGRESS_MAX, style: ProgressStyle.Linear })
59                    .value(this.deleteProgress)
60                    .color($r('app.color.color_control_highlight'))
61                    .width(screenManager.getColumnsWidth(4) - Constants.PROGRESS_LENGTH_DIFF)
62                    .margin({
63                        right: $r('app.float.progress_padding_right')
64                    })
65                if (this.progressParam.operationType != MediaOperationType.Delete &&
66                this.progressParam.operationType != MediaOperationType.Recover) {
67                    Image($r('app.media.ic_progress_cancel'))
68                        .width($r('app.float.icon_size'))
69                        .height($r('app.float.icon_size'))
70                        .onClick(() => {
71                            this.progressParam.cancelFunc();
72                        })
73                }
74            }
75            .width('100%')
76            .margin({ top: $r('app.float.id_icon_margin_horizontal') })
77        }
78        .padding({
79            left: $r('app.float.max_padding_start'),
80            right: $r('app.float.max_padding_end'),
81            top: $r('app.float.max_padding_start'),
82            bottom: $r('app.float.max_padding_end'),
83        })
84        .border({ radius: $r('sys.float.ohos_id_corner_radius_default_l') })
85        .backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
86        .borderRadius($r('app.float.dialog_border_radius'))
87        .width(screenManager.getColumnsWidth(4))
88        .margin({
89            right: $r('app.float.dialog_window_margin'),
90            left: $r('app.float.dialog_window_margin'),
91            bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + px2vp(this.leftBlank[3])
92        })
93    }
94}
95