• 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/src/main/ets/util/HiLog';
17import callLogService from '../../../model/calllog/CalllogModel';
18import MorandiColor from '../../../model/bean/MorandiColor';
19import { ArrayUtil } from '../../../../../../../common/src/main/ets/util/ArrayUtil';
20import { StringUtil } from '../../../../../../../common/src/main/ets/util/StringUtil';
21import { ObjectUtil } from '../../../../../../../common/src/main/ets/util/ObjectUtil';
22import ContactAbilityModel from '../../../model/ContactAbilityModel';
23import router from '@ohos.router';
24import BatchSelectRecentSource from '../../../model/bean/BatchSelectRecentSource';
25import BatchSelectContactSource from '../../../model/bean/BatchSelectContactSource';
26import CallLogSetting from "../../../../../../../feature/call/src/main/ets/CallLogSetting"
27
28const TAG = 'BatchSelectContactsPresenter ';
29
30/**
31 * Selecting a contact list by SMS
32 */
33export default class BatchSelectContactsPresenter {
34  private static sInstance: BatchSelectContactsPresenter;
35  sizeType: SizeType = SizeType.LG;
36  selectCount: number = 0;
37  // Recent Call Records
38  callLogTemp: Array<any> = [];
39  contactsList: Array<any> = [];
40  searchContactList: Array<any> = [];
41  groupList: Array<any> = [];
42  emptyViewText: Resource = $r("app.string.no_recent_contacts");
43  controller: TabsController = new TabsController();
44  currentIndex: number = 0;
45  tabTextSrc: string[] | Resource[] = [$r("app.string.recent"), $r("app.string.contact")];
46  tabInfo: TabInfo = new TabInfo(0);
47  contactsInfo: ContactsInfo = new ContactsInfo();
48  // Whether to display the Select All button at the bottom
49  showOption: boolean = false;
50  // Search Keyword
51  searchText: string = '';
52  // Selected data for the current population,key:phone number,value:name and number
53  selectedNumberMap: Map<number, any> = new Map();
54  // Whether to display the search list
55  searchLayoutShow: boolean = false;
56  selectDisabled: boolean = true;
57  isSelectAll: boolean = false;
58  icSelectAll: Resource = $r("app.media.ic_public_select_all");
59  allSelectMessage: Resource = $r("app.string.select_all");
60  allSelectTextStyle: Resource = $r("sys.color.ohos_id_color_primary");
61  initialIndex: number = 0;
62  recentSource: BatchSelectRecentSource = new BatchSelectRecentSource();
63  contactsSource: BatchSelectContactSource = new BatchSelectContactSource();
64  actionData: { [key: string]: any } = {};
65
66  public static getInstance(): BatchSelectContactsPresenter {
67    if (BatchSelectContactsPresenter.sInstance == null) {
68      BatchSelectContactsPresenter.sInstance = new BatchSelectContactsPresenter();
69    }
70    return BatchSelectContactsPresenter.sInstance;
71  }
72
73  aboutToAppear() {
74    this.initCallLog();
75    this.initContactsList();
76  }
77
78  aboutToDisappear() {
79  }
80
81  onPageShow() {
82  }
83
84  onPageHide() {
85  }
86
87  cancel() {
88    let parameters = {
89      contactObjects: ""
90    };
91    let result = {
92      resultCode: 0,
93      want: {
94        parameters: parameters
95      }
96    };
97    // Selecting a contact for creating an SMS message
98    globalThis.context?.terminateSelfWithResult(result)
99      .then((data) => {
100        HiLog.i(TAG, "terminateSelfWithResult Operation succeeded: ");
101      })
102      .catch((error) => {
103        HiLog.e(TAG, "Operation failed. Cause: %s", JSON.stringify(error.message));
104      });
105  }
106
107  resetInitialIndex(firstIndex: number) {
108    HiLog.i(TAG, "resetInitialIndex firstIndex is %s", firstIndex);
109    this.initialIndex = firstIndex;
110  }
111
112  comfirm() {
113    let checkedList = [];
114    this.selectedNumberMap.forEach((value) => {
115      checkedList.push(value);
116    });
117    let contacts = this.dealContactName(checkedList);
118    let parameters = {
119      contactObjects: JSON.stringify(contacts)
120    };
121    let result = {
122      resultCode: 0,
123      want: {
124        parameters: parameters
125      }
126    };
127    // Selecting a contact for creating an SMS message
128    globalThis.context?.terminateSelfWithResult(result)
129      .then((data) => {
130        HiLog.i(TAG, "terminateSelfWithResult Operation succeeded ");
131      })
132      .catch((error) => {
133        HiLog.e(TAG, "Operation failed. Cause: %s", JSON.stringify(error.message));
134      });
135  }
136
137  dealContactName(checkedList) {
138    let contacts = [];
139    for (let item of checkedList) {
140      let contact = {
141        contactName: item.name,
142        telephone: item.number
143      };
144      contacts.push(contact);
145    }
146    return contacts;
147  }
148
149  clickSelectAll() {
150    switch (this.tabInfo.tabIndex) {
151      case 0:
152        if (this.tabInfo.recentCount != 0 && this.tabInfo.recentCount === this.tabInfo.recentTotal) {
153          this.tabInfo.allClickedRecent = false;
154          this.unSelectAll();
155        } else {
156          this.tabInfo.allClickedRecent = true;
157          this.selectAll();
158        }
159        break;
160      case 1:
161        if (this.tabInfo.contactsCount != 0 && this.tabInfo.contactsCount === this.tabInfo.contactsTotal) {
162          this.tabInfo.allClickedContacts = false;
163          this.unSelectAll();
164        } else {
165          this.tabInfo.allClickedContacts = true;
166          this.selectAll();
167        }
168        break;
169      case 2:
170        if (this.tabInfo.groupsCount != 0 && this.tabInfo.groupsCount === this.tabInfo.groupsTotal) {
171          this.tabInfo.allClickedGroups = false;
172          this.unSelectAll();
173        } else {
174          this.tabInfo.allClickedGroups = true;
175          this.selectAll();
176        }
177        break;
178      default:
179        break;
180    }
181    this.refreshPageMessage();
182  }
183
184  unSelectAll() {
185    switch (this.tabInfo.tabIndex) {
186      case 0:
187        this.unSelectAllRecentProc();
188        break;
189      case 1:
190        this.unSelectAllContactProc();
191        break;
192      case 2:
193        this.groupList.forEach(element => {
194          element.checked = false;
195        });
196        this.tabInfo.groupsCount = 0;
197        break;
198      default:
199        break;
200    }
201  }
202
203  selectAll() {
204    switch (this.tabInfo.tabIndex) {
205      case 0:
206        this.selectAllRecentProc();
207        break;
208      case 1:
209        this.selectAllContactProc();
210        break;
211      case 2:
212        this.groupList.forEach(element => {
213          element.checked = true;
214        });
215        this.tabInfo.groupsCount = this.tabInfo.groupsTotal;
216        break;
217      default:
218        break;
219    }
220  }
221
222  unSelectAllRecentProc() {
223    this.callLogTemp.forEach(element => {
224      if (element.checked) {
225        element.checked = false;
226        this.deleteSelectedNumber(element.phoneNumber, element.displayName, true, element.quickSearchKey);
227      }
228    });
229    this.recentSource.refresh(this.callLogTemp);
230    this.tabInfo.recentCount = 0;
231  }
232
233  unSelectAllContactProc() {
234    if (this.contactsInfo.searchLayoutShow) {
235      this.contactsInfo.searchContactList.forEach(element => {
236        for (let i = 0; i < element.phoneNumbers.length; i++) {
237          if (element.phoneNumbers[i].checked) {
238            element.phoneNumbers[i].checked = false;
239            this.deleteSelectedNumber(element.phoneNumbers[i].phoneNumber, element.name.fullName, false, element.contactId);
240          }
241        }
242      });
243    } else {
244      this.contactsList.forEach(element => {
245        for (let i = 0; i < element.phoneNumbers.length; i++) {
246          if (element.phoneNumbers[i].checked) {
247            element.phoneNumbers[i].checked = false;
248            this.deleteSelectedNumber(element.phoneNumbers[i].phoneNumber, element.name.fullName, false, element.contactId);
249          }
250        }
251      });
252      this.contactsSource.refresh(this.contactsList);
253    }
254    this.tabInfo.contactsCount = 0;
255  }
256
257  selectAllRecentProc() {
258    this.callLogTemp.forEach(element => {
259      element.checked = true;
260      this.addOrUpdateSelectedNumberMap(element.phoneNumber, element.displayName, true, element.quickSearchKey);
261    });
262    this.recentSource.refresh(this.callLogTemp);
263    this.tabInfo.recentCount = this.tabInfo.recentTotal;
264  }
265
266  selectAllContactProc() {
267    if (this.contactsInfo.searchLayoutShow) {
268      this.contactsInfo.searchContactList.forEach(element => {
269        if (!element.phoneNumbers[0].checked) {
270          element.phoneNumbers[0].checked = true;
271          this.addOrUpdateSelectedNumberMap(element.phoneNumbers[0].phoneNumber, element.name.fullName, false, element.contactId);
272        }
273      });
274    } else {
275      this.contactsList.forEach(element => {
276        if (!element.phoneNumbers[0].checked) {
277          element.phoneNumbers[0].checked = true;
278          this.addOrUpdateSelectedNumberMap(element.phoneNumbers[0].phoneNumber, element.name.fullName, false, element.contactId);
279        }
280      });
281      this.contactsSource.refresh(this.contactsList);
282    }
283    this.tabInfo.contactsCount = this.tabInfo.contactsTotal;
284  }
285
286  onTabChange(tabIndex: number) {
287    HiLog.i(TAG, 'onTabChange tabIndex is %s', tabIndex);
288    this.tabInfo.tabIndex = tabIndex;
289    this.refreshPageMessage();
290  }
291
292  getEmptyText(): Resource {
293    switch (this.tabInfo.tabIndex) {
294      case 0:
295        this.emptyViewText = $r("app.string.no_recent_contacts");
296        break
297      case 1:
298        this.emptyViewText = $r("app.string.no_select_contacts");
299        break
300      case 2:
301        this.emptyViewText = $r("app.string.no_group_contacts");
302        break
303      default:
304        this.emptyViewText = $r("app.string.no_recent_contacts");
305        break
306    }
307    return this.emptyViewText;
308  }
309
310  onRecentItemClicked(index: number) {
311    HiLog.i(TAG, 'onRecentItemClicked index is %s', index);
312    this.checkStateChange(index, {
313      checked: !(this.callLogTemp[index].checked)
314    });
315  }
316
317  onSingleContactItemClick(num: number, name: string) {
318    HiLog.i(TAG, 'onSingleContactItemClick in ');
319    this.selectedNumberMap.set(num, {
320      name: name,
321      number: num
322    });
323    this.comfirm();
324  }
325
326  onContactItemClicked(index: number, indexChild: number) {
327    HiLog.i(TAG, 'onContactItemClicked index is ' + index);
328    HiLog.i(TAG, 'onContactItemClicked indexChild is ' + indexChild);
329    let event = {
330      contactIndex: index,
331      numberIndex: indexChild,
332      checked: this.searchLayoutShow ? !(this.searchContactList[index].phoneNumbers[indexChild].checked)
333                                     : !(this.contactsList[index].phoneNumbers[indexChild].checked)
334    }
335    this.checkStateChange(index, event);
336  }
337
338  checkStateChange(index, event) {
339    HiLog.i(TAG, 'checkStateChange event:  ' + JSON.stringify(event));
340    switch (this.tabInfo.tabIndex) {
341      case 0:
342        this.changeCallLogItemState(index, event);
343        break;
344      case 1:
345        this.changeContactsItemState(index, event);
346        break;
347      default:
348        break;
349    }
350    this.refreshPageMessage();
351  }
352
353  changeContactState(event) {
354    this.checkStateChange(event.contactIndex, event);
355  }
356
357  changeCallLogItemState(index, event) {
358    HiLog.i(TAG, 'changeCallLogItemState event :  ' + JSON.stringify(event));
359    this.callLogTemp[index].checked = event.checked;
360    this.recentSource.refreshSpecificOne(index, event.checked)
361
362    if (this.callLogTemp[index].checked) {
363      this.addOrUpdateSelectedNumberMap(this.callLogTemp[index].phoneNumber, this.callLogTemp[index].displayName, true, this.callLogTemp[index].quickSearchKey);
364      this.tabInfo.recentCount++;
365    } else {
366      this.deleteSelectedNumber(this.callLogTemp[index].phoneNumber, this.callLogTemp[index].displayName, true, this.callLogTemp[index].quickSearchKey);
367      this.tabInfo.recentCount--;
368    }
369  }
370
371  changeContactsItemState(index, event) {
372    HiLog.i(TAG, "SHOW changeContactsItemState searchLayoutShow");
373    let contactId = '';
374    if (!this.contactsInfo.searchLayoutShow) {
375      contactId = this.contactsList[index].contactId;
376    } else {
377      contactId = this.contactsInfo.searchContactList[index].contactId;
378    }
379    this.checkContactsCount(event, contactId);
380  }
381
382  checkContactsCount(event, contactId) {
383    HiLog.i(TAG, "SHOW checkContactsCount searchLayoutShow");
384    if (this.contactsInfo.searchLayoutShow) {
385      this.contactsInfo.searchContactList.forEach(element => {
386        if (contactId == element.contactId) {
387          if (event.checked) {
388            if (!this.checkIfNeedCount(element)) {
389              this.tabInfo.contactsCount++;
390            }
391            element.phoneNumbers[event.numberIndex].checked = true;
392            this.contactsInfo.contactsNumberCount++;
393            this.addOrUpdateSelectedNumberMap(element.phoneNumbers[event.numberIndex].phoneNumber,
394            element.name.fullName, false, element.contactId);
395          } else {
396            element.phoneNumbers[event.numberIndex].checked = false;
397            this.contactsInfo.contactsNumberCount--;
398            if (!this.checkIfNeedCount(element)) {
399              this.tabInfo.contactsCount--;
400            }
401            this.deleteSelectedNumber(element.phoneNumbers[event.numberIndex].phoneNumber, element.name.fullName, false, element.contactId);
402          }
403        }
404      });
405    } else {
406      this.contactsList.forEach(element => {
407        if (contactId == element.contactId) {
408          if (event.checked) {
409            if (!this.checkIfNeedCount(element)) {
410              this.tabInfo.contactsCount++;
411            }
412            element.phoneNumbers[event.numberIndex].checked = true;
413            this.contactsInfo.contactsNumberCount++;
414            this.addOrUpdateSelectedNumberMap(element.phoneNumbers[event.numberIndex].phoneNumber,
415            element.name.fullName, false, element.contactId);
416          } else {
417            element.phoneNumbers[event.numberIndex].checked = false;
418            this.contactsInfo.contactsNumberCount--;
419            if (!this.checkIfNeedCount(element)) {
420              this.tabInfo.contactsCount--;
421            }
422            this.deleteSelectedNumber(element.phoneNumbers[event.numberIndex].phoneNumber, element.name.fullName, false, element.contactId);
423          }
424        }
425      });
426      this.contactsSource.refresh(this.contactsList);
427    }
428  }
429
430  /**
431   * Determines whether the current contact element has an option.
432   *
433   * @param {Object} contact
434   * @return {boolean} true,false
435   */
436  checkIfNeedCount(contact) {
437    if (contact.phoneNumbers.length > 0) {
438      for (let index = 0; index < contact.phoneNumbers.length; index++) {
439        const element = contact.phoneNumbers[index];
440        if (element.checked) {
441          return true;
442        }
443      }
444    } else {
445      return false;
446    }
447  }
448
449  // Header Count Refresh Function
450  refreshPageMessage() {
451    HiLog.i(TAG, "refreshPageMessage start !")
452    this.selectCount = this.selectedNumberMap.size;
453    if (this.selectedNumberMap.size > 0) {
454      this.selectDisabled = false;
455      this.checkAllClickButtonStyle();
456    } else {
457      this.selectDisabled = true;
458      this.isSelectAll = false;
459      this.changeToUnFullSelect();
460    }
461  }
462
463  /**
464   * Verify the display style of the Select All button.
465   */
466  checkAllClickButtonStyle() {
467    HiLog.i(TAG, "checkAllClickButtonStyle start , and tabIndex is " + this.tabInfo.tabIndex);
468    switch (this.tabInfo.tabIndex) {
469      case 0:
470        if (this.tabInfo.recentCount === this.tabInfo.recentTotal) {
471          HiLog.i(TAG, "checkAllClickButtonStyle recent select all ");
472          this.changeToFullSelect();
473          this.tabInfo.allClickedRecent = true;
474        } else {
475          HiLog.i(TAG, "checkAllClickButtonStyle recent unselect all ");
476          this.changeToUnFullSelect();
477        }
478        break;
479      case 1:
480        if (this.tabInfo.contactsCount === this.tabInfo.contactsTotal) {
481          HiLog.i(TAG, "checkAllClickButtonStyle contact select all ");
482          this.changeToFullSelect();
483          this.tabInfo.allClickedContacts = true;
484        } else {
485          HiLog.i(TAG, "checkAllClickButtonStyle contact unselect all ");
486          this.changeToUnFullSelect();
487        }
488        break;
489      default:
490        break;
491    }
492  }
493
494  changeToFullSelect() {
495    this.icSelectAll = $r("app.media.ic_public_select_all_filled");
496    this.allSelectMessage = $r("app.string.unselect_all");
497    this.allSelectTextStyle = $r("sys.color.ohos_id_color_connected");
498  }
499
500  changeToUnFullSelect() {
501    this.icSelectAll = $r("app.media.ic_public_select_all");
502    this.allSelectMessage = $r("app.string.select_all");
503    this.allSelectTextStyle = $r("sys.color.ohos_id_color_primary");
504  }
505
506  addOrUpdateSelectedNumberMap(number, name, isCalllogs, keyOrId) {
507    HiLog.i(TAG, "addOrUpdateSelectedNumberMap isCalllogs is " + isCalllogs + " , keyOrId is " + keyOrId);
508    if (StringUtil.isEmpty(number)) {
509      return;
510    }
511    this.selectedNumberMap.set((keyOrId + number.replace(/\s+/g, '')), {
512      name: name,
513      number: number.replace(/\s+/g, '')
514    });
515    this.updataConnectedContact(number, name, isCalllogs, keyOrId, true);
516  }
517
518  deleteSelectedNumber(number, name, isCalllogs, keyOrId) {
519    HiLog.i(TAG, "deleteSelectedNumber isCalllogs is " + isCalllogs + " , keyOrId is " + keyOrId);
520    if (StringUtil.isEmpty(number)) {
521      return;
522    }
523    this.selectedNumberMap.delete(keyOrId + number.replace(/\s+/g, ''));
524    this.updataConnectedContact(number, name, isCalllogs, keyOrId, false);
525  }
526
527  updataConnectedContact(number, name, isCalllogs, keyOrId, isAdd) {
528    HiLog.i(TAG, "updataConnectedContact isCalllogs is " + isCalllogs + " , keyOrId is " + keyOrId);
529    if (isCalllogs) {
530      this.contactsList.forEach(element => {
531        if (!ObjectUtil.isEmpty(element) && element.contactId == keyOrId) {
532          for (let i = 0; i < element.phoneNumbers.length; i++) {
533            let childElement = element.phoneNumbers[i];
534            if (!ObjectUtil.isEmpty(childElement) && childElement.phoneNumber == number && element.name.fullName == name) {
535              if (isAdd) {
536                // If the original data does not contain the selected item before modification, the tab count increases by 1.
537                if (!this.checkIfNeedCount(element)) {
538                  this.tabInfo.contactsCount++;
539                }
540                childElement.checked = true;
541                this.contactsInfo.contactsNumberCount++;
542              } else {
543                // After the modification, the tab count decreases by 1 when the original data does not contain the selected item.
544                childElement.checked = false;
545                this.contactsInfo.contactsNumberCount--;
546                if (!this.checkIfNeedCount(element)) {
547                  this.tabInfo.contactsCount--;
548                }
549              }
550            }
551          }
552          return;
553        }
554      });
555      this.contactsSource.refresh(this.contactsList);
556    } else {
557      this.callLogTemp.forEach(element => {
558        if (!ObjectUtil.isEmpty(element) && element.quickSearchKey == keyOrId && element.phoneNumber == number && element.displayName == name) {
559          element.checked = isAdd;
560          if (isAdd) {
561            this.tabInfo.recentCount++;
562          } else {
563            this.tabInfo.recentCount--;
564          }
565          return;
566        }
567      })
568      this.recentSource.refresh(this.callLogTemp);
569    }
570  }
571
572  /**
573   * Obtaining Recent Call Records
574   * */
575  initCallLog() {
576    HiLog.i(TAG, 'initCallLog start !');
577    let tempMap = new Map();
578    let tempList: any[] = [];
579
580    globalThis.DataWorker?.sendRequest("getAllCalls", {
581      context: globalThis.context,
582      mergeRule: CallLogSetting.getInstance().getMergeRule(),
583      actionData: this.actionData
584    }, (data) => {
585      if (data.hasOwnProperty('callLogList') && !ArrayUtil.isEmpty(data.callLogList)) {
586        HiLog.i(TAG, 'data  has callLogList key');
587        for (let i = 0; i < data.callLogList.length; i++) {
588          let element = data.callLogList[i];
589          let bgColorIndex = parseInt(element.id, 10) % (MorandiColor.Color.length);
590          element.portraitColor = MorandiColor.Color[bgColorIndex];
591          element.suffix = StringUtil.isEmpty(element.displayName) ? '' : element.displayName.substr(element.displayName.length - 1);
592          element.checked = false;
593          // 重复的号码无需显示
594          if (!tempMap.has(StringUtil.removeSpace(element.phoneNumber))) {
595            tempList.push(element);
596            tempMap.set(element.phoneNumber, null);
597          }
598          //Displays the 50 numbers that have generated the latest call records.
599          if (tempList.length > 50) {
600            HiLog.i(TAG, 'callLogList more 50 break!');
601            break;
602          }
603        }
604      }
605      this.callLogTemp = tempList;
606      this.recentSource.refresh(this.callLogTemp);
607      this.tabInfo.recentTotal = this.callLogTemp.length;
608      this.checkOptionState();
609    });
610  }
611
612  /**
613   * Check whether the Select All button at the bottom needs to be displayed.
614   * */
615  checkOptionState() {
616    switch (this.tabInfo.tabIndex) {
617      case 0:
618        ArrayUtil.isEmpty(this.callLogTemp) ? this.showOption = false : this.showOption = true;
619        break;
620      case 1:
621        ArrayUtil.isEmpty(this.contactsList) ? this.showOption = false : this.showOption = true;
622        break;
623      case 2:
624        ArrayUtil.isEmpty(this.groupList) ? this.showOption = false : this.showOption = true;
625        break;
626      default:
627        break;
628    }
629  }
630
631  /*
632   * Initializing Contact List Data
633   */
634  initContactsList() {
635    HiLog.i(TAG, 'initContactsList start!');
636    globalThis.DataWorker.sendRequest("getAllContactWithPhoneNumbers", {
637      context: globalThis.context
638    }, (resultList) => {
639      HiLog.i(TAG, 'initContactsList resultList success ' + resultList.length);
640      let listTemp: any[] = [];
641      if (!ArrayUtil.isEmpty(resultList)) {
642        for (let element of resultList) {
643          element.name = {};
644          element.name.fullName = element.emptyNameData;
645          element.name.namePrefix = element.namePrefix;
646          element.name.nameSuffix = element.nameSuffix;
647          if (element.phoneNumbers != null && element.phoneNumbers.length > 0) {
648            element.phoneNumbers.forEach(childEle => {
649              childEle.checked = false;
650              childEle.labelName = this.getPhoneLabelNameById(childEle.numType, childEle.phoneNumber);
651              this.initVariableSpan(element);
652            });
653            listTemp.push(element);
654          }
655        }
656        this.contactsList = listTemp;
657        this.contactsSource.refresh(this.contactsList);
658        this.tabInfo.contactsTotal = this.contactsList.length;
659        this.contactsInfo.contactsListTotal = this.contactsList.length;
660      } else {
661        HiLog.e(TAG, 'select contact list is empty!');
662      }
663    });
664  }
665
666
667  /**
668   * Assign a custom attribute to prepare for later variable font searches
669   *
670   * @param {Object} item contacts data
671   */
672  initVariableSpan(item) {
673    // Initialize Variable Names
674    let matchString = StringUtil.getMatchedString(item.emptyNameData, this.searchText);
675    if (StringUtil.isEmpty(matchString) || StringUtil.isEmpty(this.searchText.trim())) {
676      item.name.searchTextStart = '';
677      item.name.searchTextMiddle = '';
678      item.name.searchTextEnd = item.emptyNameData;
679    } else {
680      let name = item.emptyNameData;
681      let index = name.indexOf(matchString);
682      item.name.searchTextStart = name.substr(0, index);
683      item.name.searchTextMiddle = name.substr(index, matchString.length);
684      item.name.searchTextEnd = name.substr(index + matchString.length);
685    }
686    // Initialize Variable Numbers
687    for (let i = 0; i < item.phoneNumbers.length; i++) {
688      let phoneNumber = item.phoneNumbers[i].phoneNumber;
689      let matchStringPhone = StringUtil.getMatchedString(phoneNumber, this.searchText);
690      if (StringUtil.isEmpty(matchStringPhone) || StringUtil.isEmpty(this.searchText.trim())) {
691        item.phoneNumbers[i].startPhone = '';
692        item.phoneNumbers[i].middlePhone = '';
693        item.phoneNumbers[i].endPhone = phoneNumber;
694      } else {
695        let phoneIndex = phoneNumber.indexOf(matchStringPhone);
696        item.phoneNumbers[i].startPhone = phoneNumber.substr(0, phoneIndex);
697        item.phoneNumbers[i].middlePhone = phoneNumber.substr(phoneIndex, matchStringPhone.length);
698        item.phoneNumbers[i].endPhone = phoneNumber.substr(phoneIndex + matchStringPhone.length);
699      }
700    }
701  }
702
703  getPhoneLabelNameById(phoneLabelId: string, phoneNumber) {
704    let labelName: Resource;
705    switch (parseInt(phoneLabelId, 10)) {
706      case 1:
707        labelName = $r("app.string.phone_type_mobile_expansion", phoneNumber);
708        break;
709      case 2:
710        labelName = $r("app.string.phone_type_home_expansion", phoneNumber);
711        break;
712      case 3:
713        labelName = $r("app.string.phone_type_work_expansion", phoneNumber);
714        break;
715      case 4:
716        labelName = $r("app.string.phone_type_fax_work_expansion", phoneNumber);
717        break;
718      case 5:
719        labelName = $r("app.string.phone_type_fax_home_expansion", phoneNumber);
720        break;
721      case 6:
722        labelName = $r("app.string.phone_type_pager_expansion", phoneNumber);
723        break;
724      case 7:
725        labelName = $r("app.string.phone_type_other_expansion", phoneNumber);
726        break;
727      case 12:
728        labelName = $r("app.string.phone_type_main_expansion", phoneNumber);
729        break;
730      case 99:
731        labelName = $r("app.string.phone_type_custom_expansion", phoneNumber);
732        break;
733      default:
734        break;
735    }
736    return labelName;
737  }
738}
739
740export class TabInfo {
741  tabIndex: number = 0;
742  recentTotal: number = 0;
743  contactsTotal: number = 0;
744  groupsTotal: number = 0;
745  // Select All Clicked
746  allClickedRecent: boolean = false;
747  allClickedContacts: boolean = false;
748  allClickedGroups: boolean = false;
749  // Count on each tab page
750  recentCount: number = 0;
751  contactsCount: number = 0;
752  groupsCount: number = 0;
753  refreshGroupItemState: boolean = false;
754
755  constructor(tabIndex: number) {
756    this.tabIndex = tabIndex;
757  }
758}
759
760/**
761 * Data related to the contact list
762 */
763export class ContactsInfo {
764  searchContactList = [];
765  // List of selected contacts, which will be used for big data.
766  selectedContactMap = new Map();
767  // Whether to display the search page
768  searchLayoutShow: boolean = false;
769  // Number of Matched Search Records
770  searchPhoneNum: number = 0;
771  // Indicates whether to search a list.
772  showSearchList: boolean = false;
773  // Display Default Number
774  showDefaultNumber: boolean = true;
775  // Indicates whether to display the child number list.
776  showNumberList: boolean = true;
777  // Display primary number check box
778  phoneCheckShow: boolean = true;
779  // Display child number list check box
780  childPhoneCheckShow: boolean = true;
781  contactsListCount: number = 0;
782  contactsListTotal: number = 0;
783  // Count of selected numbers in the contact list
784  contactsNumberCount: number = 0;
785
786  constructor() {
787  }
788}