properly show private local contact details/edit screen

This commit is contained in:
tibbi 2018-02-11 20:42:44 +01:00
parent 6c39757cec
commit 097344dd26
6 changed files with 18 additions and 9 deletions

View File

@ -119,7 +119,7 @@ class EditContactActivity : ContactActivity() {
}
if (contactId != 0) {
contact = ContactsHelper(this).getContactWithId(contactId)
contact = ContactsHelper(this).getContactWithId(contactId, intent.getBooleanExtra(IS_PRIVATE, false))
if (contact == null) {
toast(R.string.unknown_error_occurred)
finish()

View File

@ -76,7 +76,7 @@ class ViewContactActivity : ContactActivity() {
}
if (contactId != 0) {
contact = ContactsHelper(this).getContactWithId(contactId)
contact = ContactsHelper(this).getContactWithId(contactId, intent.getBooleanExtra(IS_PRIVATE, false))
if (contact == null) {
toast(R.string.unknown_error_occurred)
finish()

View File

@ -15,9 +15,7 @@ import com.simplemobiletools.contacts.BuildConfig
import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.EditContactActivity
import com.simplemobiletools.contacts.activities.ViewContactActivity
import com.simplemobiletools.contacts.helpers.CONTACT_ID
import com.simplemobiletools.contacts.helpers.Config
import com.simplemobiletools.contacts.helpers.DBHelper
import com.simplemobiletools.contacts.helpers.*
import com.simplemobiletools.contacts.models.Contact
import java.io.File
@ -28,6 +26,7 @@ val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext)
fun Context.viewContact(contact: Contact) {
Intent(applicationContext, ViewContactActivity::class.java).apply {
putExtra(CONTACT_ID, contact.id)
putExtra(IS_PRIVATE, contact.source == SMT_PRIVATE)
startActivity(this)
}
}
@ -35,6 +34,7 @@ fun Context.viewContact(contact: Contact) {
fun Context.editContact(contact: Contact) {
Intent(applicationContext, EditContactActivity::class.java).apply {
putExtra(CONTACT_ID, contact.id)
putExtra(IS_PRIVATE, contact.source == SMT_PRIVATE)
startActivity(this)
}
}

View File

@ -14,7 +14,8 @@ const val LOCAL_ACCOUNT_TYPE = "local_account_type"
const val ON_CONTACT_CLICK = "on_contact_click"
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
const val PHOTO_ADDED = 1

View File

@ -198,9 +198,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
return events
}
fun getContactWithId(id: Int): Contact? {
fun getContactWithId(id: Int, isLocalPrivate: Boolean): Contact? {
if (id == 0) {
return null
} else if (isLocalPrivate) {
return activity.dbHelper.getContactWithId(id)
}
val uri = ContactsContract.Data.CONTENT_URI

View File

@ -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 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 {
while (cursor.moveToNext()) {
val id = cursor.getIntValue(COL_ID)
@ -103,4 +103,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
return contacts
}
fun getContactWithId(id: Int): Contact? {
val selection = "$COL_ID = ?"
val selectionArgs = arrayOf(id.toString())
return getContacts(selection, selectionArgs).firstOrNull()
}
}