use the new contact avatars at the Select Contact dialog and screens too
This commit is contained in:
parent
9e51d96afb
commit
7bd9d34cd0
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.contacts.pro.adapters
|
||||
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.util.SparseArray
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
|
@ -7,7 +8,6 @@ import android.view.ViewGroup
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
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.bumptech.glide.signature.ObjectKey
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
|
@ -27,20 +27,14 @@ class SelectContactsAdapter(val activity: SimpleActivity, var contacts: ArrayLis
|
|||
private val itemViews = SparseArray<View>()
|
||||
private val selectedPositions = HashSet<Int>()
|
||||
private val config = activity.config
|
||||
private val textColor = config.textColor
|
||||
private val adjustedPrimaryColor = activity.getAdjustedPrimaryColor()
|
||||
private val fontSize = activity.getTextSize()
|
||||
|
||||
private val contactDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_person_vector, textColor)
|
||||
private val showContactThumbnails = config.showContactThumbnails
|
||||
private val showPhoneNumbers = config.showPhoneNumbers
|
||||
private val itemLayout = if (showPhoneNumbers) R.layout.item_add_favorite_with_number else R.layout.item_add_favorite_without_number
|
||||
private var textToHighlight = ""
|
||||
|
||||
private var smallPadding = activity.resources.getDimension(R.dimen.small_margin).toInt()
|
||||
private var mediumPadding = activity.resources.getDimension(R.dimen.medium_margin).toInt()
|
||||
private var bigPadding = activity.resources.getDimension(R.dimen.normal_margin).toInt()
|
||||
|
||||
init {
|
||||
contacts.forEachIndexed { index, contact ->
|
||||
if (selectedContacts.asSequence().map { it.id }.contains(contact.id)) {
|
||||
|
@ -121,11 +115,6 @@ class SelectContactsAdapter(val activity: SimpleActivity, var contacts: ArrayLis
|
|||
|
||||
contact_name.setTextColor(textColor)
|
||||
contact_name.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
|
||||
if (!showContactThumbnails && !showPhoneNumbers) {
|
||||
contact_name.setPadding(bigPadding, bigPadding, bigPadding, bigPadding)
|
||||
} else {
|
||||
contact_name.setPadding(if (showContactThumbnails) smallPadding else bigPadding, smallPadding, smallPadding, 0)
|
||||
}
|
||||
|
||||
if (contact_number != null) {
|
||||
val phoneNumberToUse = if (textToHighlight.isEmpty()) {
|
||||
|
@ -137,7 +126,6 @@ class SelectContactsAdapter(val activity: SimpleActivity, var contacts: ArrayLis
|
|||
val numberText = phoneNumberToUse?.value ?: ""
|
||||
contact_number.text = if (textToHighlight.isEmpty()) numberText else numberText.highlightTextPart(textToHighlight, adjustedPrimaryColor, false, true)
|
||||
contact_number.setTextColor(textColor)
|
||||
contact_number.setPadding(if (showContactThumbnails) smallPadding else bigPadding, 0, smallPadding, 0)
|
||||
contact_number.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
|
||||
}
|
||||
|
||||
|
@ -150,40 +138,36 @@ class SelectContactsAdapter(val activity: SimpleActivity, var contacts: ArrayLis
|
|||
}
|
||||
|
||||
contact_tmb.beVisibleIf(showContactThumbnails)
|
||||
|
||||
if (showContactThumbnails) {
|
||||
if (contact.photoUri.isNotEmpty()) {
|
||||
val avatarName = when {
|
||||
contact.isABusinessContact() -> contact.getFullCompany()
|
||||
config.startNameWithSurname -> contact.surname
|
||||
else -> contact.firstName
|
||||
}
|
||||
|
||||
val placeholderImage = BitmapDrawable(resources, context.getContactLetterIcon(avatarName))
|
||||
|
||||
if (contact.photoUri.isEmpty() && contact.photo == null) {
|
||||
contact_tmb.setImageDrawable(placeholderImage)
|
||||
} else {
|
||||
val options = RequestOptions()
|
||||
.signature(ObjectKey(contact.photoUri))
|
||||
.signature(ObjectKey(contact.getSignatureKey()))
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.error(contactDrawable)
|
||||
.error(placeholderImage)
|
||||
.centerCrop()
|
||||
|
||||
if (!activity.isDestroyed && !activity.isFinishing) {
|
||||
Glide.with(activity)
|
||||
.load(contact.photoUri)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.apply(options)
|
||||
.apply(RequestOptions.circleCropTransform())
|
||||
.into(contact_tmb)
|
||||
contact_tmb.setPadding(smallPadding, smallPadding, smallPadding, smallPadding)
|
||||
val itemToLoad: Any? = if (contact.photoUri.isNotEmpty()) {
|
||||
contact.photoUri
|
||||
} else {
|
||||
contact.photo
|
||||
}
|
||||
} else if (contact.photo != null) {
|
||||
val options = RequestOptions()
|
||||
.signature(ObjectKey(contact.hashCode()))
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.error(contactDrawable)
|
||||
.centerCrop()
|
||||
|
||||
Glide.with(activity)
|
||||
.load(contact.photo)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.load(itemToLoad)
|
||||
.apply(options)
|
||||
.apply(RequestOptions.circleCropTransform())
|
||||
.into(contact_tmb)
|
||||
contact_tmb.setPadding(smallPadding, smallPadding, smallPadding, smallPadding)
|
||||
} else {
|
||||
contact_tmb.setPadding(mediumPadding, mediumPadding, mediumPadding, mediumPadding)
|
||||
contact_tmb.setImageDrawable(contactDrawable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,16 +12,19 @@
|
|||
android:id="@+id/contact_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:paddingEnd="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/medium_margin">
|
||||
android:minHeight="@dimen/min_row_height"
|
||||
android:paddingStart="@dimen/tiny_margin"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
android:paddingBottom="@dimen/normal_margin">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_tmb"
|
||||
android:layout_width="@dimen/normal_icon_size"
|
||||
android:layout_height="@dimen/normal_icon_size"
|
||||
android:layout_centerVertical="true"
|
||||
android:padding="@dimen/medium_margin"
|
||||
android:layout_marginStart="@dimen/small_margin"
|
||||
android:padding="@dimen/tiny_margin"
|
||||
android:src="@drawable/ic_person_vector" />
|
||||
|
||||
<TextView
|
||||
|
@ -32,8 +35,8 @@
|
|||
android:layout_toEndOf="@+id/contact_tmb"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:paddingStart="@dimen/small_margin"
|
||||
android:paddingEnd="@dimen/small_margin"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
tools:text="John Doe" />
|
||||
|
||||
|
@ -47,6 +50,9 @@
|
|||
android:layout_toEndOf="@+id/contact_tmb"
|
||||
android:alpha="0.6"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
tools:text="0123 456 789" />
|
||||
|
||||
|
|
|
@ -12,16 +12,19 @@
|
|||
android:id="@+id/contact_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/tiny_margin"
|
||||
android:paddingEnd="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/tiny_margin">
|
||||
android:minHeight="@dimen/min_row_height"
|
||||
android:paddingStart="@dimen/tiny_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
android:paddingBottom="@dimen/medium_margin">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_tmb"
|
||||
android:layout_width="@dimen/normal_icon_size"
|
||||
android:layout_height="@dimen/normal_icon_size"
|
||||
android:layout_centerVertical="true"
|
||||
android:padding="@dimen/medium_margin"
|
||||
android:layout_marginStart="@dimen/small_margin"
|
||||
android:padding="@dimen/tiny_margin"
|
||||
android:src="@drawable/ic_person_vector" />
|
||||
|
||||
<TextView
|
||||
|
@ -34,6 +37,8 @@
|
|||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
android:textSize="@dimen/big_text_size"
|
||||
tools:text="John Doe" />
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
android:layout_alignStart="@+id/contact_name"
|
||||
android:layout_toEndOf="@+id/contact_tmb"
|
||||
android:alpha="0.6"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
|
|
Loading…
Reference in New Issue