• 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 { Broadcast } from '@ohos/base/src/main/ets/utils/Broadcast';
17import { Log } from '@ohos/base/src/main/ets/utils/Log';
18import  screenManager  from '@ohos/base/src/main/ets/manager/ScreenManager';
19import { Constants } from '../../model/common/Constants';
20
21@Observed
22export class CancelParam {
23    continueFunc: Function
24    cancelFunc: Function
25}
26
27@CustomDialog
28export struct DownloadCancelOperationDialog {
29    private TAG: string = 'DownloadCancelOperationDialog'
30    @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal();
31    @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar();
32    @StorageLink('leftBlank') leftBlank: [number, number, number, number] = [0, 0, 0, 0];
33    controller: CustomDialogController;
34    @Consume broadCast: Broadcast;
35    @Consume deleteProgress: number;
36    @Consume cancelParam: CancelParam;
37
38    build() {
39        Column() {
40            Row() {
41                Text($r('app.string.download_cancel_message'))
42                    .fontSize($r('sys.float.ohos_id_text_size_body1'))
43                    .fontFamily($r('app.string.id_text_font_family_regular'))
44                    .fontColor($r('sys.color.ohos_id_color_text_primary'))
45                    .padding({
46                        bottom: 8
47                    })
48                    .width('100%')
49                    .textAlign(TextAlign.Center)
50            }
51            .alignItems(VerticalAlign.Center)
52            .width('100%')
53
54            Stack({ alignContent: Alignment.Top }) {
55                Row() {
56                    Button() {
57                        Text($r('app.string.download_progress_continue'))
58                            .fontSize($r('sys.float.ohos_id_text_size_button1'))
59                            .fontColor($r('app.color.color_control_highlight'))
60                            .fontWeight(FontWeight.Medium)
61                            .width('50%')
62                            .textAlign(TextAlign.Center)
63                    }
64                    .margin({
65                        left: $r('app.float.details_dialog_button_margin_left'),
66                        right: $r('app.float.details_dialog_button_margin_right')
67                    })
68                    .backgroundColor($r('app.color.transparent'))
69                    .height($r('app.float.details_dialog_button_height'))
70                    .onClick(() => {
71                        Log.info(this.TAG, 'click continue')
72                        this.cancelParam.continueFunc();
73                        this.controller.close()
74                    })
75
76                    Row() {
77                        Divider()
78                            .vertical(true)
79                            .height($r('app.float.dialog_divider_height'))
80                            .color($r('app.color.divider_vertical_color'))
81                    }
82                    .height($r('app.float.details_dialog_button_height'))
83                    .alignItems(VerticalAlign.Center)
84
85                    Button() {
86                        Text($r('app.string.download_progress_cancel'))
87                            .fontSize($r('sys.float.ohos_id_text_size_button1'))
88                            .fontColor($r('app.color.color_control_highlight'))
89                            .fontWeight(FontWeight.Medium)
90                            .width('50%')
91                            .textAlign(TextAlign.Center)
92                    }
93                    .margin({
94                        left: $r('app.float.details_dialog_button_margin_left'),
95                        right: $r('app.float.details_dialog_button_margin_right')
96                    })
97                    .backgroundColor($r('app.color.transparent'))
98                    .height($r('app.float.details_dialog_button_height'))
99                    .onClick(() => {
100                        Log.info(this.TAG, 'click cancel')
101                        this.cancelParam.cancelFunc();
102                        this.controller.close()
103                    })
104                }
105            }
106            .width('100%')
107            .height($r('app.float.details_dialog_button_area_height'))
108        }
109        .padding({
110            left: $r('app.float.max_padding_start'),
111            right: $r('app.float.max_padding_end'),
112            top: $r('app.float.max_padding_start'),
113        })
114        .alignItems(HorizontalAlign.Center)
115        .border({ radius: $r('sys.float.ohos_id_corner_radius_default_l') })
116        .backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
117        .borderRadius($r('app.float.dialog_border_radius'))
118        .width(screenManager.getColumnsWidth(4))
119        .margin({
120            right: $r('app.float.dialog_window_margin'),
121            left: $r('app.float.dialog_window_margin'),
122            bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + px2vp(this.leftBlank[3])
123        })
124    }
125}
126