Set shortcut ID to chat room notifications
This commit is contained in:
parent
e201977c00
commit
59b758e682
4 changed files with 25 additions and 6 deletions
|
@ -23,6 +23,7 @@ import androidx.lifecycle.MutableLiveData
|
|||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.activities.main.viewmodels.ErrorReportingViewModel
|
||||
import org.linphone.compatibility.Compatibility
|
||||
import org.linphone.contact.ContactsUpdatedListenerStub
|
||||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
|
@ -116,8 +117,11 @@ class ChatRoomsListViewModel : ErrorReportingViewModel() {
|
|||
}
|
||||
|
||||
chatRoomsToDeleteCount = 1
|
||||
chatRoom?.addListener(chatRoomListener)
|
||||
chatRoom?.core?.deleteChatRoom(chatRoom)
|
||||
if (chatRoom != null) {
|
||||
Compatibility.removeChatRoomShortcut(chatRoom)
|
||||
chatRoom.addListener(chatRoomListener)
|
||||
coreContext.core.deleteChatRoom(chatRoom)
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteChatRooms(chatRooms: ArrayList<ChatRoom>) {
|
||||
|
@ -127,6 +131,7 @@ class ChatRoomsListViewModel : ErrorReportingViewModel() {
|
|||
LinphoneUtils.deleteFilesAttachedToEventLog(eventLog)
|
||||
}
|
||||
|
||||
Compatibility.removeChatRoomShortcut(chatRoom)
|
||||
chatRoom.addListener(chatRoomListener)
|
||||
chatRoom.core?.deleteChatRoom(chatRoom)
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.content.pm.PackageManager
|
|||
import android.os.Vibrator
|
||||
import android.view.WindowManager
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import org.linphone.core.ChatRoom
|
||||
import org.linphone.core.Content
|
||||
import org.linphone.mediastream.Version
|
||||
|
||||
|
@ -109,6 +110,10 @@ class Compatibility {
|
|||
}
|
||||
}
|
||||
|
||||
fun removeChatRoomShortcut(chatRoom: ChatRoom) {
|
||||
// TODO Use removeLongLivedShortcuts() starting Android R (API 30)
|
||||
}
|
||||
|
||||
fun addImageToMediaStore(context: Context, content: Content): Boolean {
|
||||
if (Version.sdkAboveOrEqual(Version.API29_ANDROID_10)) {
|
||||
return Api29Compatibility.addImageToMediaStore(context, content)
|
||||
|
|
|
@ -500,9 +500,11 @@ class NotificationsManager(private val context: Context) {
|
|||
/* Chat related */
|
||||
|
||||
private fun displayChatNotifiable(room: ChatRoom, notifiable: Notifiable) {
|
||||
val localAddress = room.localAddress.asStringUriOnly()
|
||||
val peerAddress = room.peerAddress.asStringUriOnly()
|
||||
val args = Bundle()
|
||||
args.putString("RemoteSipUri", room.peerAddress.asStringUriOnly())
|
||||
args.putString("LocalSipUri", room.localAddress.asStringUriOnly())
|
||||
args.putString("RemoteSipUri", peerAddress)
|
||||
args.putString("LocalSipUri", localAddress)
|
||||
|
||||
val pendingIntent = NavDeepLinkBuilder(context)
|
||||
.setComponentName(MainActivity::class.java)
|
||||
|
@ -511,7 +513,7 @@ class NotificationsManager(private val context: Context) {
|
|||
.setArguments(args)
|
||||
.createPendingIntent()
|
||||
|
||||
val notification = createMessageNotification(notifiable, pendingIntent)
|
||||
val notification = createMessageNotification(notifiable, pendingIntent, "$localAddress#$peerAddress")
|
||||
if (notification != null) notify(notifiable.notificationId, notification)
|
||||
}
|
||||
|
||||
|
@ -572,7 +574,11 @@ class NotificationsManager(private val context: Context) {
|
|||
|
||||
/* Notifications */
|
||||
|
||||
private fun createMessageNotification(notifiable: Notifiable, pendingIntent: PendingIntent): Notification? {
|
||||
private fun createMessageNotification(
|
||||
notifiable: Notifiable,
|
||||
pendingIntent: PendingIntent,
|
||||
shortcutId: String
|
||||
): Notification? {
|
||||
val me = Person.Builder().setName(notifiable.myself).build()
|
||||
val style = NotificationCompat.MessagingStyle(me)
|
||||
val largeIcon: Bitmap? = notifiable.messages.last().senderAvatar
|
||||
|
@ -613,6 +619,7 @@ class NotificationsManager(private val context: Context) {
|
|||
.setColor(ContextCompat.getColor(context, R.color.primary_color))
|
||||
.addAction(getReplyMessageAction(notifiable))
|
||||
.addAction(getMarkMessageAsReadAction(notifiable))
|
||||
.setShortcutId(shortcutId)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.linphone.core.Address
|
|||
import org.linphone.core.ChatRoom
|
||||
import org.linphone.core.ChatRoomCapabilities
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.mediastream.Version
|
||||
|
||||
@TargetApi(25)
|
||||
class ShortcutsHelper(val context: Context) {
|
||||
|
@ -197,6 +198,7 @@ class ShortcutsHelper(val context: Context) {
|
|||
.setPersons(persons)
|
||||
.setCategories(categories)
|
||||
.setIntent(intent)
|
||||
.setLongLived(Version.sdkAboveOrEqual(30)) // TODO Use Android R API code
|
||||
.build().toShortcutInfo()
|
||||
} catch (e: Exception) {
|
||||
Log.e("[Shortcuts Helper] ShortcutInfo.Builder exception: $e")
|
||||
|
|
Loading…
Reference in a new issue