diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/MainActivity.kt index 96ae42cc..379d7669 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/activities/MainActivity.kt @@ -164,8 +164,6 @@ class MainActivity : SimpleActivity() { MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener { override fun onMenuItemActionExpand(item: MenuItem?): Boolean { - mydebug("search open") - contacts_fragment.onSearchOpened() isSearchOpen = true main_dialpad_button.beGone() return true diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/ContactsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/ContactsFragment.kt index a3405a14..827f65ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/ContactsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/ContactsFragment.kt @@ -20,6 +20,8 @@ import kotlinx.android.synthetic.main.fragment_letters_layout.view.* import java.util.* class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshItemsListener { + private var allContacts = ArrayList() + override fun setupFragment() { val placeholderResId = if (context.hasPermission(PERMISSION_READ_CONTACTS)) { R.string.no_contacts_found @@ -74,13 +76,14 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag override fun refreshItems() { SimpleContactsHelper(context).getAvailableContacts { contacts -> + allContacts = contacts activity?.runOnUiThread { gotContacts(contacts) } } } - fun gotContacts(contacts: ArrayList) { + private fun gotContacts(contacts: ArrayList) { setupLetterFastscroller(contacts) if (contacts.isEmpty()) { fragment_placeholder.beVisible() @@ -118,16 +121,14 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag }) } - fun onSearchOpened() { - - } - fun onSearchClosed() { - + (fragment_list.adapter as? ContactsAdapter)?.updateItems(allContacts) } fun onSearchQueryChanged(text: String) { - + val contacts = allContacts.filter { it.name.contains(text, true) }.toMutableList() as ArrayList + (fragment_list.adapter as? ContactsAdapter)?.updateItems(contacts, text) + setupLetterFastscroller(contacts) } private fun requestReadContactsPermission() {