mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Changes to make chat room shortcuts work
This commit is contained in:
parent
58c30a638f
commit
1d7ca67053
8 changed files with 108 additions and 7 deletions
|
|
@ -50,13 +50,22 @@
|
|||
<activity
|
||||
android:name=".ui.main.MainActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:exported="true">
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask">
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcuts" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW_LOCUS" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import android.content.pm.PackageManager
|
|||
import android.content.pm.ServiceInfo
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.annotation.AnyThread
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.annotation.WorkerThread
|
||||
|
|
@ -40,6 +41,7 @@ import androidx.core.app.NotificationManagerCompat
|
|||
import androidx.core.app.Person
|
||||
import androidx.core.app.RemoteInput
|
||||
import androidx.core.content.LocusIdCompat
|
||||
import androidx.navigation.NavDeepLinkBuilder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
|
|
@ -63,6 +65,7 @@ import org.linphone.core.CoreListenerStub
|
|||
import org.linphone.core.Friend
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.ui.call.CallActivity
|
||||
import org.linphone.ui.main.MainActivity
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.LinphoneUtils
|
||||
import org.linphone.utils.ShortcutUtils
|
||||
|
|
@ -242,8 +245,10 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
"$TAG After removing original reaction notification there is still messages, updating notification"
|
||||
)
|
||||
val me = coreContext.contactsManager.getMePerson(chatRoom.localAddress)
|
||||
val pendingIntent = getChatRoomPendingIntent(chatRoom)
|
||||
val notification = createMessageNotification(
|
||||
notifiable,
|
||||
pendingIntent,
|
||||
LinphoneUtils.getChatRoomId(chatRoom),
|
||||
me
|
||||
)
|
||||
|
|
@ -503,8 +508,10 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
|
||||
if (notifiable.messages.isNotEmpty()) {
|
||||
val me = coreContext.contactsManager.getMePerson(chatRoom.localAddress)
|
||||
val pendingIntent = getChatRoomPendingIntent(chatRoom)
|
||||
val notification = createMessageNotification(
|
||||
notifiable,
|
||||
pendingIntent,
|
||||
LinphoneUtils.getChatRoomId(chatRoom),
|
||||
me
|
||||
)
|
||||
|
|
@ -566,8 +573,10 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
|
||||
if (notifiable.messages.isNotEmpty()) {
|
||||
val me = coreContext.contactsManager.getMePerson(chatRoom.localAddress)
|
||||
val pendingIntent = getChatRoomPendingIntent(chatRoom)
|
||||
val notification = createMessageNotification(
|
||||
notifiable,
|
||||
pendingIntent,
|
||||
LinphoneUtils.getChatRoomId(chatRoom),
|
||||
me
|
||||
)
|
||||
|
|
@ -772,6 +781,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
|
||||
private fun createMessageNotification(
|
||||
notifiable: Notifiable,
|
||||
pendingIntent: PendingIntent,
|
||||
id: String,
|
||||
me: Person
|
||||
): Notification {
|
||||
|
|
@ -827,6 +837,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
.setWhen(System.currentTimeMillis())
|
||||
.setShowWhen(true)
|
||||
.setStyle(style)
|
||||
.setContentIntent(pendingIntent)
|
||||
.addAction(getReplyMessageAction(notifiable))
|
||||
.addAction(getMarkMessageAsReadAction(notifiable))
|
||||
.setShortcutId(id)
|
||||
|
|
@ -925,9 +936,11 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
notifiable.messages.add(reply)
|
||||
|
||||
val chatRoom = message.chatRoom
|
||||
val pendingIntent = getChatRoomPendingIntent(chatRoom)
|
||||
val me = coreContext.contactsManager.getMePerson(chatRoom.localAddress)
|
||||
val notification = createMessageNotification(
|
||||
notifiable,
|
||||
pendingIntent,
|
||||
LinphoneUtils.getChatRoomId(chatRoom),
|
||||
me
|
||||
)
|
||||
|
|
@ -1064,6 +1077,19 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun getChatRoomPendingIntent(chatRoom: ChatRoom): PendingIntent {
|
||||
val args = Bundle()
|
||||
args.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly())
|
||||
args.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly())
|
||||
return NavDeepLinkBuilder(context)
|
||||
.setComponentName(MainActivity::class.java)
|
||||
.setGraph(R.navigation.main_nav_graph)
|
||||
.setDestination(R.id.conversationsFragment)
|
||||
.setArguments(args)
|
||||
.createPendingIntent()
|
||||
}
|
||||
|
||||
class Notifiable(val notificationId: Int) {
|
||||
var myself: String? = null
|
||||
var callId: String? = null
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.linphone.ui.main
|
|||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
|
|
@ -183,9 +184,14 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
coreContext.postOnMainThread {
|
||||
val navGraph = findNavController().navInflater.inflate(R.navigation.main_nav_graph)
|
||||
navGraph.setStartDestination(startDestination)
|
||||
findNavController().setGraph(navGraph, null)
|
||||
if (intent != null) {
|
||||
handleIntent(intent, startDestination, false)
|
||||
} else {
|
||||
/*val navGraph = findNavController().navInflater.inflate(R.navigation.main_nav_graph)
|
||||
navGraph.setStartDestination(startDestination)
|
||||
findNavController().setGraph(navGraph, null)*/
|
||||
Log.e("$TAG Started without intent !")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -219,6 +225,13 @@ class MainActivity : AppCompatActivity() {
|
|||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
if (intent != null) {
|
||||
handleIntent(intent, -1, true)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
fun toggleDrawerMenu() {
|
||||
if (binding.drawerMenu.isDrawerOpen(Gravity.LEFT)) {
|
||||
|
|
@ -276,7 +289,7 @@ class MainActivity : AppCompatActivity() {
|
|||
)
|
||||
}
|
||||
|
||||
fun removePersistentRedToast(tag: String) {
|
||||
private fun removePersistentRedToast(tag: String) {
|
||||
for (child in binding.toastsArea.children) {
|
||||
if (child.tag == tag) {
|
||||
binding.toastsArea.removeView(child)
|
||||
|
|
@ -284,6 +297,34 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleIntent(intent: Intent, defaultDestination: Int, isNewIntent: Boolean) {
|
||||
Log.i("$TAG Handling intent [$intent]")
|
||||
val navGraph = findNavController().navInflater.inflate(R.navigation.main_nav_graph)
|
||||
|
||||
if (intent.hasExtra("Chat")) {
|
||||
Log.i("$TAG New intent with [Chat] extra")
|
||||
coreContext.postOnMainThread {
|
||||
if (isNewIntent) {
|
||||
Log.i("$TAG Going to Conversations fragment")
|
||||
findNavController().navigate(
|
||||
R.id.action_global_conversationsFragment,
|
||||
intent.extras
|
||||
)
|
||||
} else {
|
||||
Log.i("$TAG Going to Conversations fragment instead of default destination")
|
||||
navGraph.setStartDestination(R.id.conversationsFragment)
|
||||
findNavController().setGraph(navGraph, intent.extras)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isNewIntent && defaultDestination > 0) {
|
||||
Log.i("$TAG Setting nav graph with expected default destination")
|
||||
navGraph.setStartDestination(defaultDestination)
|
||||
findNavController().setGraph(navGraph, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadContacts() {
|
||||
coreContext.contactsManager.loadContacts(this)
|
||||
|
||||
|
|
|
|||
|
|
@ -348,7 +348,6 @@ class ConversationFragment : GenericFragment() {
|
|||
prepareBottomSheetForReactions(chatMessageModel)
|
||||
}
|
||||
|
||||
binding.messageBottomSheet.root.visibility = View.VISIBLE
|
||||
deliveryBottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import org.linphone.R
|
|||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.ChatFragmentBinding
|
||||
import org.linphone.ui.main.fragment.GenericFragment
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.SlidingPaneBackPressedCallback
|
||||
|
||||
@UiThread
|
||||
|
|
@ -78,6 +79,18 @@ class ConversationsFragment : GenericFragment() {
|
|||
)
|
||||
}
|
||||
|
||||
val args = arguments
|
||||
if (args != null) {
|
||||
val localSipUri = args.getString("LocalSipUri")
|
||||
val remoteSipUri = args.getString("RemoteSipUri")
|
||||
if (localSipUri != null && remoteSipUri != null) {
|
||||
Log.i("$TAG Found local [$localSipUri] & remote [$remoteSipUri] URIs in arguments")
|
||||
val pair = Pair(localSipUri, remoteSipUri)
|
||||
sharedViewModel.showConversationEvent.value = Event(pair)
|
||||
args.clear()
|
||||
}
|
||||
}
|
||||
|
||||
sharedViewModel.closeSlidingPaneEvent.observe(
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -236,7 +236,6 @@
|
|||
|
||||
<include
|
||||
android:id="@+id/message_bottom_sheet"
|
||||
android:visibility="gone"
|
||||
layout="@layout/chat_message_bottom_sheet" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
|||
|
|
@ -282,4 +282,8 @@
|
|||
android:label="AddParticipantsFragment"
|
||||
tools:layout="@layout/generic_add_participants_fragment"/>
|
||||
|
||||
<action android:id="@+id/action_global_conversationsFragment"
|
||||
app:destination="@id/conversationsFragment"
|
||||
app:launchSingleTop="true"/>
|
||||
|
||||
</navigation>
|
||||
10
app/src/main/res/xml/shortcuts.xml
Normal file
10
app/src/main/res/xml/shortcuts.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<share-target android:targetClass="org.linphone.ui.main.MainActivity">
|
||||
<data android:mimeType="text/*" />
|
||||
<data android:mimeType="image/*" />
|
||||
<data android:mimeType="audio/*" />
|
||||
<data android:mimeType="video/*" />
|
||||
<category android:name="android.shortcut.conversation" />
|
||||
</share-target>
|
||||
</shortcuts>
|
||||
Loading…
Add table
Reference in a new issue