remove the redundant Emails and PhoneNumbers models
This commit is contained in:
parent
b40be40bb4
commit
f043e40dd3
|
@ -23,8 +23,6 @@ import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.helpers.CONTACT_ID
|
import com.simplemobiletools.contacts.helpers.CONTACT_ID
|
||||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||||
import com.simplemobiletools.contacts.models.Contact
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
import com.simplemobiletools.contacts.models.Emails
|
|
||||||
import com.simplemobiletools.contacts.models.PhoneNumbers
|
|
||||||
import kotlinx.android.synthetic.main.activity_contact.*
|
import kotlinx.android.synthetic.main.activity_contact.*
|
||||||
|
|
||||||
class ContactActivity : SimpleActivity() {
|
class ContactActivity : SimpleActivity() {
|
||||||
|
@ -150,7 +148,7 @@ class ContactActivity : SimpleActivity() {
|
||||||
private fun setupNewContact() {
|
private fun setupNewContact() {
|
||||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
|
||||||
supportActionBar?.title = resources.getString(R.string.new_contact)
|
supportActionBar?.title = resources.getString(R.string.new_contact)
|
||||||
contact = Contact(0, "", "", "", "", PhoneNumbers(), Emails(), "")
|
contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applyPhotoPlaceholder() {
|
private fun applyPhotoPlaceholder() {
|
||||||
|
|
|
@ -113,7 +113,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
||||||
view.apply {
|
view.apply {
|
||||||
contact_first_name.text = contact.getFullName(startNameWithSurname)
|
contact_first_name.text = contact.getFullName(startNameWithSurname)
|
||||||
contact_first_name.setTextColor(textColor)
|
contact_first_name.setTextColor(textColor)
|
||||||
contact_number.text = contact.phoneNumbers.phoneNumbers.firstOrNull()?.value ?: ""
|
contact_number.text = contact.phoneNumbers.firstOrNull()?.value ?: ""
|
||||||
contact_number.setTextColor(textColor)
|
contact_number.setTextColor(textColor)
|
||||||
|
|
||||||
if (contact.photoUri.isNotEmpty()) {
|
if (contact.photoUri.isNotEmpty()) {
|
||||||
|
|
|
@ -13,7 +13,9 @@ import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_SURNAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_SURNAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.models.*
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
|
import com.simplemobiletools.contacts.models.Email
|
||||||
|
import com.simplemobiletools.contacts.models.PhoneNumber
|
||||||
import com.simplemobiletools.contacts.overloads.times
|
import com.simplemobiletools.contacts.overloads.times
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -67,8 +69,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val photoUri = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI) ?: ""
|
val photoUri = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI) ?: ""
|
||||||
val number = PhoneNumbers() // proper value is obtained below
|
val number = ArrayList<PhoneNumber>() // proper value is obtained below
|
||||||
val emails = Emails() // proper value is obtained below
|
val emails = ArrayList<Email>() // proper value is obtained below
|
||||||
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
|
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
|
||||||
val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, accountName)
|
val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, accountName)
|
||||||
contacts.put(id, contact)
|
contacts.put(id, contact)
|
||||||
|
@ -115,8 +117,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEmails(contactId: Int? = null): SparseArray<Emails> {
|
private fun getEmails(contactId: Int? = null): SparseArray<ArrayList<Email>> {
|
||||||
val emails = SparseArray<Emails>()
|
val emails = SparseArray<ArrayList<Email>>()
|
||||||
val uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI
|
val uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
ContactsContract.CommonDataKinds.Email.CONTACT_ID,
|
ContactsContract.CommonDataKinds.Email.CONTACT_ID,
|
||||||
|
@ -137,10 +139,10 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Email.TYPE)
|
val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Email.TYPE)
|
||||||
|
|
||||||
if (emails[id] == null) {
|
if (emails[id] == null) {
|
||||||
emails.put(id, Emails())
|
emails.put(id, ArrayList())
|
||||||
}
|
}
|
||||||
|
|
||||||
emails[id]!!.emails.add(Email(email, type))
|
emails[id]!!.add(Email(email, type))
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -150,8 +152,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
return emails
|
return emails
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPhoneNumbers(contactId: Int? = null): SparseArray<PhoneNumbers> {
|
private fun getPhoneNumbers(contactId: Int? = null): SparseArray<ArrayList<PhoneNumber>> {
|
||||||
val phoneNumbers = SparseArray<PhoneNumbers>()
|
val phoneNumbers = SparseArray<ArrayList<PhoneNumber>>()
|
||||||
val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI
|
val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
|
ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
|
||||||
|
@ -172,10 +174,10 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.TYPE)
|
val type = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.TYPE)
|
||||||
|
|
||||||
if (phoneNumbers[id] == null) {
|
if (phoneNumbers[id] == null) {
|
||||||
phoneNumbers.put(id, PhoneNumbers())
|
phoneNumbers.put(id, ArrayList())
|
||||||
}
|
}
|
||||||
|
|
||||||
phoneNumbers[id].phoneNumbers.add(PhoneNumber(number, type))
|
phoneNumbers[id].add(PhoneNumber(number, type))
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -184,24 +186,6 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
return phoneNumbers
|
return phoneNumbers
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContactNumber(id: Int): String {
|
|
||||||
val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI
|
|
||||||
val projection = arrayOf(ContactsContract.CommonDataKinds.Phone.NUMBER)
|
|
||||||
val selection = "${ContactsContract.CommonDataKinds.Phone.CONTACT_ID} = ?"
|
|
||||||
val selectionArgs = arrayOf(id.toString())
|
|
||||||
var cursor: Cursor? = null
|
|
||||||
try {
|
|
||||||
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
|
||||||
if (cursor?.moveToFirst() == true) {
|
|
||||||
return cursor.getStringValue(ContactsContract.CommonDataKinds.Phone.NUMBER)
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
cursor?.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getContactWithId(id: Int): Contact? {
|
fun getContactWithId(id: Int): Contact? {
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
return null
|
return null
|
||||||
|
@ -219,8 +203,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
val middleName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
|
val middleName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
|
||||||
val surname = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
|
val surname = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
|
||||||
val photoUri = cursor.getStringValue(ContactsContract.CommonDataKinds.Phone.PHOTO_URI) ?: ""
|
val photoUri = cursor.getStringValue(ContactsContract.CommonDataKinds.Phone.PHOTO_URI) ?: ""
|
||||||
val number = getPhoneNumbers(id)[id] ?: PhoneNumbers()
|
val number = getPhoneNumbers(id)[id] ?: ArrayList()
|
||||||
val emails = getEmails(id)[id] ?: Emails()
|
val emails = getEmails(id)[id] ?: ArrayList()
|
||||||
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
|
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
|
||||||
return Contact(id, firstName, middleName, surname, photoUri, number, emails, accountName)
|
return Contact(id, firstName, middleName, surname, photoUri, number, emails, accountName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
|
|
||||||
data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String, var phoneNumbers: PhoneNumbers,
|
data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String,
|
||||||
var emails: Emails, var source: String) : Comparable<Contact> {
|
var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var source: String) : Comparable<Contact> {
|
||||||
companion object {
|
companion object {
|
||||||
var sorting: Int = 0
|
var sorting: Int = 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
package com.simplemobiletools.contacts.models
|
|
||||||
|
|
||||||
data class Emails(var emails: ArrayList<Email> = ArrayList())
|
|
|
@ -1,3 +0,0 @@
|
||||||
package com.simplemobiletools.contacts.models
|
|
||||||
|
|
||||||
data class PhoneNumbers(var phoneNumbers: ArrayList<PhoneNumber> = ArrayList())
|
|
Loading…
Reference in New Issue