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 */
15
16import { BroadCast } from '../../utils/BroadCast';
17import { Log } from '../../utils/Log';
18import { ColumnSize, ScreenManager } from '../../model/common/ScreenManager';
19import { Constants } from '../../model/common/Constants';
20
21const TAG: string = 'common_DownloadCancelOperationDialog';
22
23@Observed
24export class CancelParam {
25  public continueFunc: Function = (): void => {};
26  public cancelFunc: Function = (): void => {};
27}
28
29@CustomDialog
30export struct DownloadCancelOperationDialog {
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 broadCast: BroadCast;
37  @Consume deleteProgress: number;
38  @Consume cancelParam: CancelParam;
39  private isPcDevice: boolean = AppStorage.get<string>('deviceType') === Constants.PC_DEVICE_TYPE;
40
41  build() {
42    Column() {
43      Stack({ alignContent: Alignment.Center }) {
44        Text($r('app.string.download_cancel_message'))
45          .fontSize($r('sys.float.ohos_id_text_size_body1'))
46          .fontWeight(FontWeight.Regular)
47          .fontColor($r('sys.color.ohos_id_color_text_primary'))
48      }.width('100%')
49      .margin({
50        top: $r('app.float.dialog_content_margin'),
51        bottom: $r('sys.float.ohos_id_elements_margin_vertical_l')
52      })
53
54      Stack({ alignContent: Alignment.Top }) {
55        Row() {
56          Column() {
57            Button() {
58              Text($r('app.string.download_progress_continue'))
59                .fontColor($r('app.color.color_control_highlight'))
60                .fontWeight(FontWeight.Medium)
61                .fontSize($r('sys.float.ohos_id_text_size_button1'))
62                .width('100%')
63                .textAlign(TextAlign.Center)
64            }
65            .margin({
66              right: $r('app.float.dialog_double_buttons_margin_right')
67            })
68            .backgroundColor($r('sys.color.ohos_id_color_button_normal'))
69            .borderRadius($r('sys.float.ohos_id_corner_radius_button'))
70            .height($r('app.float.details_dialog_button_height'))
71            .onClick(() => {
72              Log.info(TAG, 'click continue')
73              this.cancelParam.continueFunc();
74              this.controller?.close();
75            })
76          }.width('50%')
77
78          Column() {
79            Button() {
80              Text($r('app.string.download_progress_cancel'))
81                .fontColor($r('sys.color.ohos_id_color_warning'))
82                .fontSize($r('sys.float.ohos_id_text_size_button1'))
83                .fontWeight(FontWeight.Medium)
84                .width('100%')
85                .textAlign(TextAlign.Center)
86            }
87            .margin({
88              left: $r('app.float.dialog_double_buttons_margin_left')
89            })
90            .backgroundColor($r('sys.color.ohos_id_color_button_normal'))
91            .borderRadius($r('sys.float.ohos_id_corner_radius_button'))
92            .height($r('app.float.details_dialog_button_height'))
93            .onClick(() => {
94              Log.info(TAG, 'click cancel')
95              this.cancelParam.cancelFunc();
96              this.controller?.close();
97            })
98          }.width('50%')
99        }
100      }.width('100%')
101      .height($r('app.float.details_dialog_button_area_height'))
102    }
103    .borderRadius($r('sys.float.ohos_id_corner_radius_default_l'))
104    .width(this.isPcDevice ? $r('app.float.pc_dialog_width') : ScreenManager.getInstance()
105                                                                 .getColumnsWidth(ColumnSize.COLUMN_FOUR))
106    .backgroundColor($r('app.color.white'))
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    .padding({
113      left: $r('app.float.dialog_double_buttons_padding'),
114      right: $r('app.float.dialog_double_buttons_padding')
115    })
116    .alignItems(HorizontalAlign.Start)
117    .shadow({
118      radius: $r('app.float.dialog_defult_shadow_m_radio'),
119      color: $r('app.color.dialog_defult_shadow_m_color'),
120      offsetX: $r('app.float.dialog_defult_shadow_m_offsetX'),
121      offsetY: $r('app.float.dialog_defult_shadow_m_offsetY')
122    })
123  }
124}
125