properly refresh the letters fastscroller if contacts change
This commit is contained in:
parent
6db7f548ee
commit
4df2f32780
2 changed files with 31 additions and 31 deletions
|
@ -61,7 +61,7 @@ dependencies {
|
||||||
implementation 'joda-time:joda-time:2.10.1'
|
implementation 'joda-time:joda-time:2.10.1'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
|
||||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
|
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"
|
kapt "androidx.room:room-compiler:2.2.2"
|
||||||
implementation "androidx.room:room-runtime:2.2.2"
|
implementation "androidx.room:room-runtime:2.2.2"
|
||||||
|
|
|
@ -45,7 +45,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
|
|
||||||
var skipHashComparing = false
|
var skipHashComparing = false
|
||||||
var forceListRedraw = false
|
var forceListRedraw = false
|
||||||
var wasLetterFastScrollerSetup = false
|
|
||||||
|
|
||||||
fun setupFragment(activity: SimpleActivity) {
|
fun setupFragment(activity: SimpleActivity) {
|
||||||
config = activity.config
|
config = activity.config
|
||||||
|
@ -151,38 +150,21 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
setupContactsFavoritesAdapter(contacts)
|
setupContactsFavoritesAdapter(contacts)
|
||||||
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
||||||
|
|
||||||
if (!wasLetterFastScrollerSetup) {
|
val states = arrayOf(intArrayOf(android.R.attr.state_enabled),
|
||||||
wasLetterFastScrollerSetup = true
|
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),
|
val textColor = config.textColor
|
||||||
intArrayOf(-android.R.attr.state_enabled),
|
val colors = intArrayOf(textColor, textColor, textColor, textColor)
|
||||||
intArrayOf(-android.R.attr.state_checked),
|
|
||||||
intArrayOf(android.R.attr.state_pressed)
|
|
||||||
)
|
|
||||||
|
|
||||||
val textColor = config.textColor
|
val myList = ColorStateList(states, colors)
|
||||||
val colors = intArrayOf(textColor, textColor, textColor, textColor)
|
letter_fastscroller.textColor = myList
|
||||||
|
setupLetterFastscroller(contacts)
|
||||||
|
|
||||||
val myList = ColorStateList(states, colors)
|
letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller)
|
||||||
letter_fastscroller.textColor = myList
|
letter_fastscroller_thumb.textColor = config.primaryColor.getContrastColor()
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +252,22 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupLetterFastscroller(contacts: ArrayList<Contact>) {
|
||||||
|
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() {
|
fun fontSizeChanged() {
|
||||||
if (this is GroupsFragment) {
|
if (this is GroupsFragment) {
|
||||||
(fragment_list.adapter as? GroupsAdapter)?.apply {
|
(fragment_list.adapter as? GroupsAdapter)?.apply {
|
||||||
|
@ -321,6 +319,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
|
|
||||||
fragment_placeholder.beVisibleIf(filtered.isEmpty())
|
fragment_placeholder.beVisibleIf(filtered.isEmpty())
|
||||||
(adapter as? ContactsAdapter)?.updateItems(filtered, text.normalizeString())
|
(adapter as? ContactsAdapter)?.updateItems(filtered, text.normalizeString())
|
||||||
|
setupLetterFastscroller(filtered)
|
||||||
} else if (adapter is GroupsAdapter) {
|
} else if (adapter is GroupsAdapter) {
|
||||||
val filtered = groupsIgnoringSearch.filter {
|
val filtered = groupsIgnoringSearch.filter {
|
||||||
it.title.contains(text, true)
|
it.title.contains(text, true)
|
||||||
|
@ -343,6 +342,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
fun onSearchClosed() {
|
fun onSearchClosed() {
|
||||||
if (fragment_list.adapter is ContactsAdapter) {
|
if (fragment_list.adapter is ContactsAdapter) {
|
||||||
(fragment_list.adapter as? ContactsAdapter)?.updateItems(contactsIgnoringSearch)
|
(fragment_list.adapter as? ContactsAdapter)?.updateItems(contactsIgnoringSearch)
|
||||||
|
setupLetterFastscroller(contactsIgnoringSearch)
|
||||||
setupViewVisibility(contactsIgnoringSearch.isNotEmpty())
|
setupViewVisibility(contactsIgnoringSearch.isNotEmpty())
|
||||||
} else if (fragment_list.adapter is GroupsAdapter) {
|
} else if (fragment_list.adapter is GroupsAdapter) {
|
||||||
(fragment_list.adapter as? GroupsAdapter)?.updateItems(groupsIgnoringSearch)
|
(fragment_list.adapter as? GroupsAdapter)?.updateItems(groupsIgnoringSearch)
|
||||||
|
|
Loading…
Reference in a new issue