• 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 { HiLog } from '../../../../../../common';
17
18const TAG = "SelectSimIdDialog";
19
20@CustomDialog
21export struct SelectSimIdDialog {
22  @Link builder: SelectDialogBuilder;
23  private controller: CustomDialogController;
24
25  aboutToAppear() {
26    HiLog.i(TAG, JSON.stringify(this.builder));
27  }
28
29  build() {
30    Column() {
31      Text(this.builder.title)
32        .fontSize($r("sys.float.ohos_id_text_size_dialog_tittle"))
33        .fontColor($r("sys.color.ohos_id_color_text_primary"))
34        .fontWeight(FontWeight.Bold)
35        .alignSelf(ItemAlign.Center)
36        .width("100%")
37        .height($r("app.float.id_item_height_mid"))
38        .padding({ left: $r("app.float.id_card_margin_xxl"), })
39      List() {
40        ForEach(this.builder.multiSimCardItems, (item, index) => {
41          ListItem() {
42            Row() {
43              Image(item.img)
44                .height($r("app.float.id_card_image_mid"))
45                .width($r("app.float.id_card_image_mid"))
46                .margin({ right: $r("app.float.id_card_margin_large") })
47                .onError((event => {
48                  HiLog.e(TAG, "Sim:" + index + " Image onError" + JSON.stringify(event))
49                }))
50              Column() {
51                Text(item.name)
52                  .fontSize($r("sys.float.ohos_id_text_size_body1"))
53                  .fontColor($r("sys.color.ohos_id_color_text_primary"))
54                  .fontWeight(FontWeight.Medium)
55                Text($r("app.string.choose_sub_recommend"))
56                  .fontSize($r("sys.float.ohos_id_text_size_body2"))
57                  .fontColor($r('sys.color.ohos_dialog_text_alert_transparent'))
58                  .fontWeight(FontWeight.Lighter)
59                  .visibility(this.builder.lastSimId == index ? Visibility.Visible : Visibility.None);
60              }.alignItems(HorizontalAlign.Start)
61            }.width('100%')
62            .height($r("app.float.id_item_height_large"))
63            .justifyContent(FlexAlign.Start)
64            .padding({ left: $r("app.float.id_card_margin_xxl"), })
65          }.onClick(() => {
66            this.confirm(index);
67          })
68        })
69      }.divider({
70        strokeWidth: 1
71      })
72
73      Text($r("app.string.cancel"))
74        .alignSelf(ItemAlign.Center)
75        .textAlign(TextAlign.Center)
76        .fontWeight(FontWeight.Medium)
77        .fontColor(Color.Blue)
78        .fontSize($r("sys.float.ohos_id_text_size_body1"))
79        .width("100%")
80        .height($r("app.float.id_item_height_mid"))
81        .onClick(() => {
82          this.cancel()
83        });
84    }.backgroundColor(Color.White)
85  }
86
87  confirm(slotId: number) {
88    this.controller.close()
89    if (this.builder.callback) {
90      this.builder.callback(slotId);
91    }
92  }
93
94  cancel() {
95    this.controller.close()
96  }
97}
98
99class MultiSimCardItems {
100  name: string | Resource;
101  img: Resource;
102}
103
104interface Controller {
105  close();
106  open();
107}
108
109export class SelectDialogBuilder {
110  title: string | Resource;
111  multiSimCardItems: Array<MultiSimCardItems>;
112  lastSimId?: number = -1;
113  callback?: (simId: number) => void;
114  controller?: Controller;
115}
116