implementing actual Search functionality

This commit is contained in:
tibbi 2020-05-12 15:31:59 +02:00
parent f1250ae1f7
commit ba4a3ae8d7
2 changed files with 8 additions and 9 deletions

View File

@ -164,8 +164,6 @@ class MainActivity : SimpleActivity() {
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener { MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem?): Boolean { override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
mydebug("search open")
contacts_fragment.onSearchOpened()
isSearchOpen = true isSearchOpen = true
main_dialpad_button.beGone() main_dialpad_button.beGone()
return true return true

View File

@ -20,6 +20,8 @@ import kotlinx.android.synthetic.main.fragment_letters_layout.view.*
import java.util.* import java.util.*
class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshItemsListener { class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshItemsListener {
private var allContacts = ArrayList<SimpleContact>()
override fun setupFragment() { override fun setupFragment() {
val placeholderResId = if (context.hasPermission(PERMISSION_READ_CONTACTS)) { val placeholderResId = if (context.hasPermission(PERMISSION_READ_CONTACTS)) {
R.string.no_contacts_found R.string.no_contacts_found
@ -74,13 +76,14 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
override fun refreshItems() { override fun refreshItems() {
SimpleContactsHelper(context).getAvailableContacts { contacts -> SimpleContactsHelper(context).getAvailableContacts { contacts ->
allContacts = contacts
activity?.runOnUiThread { activity?.runOnUiThread {
gotContacts(contacts) gotContacts(contacts)
} }
} }
} }
fun gotContacts(contacts: ArrayList<SimpleContact>) { private fun gotContacts(contacts: ArrayList<SimpleContact>) {
setupLetterFastscroller(contacts) setupLetterFastscroller(contacts)
if (contacts.isEmpty()) { if (contacts.isEmpty()) {
fragment_placeholder.beVisible() fragment_placeholder.beVisible()
@ -118,16 +121,14 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
}) })
} }
fun onSearchOpened() {
}
fun onSearchClosed() { fun onSearchClosed() {
(fragment_list.adapter as? ContactsAdapter)?.updateItems(allContacts)
} }
fun onSearchQueryChanged(text: String) { fun onSearchQueryChanged(text: String) {
val contacts = allContacts.filter { it.name.contains(text, true) }.toMutableList() as ArrayList<SimpleContact>
(fragment_list.adapter as? ContactsAdapter)?.updateItems(contacts, text)
setupLetterFastscroller(contacts)
} }
private fun requestReadContactsPermission() { private fun requestReadContactsPermission() {