Protect navigate() calls

This commit is contained in:
Sylvain Berfini 2024-12-03 13:39:54 +01:00
parent 6b11e37b14
commit f48da167ab
10 changed files with 107 additions and 55 deletions

View file

@ -86,8 +86,11 @@ class LandingFragment : GenericFragment() {
}
binding.setQrCodeClickListener {
val action = LandingFragmentDirections.actionLandingFragmentToQrCodeScannerFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.landingFragment) {
val action =
LandingFragmentDirections.actionLandingFragmentToQrCodeScannerFragment()
findNavController().navigate(action)
}
}
binding.setThirdPartySipAccountLoginClickListener {
@ -151,17 +154,21 @@ class LandingFragment : GenericFragment() {
}
private fun goToRegisterFragment() {
val action = LandingFragmentDirections.actionLandingFragmentToRegisterFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.landingFragment) {
val action = LandingFragmentDirections.actionLandingFragmentToRegisterFragment()
findNavController().navigate(action)
}
}
private fun goToLoginThirdPartySipAccountFragment(skipWarning: Boolean) {
val action = if (skipWarning) {
LandingFragmentDirections.actionLandingFragmentToThirdPartySipAccountLoginFragment()
} else {
LandingFragmentDirections.actionLandingFragmentToThirdPartySipAccountWarningFragment()
if (findNavController().currentDestination?.id == R.id.landingFragment) {
val action = if (skipWarning) {
LandingFragmentDirections.actionLandingFragmentToThirdPartySipAccountLoginFragment()
} else {
LandingFragmentDirections.actionLandingFragmentToThirdPartySipAccountWarningFragment()
}
findNavController().navigate(action)
}
findNavController().navigate(action)
}
private fun showAcceptConditionsAndPrivacyDialog(

View file

@ -156,8 +156,11 @@ class RegisterFragment : GenericFragment() {
viewModel.goToSmsCodeConfirmationViewEvent.observe(viewLifecycleOwner) {
it.consume {
Log.i("$TAG Going to SMS code confirmation fragment")
val action = RegisterFragmentDirections.actionRegisterFragmentToRegisterCodeConfirmationFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.registerFragment) {
val action =
RegisterFragmentDirections.actionRegisterFragmentToRegisterCodeConfirmationFragment()
findNavController().navigate(action)
}
}
}

View file

@ -135,11 +135,13 @@ class ThirdPartySipAccountLoginFragment : GenericFragment() {
Log.i(
"$TAG Navigating to Single Sign On Fragment with server URL [$serverUrl] and username [$username]"
)
val action = SingleSignOnFragmentDirections.actionGlobalSingleSignOnFragment(
serverUrl,
username
)
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.thirdPartySipAccountLoginFragment) {
val action = SingleSignOnFragmentDirections.actionGlobalSingleSignOnFragment(
serverUrl,
username
)
findNavController().navigate(action)
}
}
}

View file

@ -71,13 +71,19 @@ class ThirdPartySipAccountWarningFragment : GenericFragment() {
}
binding.setCreateAccountClickListener {
val action = ThirdPartySipAccountWarningFragmentDirections.actionThirdPartySipAccountWarningFragmentToRegisterFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.thirdPartySipAccountWarningFragment) {
val action =
ThirdPartySipAccountWarningFragmentDirections.actionThirdPartySipAccountWarningFragmentToRegisterFragment()
findNavController().navigate(action)
}
}
binding.setLoginClickListener {
val action = ThirdPartySipAccountWarningFragmentDirections.actionThirdPartySipAccountWarningFragmentToThirdPartySipAccountLoginFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.thirdPartySipAccountWarningFragment) {
val action =
ThirdPartySipAccountWarningFragmentDirections.actionThirdPartySipAccountWarningFragmentToThirdPartySipAccountLoginFragment()
findNavController().navigate(action)
}
}
}

View file

@ -284,14 +284,20 @@ class ActiveConferenceCallFragment : GenericCallFragment() {
binding.setCallsListClickListener {
Log.i("$TAG Going to calls list fragment")
val action = ActiveConferenceCallFragmentDirections.actionActiveConferenceCallFragmentToCallsListFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.activeConferenceCallFragment) {
val action =
ActiveConferenceCallFragmentDirections.actionActiveConferenceCallFragmentToCallsListFragment()
findNavController().navigate(action)
}
}
binding.setParticipantsListClickListener {
Log.i("$TAG Going to conference participants list fragment")
val action = ActiveConferenceCallFragmentDirections.actionActiveConferenceCallFragmentToConferenceParticipantsListFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.activeConferenceCallFragment) {
val action =
ActiveConferenceCallFragmentDirections.actionActiveConferenceCallFragmentToConferenceParticipantsListFragment()
findNavController().navigate(action)
}
}
binding.setShareConferenceClickListener {

View file

@ -214,18 +214,27 @@ class ActiveCallFragment : GenericCallFragment() {
}
binding.setTransferCallClickListener {
val action = ActiveCallFragmentDirections.actionActiveCallFragmentToTransferCallFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.activeCallFragment) {
val action =
ActiveCallFragmentDirections.actionActiveCallFragmentToTransferCallFragment()
findNavController().navigate(action)
}
}
binding.setNewCallClickListener {
val action = ActiveCallFragmentDirections.actionActiveCallFragmentToNewCallFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.activeCallFragment) {
val action =
ActiveCallFragmentDirections.actionActiveCallFragmentToNewCallFragment()
findNavController().navigate(action)
}
}
binding.setCallsListClickListener {
val action = ActiveCallFragmentDirections.actionActiveCallFragmentToCallsListFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.activeCallFragment) {
val action =
ActiveCallFragmentDirections.actionActiveCallFragmentToCallsListFragment()
findNavController().navigate(action)
}
}
binding.setCallStatisticsClickListener {

View file

@ -69,8 +69,10 @@ class HelpFragment : GenericMainFragment() {
}
binding.setDebugClickListener {
val action = HelpFragmentDirections.actionHelpFragmentToDebugFragment()
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.helpFragment) {
val action = HelpFragmentDirections.actionHelpFragmentToDebugFragment()
findNavController().navigate(action)
}
}
binding.setPrivacyPolicyClickListener {

View file

@ -127,10 +127,13 @@ class MeetingFragment : SlidingPaneChildFragment() {
Log.i(
"$TAG Navigating to meeting edit fragment with conference URI [$conferenceUri]"
)
val action = MeetingFragmentDirections.actionMeetingFragmentToEditMeetingFragment(
conferenceUri
)
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.meetingFragment) {
val action =
MeetingFragmentDirections.actionMeetingFragmentToEditMeetingFragment(
conferenceUri
)
findNavController().navigate(action)
}
}
}

View file

@ -143,9 +143,11 @@ class MeetingsListFragment : AbstractMainFragment() {
Log.w("$TAG Meeting with ID [${model.id}] is cancelled, can't show the details")
} else {
Log.i("$TAG Show meeting with ID [${model.id}]")
sharedViewModel.displayedMeeting = model.conferenceInfo
val action = MeetingFragmentDirections.actionGlobalMeetingFragment(model.id)
binding.meetingsNavContainer.findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.meetingsListFragment) {
sharedViewModel.displayedMeeting = model.conferenceInfo
val action = MeetingFragmentDirections.actionGlobalMeetingFragment(model.id)
binding.meetingsNavContainer.findNavController().navigate(action)
}
}
}
}

View file

@ -155,37 +155,49 @@ class SettingsFragment : GenericMainFragment() {
viewModel.addLdapServerEvent.observe(viewLifecycleOwner) {
it.consume {
val action = SettingsFragmentDirections.actionSettingsFragmentToLdapServerConfigurationFragment(
null
)
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.settingsFragment) {
val action =
SettingsFragmentDirections.actionSettingsFragmentToLdapServerConfigurationFragment(
null
)
findNavController().navigate(action)
}
}
}
viewModel.editLdapServerEvent.observe(viewLifecycleOwner) {
it.consume { name ->
val action = SettingsFragmentDirections.actionSettingsFragmentToLdapServerConfigurationFragment(
name
)
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.settingsFragment) {
val action =
SettingsFragmentDirections.actionSettingsFragmentToLdapServerConfigurationFragment(
name
)
findNavController().navigate(action)
}
}
}
viewModel.addCardDavServerEvent.observe(viewLifecycleOwner) {
it.consume {
val action = SettingsFragmentDirections.actionSettingsFragmentToCardDavAddressBookConfigurationFragment(
null
)
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.settingsFragment) {
val action =
SettingsFragmentDirections.actionSettingsFragmentToCardDavAddressBookConfigurationFragment(
null
)
findNavController().navigate(action)
}
}
}
viewModel.editCardDavServerEvent.observe(viewLifecycleOwner) {
it.consume { name ->
val action = SettingsFragmentDirections.actionSettingsFragmentToCardDavAddressBookConfigurationFragment(
name
)
findNavController().navigate(action)
if (findNavController().currentDestination?.id == R.id.settingsFragment) {
val action =
SettingsFragmentDirections.actionSettingsFragmentToCardDavAddressBookConfigurationFragment(
name
)
findNavController().navigate(action)
}
}
}