fix #421, allow searching groups
This commit is contained in:
parent
d2a7a6f481
commit
5e0386ee0e
|
@ -183,7 +183,6 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||||
val currentFragment = getCurrentFragment()
|
val currentFragment = getCurrentFragment()
|
||||||
|
|
||||||
menu.apply {
|
menu.apply {
|
||||||
findItem(R.id.search).isVisible = currentFragment != groups_fragment
|
|
||||||
findItem(R.id.sort).isVisible = currentFragment != groups_fragment
|
findItem(R.id.sort).isVisible = currentFragment != groups_fragment
|
||||||
findItem(R.id.filter).isVisible = currentFragment != groups_fragment
|
findItem(R.id.filter).isVisible = currentFragment != groups_fragment
|
||||||
setupSearch(this)
|
setupSearch(this)
|
||||||
|
@ -225,7 +224,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||||
(searchMenuItem!!.actionView as SearchView).apply {
|
(searchMenuItem!!.actionView as SearchView).apply {
|
||||||
setSearchableInfo(searchManager.getSearchableInfo(componentName))
|
setSearchableInfo(searchManager.getSearchableInfo(componentName))
|
||||||
isSubmitButtonEnabled = false
|
isSubmitButtonEnabled = false
|
||||||
queryHint = getString(if (getCurrentFragment() == contacts_fragment) R.string.search_contacts else R.string.search_favorites)
|
queryHint = getString(getSearchString())
|
||||||
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||||
override fun onQueryTextSubmit(query: String) = false
|
override fun onQueryTextSubmit(query: String) = false
|
||||||
|
|
||||||
|
@ -253,6 +252,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getSearchString(): Int {
|
||||||
|
return when (getCurrentFragment()) {
|
||||||
|
favorites_fragment -> R.string.search_favorites
|
||||||
|
groups_fragment -> R.string.search_groups
|
||||||
|
else -> R.string.search_contacts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private fun checkShortcuts() {
|
private fun checkShortcuts() {
|
||||||
val appIconColor = config.appIconColor
|
val appIconColor = config.appIconColor
|
||||||
|
|
|
@ -29,6 +29,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
|
|
||||||
private var lastHashCode = 0
|
private var lastHashCode = 0
|
||||||
private var contactsIgnoringSearch = ArrayList<Contact>()
|
private var contactsIgnoringSearch = ArrayList<Contact>()
|
||||||
|
private var groupsIgnoringSearch = ArrayList<Group>()
|
||||||
private lateinit var config: Config
|
private lateinit var config: Config
|
||||||
|
|
||||||
var skipHashComparing = false
|
var skipHashComparing = false
|
||||||
|
@ -130,6 +131,8 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
|
|
||||||
if (this is ContactsFragment || this is FavoritesFragment) {
|
if (this is ContactsFragment || this is FavoritesFragment) {
|
||||||
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
||||||
|
} else if (this is GroupsFragment) {
|
||||||
|
groupsIgnoringSearch = (fragment_list?.adapter as? GroupsAdapter)?.groups ?: ArrayList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +180,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupContactsFavoritesAdapter(contacts: ArrayList<Contact>) {
|
private fun setupContactsFavoritesAdapter(contacts: ArrayList<Contact>) {
|
||||||
setupViewVisibility(contacts)
|
setupViewVisibility(contacts.isNotEmpty())
|
||||||
val currAdapter = fragment_list.adapter
|
val currAdapter = fragment_list.adapter
|
||||||
if (currAdapter == null || forceListRedraw) {
|
if (currAdapter == null || forceListRedraw) {
|
||||||
forceListRedraw = false
|
forceListRedraw = false
|
||||||
|
@ -227,9 +230,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onSearchQueryChanged(text: String) {
|
fun onSearchQueryChanged(text: String) {
|
||||||
|
val adapter = fragment_list.adapter
|
||||||
|
if (adapter is ContactsAdapter) {
|
||||||
val shouldNormalize = text.normalizeString() == text
|
val shouldNormalize = text.normalizeString() == text
|
||||||
val convertLetters = config.showDialpadLetters
|
val convertLetters = config.showDialpadLetters
|
||||||
(fragment_list.adapter as? ContactsAdapter)?.apply {
|
|
||||||
val filtered = contactsIgnoringSearch.filter {
|
val filtered = contactsIgnoringSearch.filter {
|
||||||
getProperText(it.getNameToDisplay(), shouldNormalize).contains(text, true) ||
|
getProperText(it.getNameToDisplay(), shouldNormalize).contains(text, true) ||
|
||||||
getProperText(it.nickname, shouldNormalize).contains(text, true) ||
|
getProperText(it.nickname, shouldNormalize).contains(text, true) ||
|
||||||
|
@ -249,11 +253,22 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filtered.isEmpty() && this@MyViewPagerFragment is FavoritesFragment) {
|
if (filtered.isEmpty() && this@MyViewPagerFragment is FavoritesFragment) {
|
||||||
fragment_placeholder.text = activity.getString(R.string.no_items_found)
|
fragment_placeholder.text = activity?.getString(R.string.no_items_found)
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment_placeholder.beVisibleIf(filtered.isEmpty())
|
fragment_placeholder.beVisibleIf(filtered.isEmpty())
|
||||||
updateItems(filtered, text.normalizeString())
|
(adapter as? ContactsAdapter)?.updateItems(filtered, text.normalizeString())
|
||||||
|
} else if (adapter is GroupsAdapter) {
|
||||||
|
val filtered = groupsIgnoringSearch.filter {
|
||||||
|
it.title.contains(text, true)
|
||||||
|
} as ArrayList
|
||||||
|
|
||||||
|
if (filtered.isEmpty()) {
|
||||||
|
fragment_placeholder.text = activity?.getString(R.string.no_items_found)
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment_placeholder.beVisibleIf(filtered.isEmpty())
|
||||||
|
(adapter as? GroupsAdapter)?.updateItems(filtered)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,11 +276,17 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
|
|
||||||
fun onSearchOpened() {
|
fun onSearchOpened() {
|
||||||
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
||||||
|
groupsIgnoringSearch = (fragment_list?.adapter as? GroupsAdapter)?.groups ?: ArrayList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onSearchClosed() {
|
fun onSearchClosed() {
|
||||||
|
if (fragment_list.adapter is ContactsAdapter) {
|
||||||
(fragment_list.adapter as? ContactsAdapter)?.updateItems(contactsIgnoringSearch)
|
(fragment_list.adapter as? ContactsAdapter)?.updateItems(contactsIgnoringSearch)
|
||||||
setupViewVisibility(contactsIgnoringSearch)
|
setupViewVisibility(contactsIgnoringSearch.isNotEmpty())
|
||||||
|
} else if (fragment_list.adapter is GroupsAdapter) {
|
||||||
|
(fragment_list.adapter as? GroupsAdapter)?.updateItems(groupsIgnoringSearch)
|
||||||
|
setupViewVisibility(groupsIgnoringSearch.isNotEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
if (this is FavoritesFragment) {
|
if (this is FavoritesFragment) {
|
||||||
fragment_placeholder.text = activity?.getString(R.string.no_favorites)
|
fragment_placeholder.text = activity?.getString(R.string.no_favorites)
|
||||||
|
@ -279,10 +300,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
fragment_placeholder_2.setTextColor(context.getAdjustedPrimaryColor())
|
fragment_placeholder_2.setTextColor(context.getAdjustedPrimaryColor())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupViewVisibility(contacts: ArrayList<Contact>) {
|
private fun setupViewVisibility(hasItemsToShow: Boolean) {
|
||||||
fragment_placeholder_2.beVisibleIf(contacts.isEmpty())
|
fragment_placeholder_2.beVisibleIf(!hasItemsToShow)
|
||||||
fragment_placeholder.beVisibleIf(contacts.isEmpty())
|
fragment_placeholder.beVisibleIf(!hasItemsToShow)
|
||||||
fragment_list.beVisibleIf(contacts.isNotEmpty())
|
fragment_list.beVisibleIf(hasItemsToShow)
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun fabClicked()
|
abstract fun fabClicked()
|
||||||
|
|
Loading…
Reference in New Issue