Check if current fragment matches before going back

This commit is contained in:
Sylvain Berfini 2024-04-28 19:18:58 +02:00
parent 39fba60066
commit 0dbd403d5b
4 changed files with 28 additions and 16 deletions

View file

@ -325,10 +325,13 @@ class ConversationFragment : SlidingPaneChildFragment() {
override fun goBack(): Boolean {
sharedViewModel.closeSlidingPaneEvent.value = Event(true)
// If not done this fragment won't be paused, which will cause us issues
val action = ConversationFragmentDirections.actionConversationFragmentToEmptyFragment()
findNavController().navigate(action)
return true
if (findNavController().currentDestination?.id == R.id.conversationFragment) {
// If not done this fragment won't be paused, which will cause us issues
val action = ConversationFragmentDirections.actionConversationFragmentToEmptyFragment()
findNavController().navigate(action)
return true
}
return false
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

View file

@ -81,10 +81,13 @@ class ContactFragment : SlidingPaneChildFragment() {
override fun goBack(): Boolean {
sharedViewModel.closeSlidingPaneEvent.value = Event(true)
// If not done this fragment won't be paused, which will cause us issues
val action = ContactFragmentDirections.actionContactFragmentToEmptyFragment()
findNavController().navigate(action)
return true
if (findNavController().currentDestination?.id == R.id.contactFragment) {
// If not done this fragment won't be paused, which will cause us issues
val action = ContactFragmentDirections.actionContactFragmentToEmptyFragment()
findNavController().navigate(action)
return true
}
return false
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

View file

@ -64,10 +64,13 @@ class HistoryFragment : SlidingPaneChildFragment() {
override fun goBack(): Boolean {
sharedViewModel.closeSlidingPaneEvent.value = Event(true)
// If not done this fragment won't be paused, which will cause us issues
val action = HistoryFragmentDirections.actionHistoryFragmentToEmptyFragment()
findNavController().navigate(action)
return true
if (findNavController().currentDestination?.id == R.id.historyFragment) {
// If not done this fragment won't be paused, which will cause us issues
val action = HistoryFragmentDirections.actionHistoryFragmentToEmptyFragment()
findNavController().navigate(action)
return true
}
return false
}
override fun onCreate(savedInstanceState: Bundle?) {

View file

@ -82,10 +82,13 @@ class MeetingFragment : SlidingPaneChildFragment() {
override fun goBack(): Boolean {
sharedViewModel.closeSlidingPaneEvent.value = Event(true)
// If not done this fragment won't be paused, which will cause us issues
val action = MeetingFragmentDirections.actionMeetingFragmentToEmptyFragment()
findNavController().navigate(action)
return true
if (findNavController().currentDestination?.id == R.id.meetingFragment) {
// If not done this fragment won't be paused, which will cause us issues
val action = MeetingFragmentDirections.actionMeetingFragmentToEmptyFragment()
findNavController().navigate(action)
return true
}
return false
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {