forked from upstream-mirrors/quik
Clean up icon generation code
This commit is contained in:
+7
-4
@@ -6,6 +6,7 @@ import android.graphics.Bitmap
|
|||||||
import android.graphics.Path
|
import android.graphics.Path
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
|
import android.view.ContextThemeWrapper
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View.GONE
|
import android.view.View.GONE
|
||||||
@@ -28,11 +29,12 @@ import timber.log.Timber
|
|||||||
|
|
||||||
fun Recipient.getThemedIcon(context: Context, theme: Colors.Theme, width: Int, height: Int): IconCompat {
|
fun Recipient.getThemedIcon(context: Context, theme: Colors.Theme, width: Int, height: Int): IconCompat {
|
||||||
var icon : IconCompat? = null
|
var icon : IconCompat? = null
|
||||||
if(contact != null) {
|
val photoUri = contact?.photoUri
|
||||||
|
if (photoUri != null) {
|
||||||
val req = GlideApp.with(context)
|
val req = GlideApp.with(context)
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.circleCrop()
|
.circleCrop()
|
||||||
.load(contact!!.photoUri)
|
.load(photoUri)
|
||||||
.submit(width, height)
|
.submit(width, height)
|
||||||
|
|
||||||
val bitmap = tryOrNull { req.get() }
|
val bitmap = tryOrNull { req.get() }
|
||||||
@@ -44,8 +46,9 @@ fun Recipient.getThemedIcon(context: Context, theme: Colors.Theme, width: Int, h
|
|||||||
if (icon == null) {
|
if (icon == null) {
|
||||||
// If there is no contact or no photo, create the default icon using the avatar_view layout
|
// If there is no contact or no photo, create the default icon using the avatar_view layout
|
||||||
try {
|
try {
|
||||||
val inflater = LayoutInflater.from(context)
|
val themedContext = ContextThemeWrapper(context, R.style.AppTheme)
|
||||||
val container = FrameLayout(context)
|
val inflater = LayoutInflater.from(themedContext)
|
||||||
|
val container = FrameLayout(themedContext)
|
||||||
container.layoutParams = FrameLayout.LayoutParams(width, height)
|
container.layoutParams = FrameLayout.LayoutParams(width, height)
|
||||||
val view = inflater.inflate(R.layout.avatar_view, container)
|
val view = inflater.inflate(R.layout.avatar_view, container)
|
||||||
val textView = view.findViewById<QkTextView>(R.id.initial)
|
val textView = view.findViewById<QkTextView>(R.id.initial)
|
||||||
|
|||||||
Reference in New Issue
Block a user