From 5a1242109da4e990a2bd4f0a51b8e81b30dba13c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 25 Jun 2019 16:52:34 +0200 Subject: [PATCH] Notification: display rooms and users' avatars --- .../vector/riotredesign/VectorApplication.kt | 16 ++++----- .../notifications/NotifiableEventResolver.kt | 36 ++++++++----------- .../NotificationBroadcastReceiver.kt | 2 +- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt index 6f8127536d..9bef712e0c 100644 --- a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt +++ b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt @@ -16,17 +16,11 @@ package im.vector.riotredesign -import android.app.AlarmManager import android.app.Application -import android.app.PendingIntent -import android.content.ComponentName import android.content.Context -import android.content.Intent -import android.content.ServiceConnection import android.content.res.Configuration import android.os.Handler import android.os.HandlerThread -import android.os.IBinder import androidx.core.provider.FontRequest import androidx.core.provider.FontsContractCompat import androidx.lifecycle.Lifecycle @@ -41,14 +35,13 @@ import com.github.piasy.biv.BigImageViewer import com.github.piasy.biv.loader.glide.GlideImageLoader import com.jakewharton.threetenabp.AndroidThreeTen import im.vector.matrix.android.api.Matrix -import im.vector.matrix.android.internal.session.sync.job.SyncService import im.vector.riotredesign.core.di.AppModule import im.vector.riotredesign.core.services.AlarmSyncBroadcastReceiver -import im.vector.riotredesign.core.services.VectorSyncService import im.vector.riotredesign.features.configuration.VectorConfiguration import im.vector.riotredesign.features.crypto.keysbackup.KeysBackupModule import im.vector.riotredesign.features.home.HomeModule import im.vector.riotredesign.features.lifecycle.VectorActivityLifecycleCallbacks +import im.vector.riotredesign.features.notifications.NotificationDrawerManager import im.vector.riotredesign.features.notifications.NotificationUtils import im.vector.riotredesign.features.notifications.PushRuleTriggerListener import im.vector.riotredesign.features.rageshake.VectorFileLogger @@ -64,7 +57,6 @@ import org.koin.standalone.StandAloneContext.startKoin import timber.log.Timber import java.text.SimpleDateFormat import java.util.* -import java.util.concurrent.TimeUnit class VectorApplication : Application() { @@ -75,6 +67,8 @@ class VectorApplication : Application() { val vectorConfiguration: VectorConfiguration by inject() + private val notificationDrawerManager by inject() + // var slowMode = false @@ -131,7 +125,9 @@ class VectorApplication : Application() { @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) fun entersBackground() { - Timber.i("App entered background") + Timber.i("App entered background") // call persistInfo + + notificationDrawerManager.persistInfo() if (FcmHelper.isPushSupported()) { //TODO FCM fallback diff --git a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotifiableEventResolver.kt b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotifiableEventResolver.kt index 1d7d5e214d..ca2ec6142e 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotifiableEventResolver.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotifiableEventResolver.kt @@ -17,6 +17,7 @@ package im.vector.riotredesign.features.notifications import androidx.core.app.NotificationCompat import im.vector.matrix.android.api.session.Session +import im.vector.matrix.android.api.session.content.ContentUrlResolver import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.toModel @@ -36,8 +37,8 @@ import timber.log.Timber * The NotifiableEventResolver is the only aware of session/store, the NotificationDrawerManager has no knowledge of that, * this pattern allow decoupling between the object responsible of displaying notifications and the matrix sdk. */ -class NotifiableEventResolver(val stringProvider: StringProvider, - val noticeEventFormatter: NoticeEventFormatter) { +class NotifiableEventResolver(private val stringProvider: StringProvider, + private val noticeEventFormatter: NoticeEventFormatter) { //private val eventDisplay = RiotEventDisplay(context) @@ -132,26 +133,19 @@ class NotifiableEventResolver(val stringProvider: StringProvider, notifiableEvent.matrixID = session.sessionParams.credentials.userId notifiableEvent.soundName = null - //TODO get the avatar? + // Get the avatars URL + // TODO They will be not displayed the first time (known limitation) + notifiableEvent.roomAvatarPath = session.contentUrlResolver() + .resolveThumbnail(room.roomSummary?.avatarUrl, + 250, + 250, + ContentUrlResolver.ThumbnailMethod.SCALE) -// val roomAvatarPath = session.mediaCache?.thumbnailCacheFile(room.avatarUrl, 50) -// if (roomAvatarPath != null) { -// notifiableEvent.roomAvatarPath = roomAvatarPath.path -// } else { -// // prepare for the next time -// session.mediaCache?.loadAvatarThumbnail(session.homeServerConfig, ImageView(context), room.avatarUrl, 50) -// } -// -// room.state.getMember(event.sender)?.avatarUrl?.let { -// val size = context.resources.getDimensionPixelSize(R.dimen.profile_avatar_size) -// val userAvatarUrlPath = session.mediaCache?.thumbnailCacheFile(it, size) -// if (userAvatarUrlPath != null) { -// notifiableEvent.senderAvatarPath = userAvatarUrlPath.path -// } else { -// // prepare for the next time -// session.mediaCache?.loadAvatarThumbnail(session.homeServerConfig, ImageView(context), it, size) -// } -// } + notifiableEvent.senderAvatarPath = session.contentUrlResolver() + .resolveThumbnail(event.senderAvatar, + 250, + 250, + ContentUrlResolver.ThumbnailMethod.SCALE) return notifiableEvent } diff --git a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationBroadcastReceiver.kt b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationBroadcastReceiver.kt index 499ea68ec3..501e8e499f 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationBroadcastReceiver.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationBroadcastReceiver.kt @@ -40,7 +40,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver(), KoinComponent { override fun onReceive(context: Context?, intent: Intent?) { if (intent == null || context == null) return - Timber.v("ReplyNotificationBroadcastReceiver received : $intent") + Timber.v("NotificationBroadcastReceiver received : $intent") when (intent.action) { NotificationUtils.SMART_REPLY_ACTION ->