• 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 { Log } from '@ohos/base/src/main/ets/utils/Log';
16import type { DialogCallback } from '../../model/common/DialogUtil';
17import screenManager from '@ohos/base/src/main/ets/manager/ScreenManager';
18import { Constants } from '../../model/common/Constants';
19import { showToast } from '@ohos/base/src/main/ets/utils/UiUtil';
20import { getResourceString } from '@ohos/base/src/main/ets/utils/ResourceUtils';
21
22@CustomDialog
23export struct AddNotesDialog {
24    private TAG: string = 'AddNotesDialog'
25    @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal();
26    @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar();
27    @StorageLink('leftBlank') leftBlank: [number, number, number, number] = [0, 0, 0, 0];
28    controller: CustomDialogController;
29    @Consume dialogCallback: DialogCallback;
30    @State isNull: boolean = false;
31    private inputNote: string = '';
32
33    aboutToAppear(): void {
34        Log.info(this.TAG, 'aboutToAppear');
35        this.inputNote = '';
36        this.isNull = this.inputNote === '';
37    }
38
39    build() {
40        Column() {
41            Row() {
42                Column() {
43                    Button() {
44                        Image($r('app.media.ic_gallery_public_cancel'))
45                    }.height($r('app.float.icon_size'))
46                    .width($r('app.float.icon_size'))
47                    .onClick(() => {
48                        this.dialogCallback && this.dialogCallback.cancelCallback();
49                        this.controller.close()
50                    })
51                }.margin({ right: $r('app.float.dialog_icon_margin_horizontal') })
52
53                Column() {
54                    TextInput({ placeholder: '', text: this.inputNote })
55                        .fontSize($r('sys.float.ohos_id_text_size_caption1'))
56                        .fontFamily($r('app.string.id_text_font_family_regular'))
57                        .fontColor($r('app.color.text_input_font_color_182431'))
58                        .maxLength(Constants.ADD_NOTES_MAX_LENGTH)
59                        .enterKeyType(EnterKeyType.Done)
60                        .onChange((value: string) => {
61                            Log.info(this.TAG, `TextInput onChange : ${value}`)
62                            this.inputNote = value
63                            this.isNull = this.inputNote === '';
64                        })
65                }.margin({ right: $r('app.float.dialog_icon_margin_horizontal') })
66
67                Column() {
68                    Button() {
69                        Image($r('app.media.ic_gallery_public_ok'))
70                    }.height($r('app.float.icon_size'))
71                    .width($r('app.float.icon_size'))
72                    .onClick(() => {
73                        let check = /[\\.\\\\/:*?<>\"|\[\]{}\s]/;
74                        let passCheck = check.test(this.inputNote)
75                        if (passCheck) {
76                            getResourceString($r('app.string.specific_characters_not_supported'))
77                                .then((message: string) => {
78                                    showToast(message)
79                                })
80                            this.controller.close()
81                            return
82                        }
83                        this.dialogCallback && this.dialogCallback.confirmCallback(this.inputNote);
84                        this.controller.close()
85                    })
86                }
87            }.margin({ top: $r('sys.float.ohos_id_text_paragraph_margin_s'),
88                bottom: $r('sys.float.ohos_id_text_paragraph_margin_s') })
89            .height($r('app.float.dialog_add_notes_content_height'))
90        }
91        .padding({ left: $r('app.float.dialog_content_margin'), right: $r('app.float.dialog_content_margin') })
92        .height($r('app.float.dialog_add_notes_height'))
93        .width('100%')
94        .borderRadius($r('app.float.dialog_border_radius'))
95        .width(screenManager.getColumnsWidth(4))
96        .backgroundColor($r('app.color.white'))
97        .margin({
98            right: $r('app.float.dialog_content_margin'),
99            left: $r('app.float.dialog_content_margin'),
100            bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + px2vp(this.leftBlank[3])
101        })
102    }
103}
104