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 router from '@ohos.router'; 17import prompt from '@system.prompt'; 18import { StringUtil } from '../../../../../../../common/src/main/ets/util/StringUtil'; 19import { HiLog } from '../../../../../../../common/src/main/ets/util/HiLog'; 20import { ArrayUtil } from '../../../../../../../common/src/main/ets/util/ArrayUtil'; 21import { CallLogRepository } from '../../../../../../../feature/call/src/main/ets/repo/CallLogRepository'; 22import { CallType, CallLog } from '../../../../../../../feature/call/src/main/ets/entity/CallLog'; 23import { PhoneNumber } from '../../../../../../../feature/phonenumber/src/main/ets/PhoneNumber'; 24import { ContactRepository } from '../../../../../../../feature/contact/src/main/ets/repo/ContactRepository'; 25import { House } from '../../../../../../../feature/contact/src/main/ets/contract/House'; 26import { Relation } from '../../../../../../../feature/contact/src/main/ets/contract/Relation'; 27import { Phone } from '../../../../../../../feature/contact/src/main/ets/contract/Phone'; 28import { Email } from '../../../../../../../feature/contact/src/main/ets/contract/Email'; 29import { Birthday } from '../../../../../../../feature/contact/src/main/ets/contract/Birthday'; 30import { Aim } from '../../../../../../../feature/contact/src/main/ets/contract/Aim'; 31import MorandiColor from '../../../model/bean/MorandiColor'; 32import ContactAbilityModel from '../../../model/ContactAbilityModel'; 33import DetailCallLogDataSource from '../../../model/bean/DetailCallLogDataSource'; 34import EnvironmentProp from '../../../feature/EnvironmentProp'; 35import StringFormatUtil from "../../../util/StringFormatUtil" 36 37const TAG = "DetailPresenter"; 38 39export default class DetailPresenter { 40 private static sInstance: DetailPresenter; 41 /** UI parameters */ 42 moreMenuOptions: Resource[] = [$r("app.string.delete_contact")]; 43 isFavorite: boolean = false; 44 showNameLastMenu: string = ''; 45 lastUsedSlotId: number = -1; 46 47 /** Display parameters */ 48 sourceHasId: boolean = false; 49 sourceHasPhone: boolean = false; 50 phoneNumberShow: string = ''; 51 contactId: number; 52 isNewNumber: boolean = true; 53 isNewDetail: boolean = false; 54 topbarBackgroundColor: ResourceColor = Color.Transparent; 55 newNumberBgColor: string = ''; 56 detailsColor: string = ''; 57 /** detail parameters */ 58 contactForm: any = { 59 display_name: '', 60 photoFirstName: '', 61 company: '', 62 position: '', 63 phones: [], 64 emails: [], 65 aims: [], 66 nickname: [], 67 websites: [], 68 houses: [], 69 events: [], 70 remarks: [], 71 relationships: [], 72 numRecords: [], 73 portraitColor: '', 74 detailsBgColor: '' 75 }; 76 detailCallLogDataSource: DetailCallLogDataSource = new DetailCallLogDataSource(); 77 /** Contact Temporary */ 78 contacts: { [key: string]: any } = {}; 79 80 private constructor() { 81 } 82 83 public static getInstance(): DetailPresenter { 84 if (DetailPresenter.sInstance == null) { 85 DetailPresenter.sInstance = new DetailPresenter(); 86 } 87 return DetailPresenter.sInstance; 88 } 89 90 async aboutToAppear() { 91 // Groups, favorites, contact lists,new contacts. 92 if (this.sourceHasId) { 93 HiLog.i(TAG, 'onShow:sourceHasId'); 94 this.contactForm = { 95 display_name: '', 96 photoFirstName: '', 97 company: '', 98 position: '', 99 phones: [], 100 emails: [], 101 aims: [], 102 nickname: [], 103 websites: [], 104 houses: [], 105 events: [], 106 remarks: [], 107 relationships: [], 108 numRecords: [], 109 portraitColor: '', 110 detailsBgColor: '' 111 }; 112 let requestData = { 113 contactId: this.contactId 114 }; 115 this.isNewNumber = false; 116 this.getContactDetail(requestData); 117 } else if (this.sourceHasPhone) { 118 // call log, mms. 119 HiLog.i(TAG, 'onShow:sourceHasPhone'); 120 this.contactForm = { 121 display_name: '', 122 photoFirstName: '', 123 company: '', 124 position: '', 125 phones: [], 126 emails: [], 127 aims: [], 128 nickname: [], 129 websites: [], 130 houses: [], 131 events: [], 132 remarks: [], 133 relationships: [], 134 numRecords: [], 135 portraitColor: '', 136 detailsBgColor: '' 137 }; 138 /** Query the contact ID based on the phone number. 139 If a contact exists,the contact details are displayed based on the first contact ID.*/ 140 globalThis.DataWorker.sendRequest("getIdByTelephone", { 141 context: globalThis.context, 142 phoneNumber: this.phoneNumberShow 143 }, (contactId) => { 144 if (!ArrayUtil.isEmpty(contactId)) { 145 HiLog.i(TAG, "contactid is exist"); 146 // If a contact exists, set isNewNumber to false. 147 this.isNewNumber = false; 148 let requestData = { 149 contactId: contactId[0] 150 }; 151 this.getContactDetail(requestData); 152 } 153 if (this.isNewNumber) { 154 // If the contact ID does not exist, the new number is used. 155 this.getNewNumCallLog(); 156 } 157 }); 158 } 159 this.registerCallLogObsever(); 160 this.isNewNumber = true; 161 } 162 163 aboutToDisappear() { 164 HiLog.i(TAG, 'ContactDetail aboutToDisappear!'); 165 } 166 167 registerCallLogObsever() { 168 CallLogRepository.getInstance().registerDataChangeObserver(() => { 169 this.refresh(); 170 }); 171 } 172 173 refresh() { 174 HiLog.i(TAG, 'refresh call log!'); 175 if (this.contactId != undefined) { 176 this.getContactCallLog(); 177 } else { 178 this.getNewNumCallLog(); 179 } 180 } 181 182 getContactDetail(data) { 183 HiLog.i(TAG, 'get ContactDetail by id'); 184 globalThis.DataWorker.sendRequest("getContactById", { 185 context: globalThis.context, 186 contactId: data.contactId 187 }, result => { 188 if (StringUtil.isEmpty(result)) { 189 // If the contact cannot be obtained based on the specified ID, the new number is used. 190 this.getNewNumCallLog(); 191 return; 192 } 193 this.contactId = result.data.id; 194 this.contacts = result.data; 195 this.contactForm.portraitColor = MorandiColor.Color[Math.abs(parseInt(result.data.id, 10)) % 6]; 196 this.contactForm.detailsBgColor = MorandiColor.detailColor[Math.abs(parseInt(result.data.id, 10)) % 6]; 197 this.detailsColor = MorandiColor.detailColor[Math.abs(parseInt(result.data.id, 10)) % 6]; 198 this.dealDetailsData(); 199 }); 200 } 201 202 dealDetailsData() { 203 HiLog.i(TAG, 'deal detail data'); 204 this.getLabelNameByTypeId(); 205 this.dealContactsToForm(); 206 this.getContactCallLog(); 207 } 208 209 getLabelNameByTypeId() { 210 if (this.contacts.hasOwnProperty('phones') && this.contacts.phones.length > 0) { 211 this.contacts.phones.forEach((element) => { 212 element.labelName = Phone.getTypeLabelResource(parseInt(element.numType, 10)); 213 element.phoneAddress = (element.phoneAddress == 'N' || StringUtil.isEmpty(element.phoneAddress)) ? 214 $r("app.string.unknown") : element.phoneAddress; 215 }); 216 } 217 if (this.contacts.hasOwnProperty('emails') && this.contacts.emails.length > 0) { 218 this.contacts.emails.forEach((element) => { 219 element.labelName = Email.getTypeLabelResource(parseInt(element.emailType, 10)); 220 }); 221 } 222 if (this.contacts.hasOwnProperty('aims') && this.contacts.aims.length > 0) { 223 this.contacts.aims.forEach((element) => { 224 element.labelName = Aim.getTypeLabelResource(parseInt(element.aimType, 10)); 225 }); 226 } 227 if (this.contacts.hasOwnProperty('houses') && this.contacts.houses.length > 0) { 228 this.contacts.houses.forEach((element) => { 229 element.labelName = House.getTypeLabelResource(parseInt(element.houseType, 10)); 230 }); 231 } 232 if (this.contacts.hasOwnProperty('events') && this.contacts.events.length > 0) { 233 this.contacts.events.forEach((element) => { 234 element.labelName = Birthday.getTypeLabelResource(parseInt(element.eventType, 10)); 235 }); 236 } 237 if (this.contacts.hasOwnProperty('relationships') && this.contacts.relationships.length > 0) { 238 this.contacts.relationships.forEach((element) => { 239 element.labelName = Relation.getTypeLabelResource(parseInt(element.associatedType, 10)); 240 }); 241 } 242 } 243 244 dealContactsToForm() { 245 let newContact = this.contacts; 246 this.contactForm.display_name = (newContact.display_name && newContact.display_name.length > 0) 247 ? newContact.display_name : $r('app.string.noName'); 248 this.contactForm.photoFirstName = (newContact.photoFirstName && newContact.photoFirstName.length > 0) 249 ? newContact.photoFirstName.toUpperCase() : '-1'; 250 this.contactForm.company = (newContact.company && newContact.company.length > 0) 251 ? newContact.company : ''; 252 this.contactForm.position = (newContact.position && newContact.position.length > 0) 253 ? newContact.position : ''; 254 if (newContact.phones && newContact.phones.length > 0) { 255 for (let item of newContact.phones) { 256 let itemtemp = { 257 id: item.id, 258 data: PhoneNumber.fromString(item.num).getNumber(), 259 num: item.num, 260 type: item.numType, 261 phoneAddress: item.phoneAddress, 262 labelName: item.labelName 263 } 264 if (this.contactForm.phones) { 265 this.contactForm.phones.push(itemtemp); 266 } else { 267 this.contactForm.phones = [itemtemp]; 268 } 269 } 270 } 271 if (newContact.emails && newContact.emails.length > 0) { 272 for (let item of newContact.emails) { 273 let itemtemp = { 274 id: item.id, 275 data: item.address, 276 type: item.emailType, 277 labelName: item.labelName 278 } 279 if (this.contactForm.emails) { 280 this.contactForm.emails.push(itemtemp); 281 } else { 282 this.contactForm.emails = [itemtemp]; 283 } 284 } 285 } 286 if (newContact.aims && newContact.aims.length > 0) { 287 for (let item of newContact.aims) { 288 let itemtemp = { 289 id: item.aimId, 290 data: item.aimName, 291 type: item.aimType, 292 labelName: item.labelName 293 } 294 if (this.contactForm.aims) { 295 this.contactForm.aims.push(itemtemp); 296 } else { 297 this.contactForm.aims = [itemtemp]; 298 } 299 } 300 } 301 if (newContact.nickname && newContact.nickname.length > 0) { 302 let itemtemp = { 303 id: 0, 304 data: newContact.nickname, 305 labelName: $r("app.string.nickname") 306 } 307 this.contactForm.nickname = [itemtemp]; 308 } 309 if (newContact.websites && newContact.websites.length > 0) { 310 let itemtemp = { 311 id: 0, 312 data: newContact.websites[0], 313 labelName: $r("app.string.website") 314 } 315 this.contactForm.websites = [itemtemp]; 316 } 317 if (newContact.houses && newContact.houses.length > 0) { 318 for (let item of newContact.houses) { 319 let itemtemp = { 320 id: item.houseId, 321 data: item.houseName, 322 type: item.houseType, 323 labelName: item.labelName 324 } 325 if (this.contactForm.houses) { 326 this.contactForm.houses.push(itemtemp); 327 } else { 328 this.contactForm.houses = [itemtemp]; 329 } 330 } 331 } 332 if (newContact.events && newContact.events.length > 0) { 333 for (let item of newContact.events) { 334 let itemtemp = { 335 id: item.id, 336 data: item.data, 337 type: item.eventType, 338 labelName: item.labelName 339 } 340 if (this.contactForm.events) { 341 this.contactForm.events.push(itemtemp); 342 } else { 343 this.contactForm.events = [itemtemp]; 344 } 345 } 346 } 347 if (newContact.remarks && newContact.remarks.length > 0) { 348 let itemtemp = { 349 id: 0, 350 data: newContact.remarks, 351 labelName: $r("app.string.remarks") 352 } 353 this.contactForm.remarks = [itemtemp]; 354 } 355 if (newContact.relationships && newContact.relationships.length > 0) { 356 for (let item of this.contacts.relationships) { 357 let itemtemp = { 358 id: item.id, 359 data: item.name, 360 type: item.associatedType, 361 labelName: item.labelName 362 } 363 if (this.contactForm.relationships) { 364 this.contactForm.relationships.push(itemtemp); 365 } else { 366 this.contactForm.relationships = [itemtemp]; 367 } 368 } 369 } 370 } 371 372 async getContactCallLog() { 373 HiLog.i(TAG, "get Contact CallLog"); 374 if (!ArrayUtil.isEmpty(this.contactForm.phones)) { 375 let numbers: Set<string> = new Set(); 376 this.contactForm.phones.forEach(element => { 377 numbers.add(`${element.data}`.replace(/\s+/g, '')); 378 }); 379 /* All call records of all phone numbers of the contact are obtained. */ 380 globalThis.DataWorker.sendRequest("findByNumberIn", { 381 context: globalThis.context, 382 numbers: Array.from(numbers) 383 }, (resultList) => { 384 /* Encapsulate the attributes required on the detail page based on the obtained raw call record data. */ 385 if (!ArrayUtil.isEmpty(resultList)) { 386 this.lastUsedSlotId = resultList[0].simId; 387 } else { 388 this.lastUsedSlotId = -1; 389 } 390 this.detailCallLogDataSource.refresh(this.getDetailMessage(resultList)); 391 }); 392 /* Encapsulate the attributes required on the detail page based on the obtained raw call record data. */ 393 } 394 // Processing Initialization Data 395 this.showNameLastMenu = (this.contactForm.display_name && this.contactForm.display_name.length > 6) 396 ? this.subStringWithEllipsis(this.contactForm.display_name, 7) : this.contactForm.display_name; 397 } 398 399 // Obtains call records and assembles parameters when the call is not a contact. 400 async getNewNumCallLog() { 401 this.isNewDetail = true; 402 HiLog.i(TAG, "get new number call log"); 403 let numbers: any = [this.phoneNumberShow.replace(/\s+/g, '')]; 404 let formatNum = PhoneNumber.fromString(this.phoneNumberShow).getNumber(); 405 this.contactForm.display_name = formatNum; 406 /* Creating a Contact Phone List Object */ 407 let itemtemp = { 408 id: 0, 409 data: formatNum, 410 num: this.phoneNumberShow, 411 type: 1, 412 labelName: $r("app.string.phone_type_mobile"), 413 phoneAddress: $r("app.string.unknown") 414 } 415 this.contactForm.phones = [itemtemp]; 416 this.contactForm.portraitColor = MorandiColor.Color[0]; 417 this.contactForm.detailsBgColor = MorandiColor.detailColor[0]; 418 this.newNumberBgColor = MorandiColor.detailColor[0]; 419 globalThis.DataWorker.sendRequest("findByNumberIn", { 420 context: globalThis.context, 421 numbers: numbers 422 }, (resultList) => { 423 /* Encapsulate the attributes required on the detail page based on the obtained raw call record data. */ 424 if (!ArrayUtil.isEmpty(resultList)) { 425 this.lastUsedSlotId = resultList[0].simId; 426 } else { 427 this.lastUsedSlotId = -1; 428 } 429 this.detailCallLogDataSource.refresh(this.getDetailMessage(resultList)); 430 }); 431 if (this.detailCallLogDataSource.totalCount() > 0) { 432 let bgColorId = Math.abs(parseInt(this.detailCallLogDataSource.getData(0).callLog.id, 10)); 433 this.contactForm.portraitColor = MorandiColor.Color[bgColorId % 6]; 434 this.contactForm.detailsBgColor = MorandiColor.detailColor[bgColorId % 6]; 435 this.newNumberBgColor = MorandiColor.detailColor[bgColorId % 6]; 436 } 437 } 438 439 /** 440 * Data required for converting the original 441 * callLogList content into call record details 442 * 443 * @param {Array} originList Original Call List 444 * @return {Array} resultList 445 */ 446 getDetailMessage(originList: CallLog[]) { 447 let resultList = []; 448 if (ArrayUtil.isEmpty(originList)) { 449 return resultList; 450 } 451 originList.forEach(element => { 452 let callTimeDetail = this.getTimeDetailByCallTime(element); 453 let contactDetailCallsItem = { 454 id: element.id.toString(), 455 phone: element.phoneNumber, 456 name: element.displayName, 457 callTime: element.createTime.toString(), 458 callType: element.callType, 459 callTag: element.numberLocation, 460 simType: element.simType.toString(), 461 simId: element.simId, 462 isHd: element.isHD, 463 ringTime: element.ringDuration, 464 formatNumber: element.formattedNumber, 465 talkTime: this.getTalkTimeMessage(element), 466 dateDetail: callTimeDetail.date, 467 timeDetail: callTimeDetail.time 468 }; 469 resultList.push(contactDetailCallsItem) 470 }); 471 return resultList; 472 } 473 474 /** 475 * Obtain the call details of the call record according to the call record. 476 * 477 * @param {Object} callLogElement Call log 478 * @return {string} resultMessage Status information 479 */ 480 getTalkTimeMessage(callLogElement: CallLog) { 481 let resultMessage: Resource | string = null; 482 switch (callLogElement.callType) { 483 case CallType.IN: 484 resultMessage = this.getDescriptionByDuration(callLogElement.talkDuration); 485 break; 486 case CallType.OUT: 487 resultMessage = callLogElement.talkDuration == 0 488 ? $r('app.string.blockCall') : this.getDescriptionByDuration(callLogElement.talkDuration); 489 break; 490 case CallType.MISSED: 491 resultMessage = this.getDescriptionByDuration(callLogElement.ringDuration); 492 break; 493 case CallType.REJECTED: 494 resultMessage = $r('app.string.reject'); 495 break; 496 default: 497 resultMessage = ""; 498 break; 499 } 500 return resultMessage; 501 } 502 503 /** 504 * Obtains the call duration based on the specified timestamp. The unit is s. 505 * 506 * @param {number} timeDuration 507 * @return {Object} Return time unit 508 */ 509 getDescriptionByDuration(timeDuration) { 510 let seconds = parseInt(timeDuration); 511 if (seconds < 60) { 512 // Less than one minute 513 return $r('app.string.secondsFormat', seconds); 514 } else { 515 let minutes = Math.floor(seconds / 60); 516 if (minutes < 60) { 517 // Within an hour 518 return $r('app.string.minutesSecondsFormat', minutes, seconds % 60); 519 } else { 520 let hours = Math.floor(minutes / 60); 521 return $r('app.string.hourMinutesSecondsFormat', hours, minutes % 60, seconds % 3600 % 60); 522 } 523 } 524 } 525 526 /** 527 * Obtain the time details based on the call record generation time. 528 * 529 * @param {number} callTime Initial Talk Time 530 * @return {string} timeDetail Talk time after processing 531 */ 532 getTimeDetailByCallTime(element: CallLog) { 533 let callTime = element.createTime.toString(); 534 let callLogTime = new Date(parseInt(callTime, 10) * 1000); 535 // time detail 536 let year = callLogTime.getFullYear(); 537 let mounth = callLogTime.getMonth() + 1; 538 let day = callLogTime.getDate(); 539 let hour = callLogTime.getHours().toString(); 540 let minutes = callLogTime.getMinutes() < 10 ? '0' + callLogTime.getMinutes() : callLogTime.getMinutes().toString(); 541 // description 542 let now = new Date(); 543 let timeDetail: any = {}; 544 if (parseInt(StringFormatUtil.judgeSysTime()) == 12) { 545 timeDetail.time = StringFormatUtil.getDayMessage(hour, minutes); 546 } else { 547 timeDetail.time = $r("app.string.time_normal", hour, minutes); 548 } 549 if (now.getFullYear() - callLogTime.getFullYear() == 0) { 550 if (now.getMonth() - callLogTime.getMonth() == 0) { 551 if (now.getDate() - callLogTime.getDate() == 0) { 552 timeDetail.date = ""; 553 return timeDetail; 554 } 555 } 556 timeDetail.date = $r("app.string.monthDay", mounth, day); 557 } else { 558 timeDetail.date = $r("app.string.yearMonthDay", year, mounth, day); 559 } 560 return timeDetail; 561 } 562 563 // Edit Contact 564 updateContact() { 565 let phoneNumbers = [{ 566 'phoneNumber': '', 567 'phoneAddress': '' 568 }]; 569 if (this.isNewNumber) { 570 phoneNumbers[0].phoneNumber = this.phoneNumberShow; 571 phoneNumbers[0].phoneAddress = this.contactForm?.phones[0]?.phoneAddress; 572 } 573 let upDataShow = false; 574 if (this.contactId != undefined) { 575 upDataShow = true 576 } 577 router.replace({ 578 url: 'pages/contacts/accountants/Accountants', 579 params: { 580 updataShow: upDataShow, 581 contactId: this.contacts.id, 582 phoneNumbers: phoneNumbers 583 }, 584 }); 585 } 586 587 clearAllCallLog() { 588 let id = ''; 589 let ids = []; 590 for (let index = 0; index < this.detailCallLogDataSource.totalCount(); index++) { 591 id = this.detailCallLogDataSource.getData(index).callLog.id; 592 ids.push(id); 593 } 594 this.removeCallLog(ids); 595 } 596 597 // Delete call records based on the ID set. 598 removeCallLog(ids) { 599 HiLog.i(TAG, 'removeCallLog'); 600 globalThis.DataWorker.sendRequest("deleteCallLogsById", { 601 context: globalThis.context, 602 ids: ids 603 }, (data) => { 604 HiLog.i(TAG, 'removeCallLog Success'); 605 CallLogRepository.getInstance().notifyChange() 606 }); 607 } 608 609 // Deleting a contact 610 deleteContact() { 611 AlertDialog.show({ 612 message: $r('app.string.delete_contact_sure'), 613 alignment: EnvironmentProp.isTablet() ? DialogAlignment.Center : DialogAlignment.Bottom, 614 autoCancel: true, 615 primaryButton: { 616 value: $r('app.string.dialog_cancel'), 617 action: () => { 618 } 619 }, 620 secondaryButton: { 621 value: $r('app.string.dialog_delete'), 622 fontColor: $r("sys.color.ohos_id_color_handup"), 623 action: () => { 624 HiLog.i(TAG, 'delete contact') 625 this.doDeleteContact(); 626 } 627 }, 628 cancel: () => { 629 HiLog.i(TAG, 'Closed callbacks') 630 }, 631 offset: { 632 dx: 0, dy: -52 633 }, 634 gridCount: 4 635 }) 636 } 637 638 // Delete a contact 639 doDeleteContact() { 640 globalThis.DataWorker.sendRequest("deleteContactById", { 641 context: globalThis.context, 642 contactId: this.contactId 643 }, (result) => { 644 if (result == 0 || result == undefined) { 645 ContactRepository.getInstance().notifyChange() 646 } else { 647 HiLog.i(TAG, `doDeleteContact Failed ${JSON.stringify(result)}`); 648 prompt.showToast({ 649 message: 'contactDetail Failed to delete data.' 650 }); 651 } 652 }); 653 router.back(); 654 } 655 656 // Sending Messages 657 sendMessage(phoneNumber, formatnum, name) { 658 PhoneNumber.fromString(phoneNumber).sendMessage(formatnum, name); 659 } 660 661 changeTopBarBackgroundColor(isTopForItem) { 662 if (isTopForItem) { 663 this.topbarBackgroundColor = Color.White; 664 } else { 665 this.topbarBackgroundColor = Color.Transparent; 666 } 667 } 668 669 getTopBarBackgroundColor() { 670 return this.topbarBackgroundColor; 671 } 672 673 // Truncates the first five characters of the string plus.. 674 subStringWithEllipsis(str, len) { 675 let newLength = 0; 676 let newStr = ''; 677 let chineseRegex = /[^\x00-\xff]/g; 678 let singleChar = ''; 679 let strLength = str.replace(chineseRegex, '**').length; 680 for (let i = 0; i < strLength; i++) { 681 singleChar = str.charAt(i).toString(); 682 if (singleChar.match(chineseRegex) != null) { 683 newLength += 2; 684 } else { 685 newLength++; 686 } 687 if (newLength > len) { 688 break; 689 } 690 newStr += singleChar; 691 } 692 newStr += '..' 693 return newStr; 694 } 695 696 getSettingsMenus() { 697 let tmpMoreMenu = []; 698 this.moreMenuOptions.forEach(element => { 699 tmpMoreMenu.push({}); 700 }); 701 let mMoreMenu: Array<{ 702 value: string, 703 action: () => void 704 }> = [{ 705 value: "", 706 action: () => { 707 } 708 }]; 709 mMoreMenu = tmpMoreMenu; 710 this.moreMenuOptions.forEach((element, i) => { 711 globalThis.context.resourceManager.getString(element.id, (err, typeName) => { 712 mMoreMenu[i] = { 713 value: typeName, 714 action: () => { 715 switch (i) { 716 case 0: 717 this.deleteContact(); 718 break; 719 } 720 } 721 }; 722 }); 723 }); 724 return mMoreMenu; 725 } 726}