properly show private local contact details/edit screen
This commit is contained in:
parent
6c39757cec
commit
097344dd26
|
@ -119,7 +119,7 @@ class EditContactActivity : ContactActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contactId != 0) {
|
if (contactId != 0) {
|
||||||
contact = ContactsHelper(this).getContactWithId(contactId)
|
contact = ContactsHelper(this).getContactWithId(contactId, intent.getBooleanExtra(IS_PRIVATE, false))
|
||||||
if (contact == null) {
|
if (contact == null) {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
finish()
|
finish()
|
||||||
|
|
|
@ -76,7 +76,7 @@ class ViewContactActivity : ContactActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contactId != 0) {
|
if (contactId != 0) {
|
||||||
contact = ContactsHelper(this).getContactWithId(contactId)
|
contact = ContactsHelper(this).getContactWithId(contactId, intent.getBooleanExtra(IS_PRIVATE, false))
|
||||||
if (contact == null) {
|
if (contact == null) {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
finish()
|
finish()
|
||||||
|
|
|
@ -15,9 +15,7 @@ import com.simplemobiletools.contacts.BuildConfig
|
||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.activities.EditContactActivity
|
import com.simplemobiletools.contacts.activities.EditContactActivity
|
||||||
import com.simplemobiletools.contacts.activities.ViewContactActivity
|
import com.simplemobiletools.contacts.activities.ViewContactActivity
|
||||||
import com.simplemobiletools.contacts.helpers.CONTACT_ID
|
import com.simplemobiletools.contacts.helpers.*
|
||||||
import com.simplemobiletools.contacts.helpers.Config
|
|
||||||
import com.simplemobiletools.contacts.helpers.DBHelper
|
|
||||||
import com.simplemobiletools.contacts.models.Contact
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
@ -28,6 +26,7 @@ val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext)
|
||||||
fun Context.viewContact(contact: Contact) {
|
fun Context.viewContact(contact: Contact) {
|
||||||
Intent(applicationContext, ViewContactActivity::class.java).apply {
|
Intent(applicationContext, ViewContactActivity::class.java).apply {
|
||||||
putExtra(CONTACT_ID, contact.id)
|
putExtra(CONTACT_ID, contact.id)
|
||||||
|
putExtra(IS_PRIVATE, contact.source == SMT_PRIVATE)
|
||||||
startActivity(this)
|
startActivity(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +34,7 @@ fun Context.viewContact(contact: Contact) {
|
||||||
fun Context.editContact(contact: Contact) {
|
fun Context.editContact(contact: Contact) {
|
||||||
Intent(applicationContext, EditContactActivity::class.java).apply {
|
Intent(applicationContext, EditContactActivity::class.java).apply {
|
||||||
putExtra(CONTACT_ID, contact.id)
|
putExtra(CONTACT_ID, contact.id)
|
||||||
|
putExtra(IS_PRIVATE, contact.source == SMT_PRIVATE)
|
||||||
startActivity(this)
|
startActivity(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ const val LOCAL_ACCOUNT_TYPE = "local_account_type"
|
||||||
const val ON_CONTACT_CLICK = "on_contact_click"
|
const val ON_CONTACT_CLICK = "on_contact_click"
|
||||||
|
|
||||||
const val CONTACT_ID = "contact_id"
|
const val CONTACT_ID = "contact_id"
|
||||||
const val SMT_PRIVATE = "smt_private"
|
const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps
|
||||||
|
const val IS_PRIVATE = "is_private"
|
||||||
|
|
||||||
// contact photo changes
|
// contact photo changes
|
||||||
const val PHOTO_ADDED = 1
|
const val PHOTO_ADDED = 1
|
||||||
|
|
|
@ -198,9 +198,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContactWithId(id: Int): Contact? {
|
fun getContactWithId(id: Int, isLocalPrivate: Boolean): Contact? {
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
return null
|
return null
|
||||||
|
} else if (isLocalPrivate) {
|
||||||
|
return activity.dbHelper.getContactWithId(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
val uri = ContactsContract.Data.CONTENT_URI
|
val uri = ContactsContract.Data.CONTENT_URI
|
||||||
|
|
|
@ -73,10 +73,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContacts(): ArrayList<Contact> {
|
fun getContacts(selection: String? = null, selectionArgs: Array<String>? = null): ArrayList<Contact> {
|
||||||
val contacts = ArrayList<Contact>()
|
val contacts = ArrayList<Contact>()
|
||||||
val projection = arrayOf(COL_ID, COL_FIRST_NAME, COL_MIDDLE_NAME, COL_SURNAME, COL_PHONE_NUMBERS, COL_EMAILS, COL_EVENTS, COL_STARRED)
|
val projection = arrayOf(COL_ID, COL_FIRST_NAME, COL_MIDDLE_NAME, COL_SURNAME, COL_PHONE_NUMBERS, COL_EMAILS, COL_EVENTS, COL_STARRED)
|
||||||
val cursor = mDb.query(CONTACTS_TABLE_NAME, projection, null, null, null, null, null)
|
val cursor = mDb.query(CONTACTS_TABLE_NAME, projection, selection, selectionArgs, null, null, null)
|
||||||
cursor.use {
|
cursor.use {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val id = cursor.getIntValue(COL_ID)
|
val id = cursor.getIntValue(COL_ID)
|
||||||
|
@ -103,4 +103,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
}
|
}
|
||||||
return contacts
|
return contacts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getContactWithId(id: Int): Contact? {
|
||||||
|
val selection = "$COL_ID = ?"
|
||||||
|
val selectionArgs = arrayOf(id.toString())
|
||||||
|
return getContacts(selection, selectionArgs).firstOrNull()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue