mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-18 12:30:38 +01:00
add a Groups field to contacts
This commit is contained in:
parent
32e7eadbb3
commit
20a333071e
@ -321,7 +321,7 @@ class EditContactActivity : ContactActivity() {
|
|||||||
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, "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), config.lastUsedContactSource, 0, 0, "", null, "")
|
contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), config.lastUsedContactSource, 0, 0, "", null, "", ArrayList())
|
||||||
contact_source.text = getPublicContactSource(contact!!.source)
|
contact_source.text = getPublicContactSource(contact!!.source)
|
||||||
contact_source.setOnClickListener {
|
contact_source.setOnClickListener {
|
||||||
showContactSourcePicker(contact!!.source) {
|
showContactSourcePicker(contact!!.source) {
|
||||||
|
@ -57,8 +57,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
val contactId = cursor.getIntValue(ContactsContract.Data.CONTACT_ID)
|
val contactId = cursor.getIntValue(ContactsContract.Data.CONTACT_ID)
|
||||||
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
||||||
val notes = ""
|
val notes = ""
|
||||||
|
val groups = ArrayList<Group>()
|
||||||
val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName,
|
val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName,
|
||||||
starred, contactId, thumbnailUri, null, notes)
|
starred, contactId, thumbnailUri, null, notes, groups)
|
||||||
contacts.put(id, contact)
|
contacts.put(id, contact)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
@ -103,6 +104,13 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
contacts[key]?.notes = notes.valueAt(i)
|
contacts[key]?.notes = notes.valueAt(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val groups = getContactGroups(getStoredGroups())
|
||||||
|
size = groups.size()
|
||||||
|
for (i in 0 until size) {
|
||||||
|
val key = groups.keyAt(i)
|
||||||
|
contacts[key]?.groups = groups.valueAt(i)
|
||||||
|
}
|
||||||
|
|
||||||
activity.dbHelper.getContacts().forEach {
|
activity.dbHelper.getContacts().forEach {
|
||||||
contacts.put(it.id, it)
|
contacts.put(it.id, it)
|
||||||
}
|
}
|
||||||
@ -305,19 +313,19 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
return notes
|
return notes
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getContactGroups(contactId: Int? = null): SparseArray<ArrayList<Group>> {
|
private fun getContactGroups(storedGroups: ArrayList<Group>, contactId: Int? = null): SparseArray<ArrayList<Group>> {
|
||||||
val groups = SparseArray<ArrayList<Group>>()
|
val groups = SparseArray<ArrayList<Group>>()
|
||||||
val uri = ContactsContract.Data.CONTENT_URI
|
val uri = ContactsContract.Data.CONTENT_URI
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
ContactsContract.Data.RAW_CONTACT_ID,
|
ContactsContract.Data.CONTACT_ID,
|
||||||
CommonDataKinds.GroupMembership.GROUP_ROW_ID
|
ContactsContract.Data.DATA1
|
||||||
)
|
)
|
||||||
|
|
||||||
var selection = "${ContactsContract.Data.MIMETYPE} = ?"
|
var selection = "${ContactsContract.Data.MIMETYPE} = ?"
|
||||||
var selectionArgs = arrayOf(CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE)
|
var selectionArgs = arrayOf(CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE)
|
||||||
|
|
||||||
if (contactId != null) {
|
if (contactId != null) {
|
||||||
selection += " AND ${ContactsContract.Data.RAW_CONTACT_ID} = ?"
|
selection += " AND ${ContactsContract.Data.CONTACT_ID} = ?"
|
||||||
selectionArgs = arrayOf(CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE, contactId.toString())
|
selectionArgs = arrayOf(CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE, contactId.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,14 +334,16 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
val id = cursor.getIntValue(ContactsContract.Data.CONTACT_ID)
|
||||||
val rowId = cursor.getIntValue(CommonDataKinds.GroupMembership.GROUP_ROW_ID)
|
val newRowId = cursor.getIntValue(ContactsContract.Data.DATA1)
|
||||||
|
|
||||||
if (groups[id] == null) {
|
if (groups[id] == null) {
|
||||||
groups.put(id, ArrayList())
|
groups.put(id, ArrayList())
|
||||||
}
|
}
|
||||||
|
|
||||||
groups[id]!!.add(Group(rowId, ""))
|
val groupTitle = storedGroups.firstOrNull { it.id == newRowId }?.title ?: ""
|
||||||
|
val group = Group(newRowId, groupTitle)
|
||||||
|
groups[id]!!.add(group)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -345,7 +355,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
return groups
|
return groups
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGroups(): ArrayList<Group> {
|
fun getStoredGroups(): ArrayList<Group> {
|
||||||
val groups = ArrayList<Group>()
|
val groups = ArrayList<Group>()
|
||||||
val uri = ContactsContract.Groups.CONTENT_URI
|
val uri = ContactsContract.Groups.CONTENT_URI
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
@ -391,6 +401,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun parseContactCursor(selection: String, selectionArgs: Array<String>): Contact? {
|
private fun parseContactCursor(selection: String, selectionArgs: Array<String>): Contact? {
|
||||||
|
val storedGroups = getStoredGroups()
|
||||||
val uri = ContactsContract.Data.CONTENT_URI
|
val uri = ContactsContract.Data.CONTENT_URI
|
||||||
val projection = getContactProjection()
|
val projection = getContactProjection()
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
@ -410,8 +421,10 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: ""
|
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: ""
|
||||||
val starred = cursor.getIntValue(CommonDataKinds.StructuredName.STARRED)
|
val starred = cursor.getIntValue(CommonDataKinds.StructuredName.STARRED)
|
||||||
val contactId = cursor.getIntValue(ContactsContract.Data.CONTACT_ID)
|
val contactId = cursor.getIntValue(ContactsContract.Data.CONTACT_ID)
|
||||||
|
val groups = getContactGroups(storedGroups, contactId)[contactId] ?: ArrayList()
|
||||||
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
||||||
return Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName, starred, contactId, thumbnailUri, null, notes)
|
return Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName, starred, contactId,
|
||||||
|
thumbnailUri, null, notes, groups)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
|
@ -163,8 +163,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
|
|
||||||
val notes = cursor.getStringValue(COL_NOTES)
|
val notes = cursor.getStringValue(COL_NOTES)
|
||||||
val starred = cursor.getIntValue(COL_STARRED)
|
val starred = cursor.getIntValue(COL_STARRED)
|
||||||
|
val groups = ArrayList<Group>()
|
||||||
|
|
||||||
val contact = Contact(id, firstName, middleName, surname, "", phoneNumbers, emails, addresses, events, SMT_PRIVATE, starred, id, "", photo, notes)
|
val contact = Contact(id, firstName, middleName, surname, "", phoneNumbers, emails, addresses, events, SMT_PRIVATE, starred, id, "", photo, notes, groups)
|
||||||
contacts.add(contact)
|
contacts.add(contact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
private var curEmails = ArrayList<Email>()
|
private var curEmails = ArrayList<Email>()
|
||||||
private var curEvents = ArrayList<Event>()
|
private var curEvents = ArrayList<Event>()
|
||||||
private var curAddresses = ArrayList<Address>()
|
private var curAddresses = ArrayList<Address>()
|
||||||
|
private var curGroups = ArrayList<Group>()
|
||||||
|
|
||||||
private var isGettingPhoto = false
|
private var isGettingPhoto = false
|
||||||
private var currentPhotoString = StringBuilder()
|
private var currentPhotoString = StringBuilder()
|
||||||
@ -234,7 +235,8 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun saveContact(source: String) {
|
private fun saveContact(source: String) {
|
||||||
val contact = Contact(0, curFirstName, curMiddleName, curSurname, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents, source, 0, 0, "", null, curNotes)
|
val contact = Contact(0, curFirstName, curMiddleName, curSurname, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents,
|
||||||
|
source, 0, 0, "", null, curNotes, curGroups)
|
||||||
if (ContactsHelper(activity).insertContact(contact)) {
|
if (ContactsHelper(activity).insertContact(contact)) {
|
||||||
contactsImported++
|
contactsImported++
|
||||||
}
|
}
|
||||||
@ -250,6 +252,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
curEmails = ArrayList()
|
curEmails = ArrayList()
|
||||||
curEvents = ArrayList()
|
curEvents = ArrayList()
|
||||||
curAddresses = ArrayList()
|
curAddresses = ArrayList()
|
||||||
|
curGroups = ArrayList()
|
||||||
|
|
||||||
isGettingPhoto = false
|
isGettingPhoto = false
|
||||||
currentPhotoString = StringBuilder()
|
currentPhotoString = StringBuilder()
|
||||||
|
@ -7,7 +7,8 @@ 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,
|
data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String,
|
||||||
var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var addresses: ArrayList<Address>, var events: ArrayList<Event>,
|
var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var addresses: ArrayList<Address>, var events: ArrayList<Event>,
|
||||||
var source: String, var starred: Int, val contactId: Int, val thumbnailUri: String, var photo: Bitmap?, var notes: String) : Comparable<Contact> {
|
var source: String, var starred: Int, val contactId: Int, val thumbnailUri: String, var photo: Bitmap?, var notes: String,
|
||||||
|
var groups: ArrayList<Group>) : Comparable<Contact> {
|
||||||
companion object {
|
companion object {
|
||||||
var sorting = 0
|
var sorting = 0
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user