mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-05-31 19:19:20 +02:00
adding a contact Notes field
This commit is contained in:
parent
e7faeffc42
commit
8f743f3397
@ -315,7 +315,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, "")
|
||||||
contact_source.text = getPublicContactSource(contact!!.source)
|
contact_source.text = getPublicContactSource(contact!!.source)
|
||||||
contact_source.setOnClickListener {
|
contact_source.setOnClickListener {
|
||||||
showContactSourcePicker(contact!!.source) {
|
showContactSourcePicker(contact!!.source) {
|
||||||
|
@ -9,6 +9,7 @@ import android.graphics.Bitmap
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import android.provider.ContactsContract.CommonDataKinds
|
import android.provider.ContactsContract.CommonDataKinds
|
||||||
|
import android.provider.ContactsContract.CommonDataKinds.Note
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
@ -26,9 +27,7 @@ import com.simplemobiletools.contacts.extensions.dbHelper
|
|||||||
import com.simplemobiletools.contacts.extensions.getByteArray
|
import com.simplemobiletools.contacts.extensions.getByteArray
|
||||||
import com.simplemobiletools.contacts.extensions.getPhotoThumbnailSize
|
import com.simplemobiletools.contacts.extensions.getPhotoThumbnailSize
|
||||||
import com.simplemobiletools.contacts.models.*
|
import com.simplemobiletools.contacts.models.*
|
||||||
import java.io.ByteArrayOutputStream
|
|
||||||
import java.util.*
|
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
|
|
||||||
class ContactsHelper(val activity: BaseSimpleActivity) {
|
class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
fun getContacts(callback: (ArrayList<Contact>) -> Unit) {
|
fun getContacts(callback: (ArrayList<Contact>) -> Unit) {
|
||||||
@ -58,8 +57,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
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 thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
||||||
|
val notes = ""
|
||||||
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)
|
starred, contactId, thumbnailUri, null, notes)
|
||||||
contacts.put(id, contact)
|
contacts.put(id, contact)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
@ -90,6 +90,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
contacts[key]?.addresses = addresses.valueAt(i)
|
contacts[key]?.addresses = addresses.valueAt(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//getNotes()
|
||||||
|
|
||||||
activity.dbHelper.getContacts().forEach {
|
activity.dbHelper.getContacts().forEach {
|
||||||
contacts.put(it.id, it)
|
contacts.put(it.id, it)
|
||||||
}
|
}
|
||||||
@ -248,6 +250,27 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getNotes(contactId: Int): String {
|
||||||
|
val uri = ContactsContract.Data.CONTENT_URI
|
||||||
|
val projection = arrayOf(Note.NOTE)
|
||||||
|
val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ? AND ${ContactsContract.Data.MIMETYPE} = '${Note.CONTENT_ITEM_TYPE}'"
|
||||||
|
val selectionArgs = arrayOf(contactId.toString())
|
||||||
|
|
||||||
|
var cursor: Cursor? = null
|
||||||
|
try {
|
||||||
|
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
|
if (cursor?.moveToFirst() == true) {
|
||||||
|
return cursor.getStringValue(CommonDataKinds.Note.NOTE) ?: ""
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
activity.showErrorToast(e)
|
||||||
|
} finally {
|
||||||
|
cursor?.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
fun getContactWithId(id: Int, isLocalPrivate: Boolean): Contact? {
|
fun getContactWithId(id: Int, isLocalPrivate: Boolean): Contact? {
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
return null
|
return null
|
||||||
@ -275,7 +298,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
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 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)
|
val notes = getNotes(id)
|
||||||
|
return Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName, starred, contactId, thumbnailUri, null, notes)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
@ -661,17 +685,6 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
fileDescriptor.close()
|
fileDescriptor.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bitmapToByteArray(bitmap: Bitmap): ByteArray {
|
|
||||||
var baos: ByteArrayOutputStream? = null
|
|
||||||
try {
|
|
||||||
baos = ByteArrayOutputStream()
|
|
||||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, baos)
|
|
||||||
return baos.toByteArray()
|
|
||||||
} finally {
|
|
||||||
baos?.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getContactLookupKey(contactId: String): String {
|
fun getContactLookupKey(contactId: String): String {
|
||||||
val uri = ContactsContract.Data.CONTENT_URI
|
val uri = ContactsContract.Data.CONTENT_URI
|
||||||
val projection = arrayOf(ContactsContract.Data.CONTACT_ID, ContactsContract.Data.LOOKUP_KEY)
|
val projection = arrayOf(ContactsContract.Data.CONTACT_ID, ContactsContract.Data.LOOKUP_KEY)
|
||||||
|
@ -156,8 +156,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val notes = ""
|
||||||
|
|
||||||
val starred = cursor.getIntValue(COL_STARRED)
|
val starred = cursor.getIntValue(COL_STARRED)
|
||||||
val contact = Contact(id, firstName, middleName, surname, "", phoneNumbers, emails, addresses, events, SMT_PRIVATE, starred, id, "", photo)
|
val contact = Contact(id, firstName, middleName, surname, "", phoneNumbers, emails, addresses, events, SMT_PRIVATE, starred, id, "", photo, notes)
|
||||||
contacts.add(contact)
|
contacts.add(contact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
private var curMiddleName = ""
|
private var curMiddleName = ""
|
||||||
private var curSurname = ""
|
private var curSurname = ""
|
||||||
private var curPhotoUri = ""
|
private var curPhotoUri = ""
|
||||||
|
private var curNotes = ""
|
||||||
private var curPhoneNumbers = ArrayList<PhoneNumber>()
|
private var curPhoneNumbers = ArrayList<PhoneNumber>()
|
||||||
private var curEmails = ArrayList<Email>()
|
private var curEmails = ArrayList<Email>()
|
||||||
private var curEvents = ArrayList<Event>()
|
private var curEvents = ArrayList<Event>()
|
||||||
@ -217,7 +218,7 @@ 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)
|
val contact = Contact(0, curFirstName, curMiddleName, curSurname, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents, source, 0, 0, "", null, curNotes)
|
||||||
if (ContactsHelper(activity).insertContact(contact)) {
|
if (ContactsHelper(activity).insertContact(contact)) {
|
||||||
contactsImported++
|
contactsImported++
|
||||||
}
|
}
|
||||||
@ -228,6 +229,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
curMiddleName = ""
|
curMiddleName = ""
|
||||||
curSurname = ""
|
curSurname = ""
|
||||||
curPhotoUri = ""
|
curPhotoUri = ""
|
||||||
|
curNotes = ""
|
||||||
curPhoneNumbers = ArrayList()
|
curPhoneNumbers = ArrayList()
|
||||||
curEmails = ArrayList()
|
curEmails = ArrayList()
|
||||||
curEvents = ArrayList()
|
curEvents = ArrayList()
|
||||||
|
@ -7,7 +7,7 @@ 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?) : Comparable<Contact> {
|
var source: String, var starred: Int, val contactId: Int, val thumbnailUri: String, var photo: Bitmap?, var notes: String) : Comparable<Contact> {
|
||||||
companion object {
|
companion object {
|
||||||
var sorting = 0
|
var sorting = 0
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user