use a helper function at loading contact thumbnails
This commit is contained in:
parent
d8080848c6
commit
f96f992203
|
@ -2,15 +2,11 @@ package com.simplemobiletools.smsmessenger.adapters
|
|||
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.net.Uri
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
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.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.formatDateOrTime
|
||||
|
@ -22,6 +18,7 @@ import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
|||
import com.simplemobiletools.smsmessenger.extensions.deleteThread
|
||||
import com.simplemobiletools.smsmessenger.extensions.getNameLetter
|
||||
import com.simplemobiletools.smsmessenger.extensions.getNotificationLetterIcon
|
||||
import com.simplemobiletools.smsmessenger.extensions.loadImage
|
||||
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||
import com.simplemobiletools.smsmessenger.models.Message
|
||||
import kotlinx.android.synthetic.main.item_message.view.*
|
||||
|
@ -142,20 +139,8 @@ class MessagesAdapter(
|
|||
}
|
||||
|
||||
val participant = message.participants.first()
|
||||
val uri = Uri.parse(participant.photoUri)
|
||||
val placeholder = BitmapDrawable(activity.resources, activity.getNotificationLetterIcon(participant.name.getNameLetter()))
|
||||
val options = RequestOptions()
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.error(placeholder)
|
||||
.centerCrop()
|
||||
|
||||
Glide.with(context)
|
||||
.load(uri)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.placeholder(placeholder)
|
||||
.apply(options)
|
||||
.apply(RequestOptions.circleCropTransform())
|
||||
.into(message_image)
|
||||
context.loadImage(participant.photoUri, message_image, placeholder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.content.Intent
|
|||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.media.AudioAttributes
|
||||
import android.media.AudioManager
|
||||
import android.media.RingtoneManager
|
||||
|
@ -22,8 +23,13 @@ import android.provider.ContactsContract.CommonDataKinds.StructuredName
|
|||
import android.provider.ContactsContract.PhoneLookup
|
||||
import android.provider.Telephony.*
|
||||
import android.text.TextUtils
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.core.app.NotificationCompat
|
||||
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.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
|
@ -511,3 +517,18 @@ fun Context.getNotificationLetterIcon(letter: String): Bitmap {
|
|||
view.draw(canvas)
|
||||
return bitmap
|
||||
}
|
||||
|
||||
fun Context.loadImage(path: String, imageView: ImageView, placeholder: Drawable) {
|
||||
val options = RequestOptions()
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.error(placeholder)
|
||||
.centerCrop()
|
||||
|
||||
Glide.with(this)
|
||||
.load(path)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.placeholder(placeholder)
|
||||
.apply(options)
|
||||
.apply(RequestOptions.circleCropTransform())
|
||||
.into(imageView)
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@ package com.simplemobiletools.smsmessenger.models
|
|||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.widget.ImageView
|
||||
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.smsmessenger.extensions.loadImage
|
||||
|
||||
data class Contact(
|
||||
val id: Int,
|
||||
|
@ -19,18 +16,7 @@ data class Contact(
|
|||
if (photoUri.isEmpty()) {
|
||||
imageView.setImageDrawable(placeholder)
|
||||
} else {
|
||||
val options = RequestOptions()
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.error(placeholder)
|
||||
.centerCrop()
|
||||
|
||||
Glide.with(context)
|
||||
.load(photoUri)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.placeholder(placeholder)
|
||||
.apply(options)
|
||||
.apply(RequestOptions.circleCropTransform())
|
||||
.into(imageView)
|
||||
context.loadImage(photoUri, imageView, placeholder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue