Skip to content

Commit

Permalink
feat(bank-sdk): Always call the cancelled result when the user leaves…
Browse files Browse the repository at this point in the history
… the host fragment via a back action

The top and bottom navigation bar back/close buttons trigger a back button press to allow the
nav graph to handle back navigation the same way for our navbars as for the system back button.

For popping the back stack a back button press is triggered as well.

BSDK-258
  • Loading branch information
a-szotyori committed Jan 19, 2024
1 parent 7d4fdd6 commit 70bd7b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class CaptureFlowFragment(private val openWithDocument: Document? = null) :
// Remember the original primary navigation fragment so that we can restore it when this fragment is detached
private var originalPrimaryNavigationFragment: Fragment? = null

private var willBeRestored = false
private var didFinishWithResult = false

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -68,8 +71,23 @@ class CaptureFlowFragment(private val openWithDocument: Document? = null) :
super.onCreate(savedInstanceState)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
willBeRestored = true
}

override fun onDestroy() {
super.onDestroy()
if (!didFinishWithResult && !willBeRestored) {
captureFlowFragmentListener.onFinishedWithResult(CaptureResult.Cancel)
}
}


override fun onResume() {
super.onResume()
willBeRestored = false

originalPrimaryNavigationFragment = parentFragmentManager.primaryNavigationFragment

// To be the first to handle back button pressed events we need to set this fragment as the primary navigation fragment
Expand Down Expand Up @@ -104,20 +122,26 @@ class CaptureFlowFragment(private val openWithDocument: Document? = null) :
DigitalInvoiceFragment.getAmountsAreConsistentExtraction(result.specificExtractions)
))
} catch (notUsed: DigitalInvoiceException) {
didFinishWithResult = true
captureFlowFragmentListener.onFinishedWithResult(result.toCaptureResult())
}
} else {
didFinishWithResult = true
captureFlowFragmentListener.onFinishedWithResult(result.toCaptureResult())
}
}
else -> captureFlowFragmentListener.onFinishedWithResult(result.toCaptureResult())
else -> {
didFinishWithResult = true
captureFlowFragmentListener.onFinishedWithResult(result.toCaptureResult())
}
}
}

override fun onPayInvoice(
specificExtractions: Map<String, GiniCaptureSpecificExtraction>,
compoundExtractions: Map<String, GiniCaptureCompoundExtraction>
) {
didFinishWithResult = true
captureFlowFragmentListener.onFinishedWithResult(CaptureResult.Success(
specificExtractions,
compoundExtractions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DigitalInvoiceHelpFragment : Fragment() {
injectedAdapterView.setTitle(getString(net.gini.android.capture.R.string.gc_title_help))

injectedAdapterView.setOnNavButtonClickListener(IntervalClickListener {
findNavController().popBackStack()
activity?.onBackPressedDispatcher?.onBackPressed()
})
}
}
Expand All @@ -63,7 +63,7 @@ class DigitalInvoiceHelpFragment : Fragment() {
injectedViewContainer.injectedViewAdapterHolder =
InjectedViewAdapterHolder(GiniBank.digitalInvoiceHelpNavigationBarBottomAdapterInstance) { injectedViewAdapter ->
injectedViewAdapter.setOnBackButtonClickListener(IntervalClickListener {
findNavController().popBackStack()
activity?.onBackPressedDispatcher?.onBackPressed()
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DigitalInvoiceOnboardingFragment : Fragment(), DigitalOnboardingScreenCont
)

override fun close() {
findNavController().popBackStack()
activity?.onBackPressedDispatcher?.onBackPressed()
}

/**
Expand Down

0 comments on commit 70bd7b2

Please sign in to comment.