do not store the visible contact sources, store the ignored ones instead
This commit is contained in:
parent
22a4cca1fe
commit
f9e3854099
11 changed files with 49 additions and 30 deletions
|
@ -18,6 +18,7 @@ import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog
|
|||
import com.simplemobiletools.contacts.dialogs.FilterContactSourcesDialog
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.getContactPublicUri
|
||||
import com.simplemobiletools.contacts.extensions.getVisibleContactSources
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.SMT_PRIVATE
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
|
@ -98,7 +99,7 @@ class SelectContactActivity : SimpleActivity() {
|
|||
}
|
||||
} as ArrayList<Contact>
|
||||
|
||||
val contactSources = config.displayContactSources
|
||||
val contactSources = getVisibleContactSources()
|
||||
contacts = contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
||||
|
||||
Contact.sorting = config.sorting
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.simplemobiletools.contacts.models.ContactSource
|
|||
import kotlinx.android.synthetic.main.item_filter_contact_source.view.*
|
||||
import java.util.*
|
||||
|
||||
class FilterContactSourcesAdapter(val activity: SimpleActivity, private val contactSources: List<ContactSource>, private val displayContactSources: Set<String>) :
|
||||
class FilterContactSourcesAdapter(val activity: SimpleActivity, private val contactSources: List<ContactSource>, private val displayContactSources: ArrayList<String>) :
|
||||
RecyclerView.Adapter<FilterContactSourcesAdapter.ViewHolder>() {
|
||||
private val itemViews = SparseArray<View>()
|
||||
private val selectedPositions = HashSet<Int>()
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.simplemobiletools.commons.extensions.*
|
|||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.adapters.FilterContactSourcesAdapter
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.getVisibleContactSources
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.SMT_PRIVATE
|
||||
import com.simplemobiletools.contacts.models.ContactSource
|
||||
|
@ -25,7 +25,7 @@ class ExportContactsDialog(val activity: SimpleActivity, val path: String, priva
|
|||
ContactsHelper(activity).getContactSources {
|
||||
it.mapTo(contactSources, { it.copy() })
|
||||
activity.runOnUiThread {
|
||||
export_contacts_list.adapter = FilterContactSourcesAdapter(activity, it, activity.config.displayContactSources)
|
||||
export_contacts_list.adapter = FilterContactSourcesAdapter(activity, it, activity.getVisibleContactSources())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.simplemobiletools.contacts.R
|
|||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.adapters.FilterContactSourcesAdapter
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.getVisibleContactSources
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.SMT_PRIVATE
|
||||
import com.simplemobiletools.contacts.models.ContactSource
|
||||
|
@ -24,7 +25,7 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb
|
|||
}
|
||||
|
||||
it.mapTo(contactSources, { it.copy() })
|
||||
val selectedSources = activity.config.displayContactSources
|
||||
val selectedSources = activity.getVisibleContactSources()
|
||||
activity.runOnUiThread {
|
||||
view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, it, selectedSources)
|
||||
|
||||
|
@ -32,21 +33,28 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb
|
|||
.setPositiveButton(R.string.ok, { dialogInterface, i -> confirmEventTypes() })
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this)
|
||||
}
|
||||
activity.setupDialogStuff(view, this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun confirmEventTypes() {
|
||||
val selectedIndexes = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedItemsSet()
|
||||
val selectedContactSources = HashSet<String>()
|
||||
selectedIndexes.forEach {
|
||||
selectedContactSources.add(if (contactSources[it].type == SMT_PRIVATE) SMT_PRIVATE else contactSources[it].name)
|
||||
val ignoredIndexes = ArrayList<Int>()
|
||||
for (i in 0 until contactSources.size) {
|
||||
if (!selectedIndexes.contains(i)) {
|
||||
ignoredIndexes.add(i)
|
||||
}
|
||||
}
|
||||
|
||||
if (activity.config.displayContactSources != selectedContactSources) {
|
||||
activity.config.displayContactSources = selectedContactSources
|
||||
val ignoredContactSources = HashSet<String>()
|
||||
ignoredIndexes.forEach {
|
||||
ignoredContactSources.add(if (contactSources[it].type == SMT_PRIVATE) SMT_PRIVATE else contactSources[it].name)
|
||||
}
|
||||
|
||||
if (activity.getVisibleContactSources() != ignoredContactSources) {
|
||||
activity.config.ignoredContactSources = ignoredContactSources
|
||||
callback()
|
||||
}
|
||||
dialog?.dismiss()
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.simplemobiletools.contacts.R
|
|||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.adapters.SelectContactsAdapter
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.getVisibleContactSources
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import kotlinx.android.synthetic.main.layout_select_contact.view.*
|
||||
|
||||
|
@ -18,7 +19,7 @@ class SelectContactsDialog(val activity: SimpleActivity, initialContacts: ArrayL
|
|||
init {
|
||||
var allContacts = initialContacts
|
||||
if (selectContacts == null) {
|
||||
val contactSources = activity.config.displayContactSources
|
||||
val contactSources = activity.getVisibleContactSources()
|
||||
allContacts = allContacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
||||
|
||||
initiallySelectedContacts = allContacts.filter { it.starred == 1 } as ArrayList<Contact>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.contacts.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.provider.ContactsContract
|
||||
|
@ -17,6 +18,7 @@ import com.simplemobiletools.contacts.helpers.ContactsHelper
|
|||
import com.simplemobiletools.contacts.helpers.SMT_PRIVATE
|
||||
import com.simplemobiletools.contacts.helpers.VcfExporter
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import com.simplemobiletools.contacts.models.ContactSource
|
||||
import java.io.File
|
||||
|
||||
fun SimpleActivity.startCallIntent(recipient: String) {
|
||||
|
@ -181,3 +183,11 @@ fun BaseSimpleActivity.getContactPublicUri(contact: Contact): Uri {
|
|||
val lookupKey = ContactsHelper(this).getContactLookupKey(contact.id.toString())
|
||||
return Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
||||
}
|
||||
|
||||
fun Activity.getVisibleContactSources(): ArrayList<String> {
|
||||
val sources = ContactsHelper(this).getDeviceContactSources()
|
||||
sources.add(ContactSource(getString(R.string.phone_storage_hidden), SMT_PRIVATE))
|
||||
val sourceNames = ArrayList(sources).map { if (it.type == SMT_PRIVATE) SMT_PRIVATE else it.name }.toMutableList() as ArrayList<String>
|
||||
sourceNames.removeAll(config.ignoredContactSources)
|
||||
return sourceNames
|
||||
}
|
||||
|
|
|
@ -15,10 +15,7 @@ import com.simplemobiletools.contacts.activities.MainActivity
|
|||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
||||
import com.simplemobiletools.contacts.adapters.GroupsAdapter
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.editContact
|
||||
import com.simplemobiletools.contacts.extensions.tryStartCall
|
||||
import com.simplemobiletools.contacts.extensions.viewContact
|
||||
import com.simplemobiletools.contacts.extensions.*
|
||||
import com.simplemobiletools.contacts.helpers.*
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import com.simplemobiletools.contacts.models.Group
|
||||
|
@ -103,7 +100,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
this is GroupsFragment -> contacts
|
||||
this is FavoritesFragment -> contacts.filter { it.starred == 1 } as ArrayList<Contact>
|
||||
else -> {
|
||||
val contactSources = config.displayContactSources
|
||||
val contactSources = activity!!.getVisibleContactSources()
|
||||
contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
fun newInstance(context: Context) = Config(context)
|
||||
}
|
||||
|
||||
var displayContactSources: HashSet<String>
|
||||
get() = prefs.getStringSet(DISPLAY_CONTACT_SOURCES, hashSetOf("-1")) as HashSet
|
||||
set(displayContactSources) = prefs.edit().remove(DISPLAY_CONTACT_SOURCES).putStringSet(DISPLAY_CONTACT_SOURCES, displayContactSources).apply()
|
||||
var ignoredContactSources: HashSet<String>
|
||||
get() = prefs.getStringSet(IGNORED_CONTACT_SOURCES, hashSetOf("")) as HashSet
|
||||
set(ignoreContactSources) = prefs.edit().remove(IGNORED_CONTACT_SOURCES).putStringSet(IGNORED_CONTACT_SOURCES, ignoreContactSources).apply()
|
||||
|
||||
var showContactThumbnails: Boolean
|
||||
get() = prefs.getBoolean(SHOW_CONTACT_THUMBNAILS, true)
|
||||
|
|
|
@ -5,7 +5,7 @@ import android.provider.ContactsContract.CommonDataKinds
|
|||
// shared prefs
|
||||
const val SHOW_CONTACT_THUMBNAILS = "show_contact_thumbnails"
|
||||
const val SHOW_PHONE_NUMBERS = "show_phone_numbers"
|
||||
const val DISPLAY_CONTACT_SOURCES = "display_contact_sources"
|
||||
const val IGNORED_CONTACT_SOURCES = "ignored_contact_sources"
|
||||
const val START_NAME_WITH_SURNAME = "start_name_with_surname"
|
||||
const val LAST_USED_CONTACT_SOURCE = "last_used_contact_source"
|
||||
const val LOCAL_ACCOUNT_NAME = "local_account_name"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simplemobiletools.contacts.helpers
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Activity
|
||||
import android.content.*
|
||||
import android.database.Cursor
|
||||
import android.graphics.Bitmap
|
||||
|
@ -11,7 +12,6 @@ import android.provider.ContactsContract.CommonDataKinds.Note
|
|||
import android.provider.MediaStore
|
||||
import android.text.TextUtils
|
||||
import android.util.SparseArray
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
||||
|
@ -22,14 +22,14 @@ import com.simplemobiletools.contacts.extensions.*
|
|||
import com.simplemobiletools.contacts.models.*
|
||||
import com.simplemobiletools.contacts.overloads.times
|
||||
|
||||
class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
class ContactsHelper(val activity: Activity) {
|
||||
private val BATCH_SIZE = 100
|
||||
private var displayContactSources = HashSet<String>()
|
||||
private var displayContactSources = ArrayList<String>()
|
||||
|
||||
fun getContacts(callback: (ArrayList<Contact>) -> Unit) {
|
||||
Thread {
|
||||
val contacts = SparseArray<Contact>()
|
||||
displayContactSources = activity.config.displayContactSources
|
||||
displayContactSources = activity.getVisibleContactSources()
|
||||
getDeviceContacts(contacts)
|
||||
|
||||
if (displayContactSources.contains(SMT_PRIVATE)) {
|
||||
|
@ -72,6 +72,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
val selectionArgs = getSourcesSelectionArgs(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
|
||||
val sortOrder = getSortString()
|
||||
|
||||
val names = HashSet<String>()
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, sortOrder)
|
||||
|
@ -89,6 +90,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
val addresses = ArrayList<Address>()
|
||||
val events = ArrayList<Event>()
|
||||
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: ""
|
||||
names.add(accountName)
|
||||
val starred = cursor.getIntValue(CommonDataKinds.StructuredName.STARRED)
|
||||
val contactId = cursor.getIntValue(ContactsContract.Data.CONTACT_ID)
|
||||
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
||||
|
@ -647,7 +649,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
return ArrayList(sources)
|
||||
}
|
||||
|
||||
private fun getDeviceContactSources(): LinkedHashSet<ContactSource> {
|
||||
fun getDeviceContactSources(): LinkedHashSet<ContactSource> {
|
||||
val sources = LinkedHashSet<ContactSource>()
|
||||
if (!activity.hasContactPermissions()) {
|
||||
return sources
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.contacts.helpers
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
|
@ -11,7 +12,6 @@ import android.provider.MediaStore
|
|||
import android.text.TextUtils
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.getBlobValue
|
||||
import com.simplemobiletools.commons.extensions.getIntValue
|
||||
import com.simplemobiletools.commons.extensions.getLongValue
|
||||
|
@ -249,7 +249,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
}
|
||||
|
||||
fun getContacts(activity: BaseSimpleActivity, selection: String? = null, selectionArgs: Array<String>? = null): ArrayList<Contact> {
|
||||
fun getContacts(activity: Activity, selection: String? = null, selectionArgs: Array<String>? = null): ArrayList<Contact> {
|
||||
val storedGroups = ContactsHelper(activity).getStoredGroups()
|
||||
val contacts = ArrayList<Contact>()
|
||||
val projection = arrayOf(COL_ID, COL_PREFIX, COL_FIRST_NAME, COL_MIDDLE_NAME, COL_SURNAME, COL_SUFFIX, COL_PHONE_NUMBERS, COL_EMAILS,
|
||||
|
@ -319,7 +319,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return contacts
|
||||
}
|
||||
|
||||
fun getContactWithId(activity: BaseSimpleActivity, id: Int): Contact? {
|
||||
fun getContactWithId(activity: Activity, id: Int): Contact? {
|
||||
val selection = "$COL_ID = ?"
|
||||
val selectionArgs = arrayOf(id.toString())
|
||||
return getContacts(activity, selection, selectionArgs).firstOrNull()
|
||||
|
|
Loading…
Reference in a new issue