Fixed file/text sharing issue if linphone is in background but current fragment is a chat conversation while initiating sharing from another app
This commit is contained in:
parent
15cd634f01
commit
48c12206d8
3 changed files with 31 additions and 22 deletions
|
@ -262,12 +262,12 @@ internal fun DialerFragment.navigateToConfigFileViewer() {
|
|||
|
||||
/* Chat related */
|
||||
|
||||
internal fun MasterChatRoomsFragment.navigateToChatRoom() {
|
||||
internal fun MasterChatRoomsFragment.navigateToChatRoom(args: Bundle) {
|
||||
if (!resources.getBoolean(R.bool.isTablet)) {
|
||||
if (findNavController().currentDestination?.id == R.id.masterChatRoomsFragment) {
|
||||
findNavController().navigate(
|
||||
R.id.action_masterChatRoomsFragment_to_detailChatRoomFragment,
|
||||
null,
|
||||
args,
|
||||
getRightToLeftAnimationNavOptions()
|
||||
)
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ internal fun MasterChatRoomsFragment.navigateToChatRoom() {
|
|||
childFragmentManager.findFragmentById(R.id.chat_nav_container) as NavHostFragment
|
||||
navHostFragment.navController.navigate(
|
||||
R.id.action_global_detailChatRoomFragment,
|
||||
null,
|
||||
args,
|
||||
getRightToLeftAnimationNavOptions(R.id.emptyChatFragment, true)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -108,10 +108,14 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
|||
|
||||
val localSipUri = arguments?.getString("LocalSipUri")
|
||||
val remoteSipUri = arguments?.getString("RemoteSipUri")
|
||||
|
||||
val textToShare = arguments?.getString("TextToShare")
|
||||
val filestoShare = arguments?.getStringArrayList("FilesToShare")
|
||||
|
||||
arguments?.clear()
|
||||
if (localSipUri != null && remoteSipUri != null) {
|
||||
Log.i("[Chat Room] Found local [$localSipUri] & remote [$remoteSipUri] addresses in arguments")
|
||||
arguments?.clear()
|
||||
|
||||
val localAddress = Factory.instance().createAddress(localSipUri)
|
||||
val remoteSipAddress = Factory.instance().createAddress(remoteSipUri)
|
||||
sharedViewModel.selectedChatRoom.value = coreContext.core.searchChatRoom(
|
||||
|
@ -323,23 +327,16 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
|||
coreContext.startCall(viewModel.addressToCall)
|
||||
}
|
||||
|
||||
sharedViewModel.textToShare.observe(viewLifecycleOwner, {
|
||||
if (it.isNotEmpty()) {
|
||||
Log.i("[Chat Room] Found text to share")
|
||||
chatSendingViewModel.textToSend.value = it
|
||||
sharedViewModel.textToShare.value = ""
|
||||
if (textToShare?.isNotEmpty() == true) {
|
||||
Log.i("[Chat Room] Found text to share")
|
||||
chatSendingViewModel.textToSend.value = textToShare
|
||||
}
|
||||
if (filestoShare?.isNotEmpty() == true) {
|
||||
for (path in filestoShare) {
|
||||
Log.i("[Chat Room] Found $path file to share")
|
||||
chatSendingViewModel.addAttachment(path)
|
||||
}
|
||||
})
|
||||
|
||||
sharedViewModel.filesToShare.observe(viewLifecycleOwner, {
|
||||
if (it.isNotEmpty()) {
|
||||
for (path in it) {
|
||||
Log.i("[Chat Room] Found $path file to share")
|
||||
chatSendingViewModel.addAttachment(path)
|
||||
}
|
||||
sharedViewModel.filesToShare.value = arrayListOf()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
sharedViewModel.messageToForwardEvent.observe(viewLifecycleOwner, {
|
||||
it.consume { chatMessage ->
|
||||
|
|
|
@ -162,7 +162,7 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
|||
sharedViewModel.destructionPendingChatRoom = chatRoom
|
||||
} else {
|
||||
sharedViewModel.selectedChatRoom.value = chatRoom
|
||||
navigateToChatRoom()
|
||||
navigateToChatRoom(createBundleWithSharedTextAndFiles())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -187,7 +187,7 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
|||
Log.w("[Chat] Found pending chat room from before activity was recreated")
|
||||
sharedViewModel.destructionPendingChatRoom = null
|
||||
sharedViewModel.selectedChatRoom.value = pendingDestructionChatRoom
|
||||
navigateToChatRoom()
|
||||
navigateToChatRoom(createBundleWithSharedTextAndFiles())
|
||||
}
|
||||
|
||||
val localSipUri = arguments?.getString("LocalSipUri")
|
||||
|
@ -247,4 +247,16 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
|||
private fun scrollToTop() {
|
||||
binding.chatList.scrollToPosition(0)
|
||||
}
|
||||
|
||||
private fun createBundleWithSharedTextAndFiles(): Bundle {
|
||||
val bundle = Bundle()
|
||||
bundle.putString("TextToShare", sharedViewModel.textToShare.value.orEmpty())
|
||||
bundle.putStringArrayList("FilesToShare", sharedViewModel.filesToShare.value)
|
||||
|
||||
// Remove values from shared view model
|
||||
sharedViewModel.textToShare.value = ""
|
||||
sharedViewModel.filesToShare.value = arrayListOf()
|
||||
|
||||
return bundle
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue