DirectReplyReceiver: fetch avatar in background

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-12-02 15:17:31 +01:00 committed by Tim Krüger
parent 4b46270362
commit 2b646845bf
No known key found for this signature in database
GPG Key ID: FECE3A7222C52A4E
2 changed files with 18 additions and 12 deletions

View File

@ -47,6 +47,7 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SYSTEM_NOTIFICATION_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SYSTEM_NOTIFICATION_ID
import io.reactivex.Observer import io.reactivex.Observer
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
@ -159,19 +160,25 @@ class DirectReplyReceiver : BroadcastReceiver() {
.extractMessagingStyleFromNotification(previousNotification) .extractMessagingStyleFromNotification(previousNotification)
// Add reply // Add reply
val avatarUrl = ApiUtils.getUrlForAvatar(currentUser.baseUrl, currentUser.userId, false) Single.fromCallable {
val me = Person.Builder() val avatarUrl = ApiUtils.getUrlForAvatar(currentUser.baseUrl, currentUser.userId, false)
.setName(currentUser.displayName) val me = Person.Builder()
.setIcon(NotificationUtils.loadAvatarSync(avatarUrl, context)) .setName(currentUser.displayName)
.build() .setIcon(NotificationUtils.loadAvatarSync(avatarUrl, context))
val message = NotificationCompat.MessagingStyle.Message(reply, System.currentTimeMillis(), me) .build()
previousStyle?.addMessage(message) val message = NotificationCompat.MessagingStyle.Message(reply, System.currentTimeMillis(), me)
previousStyle?.addMessage(message)
// Set the updated style // Set the updated style
previousBuilder.setStyle(previousStyle) previousBuilder.setStyle(previousStyle)
// Update the active notification. // Check if notification still exists
NotificationManagerCompat.from(context).notify(systemNotificationId!!, previousBuilder.build()) if (findActiveNotification(systemNotificationId!!) != null) {
NotificationManagerCompat.from(context).notify(systemNotificationId!!, previousBuilder.build())
}
}
.subscribeOn(Schedulers.io())
.subscribe()
} }
companion object { companion object {

View File

@ -330,7 +330,6 @@ object NotificationUtils {
.data(avatarUrl) .data(avatarUrl)
.transformations(CircleCropTransformation()) .transformations(CircleCropTransformation())
.placeholder(R.drawable.account_circle_96dp) .placeholder(R.drawable.account_circle_96dp)
.placeholder(R.drawable.account_circle_96dp)
.target( .target(
onSuccess = { result -> onSuccess = { result ->
val bitmap = (result as BitmapDrawable).bitmap val bitmap = (result as BitmapDrawable).bitmap