diff --git a/app/build.gradle b/app/build.gradle index 240375b6..36a16c6b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,7 +61,7 @@ dependencies { implementation 'joda-time:joda-time:2.10.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5' - implementation 'com.github.tibbi:IndicatorFastScroll:d615a5c141' + implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a' kapt "androidx.room:room-compiler:2.2.2" implementation "androidx.room:room-runtime:2.2.2" diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt index 6b20b68d..cfdd0a1a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt @@ -45,7 +45,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) var skipHashComparing = false var forceListRedraw = false - var wasLetterFastScrollerSetup = false fun setupFragment(activity: SimpleActivity) { config = activity.config @@ -151,38 +150,21 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) setupContactsFavoritesAdapter(contacts) contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList() - if (!wasLetterFastScrollerSetup) { - wasLetterFastScrollerSetup = true + val states = arrayOf(intArrayOf(android.R.attr.state_enabled), + intArrayOf(-android.R.attr.state_enabled), + intArrayOf(-android.R.attr.state_checked), + intArrayOf(android.R.attr.state_pressed) + ) - val states = arrayOf(intArrayOf(android.R.attr.state_enabled), - intArrayOf(-android.R.attr.state_enabled), - intArrayOf(-android.R.attr.state_checked), - intArrayOf(android.R.attr.state_pressed) - ) + val textColor = config.textColor + val colors = intArrayOf(textColor, textColor, textColor, textColor) - val textColor = config.textColor - val colors = intArrayOf(textColor, textColor, textColor, textColor) + val myList = ColorStateList(states, colors) + letter_fastscroller.textColor = myList + setupLetterFastscroller(contacts) - val myList = ColorStateList(states, colors) - letter_fastscroller.textColor = myList - - letter_fastscroller.setupWithRecyclerView(fragment_list, { position -> - try { - val name = contacts[position].getNameToDisplay() - var character = if (name.isNotEmpty()) name.substring(0, 1) else "" - if (!character.areLettersOnly()) { - character = "#" - } - - FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault())) - } catch (e: Exception) { - FastScrollItemIndicator.Text("") - } - }) - - letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller) - letter_fastscroller_thumb.textColor = config.primaryColor.getContrastColor() - } + letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller) + letter_fastscroller_thumb.textColor = config.primaryColor.getContrastColor() } } @@ -270,6 +252,22 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) } } + private fun setupLetterFastscroller(contacts: ArrayList) { + letter_fastscroller.setupWithRecyclerView(fragment_list, { position -> + try { + val name = contacts[position].getNameToDisplay() + var character = if (name.isNotEmpty()) name.substring(0, 1) else "" + if (!character.areLettersOnly()) { + character = "#" + } + + FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault())) + } catch (e: Exception) { + FastScrollItemIndicator.Text("") + } + }) + } + fun fontSizeChanged() { if (this is GroupsFragment) { (fragment_list.adapter as? GroupsAdapter)?.apply { @@ -321,6 +319,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) fragment_placeholder.beVisibleIf(filtered.isEmpty()) (adapter as? ContactsAdapter)?.updateItems(filtered, text.normalizeString()) + setupLetterFastscroller(filtered) } else if (adapter is GroupsAdapter) { val filtered = groupsIgnoringSearch.filter { it.title.contains(text, true) @@ -343,6 +342,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) fun onSearchClosed() { if (fragment_list.adapter is ContactsAdapter) { (fragment_list.adapter as? ContactsAdapter)?.updateItems(contactsIgnoringSearch) + setupLetterFastscroller(contactsIgnoringSearch) setupViewVisibility(contactsIgnoringSearch.isNotEmpty()) } else if (fragment_list.adapter is GroupsAdapter) { (fragment_list.adapter as? GroupsAdapter)?.updateItems(groupsIgnoringSearch)