adding a fastscroller with letters at the contact list

This commit is contained in:
tibbi 2020-04-13 21:58:12 +02:00
parent 06f61b55cb
commit 9b758b617d
4 changed files with 55 additions and 1 deletions

View File

@ -40,4 +40,5 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'org.greenrobot:eventbus:3.2.0' implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'com.klinkerapps:android-smsmms:5.2.6' implementation 'com.klinkerapps:android-smsmms:5.2.6'
implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a'
} }

View File

@ -212,7 +212,7 @@ class MainActivity : SimpleActivity() {
} }
private fun launchAbout() { private fun launchAbout() {
val licenses = LICENSE_EVENT_BUS or LICENSE_SMS_MMS val licenses = LICENSE_EVENT_BUS or LICENSE_SMS_MMS or LICENSE_INDICATOR_FAST_SCROLL
val faqItems = arrayListOf( val faqItems = arrayListOf(
FAQItem(R.string.faq_1_title, R.string.faq_1_text), FAQItem(R.string.faq_1_title, R.string.faq_1_text),

View File

@ -1,9 +1,11 @@
package com.simplemobiletools.smsmessenger.activities package com.simplemobiletools.smsmessenger.activities
import android.content.Intent import android.content.Intent
import android.content.res.ColorStateList
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.WindowManager import android.view.WindowManager
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
@ -14,6 +16,8 @@ import com.simplemobiletools.smsmessenger.helpers.*
import com.simplemobiletools.smsmessenger.models.Contact import com.simplemobiletools.smsmessenger.models.Contact
import kotlinx.android.synthetic.main.activity_conversation.* import kotlinx.android.synthetic.main.activity_conversation.*
import kotlinx.android.synthetic.main.item_suggested_contact.view.* import kotlinx.android.synthetic.main.item_suggested_contact.view.*
import java.util.*
import kotlin.collections.ArrayList
class NewConversationActivity : SimpleActivity() { class NewConversationActivity : SimpleActivity() {
private var allContacts = ArrayList<Contact>() private var allContacts = ArrayList<Contact>()
@ -73,6 +77,18 @@ class NewConversationActivity : SimpleActivity() {
} }
} }
} }
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 myList = ColorStateList(states, colors)
contacts_letter_fastscroller.textColor = myList
contacts_letter_fastscroller_thumb.setupWithFastScroller(contacts_letter_fastscroller)
contacts_letter_fastscroller_thumb.textColor = config.primaryColor.getContrastColor()
} }
private fun isThirdPartyIntent(): Boolean { private fun isThirdPartyIntent(): Boolean {
@ -88,6 +104,7 @@ class NewConversationActivity : SimpleActivity() {
fillSuggestedContacts { fillSuggestedContacts {
getAvailableContacts { getAvailableContacts {
allContacts = it allContacts = it
runOnUiThread { runOnUiThread {
setupAdapter(allContacts) setupAdapter(allContacts)
} }
@ -112,6 +129,8 @@ class NewConversationActivity : SimpleActivity() {
}.apply { }.apply {
contacts_list.adapter = this contacts_list.adapter = this
} }
setupLetterFastscroller(contacts)
} }
private fun fillSuggestedContacts(callback: () -> Unit) { private fun fillSuggestedContacts(callback: () -> Unit) {
@ -142,6 +161,22 @@ class NewConversationActivity : SimpleActivity() {
} }
} }
private fun setupLetterFastscroller(contacts: ArrayList<Contact>) {
contacts_letter_fastscroller.setupWithRecyclerView(contacts_list, { position ->
try {
val name = contacts[position].name
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("")
}
})
}
private fun launchThreadActivity(phoneNumber: String, name: String) { private fun launchThreadActivity(phoneNumber: String, name: String) {
val text = intent.getStringExtra(Intent.EXTRA_TEXT) ?: "" val text = intent.getStringExtra(Intent.EXTRA_TEXT) ?: ""
Intent(this, ThreadActivity::class.java).apply { Intent(this, ThreadActivity::class.java).apply {

View File

@ -105,4 +105,22 @@
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/contacts_letter_fastscroller"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/contacts_list"
android:layout_alignParentEnd="true"
android:paddingTop="@dimen/big_margin"
android:paddingBottom="@dimen/big_margin" />
<com.reddit.indicatorfastscroll.FastScrollerThumbView
android:id="@+id/contacts_letter_fastscroller_thumb"
android:layout_width="@dimen/fab_size"
android:layout_height="match_parent"
android:layout_alignTop="@+id/contacts_letter_fastscroller"
android:layout_alignBottom="@+id/contacts_letter_fastscroller"
android:layout_marginEnd="@dimen/activity_margin"
android:layout_toStartOf="@+id/contacts_letter_fastscroller" />
</RelativeLayout> </RelativeLayout>