mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
adding a letters fastscroller at the contact selector dialog
This commit is contained in:
@ -1,22 +1,43 @@
|
||||
package com.simplemobiletools.dialer.dialogs
|
||||
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
||||
import com.simplemobiletools.commons.extensions.getColorStateList
|
||||
import com.simplemobiletools.commons.extensions.getContrastColor
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.models.SimpleContact
|
||||
import com.simplemobiletools.dialer.R
|
||||
import com.simplemobiletools.dialer.activities.SimpleActivity
|
||||
import com.simplemobiletools.dialer.adapters.ContactsAdapter
|
||||
import kotlinx.android.synthetic.main.layout_select_contact.view.*
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import kotlinx.android.synthetic.main.dialog_select_contact.view.*
|
||||
import java.util.*
|
||||
|
||||
class SelectContactDialog(val activity: SimpleActivity, allContacts: ArrayList<SimpleContact>, val callback: (selectedContact: SimpleContact) -> Unit) {
|
||||
class SelectContactDialog(val activity: SimpleActivity, contacts: ArrayList<SimpleContact>, val callback: (selectedContact: SimpleContact) -> Unit) {
|
||||
private var dialog: AlertDialog? = null
|
||||
private var view = activity.layoutInflater.inflate(R.layout.layout_select_contact, null)
|
||||
private var view = activity.layoutInflater.inflate(R.layout.dialog_select_contact, null)
|
||||
|
||||
init {
|
||||
view.select_contact_list.adapter = ContactsAdapter(activity, allContacts, view.select_contact_list) {
|
||||
view.apply {
|
||||
letter_fastscroller.textColor = context.config.textColor.getColorStateList()
|
||||
letter_fastscroller_thumb.setupWithFastScroller(letter_fastscroller)
|
||||
letter_fastscroller_thumb.textColor = context.config.primaryColor.getContrastColor()
|
||||
|
||||
letter_fastscroller.setupWithRecyclerView(select_contact_list, { position ->
|
||||
try {
|
||||
val name = contacts[position].name
|
||||
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
||||
FastScrollItemIndicator.Text(character.toUpperCase(Locale.getDefault()))
|
||||
} catch (e: Exception) {
|
||||
FastScrollItemIndicator.Text("")
|
||||
}
|
||||
})
|
||||
|
||||
select_contact_list.adapter = ContactsAdapter(activity, contacts, select_contact_list) {
|
||||
callback(it as SimpleContact)
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
|
33
app/src/main/res/layout/dialog_select_contact.xml
Normal file
33
app/src/main/res/layout/dialog_select_contact.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/select_contact_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/select_contact_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||
|
||||
<com.reddit.indicatorfastscroll.FastScrollerView
|
||||
android:id="@+id/letter_fastscroller"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:paddingTop="@dimen/big_margin"
|
||||
android:paddingBottom="@dimen/big_margin" />
|
||||
|
||||
<com.reddit.indicatorfastscroll.FastScrollerThumbView
|
||||
android:id="@+id/letter_fastscroller_thumb"
|
||||
android:layout_width="@dimen/fab_size"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignTop="@+id/letter_fastscroller"
|
||||
android:layout_alignBottom="@+id/letter_fastscroller"
|
||||
android:layout_marginEnd="@dimen/activity_margin"
|
||||
android:layout_toStartOf="@+id/letter_fastscroller" />
|
||||
|
||||
</RelativeLayout>
|
@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/select_contact_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/select_contact_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||
|
||||
</RelativeLayout>
|
Reference in New Issue
Block a user