• 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 { FileInfo } from '../Data/FileInfo'
17import { logInfo } from '../Utils/LogUtils'
18
19let TAG: string = 'DialogUtils'
20
21@CustomDialog
22export struct ChooseDialog {
23  controller: CustomDialogController
24
25  build() {
26    Column() {
27      Row() {
28        Text('选择该文件')
29      }
30
31      Row() {
32        Button() {
33          Text('取消')
34            .height('100%')
35            .fontSize(24)
36            .fontColor(Color.Blue)
37        }
38        .width(px2vp(200))
39        .height(px2vp(50))
40        .backgroundColor(Color.White)
41        .onClick(() => {
42          this.controller.close()
43        })
44
45        Divider()
46          .vertical(true)
47          .color(Color.Gray)
48          .height(40)
49          .margin({ top: 0, right: 10, bottom: 0, left: 10 })
50
51        Button() {
52          Text('确定')
53            .height('100%')
54            .fontSize(24)
55            .fontColor(Color.Blue)
56        }
57        .width(px2vp(200))
58        .height(px2vp(50))
59        .backgroundColor(Color.White)
60        .onClick(() => {
61          let choseItem: FileInfo = AppStorage.Get<FileInfo>('selectedFileInfo')
62          if (choseItem != null) {
63            let files: Array<FileInfo> = AppStorage.Get('choseFiles')
64            let flag: boolean = true
65            files.forEach((item: FileInfo) => {
66              logInfo(TAG, 'item.name = ' + item.name + '; item.path = ' + item.path)
67              logInfo(TAG, 'choseItem.name = ' + choseItem.name + '; choseItem.path = ' + choseItem.path)
68              if (item.name == choseItem.name && item.path == choseItem.path) {
69                flag = false
70              }
71            })
72            if (flag) {
73              files.push(choseItem)
74              AppStorage.Set('choseFiles', files)
75            }
76          }
77          this.controller.close()
78        })
79      }
80      .padding(20)
81    }
82    .padding({
83      top: 25,
84      right: 0,
85      bottom: 15,
86      left: 0
87    })
88  }
89}