1/** 2 * Copyright (c) 2022-2023 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, sharedPreferencesUtils } from '../../../../../../common'; 17 18const TAG = 'SelectMultiNumDialog'; 19 20@CustomDialog 21export struct SelectMultiNumDialog { 22 @Link builder: SelectNumDialogBuilder; 23 private controller: CustomDialogController; 24 private selectDefault: Boolean = false; 25 26 aboutToAppear() { 27 HiLog.i(TAG, JSON.stringify(this.builder)); 28 sharedPreferencesUtils.init(globalThis.getContext()) 29 } 30 31 build() { 32 Column() { 33 Text(this.builder.title) 34 .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle')) 35 .fontColor($r('sys.color.ohos_id_color_text_primary')) 36 .fontWeight(FontWeight.Bold) 37 .alignSelf(ItemAlign.Center) 38 .width('100%') 39 .height('48vp') 40 .padding({ left: '16vp', }) 41 List() { 42 ForEach(this.builder.multiNumCardItems, (item, index) => { 43 ListItem() { 44 Row() { 45 Image(item.img) 46 .height('30vp') 47 .width('30vp') 48 .margin({ right: '8vp' }) 49 .onError((event => { 50 HiLog.e(TAG, 'Num:' + index + ' Image onError' + JSON.stringify(event)) 51 })) 52 Column() { 53 Text(item.number) 54 .fontSize($r('sys.float.ohos_id_text_size_body1')) 55 .fontColor($r('sys.color.ohos_id_color_text_primary')) 56 .fontWeight(FontWeight.Lighter) 57 Text(item.numType) 58 .fontSize($r('sys.float.ohos_id_text_size_body2')) 59 .fontColor($r('sys.color.ohos_dialog_text_alert_transparent')) 60 .fontWeight(FontWeight.Lighter) 61 .margin({ top: '4vp' }) 62 }.alignItems(HorizontalAlign.Start) 63 }.width('100%') 64 .height('56vp') 65 .justifyContent(FlexAlign.Start) 66 .padding({ left: '16vp', }) 67 }.onClick(() => { 68 this.confirm(item, this.builder.contactId); 69 }) 70 }) 71 }.divider({ 72 strokeWidth: 0.8, 73 startMargin: 56, 74 endMargin: $r('app.float.id_card_margin_max'), 75 }) 76 77 Row() { 78 Checkbox({ name: 'checkbox2', group: 'checkboxGroup' }) 79 .select(false) 80 .selectedColor(0x39a2db) 81 .onChange((value: boolean) => { 82 this.selectDefault = value 83 console.info(' msz Checkbox2 change is' + value) 84 }) 85 Column() { 86 Text($r('app.string.set_default_values')) 87 .fontSize($r('sys.float.ohos_id_text_size_body1')) 88 .fontColor($r('sys.color.ohos_dialog_text_alert_transparent')) 89 .fontWeight(FontWeight.Lighter) 90 }.alignItems(HorizontalAlign.Start) 91 }.width('100%') 92 .height('56vp') 93 .justifyContent(FlexAlign.Start) 94 .padding({ left: '16vp', }) 95 96 Text($r('app.string.cancel')) 97 .alignSelf(ItemAlign.Center) 98 .textAlign(TextAlign.Center) 99 .fontWeight(FontWeight.Medium) 100 .fontColor(0x39a2db) 101 .fontSize($r('sys.float.ohos_id_text_size_body1')) 102 .width('100%') 103 .height('48vp') 104 .onClick(() => { 105 this.cancel() 106 }); 107 }.backgroundColor(Color.White) 108 } 109 110 confirm(item, contactId) { 111 this.controller.close() 112 if (this.selectDefault) { 113 sharedPreferencesUtils.saveToPreferences(contactId + '', item.number); 114 } 115 if (this.builder.callback) { 116 this.builder.callback(item); 117 } 118 } 119 120 cancel() { 121 this.controller.close() 122 } 123} 124 125class MultiNumCardItems { 126 number: String; 127 numType: Resource; 128 img: Resource; 129} 130 131interface Controller { 132 close(); 133 134 open(); 135} 136 137export class SelectNumDialogBuilder { 138 title: string | Resource; 139 contactId: String 140 multiNumCardItems: Array<MultiNumCardItems>; 141 callback?: (item: MultiNumCardItems) => void; 142 controller?: Controller; 143} 144