• 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 */
15import type { DialogCallback } from '../../model/common/DialogUtil';
16import { Log } from '@ohos/base/src/main/ets/utils/Log';
17import  screenManager  from '@ohos/base/src/main/ets/manager/ScreenManager';
18import { Constants } from '../../model/common/Constants';
19
20@CustomDialog
21export struct DeleteDialog {
22    private TAG: string = 'DeleteDialog'
23    @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal();
24    @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar();
25    @StorageLink('leftBlank') leftBlank: [number, number, number, number] = [0, 0, 0, 0];
26    @Consume dialogCallback: DialogCallback;
27    @Consume dialogMessage: Resource;
28    @Consume dialogDeleteMessage: Resource;
29    controller: CustomDialogController;
30
31    aboutToAppear() {
32    }
33
34    build() {
35        Column() {
36            Stack({ alignContent: Alignment.Center }) {
37                Text(this.dialogMessage)
38                    .fontSize($r('sys.float.ohos_id_text_size_body1'))
39                    .fontColor($r('sys.color.ohos_id_color_text_primary'))
40            }.width('100%')
41            .margin({
42                top: $r('app.float.dialog_content_margin'),
43                bottom: $r('sys.float.ohos_id_text_paragraph_margin_s')
44            })
45
46            Stack({ alignContent: Alignment.Top }) {
47                Row() {
48                    Button() {
49                        Text($r('app.string.dialog_cancel'))
50                            .fontSize($r('sys.float.ohos_id_text_size_button1'))
51                            .fontColor($r('app.color.color_control_highlight'))
52                            .fontWeight(FontWeight.Medium)
53                            .width('50%')
54                            .textAlign(TextAlign.Center)
55                    }
56                    .margin({
57                        left: $r('app.float.details_dialog_button_margin_left'),
58                        right: $r('app.float.details_dialog_button_margin_right')
59                    })
60                    .backgroundColor($r('app.color.transparent'))
61                    .height($r('app.float.details_dialog_button_height'))
62                    .onClick(() => {
63                        Log.debug(this.TAG, `cancelCallback`);
64                        this.controller.close();
65                        this.dialogCallback && this.dialogCallback.cancelCallback();
66                    })
67
68                    Row() {
69                        Divider()
70                            .vertical(true)
71                            .height($r('app.float.dialog_divider_height'))
72                            .color($r('app.color.divider_vertical_color'))
73                    }
74                    .height($r('app.float.details_dialog_button_height'))
75                    .alignItems(VerticalAlign.Center)
76
77                    Button() {
78                        Text(this.dialogDeleteMessage)
79                            .fontSize($r('sys.float.ohos_id_text_size_button1'))
80                            .fontColor($r('sys.color.ohos_id_color_warning'))
81                            .fontWeight(FontWeight.Medium)
82                            .width('50%')
83                            .textAlign(TextAlign.Center)
84                    }
85                    .margin({
86                        left: $r('app.float.details_dialog_button_margin_left'),
87                        right: $r('app.float.details_dialog_button_margin_right')
88                    })
89                    .backgroundColor($r('app.color.transparent'))
90                    .height($r('app.float.details_dialog_button_height'))
91                    .onClick(() => {
92                        Log.debug(this.TAG, `confirmCallback`);
93                        this.controller.close();
94                        this.dialogCallback && this.dialogCallback.confirmCallback();
95                    })
96                }
97            }
98            .width('100%')
99            .height($r('app.float.details_dialog_button_area_height'))
100        }
101        .borderRadius($r('app.float.dialog_border_radius'))
102        .width(screenManager.getColumnsWidth(4))
103        .backgroundColor($r('app.color.white'))
104        .margin({
105            right: $r('app.float.dialog_window_margin'),
106            left: $r('app.float.dialog_window_margin'),
107            bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + px2vp(this.leftBlank[3])
108        })
109        .padding({ left: $r('app.float.dialog_content_margin'), right: $r('app.float.dialog_content_margin') })
110        .alignItems(HorizontalAlign.Start)
111    }
112}
113