diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt index 3b8b0092..814096f4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt @@ -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() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt index c86ee0c6..417ff0d7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt @@ -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() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt index 3e1f947f..b855371d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt @@ -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) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt index c8dbce1b..be179078 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt index a75b083b..c245632a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt index 5fb4a703..8efa77ed 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt @@ -73,10 +73,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } } - fun getContacts(): ArrayList { + fun getContacts(selection: String? = null, selectionArgs: Array? = null): ArrayList { val contacts = ArrayList() 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() + } }