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 inputMethod from '@ohos.inputMethod';
17import { HiLog } from '../../../../../../../common/src/main/ets/util/HiLog';
18import { StringUtil } from '../../../../../../../common/src/main/ets/util/StringUtil';
19import { ArrayUtil } from '../../../../../../../common/src/main/ets/util/ArrayUtil';
20import { ObjectUtil } from '../../../../../../../common/src/main/ets/util/ObjectUtil';
21import { AccountTypeService } from '../../../../../../../feature/account/src/main/ets/AccountTypeService';
22import { AccountType } from '../../../../../../../feature/account/src/main/ets/type/AccountType';
23import { House } from '../../../../../../../feature/contact/src/main/ets/contract/House';
24import { Relation } from '../../../../../../../feature/contact/src/main/ets/contract/Relation';
25import { Phone } from '../../../../../../../feature/contact/src/main/ets/contract/Phone';
26import { Email } from '../../../../../../../feature/contact/src/main/ets/contract/Email';
27import { Birthday } from '../../../../../../../feature/contact/src/main/ets/contract/Birthday';
28import { Aim } from '../../../../../../../feature/contact/src/main/ets/contract/Aim';
29import { EmailBean } from '../../../model/bean/EmailBean';
30import { ContactInfo } from '../../../model/bean/ContactInfo';
31import { PhoneNumBean } from '../../../model/bean/PhoneNumBean';
32import { HouseBean } from '../../../model/bean/HouseBean';
33import { AIMBean } from '../../../model/bean/AIMBean';
34import { EventBean } from '../../../model/bean/EventBean';
35import { AssociatedPersonBean } from '../../../model/bean/AssociatedPersonBean';
36import PreferencesUtil from './../../../util/PreferencesUtil'
37
38const TAG = 'AccountantsPresenter  ';
39
40/**
41 * Add Contact Presenter
42 */
43export default class AccountantsPresenter {
44  private static instance: AccountantsPresenter;
45  static readonly timeSub: number = 1000;
46  getPhones: Array<{ [key: string]: any }> = [];
47  getEmails: Array<{ [key: string]: any }> = [];
48  clickBefEvent: Date = new Date();
49  clickAftEvent: Date = new Date();
50  contactId: string = '';
51  routerAvtiveFlag: boolean = false;
52
53  // update mark
54  updateShow: boolean = false;
55  isShowPosition: boolean = false;
56  showMore: boolean = false;
57  addState: boolean = false;
58  phones: string = '';
59  editContact: number = -1;
60  phoneNumberShow: string = '';
61  callId: string = '';
62
63  // refresh mark
64  changed: boolean = false;
65  originalContactInfo = JSON.stringify(new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0));
66  // contact detail
67  contactInfoBefore: ContactInfo = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
68  contactInfoAfter: ContactInfo = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
69  MagList: object = [];
70
71  private constructor() {
72  }
73
74  public static getInstance(): AccountantsPresenter {
75    if (!AccountantsPresenter.instance) {
76      AccountantsPresenter.instance = new AccountantsPresenter()
77    }
78    return AccountantsPresenter.instance
79  }
80
81  refreshState: (presenter: AccountantsPresenter) => void;
82  clickEnable = true;
83
84  init(refreshState?) {
85    this.contactId = '';
86    this.updateShow = false;
87    this.MagList = [1];
88    this.contactInfoBefore = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
89    this.contactInfoAfter = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
90    this.refreshState = refreshState;
91    this.routerAvtiveFlag = false;
92  }
93
94  refresh() {
95    this.contactInfoBefore = this.contactInfoAfter;
96    this.getPhones = this.getArray(this.contactInfoBefore.phones);
97    this.getEmails = this.getArray(this.contactInfoBefore.emails);
98    this.changed = !this.changed;
99    this.refreshAddState();
100    if (this.refreshState) {
101      this.refreshState(this);
102    }
103  }
104
105  refreshAddState() {
106    let addState = this.originalContactInfo != this.getExistenceInfoString(this.contactInfoAfter);
107    if (this.addState != addState) {
108      HiLog.i(TAG, 'refreshAddState addState change:' + addState)
109      this.addState = addState
110    }
111  }
112
113  updatesInit() {
114    HiLog.i(TAG, ' init start');
115    this.contactInfoAfter.setID(this.contactId);
116    if (this.updateShow === true) {
117      HiLog.i(TAG, ' getPageData start ');
118      this.getPageData(this.contactId);
119    }
120  }
121
122  getExistenceInfoString(afterInfo: ContactInfo) {
123    let temp = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
124    if (!afterInfo) {
125      return JSON.stringify(temp);
126    } else {
127      if (!StringUtil.isEmpty(afterInfo.display_name)) {
128        temp.display_name = afterInfo.display_name;
129      }
130      if (!StringUtil.isEmpty(afterInfo.nickname)) {
131        temp.nickname = afterInfo.nickname
132      }
133      if (!StringUtil.isEmpty(afterInfo.remarks)) {
134        temp.remarks = afterInfo.remarks;
135      }
136      if (!StringUtil.isEmpty(afterInfo.position)) {
137        temp.position = afterInfo.position
138      }
139      if (!StringUtil.isEmpty(afterInfo.company)) {
140        temp.company = afterInfo.company
141      }
142      if (!ArrayUtil.isEmpty(afterInfo.phones)) {
143        for (let item of afterInfo.phones) {
144          if (!StringUtil.isEmpty(item?.num)) {
145            temp.phones.push(item)
146          }
147        }
148      }
149      if (!ArrayUtil.isEmpty(afterInfo.emails)) {
150        for (let item of afterInfo.emails) {
151          if (!StringUtil.isEmpty(item?.address)) {
152            temp.emails.push(item)
153          }
154        }
155      }
156      if (!ArrayUtil.isEmpty(afterInfo.aims)) {
157        for (let item of afterInfo.aims) {
158          if (!StringUtil.isEmpty(item?.aimName)) {
159            temp.aims.push(item)
160          }
161        }
162      }
163      if (!ArrayUtil.isEmpty(afterInfo.houses)) {
164        for (let item of afterInfo.houses) {
165          if (!StringUtil.isEmpty(item?.houseName)) {
166            temp.houses.push(item)
167          }
168        }
169      }
170      if (!ArrayUtil.isEmpty(afterInfo.websites)) {
171        for (let item of afterInfo.websites) {
172          if (!StringUtil.isEmpty(item)) {
173            temp.websites.push(item)
174          }
175        }
176      }
177      if (!ArrayUtil.isEmpty(afterInfo.events)) {
178        for (let item of afterInfo.events) {
179          if (!StringUtil.isEmpty(item?.data)) {
180            temp.events.push(item)
181          }
182        }
183      }
184      if (!ArrayUtil.isEmpty(afterInfo.relationships)) {
185        for (let item of afterInfo.relationships) {
186          if (!StringUtil.isEmpty(item?.name)) {
187            temp.relationships.push(item)
188          }
189        }
190      }
191      return JSON.stringify(temp);
192    }
193  }
194
195  getPageData(id: string) {
196    if (StringUtil.isEmpty(id)) {
197      HiLog.e(TAG, 'The parameter ID is empty.');
198    }
199    globalThis.DataWorker.sendRequest('getContactById', {
200      context: globalThis.context,
201      contactId: id
202    }, result => {
203      if (StringUtil.isEmpty(result)) {
204        HiLog.e(TAG, 'The result in the database is empty.');
205        return;
206      }
207      this.dealRecordDetailsData(result.data);
208    });
209  }
210
211  private dealRecordDetailsData(data) {
212    let contactTemp = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
213    if (!data.hasOwnProperty('id') || data.id != this.contactId) {
214      HiLog.e(TAG, 'Failed to query the database based on the ID.');
215      return;
216    }
217    contactTemp.setID(data.id);
218    let nameUpdate = 0;
219    if (data.hasOwnProperty('nameUpdate')) {
220      nameUpdate = data.nameUpdate;
221    }
222    if (data.hasOwnProperty('display_name') && nameUpdate == 0) {
223      contactTemp.setDisplayName(data.display_name);
224    }
225    if (data.hasOwnProperty('nickname')) {
226      contactTemp.setNickName(data.nickname);
227    }
228    if (data.hasOwnProperty('phones')) {
229      contactTemp.setPhones(data.phones);
230    }
231    if (data.hasOwnProperty('emails')) {
232      contactTemp.setEmails(data.emails);
233    }
234    if (data.hasOwnProperty('remarks')) {
235      contactTemp.setRemarks(data.remarks);
236    }
237    if (data.hasOwnProperty('position')) {
238      contactTemp.setPosition(data.position);
239      this.isShowPosition = true;
240    }
241    if (data.hasOwnProperty('company')) {
242      contactTemp.setCompany(data.company);
243    }
244    if (data.hasOwnProperty('aims')) {
245      contactTemp.setAims(data.aims);
246    }
247    if (data.hasOwnProperty('houses')) {
248      contactTemp.setHouses(data.houses);
249    }
250    if (data.hasOwnProperty('websites')) {
251      contactTemp.setWebsites(data.websites);
252    }
253    if (data.hasOwnProperty('relationships')) {
254      contactTemp.setRelationships(data.relationships);
255    }
256    if (data.hasOwnProperty('events')) {
257      contactTemp.setEvents(data.events);
258    }
259    if (data.hasOwnProperty('groups')) {
260      contactTemp.setGroups(data.groups);
261    }
262    this.contactInfoBefore = contactTemp;
263    this.originalContactInfo = this.getExistenceInfoString(contactTemp)
264    if (0 === this.editContact) {
265      if ('' !== this.phones) {
266        let saveTemp: Array<{ [key: string]: any }>  = this.getArray(this.phones);
267        for(let i = 0; i < saveTemp?.length ; i ++){
268          let phoneNumBean: PhoneNumBean = new PhoneNumBean('','','','','');
269          phoneNumBean.id = saveTemp[i]?.item?.id;
270          phoneNumBean.num = saveTemp[i]?.item?.num;
271          phoneNumBean.numType = saveTemp[i]?.item?.type;
272          phoneNumBean.homeArea = '';
273          phoneNumBean.carriers = '';
274          this.contactInfoBefore.phones.push(phoneNumBean);
275        }
276      }
277    } else if (1 === this.editContact || 2 === this.editContact) {
278      let phoneNumBean: PhoneNumBean = new PhoneNumBean('','','','','');
279      phoneNumBean.id = this.callId;
280      phoneNumBean.num = this.phoneNumberShow;
281      phoneNumBean.numType = '';
282      phoneNumBean.homeArea = '';
283      phoneNumBean.carriers = '';
284      this.contactInfoBefore.phones.push(phoneNumBean);
285    }
286    this.getPhones = this.getArray(this.contactInfoBefore.phones);
287    this.getEmails = this.getArray(this.contactInfoBefore.emails);
288    this.contactInfoAfter = contactTemp;
289    this.refreshAddState()
290  }
291
292  public getData(type: string, index: number): { [key: string]: any } {
293    let data = new Array<{ [key: string]: any }>();
294    switch (type) {
295      case 'phone':
296        if (!this.updateShow) {
297          data = this.getArray(this.contactInfoBefore.phones);
298        } else {
299          data = this.getPhones;
300        }
301        break;
302      case 'email':
303        if (!this.updateShow) {
304          data = this.getArray(this.contactInfoBefore.emails);
305        } else {
306          data = this.getEmails;
307        }
308        break;
309      case 'AIM':
310        data = this.getArray(this.contactInfoBefore.aims);
311        break;
312      case 'house':
313        data = this.getArray(this.contactInfoBefore.houses);
314        break;
315      case 'relationships':
316        data = this.getArray(this.contactInfoBefore.relationships);
317        break;
318      case 'events':
319        data = this.getArray(this.contactInfoBefore.events);
320        break;
321      default:
322        break;
323    }
324    if (index < data.length) {
325      return data[index];
326    }
327    return {
328      i: index + 1, item: {}
329    };
330  }
331
332  public getArray(array): Array<{ [key: string]: any }> {
333    if (ArrayUtil.isEmpty(array)) {
334      array = [{}];
335    }
336    let itemList = ArrayUtil.isEmpty(array) ? this.MagList : array;
337    itemList = itemList.map((item, index) => {
338      return {
339        i: index + 1, item: item
340      };
341    })
342    return itemList;
343  }
344
345  public getDataArray(type: string) {
346    let data = new Array<{ [key: string]: any }>();
347    switch (type) {
348      case 'phone':
349        if (!this.updateShow) {
350          data = this.getArray(this.contactInfoBefore.phones);
351        } else {
352          data = this.getPhones;
353        }
354        break;
355      case 'email':
356        if (!this.updateShow) {
357          data = this.getArray(this.contactInfoBefore.emails);
358        } else {
359          data = this.getEmails;
360        }
361        break;
362      case 'AIM':
363        data = this.getArray(this.contactInfoBefore.aims);
364        break;
365      case 'house':
366        data = this.getArray(this.contactInfoBefore.houses);
367        break;
368      case 'relationships':
369        data = this.getArray(this.contactInfoBefore.relationships);
370        break;
371      case 'events':
372        data = this.getArray(this.contactInfoBefore.events);
373        break;
374      default:
375        break;
376    }
377    HiLog.i(TAG, 'getDataArray type: ' + type + ', length: ' + data.length);
378    return data;
379  }
380
381  public addMore(type: any) {
382    switch (type) {
383      case 'phone':
384        this.contactInfoAfter.phones.push(new PhoneNumBean('', '', '1', '', ''));
385        break;
386      case 'email':
387        this.contactInfoAfter.emails.push(new EmailBean('', '', '1'));
388        break;
389      case 'AIM':
390        this.contactInfoAfter.aims.push(new AIMBean('', '', '1', ''));
391        break;
392      case 'house':
393        this.contactInfoAfter.houses.push(new HouseBean('', '', '1', ''));
394        break;
395      case 'relationships':
396        this.contactInfoAfter.relationships.push(new AssociatedPersonBean('', '', '', '1'));
397        break;
398      case 'events':
399        this.contactInfoAfter.events.push(new EventBean('', '', '1', ''));
400        break;
401      default:
402        break;
403    }
404    this.refresh();
405  }
406
407  public deleteItem(typeName: string, startIndex) {
408    HiLog.i(TAG, `deleteItem ${typeName} ${startIndex}`);
409    switch (typeName) {
410      case 'phone':
411        if (this.contactInfoAfter.phones.length > 1) {
412          this.contactInfoAfter.phones.splice(startIndex, 1);
413        } else {
414          this.contactInfoAfter.phones[0].num = '';
415        }
416        this.getPhones = this.getArray(this.contactInfoAfter.phones);
417        break;
418      case 'email':
419        if (this.contactInfoAfter.emails.length > 1) {
420          this.contactInfoAfter.emails.splice(startIndex, 1);
421        } else {
422          this.contactInfoAfter.emails[0].address = '';
423        }
424        this.getEmails = this.getArray(this.contactInfoAfter.emails);
425        break;
426      case 'AIM':
427        if (this.contactInfoAfter.aims.length > 1) {
428          this.contactInfoAfter.aims.splice(startIndex, 1);
429        } else {
430          this.contactInfoAfter.aims[0].aimName = '';
431        }
432        break;
433      case 'house':
434        if (this.contactInfoAfter.houses.length > 1) {
435          this.contactInfoAfter.houses.splice(startIndex, 1);
436        } else {
437          this.contactInfoAfter.houses[0].houseName = '';
438        }
439        break;
440      case 'relationships':
441        if (this.contactInfoAfter.relationships.length > 1) {
442          this.contactInfoAfter.relationships.splice(startIndex, 1);
443        } else {
444          this.contactInfoAfter.relationships[0].name = '';
445        }
446        break;
447      case 'events':
448        if (this.contactInfoAfter.events.length > 1) {
449          this.contactInfoAfter.events.splice(startIndex, 1);
450        } else {
451          this.contactInfoAfter.events[0].data = '';
452        }
453        break;
454      default:
455        break;
456    }
457    this.refresh();
458  }
459
460  public getTextDisplay(typeName: string, data: any) {
461    let display: string = '';
462    if (data && data.item) {
463      switch (typeName) {
464        case 'phone':
465          if (data.item.hasOwnProperty('num')) {
466            display = data.item.num;
467          }
468          break;
469        case 'email':
470          if (data.item.hasOwnProperty('address')) {
471            display = data.item.address;
472          }
473          break;
474        case 'AIM':
475          if (data.item.hasOwnProperty('aimName')) {
476            display = data.item.aimName;
477          }
478          break;
479        case 'house':
480          if (data.item.hasOwnProperty('houseName')) {
481            display = data.item.houseName;
482          }
483          break;
484        case 'relationships':
485          if (data?.item.hasOwnProperty('name')) {
486            display = data.item.name;
487          }
488          break;
489        case 'events':
490          if (data.item.hasOwnProperty('data')) {
491            display = data.item.data;
492          }
493          break;
494        default:
495          break;
496      }
497    }
498    return display;
499  }
500
501  public listItemChange(typeName: string, data: any, arg: string) {
502    try {
503      switch (typeName) {
504        case 'phone':
505          if (StringUtil.isEmpty(this.contactInfoAfter?.phones[data?.i - 1]?.numType)) {
506            this.contactInfoAfter.phones[data.i - 1] = new PhoneNumBean('', '', '1', '', '');
507          }
508          this.contactInfoAfter.phones[data.i - 1].num = arg.toString();
509          break;
510        case 'email':
511          if (StringUtil.isEmpty(this.contactInfoAfter?.emails[data?.i - 1]?.emailType)) {
512            this.contactInfoAfter.emails[data.i - 1] = new EmailBean('', '', '1');
513          }
514          this.contactInfoAfter.emails[data.i - 1].address = arg.toString();
515          break;
516        case 'AIM':
517          if (StringUtil.isEmpty(this.contactInfoAfter?.aims[data?.i - 1]?.aimType)) {
518            this.contactInfoAfter.aims[data.i - 1] = new AIMBean('', '', '1', '');
519          }
520          this.contactInfoAfter.aims[data.i - 1].aimName = arg.toString();
521          break;
522        case 'house':
523          if (StringUtil.isEmpty(this.contactInfoAfter?.houses[data?.i - 1]?.houseType)) {
524            this.contactInfoAfter.houses[data.i - 1] = new HouseBean('', '', '1', '');
525          }
526          this.contactInfoAfter.houses[data.i - 1].houseName = arg.toString();
527          break;
528        case 'relationships':
529          if (StringUtil.isEmpty(this.contactInfoAfter?.relationships[data?.i - 1]?.associatedType)) {
530            this.contactInfoAfter.relationships[data.i - 1] = new AssociatedPersonBean('', '', '', '1');
531          }
532          this.contactInfoAfter.relationships[data.i - 1].name = arg.toString();
533          break;
534        default:
535          break;
536      }
537      this.refreshAddState()
538    } catch (error) {
539      HiLog.e(TAG, 'something error happened: ' + JSON.stringify(error));
540    }
541  }
542
543  public menuSelect(typeName: string, data: any) {
544    let typeId = 1;
545    switch (typeName) {
546      case 'phone':
547        if (data.item.hasOwnProperty('numType')) {
548          typeId = Number(data.item.numType)
549        }
550        return Phone.getTypeLabelResource(typeId);
551        break;
552      case 'email':
553        if (data.item.hasOwnProperty('emailType')) {
554          typeId = Number(data.item.emailType)
555        }
556        return Email.getTypeLabelResource(typeId);
557        break;
558      case 'AIM':
559        if (data.item.hasOwnProperty('aimType')) {
560          typeId = Number(data.item.aimType)
561        }
562        return Aim.getTypeLabelResource(typeId);
563        break;
564      case 'house':
565        if (data.item.hasOwnProperty('houseType')) {
566          typeId = Number(data.item.houseType)
567        }
568        return House.getTypeLabelResource(typeId);
569        break;
570      case 'relationships':
571        if (data.item.hasOwnProperty('associatedType')) {
572          typeId = Number(data.item.associatedType)
573        }
574        return Relation.getTypeLabelResource(typeId);
575        break;
576      case 'events':
577        if (data.item.hasOwnProperty('eventType')) {
578          typeId = Number(data.item.eventType)
579        }
580        return Birthday.getTypeLabelResource(typeId);
581        break;
582      default:
583        return '';
584        break;
585    }
586  }
587
588  getMenuList(typeName: string) {
589    let accountTypeService = new AccountTypeService();
590    let menuKindTypeList;
591    let phoneType = accountTypeService.getAccountType(AccountType.PHONE_ACCOUNT_TYPE);
592    switch (typeName) {
593      case 'phone':
594        menuKindTypeList = phoneType.mineKinds.get(Phone.CONTENT_ITEM_TYPE).typeList;
595        break;
596      case 'email':
597        menuKindTypeList = phoneType.mineKinds.get(Email.CONTENT_ITEM_TYPE).typeList;
598        break;
599      case 'AIM':
600        menuKindTypeList = phoneType.mineKinds.get(Aim.CONTENT_ITEM_TYPE).typeList;
601        break;
602      case 'house':
603        menuKindTypeList = phoneType.mineKinds.get(House.CONTENT_ITEM_TYPE).typeList;
604        break;
605      case 'relationships':
606        menuKindTypeList = phoneType.mineKinds.get(Relation.CONTENT_ITEM_TYPE).typeList;
607        break;
608      case 'events':
609        menuKindTypeList = phoneType.mineKinds.get(Birthday.CONTENT_ITEM_TYPE).typeList;
610        break;
611      default:
612        break;
613    }
614    return menuKindTypeList;
615  }
616
617  public menuChange(typeName: string, data: any, item: any) {
618    switch (typeName) {
619      case 'phone':
620        if (ObjectUtil.isEmpty(this.contactInfoAfter.phones[data.i - 1])) {
621          this.contactInfoAfter.phones[data.i - 1] = new PhoneNumBean('', '', '', '', '');
622        }
623        this.contactInfoAfter.phones[data.i - 1].numType = item.rawValue.toString();
624        data.numType = item.rawValue.toString();
625        break;
626      case 'email':
627        if (ObjectUtil.isEmpty(this.contactInfoAfter.emails[data.i - 1])) {
628          this.contactInfoAfter.emails[data.i - 1] = new EmailBean('', '', '');
629        }
630        this.contactInfoAfter.emails[data.i - 1].emailType = item.rawValue.toString();
631        data.emailType = item.rawValue.toString();
632        break;
633      case 'AIM':
634        if (ObjectUtil.isEmpty(this.contactInfoAfter.aims[data.i - 1])) {
635          this.contactInfoAfter.aims[data.i - 1] = new AIMBean('', '', '', '');
636        }
637        this.contactInfoAfter.aims[data.i - 1].aimType = item.rawValue.toString();
638        break;
639      case 'house':
640        if (ObjectUtil.isEmpty(this.contactInfoAfter.houses[data.i - 1])) {
641          this.contactInfoAfter.houses[data.i - 1] = new HouseBean('', '', '', '');
642        }
643        this.contactInfoAfter.houses[data.i - 1].houseType = item.rawValue.toString();
644        break;
645      case 'relationships':
646        if (ObjectUtil.isEmpty(this.contactInfoAfter.relationships[data.i - 1])) {
647          this.contactInfoAfter.relationships[data.i - 1] = new AssociatedPersonBean('', '', '', '');
648        }
649        this.contactInfoAfter.relationships[data.i - 1].associatedType = item.rawValue.toString();
650        break;
651      case 'events':
652        if (ObjectUtil.isEmpty(this.contactInfoAfter.events[data.i - 1])) {
653          this.contactInfoAfter.events[data.i - 1] = new EventBean('', '', '', '');
654        }
655        this.contactInfoAfter.events[data.i - 1].eventType = item.rawValue.toString();
656        break;
657      default:
658        break;
659    }
660    this.addState = true;
661    this.refresh();
662  }
663
664  saveClickEnable() {
665    HiLog.i(TAG, 'msl, saveClickEnable in addState:' + this.addState + ',clickEnable:' + this.clickEnable)
666    return this.addState && this.clickEnable;
667  }
668
669  public saveContact() {
670    if (this.saveClickEnable()) {
671      this.clickEnable = false
672      if (this.updateShow === false) {
673        globalThis.DataWorker.sendRequest('addContact',
674          {
675            context: globalThis.context,
676            contactInfoAfter: JSON.stringify(this.contactInfoAfter)
677          }
678          , (arg) => {
679            this.clickEnable = true
680            this.contactId = arg.toString();
681            this.routerAvtiveFlag = true;
682            if (!PreferencesUtil.isUsed()) {
683              PreferencesUtil.setIsUsed(true);
684            }
685          })
686      }
687      else {
688        globalThis.DataWorker.sendRequest('updateContact', {
689          context: globalThis.context,
690          contactInfoAfter: JSON.stringify(this.contactInfoAfter)
691        }, (arg) => {
692          this.clickEnable = true
693          this.contactId = arg.toString();
694          this.routerAvtiveFlag = true;
695          if (!PreferencesUtil.isUsed()) {
696            PreferencesUtil.setIsUsed(true);
697          }
698        })
699      }
700    }
701  }
702
703  public textChange(data: string) {
704    this.refresh();
705  }
706
707  /**
708   * Hide the Keyboard to prevent occlusion dialogs.
709   */
710  hideKeyboard() {
711    inputMethod.getController().hideSoftKeyboard((err) => {
712    })
713  }
714}