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 RawContact from './RawContact'; 17import Contact from './Contact'; 18import { Contacts } from '../contract/Contacts'; 19import { Data } from '../contract/Data'; 20import { RawContacts } from '../contract/RawContacts'; 21 22/** 23 * Call log constructor 24 */ 25export default class ContactBuilder { 26 readonly id: number; 27 nameRawContactId: number; 28 quickSearchKey: string; 29 photoId: number; 30 photoFileId: number; 31 personalRingtone: string; 32 personalNotificationRingtone: string; 33 isTransferVoiceMail: boolean; 34 company: string; 35 position: string; 36 hasDisplayName: boolean; 37 hasPhoneNumber: boolean; 38 readOnly: boolean; 39 hasGroup: boolean; 40 hasEmail: boolean; 41 rowContacts: RawContact[]; 42 43 constructor(id: number) { 44 this.id = id; 45 } 46 47 static fromResultSet(resultSet: any): ContactBuilder{ 48 let contactBuilder = new ContactBuilder(resultSet.getLong(resultSet.getColumnIndex(RawContacts.CONTACT_ID))); 49 contactBuilder.setNameRawContactId(resultSet.getLong(resultSet.getColumnIndex(Data.RAW_CONTACT_ID))); 50 contactBuilder.setQuickSearchKey(resultSet.getString(resultSet.getColumnIndex(Contacts.QUICK_SEARCH_KEY))); 51 contactBuilder.setPhotoId(resultSet.getLong(resultSet.getColumnIndex(Contacts.PHOTO_ID))); 52 contactBuilder.setPhotoFileId(resultSet.getLong(resultSet.getColumnIndex(Contacts.PHOTO_FILE_ID))); 53 contactBuilder.setPersonalRingtone(resultSet.getString(resultSet.getColumnIndex(Contacts.PERSONAL_RINGTONE))); 54 contactBuilder.setPersonalNotificationRingtone(resultSet.getString(resultSet.getColumnIndex(Contacts.PERSONAL_NOTIFICATION_RINGTONE))); 55 contactBuilder.setIsTransferVoiceMail(resultSet.getLong(resultSet.getColumnIndex(Contacts.IS_TRANSFER_VOICEMAIL)) > 0 ? true : false); 56 contactBuilder.setCompany(resultSet.getString(resultSet.getColumnIndex(Contacts.COMPANY))); 57 contactBuilder.setPosition(resultSet.getString(resultSet.getColumnIndex(Contacts.POSITION))); 58 contactBuilder.setHasDisplayName(resultSet.getLong(resultSet.getColumnIndex(Contacts.HAS_DISPLAY_NAME)) > 0 ? true : false); 59 contactBuilder.setHasEmail(resultSet.getLong(resultSet.getColumnIndex(Contacts.IS_TRANSFER_VOICEMAIL)) > 0 ? true : false); 60 contactBuilder.setHasGroup(resultSet.getLong(resultSet.getColumnIndex(Contacts.HAS_GROUP)) > 0 ? true : false); 61 contactBuilder.setHasPhoneNumber(resultSet.getLong(resultSet.getColumnIndex(Contacts.HAS_PHONE_NUMBER)) > 0 ? true : false); 62 contactBuilder.setReadOnly(resultSet.getLong(resultSet.getColumnIndex(Contacts.READ_ONLY)) > 0 ? true : false); 63 contactBuilder.setRowContacts([]); 64 return contactBuilder; 65 } 66 67 setNameRawContactId(nameRawContactId: number) { 68 this.nameRawContactId = nameRawContactId; 69 return this; 70 } 71 72 setPhotoId(photoId: number) { 73 this.photoId = photoId; 74 return this; 75 } 76 77 setPhotoFileId(photoFileId: number) { 78 this.photoFileId = photoFileId; 79 return this; 80 } 81 82 setQuickSearchKey(quickSearchKey: string) { 83 this.quickSearchKey = quickSearchKey; 84 return this; 85 } 86 87 setPersonalNotificationRingtone(personalNotificationRingtone: string) { 88 this.personalNotificationRingtone = personalNotificationRingtone; 89 return this; 90 } 91 92 setPersonalRingtone(personalRingtone: string) { 93 this.personalRingtone = personalRingtone; 94 return this; 95 } 96 97 setIsTransferVoiceMail(isTransferVoiceMail: boolean) { 98 this.isTransferVoiceMail = isTransferVoiceMail; 99 return this; 100 } 101 102 setCompany(company: string) { 103 this.company = company; 104 return this; 105 } 106 107 setPosition(position: string) { 108 this.position = position; 109 return this; 110 } 111 112 setHasDisplayName(hasDisplayName: boolean) { 113 this.hasDisplayName = hasDisplayName; 114 return this; 115 } 116 117 setReadOnly(readOnly: boolean) { 118 this.readOnly = readOnly; 119 return this; 120 } 121 122 setHasPhoneNumber(hasPhoneNumber: boolean) { 123 this.hasPhoneNumber = hasPhoneNumber; 124 return this; 125 } 126 127 setHasGroup(hasGroup: boolean) { 128 this.hasGroup = hasGroup; 129 return this; 130 } 131 132 setHasEmail(hasEmail: boolean) { 133 this.hasEmail = hasEmail; 134 return this; 135 } 136 137 setRowContacts(rowContacts: RawContact[]) { 138 this.rowContacts = rowContacts; 139 return this; 140 } 141 142 buildContact() { 143 return new Contact(this); 144 } 145}