mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
Merge pull request #648 from Merkost/speed_dial_search
Speed dial search implemented
This commit is contained in:
@ -65,7 +65,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:2462c80e58'
|
implementation 'com.github.SimpleMobileTools:Simple-Commons:91763fe00f'
|
||||||
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
|
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
|
||||||
implementation 'me.grantland:autofittextview:0.2.1'
|
implementation 'me.grantland:autofittextview:0.2.1'
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
|
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
|
||||||
|
@ -217,8 +217,9 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun changeColumnCount() {
|
private fun changeColumnCount() {
|
||||||
val items = (CONTACTS_GRID_MIN_COLUMNS_COUNT..CONTACTS_GRID_MAX_COLUMNS_COUNT).map {
|
val items = ArrayList<RadioItem>()
|
||||||
RadioItem(it, resources.getQuantityString(R.plurals.column_counts, it, it))
|
for (i in 1..CONTACTS_GRID_MAX_COLUMNS_COUNT) {
|
||||||
|
items.add(RadioItem(i, resources.getQuantityString(R.plurals.column_counts, i, i)))
|
||||||
}
|
}
|
||||||
|
|
||||||
val currentColumnCount = config.contactsGridColumnCount
|
val currentColumnCount = config.contactsGridColumnCount
|
||||||
|
@ -149,9 +149,9 @@ class ContactsAdapter(
|
|||||||
|
|
||||||
override fun getItemCount() = contacts.size
|
override fun getItemCount() = contacts.size
|
||||||
|
|
||||||
fun updateItems(newItems: ArrayList<Contact>, highlightText: String = "") {
|
fun updateItems(newItems: List<Contact>, highlightText: String = "") {
|
||||||
if (newItems.hashCode() != contacts.hashCode()) {
|
if (newItems.hashCode() != contacts.hashCode()) {
|
||||||
contacts = newItems.clone() as ArrayList<Contact>
|
contacts = ArrayList(newItems)
|
||||||
textToHighlight = highlightText
|
textToHighlight = highlightText
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
@ -351,7 +351,7 @@ class ContactsAdapter(
|
|||||||
val layoutManager = recyclerView.layoutManager
|
val layoutManager = recyclerView.layoutManager
|
||||||
if (layoutManager is GridLayoutManager) {
|
if (layoutManager is GridLayoutManager) {
|
||||||
val currentSpanCount = layoutManager.spanCount
|
val currentSpanCount = layoutManager.spanCount
|
||||||
val newSpanCount = (currentSpanCount - 1).coerceIn(CONTACTS_GRID_MIN_COLUMNS_COUNT, CONTACTS_GRID_MAX_COLUMNS_COUNT)
|
val newSpanCount = (currentSpanCount - 1).coerceIn(1, CONTACTS_GRID_MAX_COLUMNS_COUNT)
|
||||||
layoutManager.spanCount = newSpanCount
|
layoutManager.spanCount = newSpanCount
|
||||||
recyclerView.requestLayout()
|
recyclerView.requestLayout()
|
||||||
onSpanCountListener(newSpanCount)
|
onSpanCountListener(newSpanCount)
|
||||||
@ -362,7 +362,7 @@ class ContactsAdapter(
|
|||||||
val layoutManager = recyclerView.layoutManager
|
val layoutManager = recyclerView.layoutManager
|
||||||
if (layoutManager is GridLayoutManager) {
|
if (layoutManager is GridLayoutManager) {
|
||||||
val currentSpanCount = layoutManager.spanCount
|
val currentSpanCount = layoutManager.spanCount
|
||||||
val newSpanCount = (currentSpanCount + 1).coerceIn(CONTACTS_GRID_MIN_COLUMNS_COUNT, CONTACTS_GRID_MAX_COLUMNS_COUNT)
|
val newSpanCount = (currentSpanCount + 1).coerceIn(1, CONTACTS_GRID_MAX_COLUMNS_COUNT)
|
||||||
layoutManager.spanCount = newSpanCount
|
layoutManager.spanCount = newSpanCount
|
||||||
recyclerView.requestLayout()
|
recyclerView.requestLayout()
|
||||||
onSpanCountListener(newSpanCount)
|
onSpanCountListener(newSpanCount)
|
||||||
|
@ -1,20 +1,28 @@
|
|||||||
package com.simplemobiletools.dialer.dialogs
|
package com.simplemobiletools.dialer.dialogs
|
||||||
|
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.view.View
|
||||||
|
import android.view.inputmethod.EditorInfo
|
||||||
|
import android.widget.EditText
|
||||||
|
import android.widget.ImageView
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.models.contacts.Contact
|
import com.simplemobiletools.commons.models.contacts.Contact
|
||||||
|
import com.simplemobiletools.commons.views.MySearchMenu
|
||||||
import com.simplemobiletools.dialer.R
|
import com.simplemobiletools.dialer.R
|
||||||
import com.simplemobiletools.dialer.activities.SimpleActivity
|
import com.simplemobiletools.dialer.activities.SimpleActivity
|
||||||
import com.simplemobiletools.dialer.adapters.ContactsAdapter
|
import com.simplemobiletools.dialer.adapters.ContactsAdapter
|
||||||
import kotlinx.android.synthetic.main.dialog_select_contact.view.letter_fastscroller
|
import kotlinx.android.synthetic.main.dialog_select_contact.view.*
|
||||||
import kotlinx.android.synthetic.main.dialog_select_contact.view.letter_fastscroller_thumb
|
|
||||||
import kotlinx.android.synthetic.main.dialog_select_contact.view.select_contact_list
|
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
class SelectContactDialog(val activity: SimpleActivity, contacts: MutableList<Contact>, val callback: (selectedContact: Contact) -> Unit) {
|
class SelectContactDialog(val activity: SimpleActivity, val contacts: List<Contact>, val callback: (selectedContact: Contact) -> Unit) {
|
||||||
private var dialog: AlertDialog? = null
|
private var dialog: AlertDialog? = null
|
||||||
private var view = activity.layoutInflater.inflate(R.layout.dialog_select_contact, null)
|
private var view = activity.layoutInflater.inflate(R.layout.dialog_select_contact, null)
|
||||||
|
private val searchView = view.contact_search_view
|
||||||
|
private val searchEditText = view.findViewById<EditText>(R.id.top_toolbar_search)
|
||||||
|
private val searchViewAppBarLayout = view.findViewById<View>(R.id.top_app_bar_layout)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
view.apply {
|
view.apply {
|
||||||
@ -23,7 +31,32 @@ class SelectContactDialog(val activity: SimpleActivity, contacts: MutableList<Co
|
|||||||
letter_fastscroller_thumb.textColor = context.getProperPrimaryColor().getContrastColor()
|
letter_fastscroller_thumb.textColor = context.getProperPrimaryColor().getContrastColor()
|
||||||
letter_fastscroller_thumb.thumbColor = context.getProperPrimaryColor().getColorStateList()
|
letter_fastscroller_thumb.thumbColor = context.getProperPrimaryColor().getColorStateList()
|
||||||
|
|
||||||
letter_fastscroller.setupWithRecyclerView(select_contact_list, { position ->
|
setupLetterFastScroller(contacts)
|
||||||
|
configureSearchView()
|
||||||
|
|
||||||
|
select_contact_list.adapter = ContactsAdapter(activity, contacts.toMutableList(), select_contact_list, allowLongClick = false) {
|
||||||
|
callback(it as Contact)
|
||||||
|
dialog?.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.getAlertDialogBuilder()
|
||||||
|
.setNegativeButton(R.string.cancel, null)
|
||||||
|
.setOnKeyListener { _, i, keyEvent ->
|
||||||
|
if (keyEvent.action == KeyEvent.ACTION_UP && i == KeyEvent.KEYCODE_BACK) {
|
||||||
|
backPressed()
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
.apply {
|
||||||
|
activity.setupDialogStuff(view, this, R.string.choose_contact) { alertDialog ->
|
||||||
|
dialog = alertDialog
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupLetterFastScroller(contacts: List<Contact>) {
|
||||||
|
view.letter_fastscroller.setupWithRecyclerView(view.select_contact_list, { position ->
|
||||||
try {
|
try {
|
||||||
val name = contacts[position].getNameToDisplay()
|
val name = contacts[position].getNameToDisplay()
|
||||||
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
val character = if (name.isNotEmpty()) name.substring(0, 1) else ""
|
||||||
@ -32,19 +65,82 @@ class SelectContactDialog(val activity: SimpleActivity, contacts: MutableList<Co
|
|||||||
FastScrollItemIndicator.Text("")
|
FastScrollItemIndicator.Text("")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
select_contact_list.adapter = ContactsAdapter(activity, contacts, select_contact_list, allowLongClick = false) {
|
private fun configureSearchView() = with(searchView) {
|
||||||
callback(it as Contact)
|
updateHintText(context.getString(R.string.search_contacts))
|
||||||
|
searchEditText.imeOptions = EditorInfo.IME_ACTION_DONE
|
||||||
|
|
||||||
|
toggleHideOnScroll(true)
|
||||||
|
setupMenu()
|
||||||
|
setSearchViewListeners()
|
||||||
|
updateSearchViewUi()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun MySearchMenu.updateSearchViewUi() {
|
||||||
|
getToolbar().beInvisible()
|
||||||
|
updateColors()
|
||||||
|
setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
searchViewAppBarLayout.setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun MySearchMenu.setSearchViewListeners() {
|
||||||
|
onSearchOpenListener = {
|
||||||
|
updateSearchViewLeftIcon(R.drawable.ic_cross_vector)
|
||||||
|
}
|
||||||
|
onSearchClosedListener = {
|
||||||
|
searchEditText.clearFocus()
|
||||||
|
activity.hideKeyboard(searchEditText)
|
||||||
|
updateSearchViewLeftIcon(R.drawable.ic_search_vector)
|
||||||
|
}
|
||||||
|
|
||||||
|
onSearchTextChangedListener = { text ->
|
||||||
|
filterContactListBySearchQuery(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateSearchViewLeftIcon(iconResId: Int) = with(view.findViewById<ImageView>(R.id.top_toolbar_search_icon)) {
|
||||||
|
post {
|
||||||
|
setImageResource(iconResId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun filterContactListBySearchQuery(query: String) {
|
||||||
|
val adapter = view.select_contact_list.adapter as? ContactsAdapter
|
||||||
|
var contactsToShow = contacts
|
||||||
|
if (query.isNotEmpty()) {
|
||||||
|
contactsToShow = contacts.filter { it.name.contains(query, true) }
|
||||||
|
}
|
||||||
|
checkPlaceholderVisibility(contactsToShow)
|
||||||
|
|
||||||
|
if (adapter?.contacts != contactsToShow) {
|
||||||
|
adapter?.updateItems(contactsToShow)
|
||||||
|
setupLetterFastScroller(contactsToShow)
|
||||||
|
|
||||||
|
view.select_contact_list.apply {
|
||||||
|
post {
|
||||||
|
scrollToPosition(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkPlaceholderVisibility(contacts: List<Contact>) = with(view) {
|
||||||
|
contacts_empty_placeholder.beVisibleIf(contacts.isEmpty())
|
||||||
|
|
||||||
|
if (contact_search_view.isSearchOpen) {
|
||||||
|
contacts_empty_placeholder.text = context.getString(R.string.no_items_found)
|
||||||
|
}
|
||||||
|
|
||||||
|
letter_fastscroller.beVisibleIf(contacts_empty_placeholder.isGone())
|
||||||
|
letter_fastscroller_thumb.beVisibleIf(contacts_empty_placeholder.isGone())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun backPressed() {
|
||||||
|
if (searchView.isSearchOpen) {
|
||||||
|
searchView.closeSearch()
|
||||||
|
} else {
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.getAlertDialogBuilder()
|
|
||||||
.setNegativeButton(R.string.cancel, null)
|
|
||||||
.apply {
|
|
||||||
activity.setupDialogStuff(view, this) { alertDialog ->
|
|
||||||
dialog = alertDialog
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,33 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MySearchMenu
|
||||||
|
android:id="@+id/contact_search_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/medium_margin"
|
||||||
|
android:paddingTop="@dimen/medium_margin" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
|
android:id="@+id/contacts_empty_placeholder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/contact_search_view"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingStart="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingEnd="@dimen/activity_margin"
|
||||||
|
android:text="@string/no_contacts_found"
|
||||||
|
android:textSize="@dimen/bigger_text_size"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
android:id="@+id/select_contact_list"
|
android:id="@+id/select_contact_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/contacts_empty_placeholder"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:scrollbars="none"
|
android:scrollbars="none"
|
||||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||||
@ -17,6 +40,7 @@
|
|||||||
android:id="@+id/letter_fastscroller"
|
android:id="@+id/letter_fastscroller"
|
||||||
android:layout_width="32dp"
|
android:layout_width="32dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/contact_search_view"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:paddingTop="@dimen/big_margin"
|
android:paddingTop="@dimen/big_margin"
|
||||||
android:paddingBottom="@dimen/big_margin" />
|
android:paddingBottom="@dimen/big_margin" />
|
||||||
@ -29,5 +53,4 @@
|
|||||||
android:layout_alignBottom="@+id/letter_fastscroller"
|
android:layout_alignBottom="@+id/letter_fastscroller"
|
||||||
android:layout_marginEnd="@dimen/activity_margin"
|
android:layout_marginEnd="@dimen/activity_margin"
|
||||||
android:layout_toStartOf="@+id/letter_fastscroller" />
|
android:layout_toStartOf="@+id/letter_fastscroller" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
Reference in New Issue
Block a user