mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Notifications: render room and user icons.
This commit is contained in:
committed by
Benoit Marty
parent
31afed1448
commit
c91e8e5050
@@ -35,6 +35,7 @@ dependencies {
|
|||||||
implementation(libs.androidx.security.crypto)
|
implementation(libs.androidx.security.crypto)
|
||||||
implementation(libs.network.retrofit)
|
implementation(libs.network.retrofit)
|
||||||
implementation(libs.serialization.json)
|
implementation(libs.serialization.json)
|
||||||
|
implementation(libs.coil)
|
||||||
|
|
||||||
implementation(projects.libraries.architecture)
|
implementation(projects.libraries.architecture)
|
||||||
implementation(projects.libraries.core)
|
implementation(projects.libraries.core)
|
||||||
|
|||||||
+26
-24
@@ -21,7 +21,13 @@ import android.graphics.Bitmap
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import androidx.core.graphics.drawable.IconCompat
|
import androidx.core.graphics.drawable.IconCompat
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
|
import coil.imageLoader
|
||||||
|
import coil.request.ImageRequest
|
||||||
|
import coil.transform.CircleCropTransformation
|
||||||
import io.element.android.libraries.di.ApplicationContext
|
import io.element.android.libraries.di.ApplicationContext
|
||||||
|
import io.element.android.libraries.matrix.api.media.MediaResolver
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -31,6 +37,7 @@ class NotificationBitmapLoader @Inject constructor(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get icon of a room.
|
* Get icon of a room.
|
||||||
|
* @param path mxc url
|
||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
fun getRoomBitmap(path: String?): Bitmap? {
|
fun getRoomBitmap(path: String?): Bitmap? {
|
||||||
@@ -43,18 +50,15 @@ class NotificationBitmapLoader @Inject constructor(
|
|||||||
@WorkerThread
|
@WorkerThread
|
||||||
private fun loadRoomBitmap(path: String): Bitmap? {
|
private fun loadRoomBitmap(path: String): Bitmap? {
|
||||||
return try {
|
return try {
|
||||||
null
|
val imageRequest = ImageRequest.Builder(context)
|
||||||
/* TODO Notification
|
.data(MediaResolver.Meta(path, MediaResolver.Kind.Thumbnail(128)))
|
||||||
Glide.with(context)
|
.build()
|
||||||
.asBitmap()
|
runBlocking {
|
||||||
.load(path)
|
val result = context.imageLoader.execute(imageRequest)
|
||||||
.format(DecodeFormat.PREFER_ARGB_8888)
|
result.drawable?.toBitmap()
|
||||||
.signature(ObjectKey("room-icon-notification"))
|
}
|
||||||
.submit()
|
|
||||||
.get()
|
|
||||||
*/
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "decodeFile failed")
|
Timber.e(e, "Unable to load room bitmap")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,6 +66,7 @@ class NotificationBitmapLoader @Inject constructor(
|
|||||||
/**
|
/**
|
||||||
* Get icon of a user.
|
* Get icon of a user.
|
||||||
* Before Android P, this does nothing because the icon won't be used
|
* Before Android P, this does nothing because the icon won't be used
|
||||||
|
* @param path mxc url
|
||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
fun getUserIcon(path: String?): IconCompat? {
|
fun getUserIcon(path: String?): IconCompat? {
|
||||||
@@ -75,20 +80,17 @@ class NotificationBitmapLoader @Inject constructor(
|
|||||||
@WorkerThread
|
@WorkerThread
|
||||||
private fun loadUserIcon(path: String): IconCompat? {
|
private fun loadUserIcon(path: String): IconCompat? {
|
||||||
return try {
|
return try {
|
||||||
null
|
val imageRequest = ImageRequest.Builder(context)
|
||||||
/* TODO Notification
|
.data(MediaResolver.Meta(path, MediaResolver.Kind.Thumbnail(128)))
|
||||||
val bitmap = Glide.with(context)
|
.transformations(CircleCropTransformation())
|
||||||
.asBitmap()
|
.build()
|
||||||
.load(path)
|
val bitmap = runBlocking {
|
||||||
.transform(CircleCrop())
|
val result = context.imageLoader.execute(imageRequest)
|
||||||
.format(DecodeFormat.PREFER_ARGB_8888)
|
result.drawable?.toBitmap()
|
||||||
.signature(ObjectKey("user-icon-notification"))
|
}
|
||||||
.submit()
|
return bitmap?.let { IconCompat.createWithBitmap(it) }
|
||||||
.get()
|
|
||||||
IconCompat.createWithBitmap(bitmap)
|
|
||||||
*/
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "decodeFile failed")
|
Timber.e(e, "Unable to load user bitmap")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user