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 .scrollBar(BarState.Off) 132 .edgeEffect(EdgeEffect.None) 133 } 134 } 135} 136 137/** 138 * Phone Item 139 */ 140@Component 141struct TelListItem { 142 @Prop private message: string; 143 @State mIndexPresenter: IndexPresenter = IndexPresenter.getInstance(); 144 @State isEmergencyNum: boolean = false; 145 @StorageLink("haveSimCard") haveSimCard: boolean = false; 146 @StorageLink('haveMultiSimCard') haveMultiSimCard: boolean = false; 147 @Link private mPresenter: { [key: string]: any }; 148 @Link selectSimBuilder: SelectDialogBuilder; 149 150 @Builder MenuBuilder() { 151 Flex({ direction: FlexDirection.Column, 152 justifyContent: FlexAlign.Center, 153 alignItems: ItemAlign.Start }) { 154 Text(JSON.parse(this.message).data) 155 .fontSize($r("sys.float.ohos_id_text_size_headline8")) 156 .fontColor($r('sys.color.ohos_id_color_text_primary')) 157 .fontWeight(FontWeight.Medium) 158 .textOverflow({ overflow: TextOverflow.Ellipsis }) 159 .maxLines(1) 160 .textAlign(TextAlign.Start) 161 .lineHeight('28vp') 162 .height($r("app.float.id_item_height_max")) 163 164 this.MenuDivider() 165 this.MenuView($r("app.string.copy_phoneNumber"), MenuType.Copy) 166 this.MenuDivider() 167 this.MenuView($r("app.string.edit_beforeCall"), MenuType.EditBeforeCall) 168 } 169 .padding({ left: $r("app.float.id_card_margin_large"), right: $r("app.float.id_card_margin_large") }) 170 .width(144) 171 .borderRadius($r("app.float.id_card_margin_xxl")) 172 .backgroundColor($r('sys.color.ohos_id_color_primary_contrary')) 173 } 174 175 @Builder MenuView(menuName, itemType) { 176 Row() { 177 Text(menuName) 178 .fontSize($r("sys.float.ohos_id_text_size_body1")) 179 .fontColor($r('sys.color.ohos_id_color_text_primary')) 180 .textAlign(TextAlign.Start) 181 } 182 .width("100%") 183 .padding({ left: $r("app.float.id_card_margin_large"), right: $r("app.float.id_card_margin_large") }) 184 .height($r("app.float.id_item_height_mid")) 185 .backgroundColor($r('sys.color.ohos_id_color_primary_contrary')) 186 .onClick(() => { 187 switch (itemType) { 188 case MenuType.Copy: 189 this.mIndexPresenter.getCopy(JSON.parse(this.message).data); 190 break; 191 case MenuType.EditBeforeCall: 192 AppStorage.SetOrCreate("isRouterBack", true); 193 DialerPresenter.getInstance().editPhoneNumber(JSON.parse(this.message).data); 194 AppStorage.SetOrCreate<boolean>("showDialBtn", true); 195 break; 196 } 197 }) 198 } 199 200 @Builder MenuDivider() { 201 Divider() 202 .color($r('sys.color.ohos_id_color_list_separator')) 203 .lineCap(LineCapStyle.Square) 204 .width('100%') 205 .padding({ left: $r("app.float.id_card_margin_large"), right: $r("app.float.id_card_margin_large") }) 206 } 207 208 build() { 209 Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 210 Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Start }) { 211 Text(PhoneNumber.fromString(JSON.parse(this.message).data).format()) 212 .fontSize($r("sys.float.ohos_id_text_size_body1")) 213 .fontWeight(FontWeight.Medium) 214 .textOverflow({ overflow: TextOverflow.Ellipsis }) 215 .maxLines(2) 216 Row() { 217 Text(JSON.parse(this.message).labelName) 218 .fontSize($r("sys.float.ohos_id_text_size_body2")) 219 .fontColor($r("sys.color.ohos_id_color_text_tertiary")) 220 .fontWeight(FontWeight.Regular) 221 .visibility(StringUtil.isEmpty(JSON.parse(this.message).labelName) ? Visibility.None : Visibility.Visible) 222 Text(" - ") 223 .fontSize($r("sys.float.ohos_id_text_size_body2")) 224 .fontColor($r("sys.color.ohos_id_color_text_tertiary")) 225 .fontWeight(FontWeight.Regular) 226 .visibility(StringUtil.isEmpty( 227 JSON.parse(this.message) 228 .phoneAddress) ? Visibility.None : Visibility.Visible) 229 Text(JSON.parse(this.message).phoneAddress) 230 .fontSize($r("sys.float.ohos_id_text_size_body2")) 231 .fontColor($r("sys.color.ohos_id_color_text_tertiary")) 232 .fontWeight(FontWeight.Regular) 233 } 234 .margin({ top: $r("app.float.id_card_margin_sm") }) 235 } 236 .flexShrink(1) 237 238 Row() { 239 if (call.hasVoiceCapability()) { 240 Button({ stateEffect: false }) { 241 if (!EnvironmentProp.isTablet()) { 242 Image($r("app.media.ic_public_phone")) 243 .objectFit(ImageFit.Contain) 244 .height($r("app.float.id_card_image_small")) 245 .width($r("app.float.id_card_image_small")) 246 .fillColor(this.haveSimCard ? $r('sys.color.ohos_id_color_connected') 247 : $r('sys.color.ohos_id_color_tertiary')) 248 } else { 249 Image($r("app.media.ic_public_phone_filled")) 250 .objectFit(ImageFit.Contain) 251 .height($r("app.float.id_card_image_small")) 252 .width($r("app.float.id_card_image_small")) 253 .fillColor(this.haveSimCard ? $r('sys.color.ohos_id_color_connected') 254 : $r('sys.color.ohos_id_color_tertiary')) 255 } 256 } 257 .backgroundColor(Color.White) 258 .margin({ right: $r("app.float.id_card_margin_max") }) 259 } 260 261 Button({ stateEffect: false }) { 262 if (!EnvironmentProp.isTablet()) { 263 Image($r("app.media.ic_public_message")) 264 .objectFit(ImageFit.Contain) 265 .height($r("app.float.id_card_image_small")) 266 .width($r("app.float.id_card_image_small")) 267 } else { 268 Image($r("app.media.ic_public_message_filled")) 269 .objectFit(ImageFit.Contain) 270 .height($r("app.float.id_card_image_small")) 271 .width($r("app.float.id_card_image_small")) 272 } 273 } 274 .backgroundColor(Color.White) 275 .onClick(() => { 276 this.mPresenter.sendMessage(JSON.parse(this.message).num, 277 JSON.parse(this.message).data, this.mPresenter.contactForm.display_name); 278 }) 279 } 280 .flexShrink(0) 281 } 282 .onClick(() => { 283 let phoneNum: string = JSON.parse(this.message).num; 284 if (!this.haveSimCard) { 285 HiLog.i(TAG, "No SIM card!"); 286 //TODO Pop-up window for dialing without a SIM card 287 PhoneNumber.fromString(phoneNum).isDialEmergencyNum().then((res) => { 288 this.isEmergencyNum = res; 289 if (!this.isEmergencyNum) { 290 HiLog.i(TAG, "Is not Emergency Phone Number!"); 291 return; 292 } else { 293 HiLog.i(TAG, "No SIM card, but is Emergency Phone Number"); 294 PhoneNumber.fromString(phoneNum).dial(); 295 } 296 }) 297 } else if (this.haveMultiSimCard) { 298 this.selectSimBuilder.title = $r("app.string.contacts_call_number", phoneNum); 299 this.selectSimBuilder.callback = (value) => { 300 PhoneNumber.fromString(phoneNum).dial({ 301 accountId: value, 302 }); 303 } 304 this.selectSimBuilder.lastSimId = this.mPresenter.lastUsedSlotId; 305 let spnList = AppStorage.Get<Array<string | Resource>>('spnList'); 306 for (var index = 0; index < spnList.length; index++) { 307 this.selectSimBuilder.multiSimCardItems[index].name = spnList[index]; 308 } 309 this.selectSimBuilder.controller?.open(); 310 } else { 311 PhoneNumber.fromString(phoneNum).dial(); 312 } 313 }) 314 .width('100%') 315 .height($r("app.float.id_item_height_max")) 316 .bindContextMenu(this.MenuBuilder, ResponseType.LongPress) 317 } 318}