adding an initial implementation of fastscroller with letters
This commit is contained in:
parent
7df23a98dd
commit
7b30d6efd5
|
@ -61,6 +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.reddit:indicator-fast-scroll:1.2.1'
|
||||||
|
|
||||||
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"
|
||||||
|
|
|
@ -35,3 +35,5 @@ fun String.getDateTimeFromDateString(viewToUpdate: TextView? = null): DateTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.normalizeNumber() = PhoneNumberUtils.normalizeNumber(this)
|
fun String.normalizeNumber() = PhoneNumberUtils.normalizeNumber(this)
|
||||||
|
|
||||||
|
fun String.areLettersOnly() = matches(Regex("[a-zA-Z]+"))
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Intent
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
||||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||||
|
@ -16,6 +17,7 @@ import com.simplemobiletools.contacts.pro.activities.MainActivity
|
||||||
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
|
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.contacts.pro.adapters.ContactsAdapter
|
import com.simplemobiletools.contacts.pro.adapters.ContactsAdapter
|
||||||
import com.simplemobiletools.contacts.pro.adapters.GroupsAdapter
|
import com.simplemobiletools.contacts.pro.adapters.GroupsAdapter
|
||||||
|
import com.simplemobiletools.contacts.pro.extensions.areLettersOnly
|
||||||
import com.simplemobiletools.contacts.pro.extensions.config
|
import com.simplemobiletools.contacts.pro.extensions.config
|
||||||
import com.simplemobiletools.contacts.pro.extensions.getVisibleContactSources
|
import com.simplemobiletools.contacts.pro.extensions.getVisibleContactSources
|
||||||
import com.simplemobiletools.contacts.pro.helpers.*
|
import com.simplemobiletools.contacts.pro.helpers.*
|
||||||
|
@ -23,6 +25,14 @@ import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
|
||||||
import com.simplemobiletools.contacts.pro.models.Contact
|
import com.simplemobiletools.contacts.pro.models.Contact
|
||||||
import com.simplemobiletools.contacts.pro.models.Group
|
import com.simplemobiletools.contacts.pro.models.Group
|
||||||
import kotlinx.android.synthetic.main.fragment_layout.view.*
|
import kotlinx.android.synthetic.main.fragment_layout.view.*
|
||||||
|
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_fab
|
||||||
|
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_list
|
||||||
|
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_placeholder
|
||||||
|
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_placeholder_2
|
||||||
|
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_wrapper
|
||||||
|
import kotlinx.android.synthetic.main.fragment_letters_layout.view.*
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
|
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
|
||||||
protected var activity: SimpleActivity? = null
|
protected var activity: SimpleActivity? = null
|
||||||
|
@ -35,6 +45,7 @@ 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
|
||||||
|
@ -139,6 +150,23 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
} else {
|
} else {
|
||||||
setupContactsFavoritesAdapter(contacts)
|
setupContactsFavoritesAdapter(contacts)
|
||||||
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList()
|
||||||
|
|
||||||
|
if (!wasLetterFastScrollerSetup) {
|
||||||
|
wasLetterFastScrollerSetup = true
|
||||||
|
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("")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,13 @@
|
||||||
android:scrollbars="none"
|
android:scrollbars="none"
|
||||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"/>
|
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"/>
|
||||||
|
|
||||||
|
<com.reddit.indicatorfastscroll.FastScrollerView
|
||||||
|
android:id="@+id/letter_fastscroller"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:paddingBottom="@dimen/activity_margin"
|
||||||
|
android:layout_alignParentEnd="true" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyFloatingActionButton
|
<com.simplemobiletools.commons.views.MyFloatingActionButton
|
||||||
|
|
Loading…
Reference in New Issue