mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
implement the Filter functionality
This commit is contained in:
@ -151,7 +151,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
contacts_fastscroller.setViews(contacts_list) {
|
contacts_fastscroller.setViews(contacts_list) {
|
||||||
val item = contacts.getOrNull(it)
|
val item = (contacts_list.adapter as ContactsAdapter).contactItems.getOrNull(it)
|
||||||
contacts_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
|
contacts_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,7 +18,7 @@ class FilterContactSourcesAdapter(val activity: SimpleActivity, val contactSourc
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
contactSources.forEachIndexed { index, value ->
|
contactSources.forEachIndexed { index, value ->
|
||||||
if ((displayContactSources.size == 1 && displayContactSources.first() == "-1") || displayContactSources.contains(value)) {
|
if (activity.config.showAllContacts() || displayContactSources.contains(value)) {
|
||||||
selectedPositions.add(index)
|
selectedPositions.add(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,4 +20,6 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var displayContactSources: Set<String>
|
var displayContactSources: Set<String>
|
||||||
get() = prefs.getStringSet(DISPLAY_CONTACT_SOURCES, hashSetOf("-1"))
|
get() = prefs.getStringSet(DISPLAY_CONTACT_SOURCES, hashSetOf("-1"))
|
||||||
set(displayContactSources) = prefs.edit().remove(DISPLAY_CONTACT_SOURCES).putStringSet(DISPLAY_CONTACT_SOURCES, displayContactSources).apply()
|
set(displayContactSources) = prefs.edit().remove(DISPLAY_CONTACT_SOURCES).putStringSet(DISPLAY_CONTACT_SOURCES, displayContactSources).apply()
|
||||||
|
|
||||||
|
fun showAllContacts() = displayContactSources.size == 1 && displayContactSources.first() == "-1"
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
|||||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.models.Contact
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
|
import com.simplemobiletools.contacts.overloads.times
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ContactsHelper(val activity: SimpleActivity) {
|
class ContactsHelper(val activity: SimpleActivity) {
|
||||||
@ -38,12 +39,16 @@ class ContactsHelper(val activity: SimpleActivity) {
|
|||||||
fun getContacts(callback: (ArrayList<Contact>) -> Unit) {
|
fun getContacts(callback: (ArrayList<Contact>) -> Unit) {
|
||||||
val contacts = HashMap<Int, Contact>()
|
val contacts = HashMap<Int, Contact>()
|
||||||
Thread {
|
Thread {
|
||||||
|
val sources = activity.config.displayContactSources
|
||||||
|
val questionMarks = ("?," * sources.size).trimEnd(',')
|
||||||
val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI
|
val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI
|
||||||
val projection = getContactProjection()
|
val projection = getContactProjection()
|
||||||
|
val selection = if (activity.config.showAllContacts()) null else "${ContactsContract.RawContacts.ACCOUNT_NAME} IN ($questionMarks)"
|
||||||
|
val selectionArgs = if (activity.config.showAllContacts()) null else sources.toTypedArray()
|
||||||
val sortOrder = getSortString()
|
val sortOrder = getSortString()
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = activity.contentResolver.query(uri, projection, null, null, sortOrder)
|
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, sortOrder)
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
val id = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.CONTACT_ID)
|
val id = cursor.getIntValue(ContactsContract.CommonDataKinds.Phone.CONTACT_ID)
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.simplemobiletools.contacts.overloads
|
||||||
|
|
||||||
|
operator fun String.times(x: Int): String {
|
||||||
|
val stringBuffer = StringBuffer()
|
||||||
|
for (i in 1..x) {
|
||||||
|
stringBuffer.append(this)
|
||||||
|
}
|
||||||
|
return stringBuffer.toString()
|
||||||
|
}
|
Reference in New Issue
Block a user