Added shortcut for conversation notifications

This commit is contained in:
Philipp Neumann 2021-04-28 09:54:05 +02:00
parent c62aa82e2a
commit dd7c264483
3 changed files with 25 additions and 5 deletions

View file

@ -325,7 +325,7 @@ dependencies {
implementation "androidx.fragment:fragment-ktx:$fragment_version"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.sharetarget:sharetarget:1.1.0"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.core:core-ktx:1.5.0-rc01'
implementation "androidx.media:media:1.3.0"
implementation "org.threeten:threetenbp:1.4.0:no-tzdb"

View file

@ -17,16 +17,21 @@ package im.vector.app.features.notifications
import android.content.Context
import android.graphics.Bitmap
import android.os.Build
import android.os.Handler
import android.os.HandlerThread
import androidx.annotation.WorkerThread
import androidx.core.app.NotificationCompat
import androidx.core.app.Person
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
import im.vector.app.ActiveSessionDataSource
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.utils.FirstThrottler
import im.vector.app.features.home.room.detail.RoomDetailActivity
import im.vector.app.features.settings.VectorPreferences
import me.gujun.android.span.span
import org.matrix.android.sdk.api.session.Session
@ -319,6 +324,21 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
.setKey(event.senderId)
.build()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val openRoomIntent = RoomDetailActivity.shortcutIntent(context, roomId)
val shortcut = ShortcutInfoCompat.Builder(context, roomId)
.setLongLived(true)
.setIntent(openRoomIntent)
.setShortLabel(roomName)
.setIcon(largeBitmap?.let{IconCompat.createWithAdaptiveBitmap(it)}?: iconLoader.getUserIcon(event.senderAvatarPath))
.setCategories()
.build()
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
}
if (event.outGoingMessage && event.outGoingMessageFailed) {
style.addMessage(stringProvider.getString(R.string.notification_inline_reply_failed), event.timestamp, senderPerson)
roomEventGroupInfo.hasSmartReplyError = true

View file

@ -38,10 +38,8 @@ import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.RemoteInput
import androidx.core.app.TaskStackBuilder
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.IconCompat
import androidx.fragment.app.Fragment
@ -500,6 +498,8 @@ class NotificationUtils @Inject constructor(private val context: Context,
// that can be displayed in not disturb mode if white listed (the later will need compat28.x)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setShortcutId(roomInfo.roomId)
// Title for API < 16 devices.
.setContentTitle(roomInfo.roomDisplayName)
// Content for API < 16 devices.
@ -559,7 +559,7 @@ class NotificationUtils @Inject constructor(private val context: Context,
NotificationCompat.Action.Builder(R.drawable.vector_notification_quick_reply,
stringProvider.getString(R.string.action_quick_reply), replyPendingIntent)
.addRemoteInput(remoteInput)
.build()?.let {
.build().let {
addAction(it)
}
}
@ -863,7 +863,7 @@ class NotificationUtils @Inject constructor(private val context: Context,
}
// We cannot use NotificationManagerCompat here.
val setting = context.getSystemService<NotificationManager>()!!.currentInterruptionFilter
val setting = context.getSystemService(NotificationManager::class.java)!!.currentInterruptionFilter
return setting == NotificationManager.INTERRUPTION_FILTER_NONE
|| setting == NotificationManager.INTERRUPTION_FILTER_ALARMS