Merge branch 'master' into fix_ime_inset

This commit is contained in:
Tibor Kaputa 2023-05-14 16:14:57 +02:00 committed by GitHub
commit a25a3e5244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 221 additions and 9 deletions

View File

@ -63,7 +63,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:94b616f462' implementation 'com.github.SimpleMobileTools:Simple-Commons:8a1114e683'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3' implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61' implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

View File

@ -10,6 +10,7 @@ import android.media.AudioManager
import android.media.RingtoneManager import android.media.RingtoneManager
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.provider.ContactsContract.CommonDataKinds import android.provider.ContactsContract.CommonDataKinds
import android.provider.ContactsContract.CommonDataKinds.* import android.provider.ContactsContract.CommonDataKinds.*
import android.provider.MediaStore import android.provider.MediaStore
@ -17,12 +18,10 @@ import android.telephony.PhoneNumberUtils
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.WindowManager import android.view.WindowManager
import android.widget.EditText import android.widget.*
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.widget.doAfterTextChanged
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.dialogs.SelectAlarmSoundDialog import com.simplemobiletools.commons.dialogs.SelectAlarmSoundDialog
@ -34,7 +33,9 @@ import com.simplemobiletools.commons.models.contacts.*
import com.simplemobiletools.commons.models.contacts.Email import com.simplemobiletools.commons.models.contacts.Email
import com.simplemobiletools.commons.models.contacts.Event import com.simplemobiletools.commons.models.contacts.Event
import com.simplemobiletools.commons.models.contacts.Organization import com.simplemobiletools.commons.models.contacts.Organization
import com.simplemobiletools.commons.views.MyAutoCompleteTextView
import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.adapters.AutoCompleteTextViewAdapter
import com.simplemobiletools.contacts.pro.dialogs.CustomLabelDialog import com.simplemobiletools.contacts.pro.dialogs.CustomLabelDialog
import com.simplemobiletools.contacts.pro.dialogs.ManageVisibleFieldsDialog import com.simplemobiletools.contacts.pro.dialogs.ManageVisibleFieldsDialog
import com.simplemobiletools.contacts.pro.dialogs.MyDatePickerDialog import com.simplemobiletools.contacts.pro.dialogs.MyDatePickerDialog
@ -59,6 +60,8 @@ class EditContactActivity : ContactActivity() {
private val CHOOSE_PHOTO = 2 private val CHOOSE_PHOTO = 2
private val REMOVE_PHOTO = 3 private val REMOVE_PHOTO = 3
private val AUTO_COMPLETE_DELAY = 5000L
private var mLastSavePromptTS = 0L private var mLastSavePromptTS = 0L
private var wasActivityInitialized = false private var wasActivityInitialized = false
private var lastPhotoIntentUri: Uri? = null private var lastPhotoIntentUri: Uri? = null
@ -261,6 +264,11 @@ class EditContactActivity : ContactActivity() {
setOnLongClickListener { toast(R.string.toggle_favorite); true; } setOnLongClickListener { toast(R.string.toggle_favorite); true; }
} }
val nameTextViews = arrayOf(contact_first_name, contact_middle_name, contact_surname).filter { it.isVisible() }
if (nameTextViews.isNotEmpty()) {
setupAutoComplete(nameTextViews)
}
updateTextColors(contact_scrollview) updateTextColors(contact_scrollview)
numberViewToColor?.setTextColor(properPrimaryColor) numberViewToColor?.setTextColor(properPrimaryColor)
emailViewToColor?.setTextColor(properPrimaryColor) emailViewToColor?.setTextColor(properPrimaryColor)
@ -1533,4 +1541,33 @@ class EditContactActivity : ContactActivity() {
getString(R.string.jabber) -> Im.PROTOCOL_JABBER getString(R.string.jabber) -> Im.PROTOCOL_JABBER
else -> Im.PROTOCOL_CUSTOM else -> Im.PROTOCOL_CUSTOM
} }
private fun setupAutoComplete(nameTextViews: List<MyAutoCompleteTextView>) {
ContactsHelper(this).getContacts { contacts ->
val adapter = AutoCompleteTextViewAdapter(this, contacts)
val handler = Handler(mainLooper)
nameTextViews.forEach { view ->
view.setAdapter(adapter)
view.setOnItemClickListener { _, _, position, _ ->
val selectedContact = adapter.resultList[position]
if (contact_first_name.isVisible()) {
contact_first_name.setText(selectedContact.firstName)
}
if (contact_middle_name.isVisible()) {
contact_middle_name.setText(selectedContact.middleName)
}
if (contact_surname.isVisible()) {
contact_surname.setText(selectedContact.surname)
}
}
view.doAfterTextChanged {
handler.postDelayed({
adapter.autoComplete = true
adapter.filter.filter(it)
}, AUTO_COMPLETE_DELAY)
}
}
}
}
} }

View File

@ -0,0 +1,114 @@
package com.simplemobiletools.contacts.pro.adapters
import android.graphics.drawable.BitmapDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Filter
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import com.simplemobiletools.commons.extensions.beGone
import com.simplemobiletools.commons.extensions.getProperBackgroundColor
import com.simplemobiletools.commons.extensions.getProperTextColor
import com.simplemobiletools.commons.extensions.normalizeString
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.models.contacts.Contact
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import kotlinx.android.synthetic.main.item_autocomplete_name_number.view.item_autocomplete_image
import kotlinx.android.synthetic.main.item_autocomplete_name_number.view.item_autocomplete_name
import kotlinx.android.synthetic.main.item_autocomplete_name_number.view.item_autocomplete_number
class AutoCompleteTextViewAdapter(
val activity: SimpleActivity,
val contacts: ArrayList<Contact>,
var autoComplete: Boolean = false
) : ArrayAdapter<Contact>(activity, 0, contacts) {
var resultList = ArrayList<Contact>()
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val contact = resultList[position]
var listItem = convertView
val nameToUse = contact.getNameToDisplay()
if (listItem == null || listItem.tag != nameToUse.isNotEmpty()) {
listItem = LayoutInflater.from(activity).inflate(R.layout.item_autocomplete_name_number, parent, false)
}
val placeholder = BitmapDrawable(activity.resources, SimpleContactsHelper(context).getContactLetterIcon(nameToUse))
listItem!!.apply {
setBackgroundColor(context.getProperBackgroundColor())
item_autocomplete_name.setTextColor(context.getProperTextColor())
item_autocomplete_number.setTextColor(context.getProperTextColor())
tag = nameToUse.isNotEmpty()
item_autocomplete_name.text = nameToUse
contact.phoneNumbers.apply {
val phoneNumber = firstOrNull { it.isPrimary }?.normalizedNumber ?: firstOrNull()?.normalizedNumber
if (phoneNumber.isNullOrEmpty()) {
item_autocomplete_number.beGone()
} else {
item_autocomplete_number.text = phoneNumber
}
}
val options = RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.error(placeholder)
.centerCrop()
Glide.with(context)
.load(contact.photoUri)
.transition(DrawableTransitionOptions.withCrossFade())
.placeholder(placeholder)
.apply(options)
.apply(RequestOptions.circleCropTransform())
.into(item_autocomplete_image)
}
return listItem
}
override fun getFilter() = object : Filter() {
override fun performFiltering(constraint: CharSequence?): FilterResults {
val filterResults = FilterResults()
if (constraint != null && autoComplete) {
val searchString = constraint.toString().normalizeString()
val results = mutableListOf<Contact>()
contacts.forEach {
if (it.getNameToDisplay().contains(searchString, true)) {
results.add(it)
}
}
results.sortWith(compareBy<Contact>
{ it.name.startsWith(searchString, true) }.thenBy
{ it.name.contains(searchString, true) })
results.reverse()
filterResults.values = results
filterResults.count = results.size
}
return filterResults
}
override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
if (results != null && results.count > 0) {
resultList.clear()
@Suppress("UNCHECKED_CAST")
resultList.addAll(results.values as List<Contact>)
notifyDataSetChanged()
} else {
notifyDataSetInvalidated()
}
}
override fun convertResultToString(resultValue: Any?) = (resultValue as? Contact)?.name
}
override fun getItem(index: Int) = resultList[index]
override fun getCount() = resultList.size
}

View File

@ -12,7 +12,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clipToPadding="false" android:clipToPadding="false"
android:scrollbars="none" android:scrollbars="none"
android:visibility="gone"> android:visibility="gone"
tools:visibility="visible">
<RelativeLayout <RelativeLayout
android:id="@+id/contact_holder" android:id="@+id/contact_holder"
@ -91,7 +92,7 @@
android:textCursorDrawable="@null" android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size" /> android:textSize="@dimen/bigger_text_size" />
<com.simplemobiletools.commons.views.MyEditText <com.simplemobiletools.commons.views.MyAutoCompleteTextView
android:id="@+id/contact_first_name" android:id="@+id/contact_first_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -100,6 +101,7 @@
android:layout_marginEnd="@dimen/activity_margin" android:layout_marginEnd="@dimen/activity_margin"
android:layout_marginBottom="@dimen/normal_margin" android:layout_marginBottom="@dimen/normal_margin"
android:layout_toEndOf="@+id/contact_name_image" android:layout_toEndOf="@+id/contact_name_image"
android:completionThreshold="2"
android:hint="@string/first_name" android:hint="@string/first_name"
android:inputType="textCapWords" android:inputType="textCapWords"
android:lines="1" android:lines="1"
@ -108,7 +110,7 @@
android:textCursorDrawable="@null" android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size" /> android:textSize="@dimen/bigger_text_size" />
<com.simplemobiletools.commons.views.MyEditText <com.simplemobiletools.commons.views.MyAutoCompleteTextView
android:id="@+id/contact_middle_name" android:id="@+id/contact_middle_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -117,6 +119,7 @@
android:layout_marginEnd="@dimen/activity_margin" android:layout_marginEnd="@dimen/activity_margin"
android:layout_marginBottom="@dimen/normal_margin" android:layout_marginBottom="@dimen/normal_margin"
android:layout_toEndOf="@+id/contact_name_image" android:layout_toEndOf="@+id/contact_name_image"
android:completionThreshold="2"
android:hint="@string/middle_name" android:hint="@string/middle_name"
android:inputType="textCapWords" android:inputType="textCapWords"
android:lines="1" android:lines="1"
@ -125,7 +128,7 @@
android:textCursorDrawable="@null" android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size" /> android:textSize="@dimen/bigger_text_size" />
<com.simplemobiletools.commons.views.MyEditText <com.simplemobiletools.commons.views.MyAutoCompleteTextView
android:id="@+id/contact_surname" android:id="@+id/contact_surname"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -134,6 +137,7 @@
android:layout_marginEnd="@dimen/activity_margin" android:layout_marginEnd="@dimen/activity_margin"
android:layout_marginBottom="@dimen/normal_margin" android:layout_marginBottom="@dimen/normal_margin"
android:layout_toEndOf="@+id/contact_name_image" android:layout_toEndOf="@+id/contact_name_image"
android:completionThreshold="2"
android:hint="@string/surname" android:hint="@string/surname"
android:inputType="textCapWords" android:inputType="textCapWords"
android:lines="1" android:lines="1"

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_autocomplete_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/small_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin">
<ImageView
android:id="@+id/item_autocomplete_image"
android:layout_width="@dimen/list_avatar_size"
android:layout_height="@dimen/list_avatar_size"
android:layout_margin="@dimen/tiny_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/item_autocomplete_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:lines="1"
android:maxLines="1"
android:paddingStart="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:singleLine="true"
android:textSize="@dimen/bigger_text_size"
app:layout_constraintBottom_toTopOf="@+id/item_autocomplete_number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/item_autocomplete_image"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="Simple Mobile" />
<TextView
android:id="@+id/item_autocomplete_number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@+id/item_autocomplete_name"
android:layout_marginEnd="8dp"
android:alpha="0.8"
android:lines="1"
android:maxLines="1"
android:paddingStart="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:singleLine="true"
android:textSize="@dimen/normal_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/item_autocomplete_image"
app:layout_constraintTop_toBottomOf="@+id/item_autocomplete_name"
tools:text="hello@simplemobiletools.com" />
</androidx.constraintlayout.widget.ConstraintLayout>