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 { StringUtil, HiLog } from '../../../../../../common'; 17import { ArrayUtil } from '../../../../../../common/src/main/ets/util/ArrayUtil'; 18import DialerPresenter from '../../presenter/dialer/DialerPresenter'; 19import { PhoneNumber } from '../../../../../../feature/phonenumber/src/main/ets/PhoneNumber'; 20import DetailInfoList from './DetailInfoList'; 21import call from '@ohos.telephony.call'; 22import EnvironmentProp from '../../feature/EnvironmentProp'; 23import { DataItemType } from '../../../../../../feature/contact/src/main/ets/contract/DataType'; 24import IndexPresenter from '../../presenter/IndexPresenter'; 25import { SelectDialogBuilder } from '../mutisim/SelectSimIdDialog'; 26 27const TAG = "ContactDetail-detailInfoList"; 28 29enum MenuType { 30 Copy, EditBeforeCall 31} 32 33@Component 34export default struct DetailInfoListView { 35 @Link mPresenter: { [key: string]: any }; 36 @Link selectSimBuilder: SelectDialogBuilder; 37 38 build() { 39 Column() { 40 //Phone List 41 TelList({ 42 List: JSON.stringify(this.mPresenter.contactForm.phones), 43 mPresenter: $mPresenter, 44 selectSimBuilder: $selectSimBuilder 45 }); 46 47 // email list 48 DetailInfoList({ 49 List: JSON.stringify(this.mPresenter.contactForm.emails), 50 hasArrow: true, 51 dataType: DataItemType.EMAIL 52 }); 53 54 // aim List 55 DetailInfoList({ 56 List: JSON.stringify(this.mPresenter.contactForm.aims), 57 hasArrow: true, 58 dataType: DataItemType.IM 59 }); 60 61 // Nickname 62 DetailInfoList({ 63 List: JSON.stringify(this.mPresenter.contactForm.nickname), 64 hasArrow: false, 65 dataType: DataItemType.NICKNAME 66 }); 67 68 // Websites 69 DetailInfoList({ 70 List: JSON.stringify(this.mPresenter.contactForm.websites), 71 hasArrow: true, 72 dataType: DataItemType.WEBSITE 73 }); 74 75 // residential address 76 DetailInfoList({ 77 List: JSON.stringify(this.mPresenter.contactForm.houses), 78 hasArrow: false, 79 dataType: DataItemType.SIP_ADDRESS 80 }); 81 82 // Remembrance Day 83 DetailInfoList({ 84 List: JSON.stringify(this.mPresenter.contactForm.events), 85 hasArrow: true, 86 dataType: DataItemType.EVENT 87 }); 88 89 // Associated Person 90 DetailInfoList({ 91 List: JSON.stringify(this.mPresenter.contactForm.relationships), 92 hasArrow: true, 93 dataType: DataItemType.RELATION 94 }); 95 96 // Remarks 97 DetailInfoList({ 98 List: JSON.stringify(this.mPresenter.contactForm.remarks), 99 hasArrow: false, 100 dataType: DataItemType.NOTE 101 }); 102 } 103 .margin({ top: $r("app.float.id_card_margin_max") }) 104 } 105} 106 107/** 108 * Phone List 109 */ 110@Component 111struct TelList { 112 @State List: string = ''; 113 @Link private mPresenter: { [key: string]: any }; 114 @Link selectSimBuilder: SelectDialogBuilder; 115 116 build() { 117 if (!ArrayUtil.isEmpty(JSON.parse(this.List))) { 118 List() { 119 ForEach(JSON.parse(this.List), item => { 120 ListItem() { 121 TelListItem({ 122 message: JSON.stringify(item), 123 mPresenter: $mPresenter, 124 selectSimBuilder: $selectSimBuilder 125 }); 126 } 127 }, item => JSON.stringify(item)) 128 } 129 .divider({ strokeWidth: $r("app.float.id_divide_width"), color: $r("sys.color.ohos_id_color_list_separator") }) 130 .backgroundColor(Color.White) 131 } 132 } 133} 134 135/** 136 * Phone Item 137 */ 138@Component 139struct TelListItem { 140 @Prop private message: string; 141 @State mIndexPresenter: IndexPresenter = IndexPresenter.getInstance(); 142 @State isEmergencyNum: boolean = false; 143 @StorageLink("haveSimCard") haveSimCard: boolean = false; 144 @StorageLink('haveMultiSimCard') haveMultiSimCard: boolean = false; 145 @Link private mPresenter: { [key: string]: any }; 146 @Link selectSimBuilder: SelectDialogBuilder; 147 148 @Builder MenuBuilder() { 149 Flex({ direction: FlexDirection.Column, 150 justifyContent: FlexAlign.Center, 151 alignItems: ItemAlign.Start }) { 152 Text(JSON.parse(this.message).data) 153 .fontSize($r("sys.float.ohos_id_text_size_headline8")) 154 .fontColor($r('sys.color.ohos_id_color_text_primary')) 155 .fontWeight(FontWeight.Medium) 156 .textOverflow({ overflow: TextOverflow.Ellipsis }) 157 .maxLines(1) 158 .textAlign(TextAlign.Start) 159 .lineHeight('28vp') 160 .height($r("app.float.id_item_height_max")) 161 162 this.MenuDivider() 163 this.MenuView($r("app.string.copy_phoneNumber"), MenuType.Copy) 164 this.MenuDivider() 165 this.MenuView($r("app.string.edit_beforeCall"), MenuType.EditBeforeCall) 166 } 167 .padding({ left: $r("app.float.id_card_margin_large"), right: $r("app.float.id_card_margin_large") }) 168 .width(144) 169 .borderRadius($r("app.float.id_card_margin_xxl")) 170 .backgroundColor($r('sys.color.ohos_id_color_primary_contrary')) 171 } 172 173 @Builder MenuView(menuName, itemType) { 174 Row() { 175 Text(menuName) 176 .fontSize($r("sys.float.ohos_id_text_size_body1")) 177 .fontColor($r('sys.color.ohos_id_color_text_primary')) 178 .textAlign(TextAlign.Start) 179 } 180 .width("100%") 181 .padding({ left: $r("app.float.id_card_margin_large"), right: $r("app.float.id_card_margin_large") }) 182 .height($r("app.float.id_item_height_mid")) 183 .backgroundColor($r('sys.color.ohos_id_color_primary_contrary')) 184 .onClick(() => { 185 switch (itemType) { 186 case MenuType.Copy: 187 this.mIndexPresenter.getCopy(JSON.parse(this.message).data); 188 break; 189 case MenuType.EditBeforeCall: 190 AppStorage.SetOrCreate("isRouterBack", true); 191 DialerPresenter.getInstance().editPhoneNumber(JSON.parse(this.message).data); 192 AppStorage.SetOrCreate<boolean>("showDialBtn", true); 193 break; 194 } 195 }) 196 } 197 198 @Builder MenuDivider() { 199 Divider() 200 .color($r('sys.color.ohos_id_color_list_separator')) 201 .lineCap(LineCapStyle.Square) 202 .width('100%') 203 .padding({ left: $r("app.float.id_card_margin_large"), right: $r("app.float.id_card_margin_large") }) 204 } 205 206 build() { 207 Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 208 Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Start }) { 209 Text(PhoneNumber.fromString(JSON.parse(this.message).data).format()) 210 .fontSize($r("sys.float.ohos_id_text_size_body1")) 211 .fontWeight(FontWeight.Medium) 212 .textOverflow({ overflow: TextOverflow.Ellipsis }) 213 .maxLines(2) 214 Row() { 215 Text(JSON.parse(this.message).labelName) 216 .fontSize($r("sys.float.ohos_id_text_size_body2")) 217 .fontColor($r("sys.color.ohos_id_color_text_tertiary")) 218 .fontWeight(FontWeight.Regular) 219 .visibility(StringUtil.isEmpty(JSON.parse(this.message).labelName) ? Visibility.None : Visibility.Visible) 220 Text(" - ") 221 .fontSize($r("sys.float.ohos_id_text_size_body2")) 222 .fontColor($r("sys.color.ohos_id_color_text_tertiary")) 223 .fontWeight(FontWeight.Regular) 224 .visibility(StringUtil.isEmpty( 225 JSON.parse(this.message) 226 .phoneAddress) ? Visibility.None : Visibility.Visible) 227 Text(JSON.parse(this.message).phoneAddress) 228 .fontSize($r("sys.float.ohos_id_text_size_body2")) 229 .fontColor($r("sys.color.ohos_id_color_text_tertiary")) 230 .fontWeight(FontWeight.Regular) 231 } 232 .margin({ top: $r("app.float.id_card_margin_sm") }) 233 } 234 .flexShrink(1) 235 236 Row() { 237 if (call.hasVoiceCapability()) { 238 Button({ stateEffect: false }) { 239 if (!EnvironmentProp.isTablet()) { 240 Image($r("app.media.ic_public_phone")) 241 .objectFit(ImageFit.Contain) 242 .height($r("app.float.id_card_image_small")) 243 .width($r("app.float.id_card_image_small")) 244 .fillColor(this.haveSimCard ? $r('sys.color.ohos_id_color_connected') 245 : $r('sys.color.ohos_id_color_tertiary')) 246 } else { 247 Image($r("app.media.ic_public_phone_filled")) 248 .objectFit(ImageFit.Contain) 249 .height($r("app.float.id_card_image_small")) 250 .width($r("app.float.id_card_image_small")) 251 .fillColor(this.haveSimCard ? $r('sys.color.ohos_id_color_connected') 252 : $r('sys.color.ohos_id_color_tertiary')) 253 } 254 } 255 .backgroundColor(Color.White) 256 .margin({ right: $r("app.float.id_card_margin_max") }) 257 } 258 259 Button({ stateEffect: false }) { 260 if (!EnvironmentProp.isTablet()) { 261 Image($r("app.media.ic_public_message")) 262 .objectFit(ImageFit.Contain) 263 .height($r("app.float.id_card_image_small")) 264 .width($r("app.float.id_card_image_small")) 265 } else { 266 Image($r("app.media.ic_public_message_filled")) 267 .objectFit(ImageFit.Contain) 268 .height($r("app.float.id_card_image_small")) 269 .width($r("app.float.id_card_image_small")) 270 } 271 } 272 .backgroundColor(Color.White) 273 .onClick(() => { 274 this.mPresenter.sendMessage(JSON.parse(this.message).num, 275 JSON.parse(this.message).data, this.mPresenter.contactForm.display_name); 276 }) 277 } 278 .flexShrink(0) 279 } 280 .onClick(() => { 281 let phoneNum: string = JSON.parse(this.message).num; 282 if (!this.haveSimCard) { 283 HiLog.i(TAG, "No SIM card!"); 284 //TODO Pop-up window for dialing without a SIM card 285 PhoneNumber.fromString(phoneNum).isDialEmergencyNum().then((res) => { 286 this.isEmergencyNum = res; 287 if (!this.isEmergencyNum) { 288 HiLog.i(TAG, "Is not Emergency Phone Number!"); 289 return; 290 } else { 291 HiLog.i(TAG, "No SIM card, but is Emergency Phone Number"); 292 PhoneNumber.fromString(phoneNum).dial(); 293 } 294 }) 295 } else if (this.haveMultiSimCard) { 296 this.selectSimBuilder.title = $r("app.string.contacts_call_number", phoneNum); 297 this.selectSimBuilder.callback = (value) => { 298 PhoneNumber.fromString(phoneNum).dial({ 299 accountId: value, 300 }); 301 } 302 this.selectSimBuilder.lastSimId = this.mPresenter.lastUsedSlotId; 303 let spnList = AppStorage.Get<Array<string | Resource>>('spnList'); 304 for (var index = 0; index < spnList.length; index++) { 305 this.selectSimBuilder.multiSimCardItems[index].name = spnList[index]; 306 } 307 this.selectSimBuilder.controller?.open(); 308 } else { 309 PhoneNumber.fromString(phoneNum).dial(); 310 } 311 }) 312 .width('100%') 313 .height($r("app.float.id_item_height_max")) 314 .bindContextMenu(this.MenuBuilder, ResponseType.LongPress) 315 } 316}