From 51dd246971e34ecd90ca930ee273c5574572b0af Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 17 Sep 2024 12:53:18 +0200 Subject: [PATCH] Prevent external file sharing to attach file in already opened conversation if any --- app/src/main/java/org/linphone/ui/main/MainActivity.kt | 10 ++++++++++ .../ui/main/chat/fragment/ConversationFragment.kt | 8 ++++++++ .../linphone/ui/main/viewmodel/SharedMainViewModel.kt | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/app/src/main/java/org/linphone/ui/main/MainActivity.kt b/app/src/main/java/org/linphone/ui/main/MainActivity.kt index 75b84bb81..f77dec41c 100644 --- a/app/src/main/java/org/linphone/ui/main/MainActivity.kt +++ b/app/src/main/java/org/linphone/ui/main/MainActivity.kt @@ -615,6 +615,16 @@ class MainActivity : GenericActivity() { Log.i("$TAG Drawer menu is opened, closing it") closeDrawerMenu() } + if (findNavController().currentDestination?.id == R.id.conversationsListFragment) { + if (sharedViewModel.displayedChatRoom != null) { + Log.w( + "$TAG Closing already opened conversation to prevent attaching file in it directly" + ) + sharedViewModel.hideConversationEvent.postValue(Event(true)) + } else { + Log.i("$TAG No chat room currently displayed, nothing to close") + } + } val paths = deferred.awaitAll() for (path in paths) { diff --git a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt index 869a075a8..072b986e2 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt @@ -364,6 +364,7 @@ open class ConversationFragment : SlidingPaneChildFragment() { override fun goBack(): Boolean { sharedViewModel.closeSlidingPaneEvent.value = Event(true) + sharedViewModel.displayedChatRoom = null if (findNavController().currentDestination?.id == R.id.conversationFragment) { // If not done this fragment won't be paused, which will cause us issues @@ -784,6 +785,13 @@ open class ConversationFragment : SlidingPaneChildFragment() { } } + sharedViewModel.hideConversationEvent.observe(viewLifecycleOwner) { + it.consume { + Log.w("$TAG We were asked to close conversation, going back") + goBack() + } + } + sharedViewModel.textToShareFromIntent.observe(viewLifecycleOwner) { text -> if (text.isNotEmpty()) { Log.i("$TAG Found text to share from intent") diff --git a/app/src/main/java/org/linphone/ui/main/viewmodel/SharedMainViewModel.kt b/app/src/main/java/org/linphone/ui/main/viewmodel/SharedMainViewModel.kt index 4c08aa2c8..75201784e 100644 --- a/app/src/main/java/org/linphone/ui/main/viewmodel/SharedMainViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/viewmodel/SharedMainViewModel.kt @@ -120,6 +120,10 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() { MutableLiveData>>() } + val hideConversationEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + // When using keyboard to share gif or other, see RichContentReceiver & RichEditText classes val richContentUri = MutableLiveData>()