-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
MutableContact.kt
151 lines (137 loc) · 6.16 KB
/
MutableContact.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package com.alexstyl.contactstore
import android.provider.ContactsContract
import com.alexstyl.contactstore.ContactColumn.Events
import com.alexstyl.contactstore.ContactColumn.GroupMemberships
import com.alexstyl.contactstore.ContactColumn.ImAddresses
import com.alexstyl.contactstore.ContactColumn.Image
import com.alexstyl.contactstore.ContactColumn.Mails
import com.alexstyl.contactstore.ContactColumn.Names
import com.alexstyl.contactstore.ContactColumn.Note
import com.alexstyl.contactstore.ContactColumn.Organization
import com.alexstyl.contactstore.ContactColumn.Phones
import com.alexstyl.contactstore.ContactColumn.PostalAddresses
import com.alexstyl.contactstore.ContactColumn.Relations
import com.alexstyl.contactstore.ContactColumn.SipAddresses
import com.alexstyl.contactstore.ContactColumn.WebAddresses
class MutableContact internal constructor(
override var contactId: Long = -1L,
override val lookupKey: LookupKey? = null,
imageData: ImageData?,
phones: MutableList<LabeledValue<PhoneNumber>>,
mails: MutableList<LabeledValue<MailAddress>>,
events: MutableList<LabeledValue<EventDate>>,
postalAddresses: MutableList<LabeledValue<PostalAddress>>,
webAddresses: MutableList<LabeledValue<WebAddress>>,
note: com.alexstyl.contactstore.Note?,
override var isStarred: Boolean,
firstName: String?,
lastName: String?,
middleName: String?,
prefix: String?,
suffix: String?,
phoneticFirstName: String?,
phoneticMiddleName: String?,
phoneticLastName: String?,
fullNameStyle: Int,
phoneticNameStyle: Int,
nickname: String?,
organization: String?,
jobTitle: String?,
groups: MutableList<GroupMembership>,
linkedAccountValues: List<LinkedAccountValue>,
imAddresses: MutableList<LabeledValue<ImAddress>>,
sipAddresses: MutableList<LabeledValue<SipAddress>>,
relations: MutableList<LabeledValue<Relation>>,
override val columns: List<ContactColumn>,
) : Contact {
override var imageData: ImageData? by readWriteField(Image, imageData)
override val phones: MutableList<LabeledValue<PhoneNumber>> by requireColumn(Phones, phones)
override val mails: MutableList<LabeledValue<MailAddress>> by requireColumn(Mails, mails)
override val events: MutableList<LabeledValue<EventDate>> by requireColumn(Events, events)
override val postalAddresses: MutableList<LabeledValue<PostalAddress>>
by requireColumn(PostalAddresses, postalAddresses)
override val webAddresses: MutableList<LabeledValue<WebAddress>>
by requireColumn(WebAddresses, webAddresses)
override val imAddresses: MutableList<LabeledValue<ImAddress>>
by requireColumn(ImAddresses, imAddresses)
override val sipAddresses: MutableList<LabeledValue<SipAddress>>
by requireColumn(SipAddresses, sipAddresses)
override val linkedAccountValues: List<LinkedAccountValue>
by requireAnyLinkedAccountColumn(linkedAccountValues)
override var note: com.alexstyl.contactstore.Note? by readWriteField(Note, note)
override val groups: MutableList<GroupMembership> by requireColumn(GroupMemberships, groups)
override val relations: MutableList<LabeledValue<Relation>> by requireColumn(Relations, relations)
override var organization: String? by readWriteField(Organization, organization)
override var jobTitle: String? by readWriteField(Organization, jobTitle)
override var firstName: String? by readWriteField(Names, firstName)
override var lastName: String? by readWriteField(Names, lastName)
override var middleName: String? by readWriteField(Names, middleName)
override var prefix: String? by readWriteField(Names, prefix)
override var suffix: String? by readWriteField(Names, suffix)
override var phoneticLastName: String? by readWriteField(Names, phoneticLastName)
override var phoneticFirstName: String? by readWriteField(Names, phoneticFirstName)
override var phoneticMiddleName: String? by readWriteField(Names, phoneticMiddleName)
override var fullNameStyle: Int by readWriteField(Names, fullNameStyle)
override var phoneticNameStyle: Int by readWriteField(Names, phoneticNameStyle)
override var nickname: String? by readWriteField(Names, nickname)
constructor() : this(
contactId = -1L,
imageData = null,
phones = mutableListOf(),
mails = mutableListOf(),
events = mutableListOf(),
postalAddresses = mutableListOf(),
webAddresses = mutableListOf(),
sipAddresses = mutableListOf(),
relations = mutableListOf(),
note = null,
isStarred = false,
firstName = null,
lastName = null,
middleName = null,
prefix = null,
suffix = null,
phoneticFirstName = null,
phoneticMiddleName = null,
phoneticLastName = null,
fullNameStyle = ContactsContract.FullNameStyle.UNDEFINED,
phoneticNameStyle = ContactsContract.PhoneticNameStyle.UNDEFINED,
nickname = null,
organization = null,
jobTitle = null,
groups = mutableListOf(),
linkedAccountValues = emptyList(),
imAddresses = mutableListOf(),
columns = standardColumns() // allow editing of all columns for new contacts
)
override val displayName: String
get() = buildString {
appendWord(buildStringFromNames())
if (isEmpty()) {
phoneticFirstName?.let { append(it) }
phoneticMiddleName?.let { appendWord(it) }
phoneticLastName?.let { appendWord(it) }
}
if (isEmpty()) {
append(nickname.orEmpty())
}
if (isEmpty()) {
append(organization.orEmpty())
}
if (isEmpty()) {
phones.firstOrNull()?.let { append(it.value.raw) }
}
if (isEmpty()) {
mails.firstOrNull()?.let { append(it.value.raw) }
}
}
override fun equals(other: Any?): Boolean {
return equalContacts(other as Contact?)
}
override fun hashCode(): Int {
return contactHashCode()
}
override fun toString(): String {
return toFullString()
}
}