• 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      .scrollBar(BarState.Off)
73      .edgeEffect(EdgeEffect.None)
74
75      Text($r('app.string.cancel'))
76        .alignSelf(ItemAlign.Center)
77        .textAlign(TextAlign.Center)
78        .fontWeight(FontWeight.Medium)
79        .fontColor(Color.Blue)
80        .fontSize($r('sys.float.ohos_id_text_size_body1'))
81        .width('100%')
82        .height($r('app.float.id_item_height_mid'))
83        .onClick(() => {
84          this.cancel()
85        });
86    }.backgroundColor(Color.White)
87  }
88
89  confirm(slotId: number) {
90    this.controller.close()
91    if (this.builder.callback) {
92      this.builder.callback(slotId);
93    }
94  }
95
96  cancel() {
97    this.controller.close()
98  }
99}
100
101class MultiSimCardItems {
102  name: string | Resource;
103  img: Resource;
104}
105
106interface Controller {
107  close();
108  open();
109}
110
111export class SelectDialogBuilder {
112  title: string | Resource;
113  multiSimCardItems: Array<MultiSimCardItems>;
114  lastSimId?: number = -1;
115  callback?: (simId: number) => void;
116  controller?: Controller;
117}
118