Skip to content

Commit

Permalink
fix(bank-sdk): Fix navigation between ClientCaptureFragment and Captu…
Browse files Browse the repository at this point in the history
…reFlowFragment

BSDK-258

#<type>(<project>): <subject>
#<body>
#<ticket-id>

# Please fill out the template above according to these conventions:
# * <type>: the type of the commit is one of the following:
#   * feat: new or modified features including UI and public API changes. Also
#     when adding tests to features.
#   * fix: bug fixes, test fixes, dependency updates for fixes.
#   * refactor: code changes without introducing public breaking changes (public API
#     or UI was not modified) or without changing functional behaviour. Also changes
#     that do code cleanup (comments, restructuring, method name changes, etc.)
#     or when refactoring tests.
#   * docs: documentation changes.
#   * ci: changes to build scripts or any other automation scripts or
#     configs (e.g., jazzy config, sphinx config). Also for git related
#     changes (e.g., .gitignore or commit template)
# * <project>: project that the commit makes changes to. If it makes
#   changes to many sections, or if no section in particular is
#   modified, leave blank without the parentheses.
#   Examples:
#   * Commit that changes the bank-sdk project:
#     feat(bank-sdk): Add error logging interface
#   * Commit that updates the health-sdk documentation:
#     doc(health-sdk): Update extraction feedback guide
#   * Commit that changes the build script:
#     ci: Send slack message with build result
#   * Commit that changes many projects:
#     chore: Update the android gradle plugin
# * <subject>: short description in imperative mood summarising
#   the changes. For example: Add photo selection button.
#   You can find more subject related advice here:
#   https://chris.beams.io/posts/git-commit/#capitalize
# * <body>: additional details about the committed changes
#   detailing the what and why (not the how):
#   https://chris.beams.io/posts/git-commit/#why-not-how
#
# The template is based on the conventional commits spec:
# https://www.conventionalcommits.org/en/v1.0.0/
# It was inspired by the ZSH project:
# https://github.com/ohmyzsh/ohmyzsh/blob/master/CONTRIBUTING.md#commit-guidelines
#
# To use this template add it to your local git configuration:
# $ git config --local commit.template .git-stuff/commit-msg-template.txt
#
# If you use Sourcetree and this template is not recognized, then you
# can copy and paste the non-comment lines to
# Repository Settings (⇧⌘,) > Commit Template.
# IMPORTANT: Don't add the lines starting with # to the template.
# Sourcetree doesn't treat those lines as comments and will add
# them to the commit message.
  • Loading branch information
abolfazlimahdi committed Jan 15, 2024
1 parent e666489 commit f686f78
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
package net.gini.android.bank.sdk.exampleapp.ui

import android.Manifest
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.core.content.ContextCompat.startActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import net.gini.android.bank.sdk.GiniBank
import net.gini.android.bank.sdk.capture.CaptureConfiguration
import net.gini.android.bank.sdk.capture.CaptureFlowFragmentListener
import net.gini.android.bank.sdk.exampleapp.R
import net.gini.android.bank.sdk.exampleapp.core.ExampleUtil.isIntentActionViewOrSend
import net.gini.android.bank.sdk.exampleapp.core.PermissionHandler
import net.gini.android.bank.sdk.exampleapp.core.di.GiniCaptureNetworkServiceDebugEnabled
import net.gini.android.capture.CaptureResult
import net.gini.android.capture.Document
import net.gini.android.capture.DocumentImportEnabledFileTypes
import net.gini.android.capture.GiniCapture
import net.gini.android.capture.GiniCaptureFragmentListener
import net.gini.android.capture.ResultError
import net.gini.android.capture.camera.CameraFragmentListener
import net.gini.android.capture.network.GiniCaptureDefaultNetworkService
import net.gini.android.capture.review.multipage.view.DefaultReviewNavigationBarBottomAdapter
import net.gini.android.capture.view.DefaultLoadingIndicatorAdapter
Expand All @@ -27,33 +34,41 @@ import javax.inject.Inject

@AndroidEntryPoint
class ClientGiniCaptureFragment : Fragment(R.layout.fragment_client_capture),
GiniCaptureFragmentListener {
//Bank SDK
CaptureFlowFragmentListener {
//Capture SDK
// GiniCaptureFragmentListener, {

@Inject
@GiniCaptureNetworkServiceDebugEnabled
lateinit var giniCaptureDefaultNetworkService: GiniCaptureDefaultNetworkService
private lateinit var permissionHandler: PermissionHandler

override fun onAttach(context: Context) {
super.onAttach(context)
checkCameraPermission()
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
configureBankSDK()
// startCaptureSDK()
}

private fun startCaptureSDK() {
configureCaptureSDK()
val giniCaptureFragment = GiniCapture.createGiniCaptureFragment()
giniCaptureFragment.setListener(this)

requireActivity().supportFragmentManager.beginTransaction()
.replace(R.id.fragment_host, giniCaptureFragment, "fragment_host")
.addToBackStack(null)
.commit()
private fun checkCameraPermission(intent: Intent? = null) {
permissionHandler = PermissionHandler(requireActivity())
lifecycleScope.launch {
if (permissionHandler.grantPermission(Manifest.permission.CAMERA)) {
configureBankSDK()
// configureCaptureSDK()
} else {
if (intent != null) {
requireActivity().finish()
}
}
}
}


private fun configureCaptureSDK() {
checkCameraPermission()
val builder = GiniCapture.newInstance(requireContext())
.setGiniCaptureNetworkService(
giniCaptureDefaultNetworkService
Expand All @@ -67,6 +82,7 @@ class ClientGiniCaptureFragment : Fragment(R.layout.fragment_client_capture),
builder.setLoadingIndicatorAdapter(DefaultLoadingIndicatorAdapter())

builder.build()
startCaptureSDK()
}


Expand Down Expand Up @@ -98,20 +114,19 @@ class ClientGiniCaptureFragment : Fragment(R.layout.fragment_client_capture),
GiniBank.setCaptureConfiguration(requireContext(), captureConfiguration)
GiniBank.enableReturnReasons = true

checkCameraPermission()
startBankSDK()
}

private fun checkCameraPermission(intent: Intent? = null) {
permissionHandler = PermissionHandler(requireActivity())
lifecycleScope.launch {
if (permissionHandler.grantPermission(Manifest.permission.CAMERA)) {
startBankSDK()
} else {
if (intent != null) {
requireActivity().finish()
}
}
}


private fun startCaptureSDK() {
val giniCaptureFragment = GiniCapture.createGiniCaptureFragment()
//giniCaptureFragment.setListener(this)

requireActivity().supportFragmentManager.beginTransaction()
.replace(R.id.fragment_host, giniCaptureFragment, "fragment_host")
.addToBackStack(null)
.commit()
}

private fun startBankSDK() {
Expand Down Expand Up @@ -178,21 +193,21 @@ class ClientGiniCaptureFragment : Fragment(R.layout.fragment_client_capture),

else -> {}
}
// if (isIntentActionViewOrSend(intent)) {
// requireActivity().finish()
// }
//if (isIntentActionViewOrSend(requireActivity().intent)) {
requireActivity().finish()
// }
}

CaptureResult.Empty -> {
// if (isIntentActionViewOrSend(intent)) {
// finish()
// }
//if (isIntentActionViewOrSend(requireActivity().intent)) {
requireActivity().finish()
//}
}

CaptureResult.Cancel -> {
// if (isIntentActionViewOrSend(intent)) {
// finish()
// }
//if (isIntentActionViewOrSend(requireActivity().intent)) {
requireActivity().finish()
//}
}

CaptureResult.EnterManually -> {
Expand All @@ -201,9 +216,9 @@ class ClientGiniCaptureFragment : Fragment(R.layout.fragment_client_capture),
"Scan exited for manual enter mode",
Toast.LENGTH_SHORT
).show()
// if (isIntentActionViewOrSend(intent)) {
// finish()
// }
if (isIntentActionViewOrSend(requireActivity().intent)) {
requireActivity().finish()
}
}
}
}
Expand All @@ -213,6 +228,15 @@ class ClientGiniCaptureFragment : Fragment(R.layout.fragment_client_capture),
requireActivity().finish()
}

override fun onCheckImportedDocument(
document: Document,
callback: CameraFragmentListener.DocumentCheckResultCallback
) {
TODO("Not yet implemented")
}




}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import net.gini.android.bank.sdk.R
import net.gini.android.capture.CaptureResult
import net.gini.android.capture.Document
import net.gini.android.capture.GiniCaptureFragment
import net.gini.android.capture.GiniCaptureFragmentListener
import net.gini.android.capture.camera.CameraFragmentListener

class CaptureFlowFragment : Fragment(), GiniCaptureFragmentListener {

Expand All @@ -22,12 +24,12 @@ class CaptureFlowFragment : Fragment(), GiniCaptureFragmentListener {
}
}

fun setListener(listener: GiniCaptureFragmentListener) {
this.giniCaptureFragmentListener = listener
fun setListener(listener: CaptureFlowFragmentListener) {
this.captureFlowFragmentListener = listener
}

private lateinit var navController: NavController
private lateinit var giniCaptureFragmentListener: GiniCaptureFragmentListener
private lateinit var captureFlowFragmentListener: CaptureFlowFragmentListener

// Related to navigation logic ported from CameraActivity
private var addPages = false
Expand Down Expand Up @@ -76,11 +78,11 @@ class CaptureFlowFragment : Fragment(), GiniCaptureFragmentListener {
}

override fun onFinishedWithResult(result: CaptureResult) {
TODO("Not yet implemented")
captureFlowFragmentListener.onFinishedWithResult(result)
}

override fun onFinishedWithCancellation() {
TODO("Not yet implemented")
captureFlowFragmentListener.onFinishedWithCancellation()
}

//it shows the camera in the start
Expand All @@ -96,6 +98,15 @@ class CaptureFlowFragment : Fragment(), GiniCaptureFragmentListener {

}

interface CaptureFlowFragmentListener {
fun onFinishedWithResult(result: CaptureResult)

fun onFinishedWithCancellation()

fun onCheckImportedDocument(document: Document, callback: CameraFragmentListener.DocumentCheckResultCallback) {
callback.documentAccepted()
}
}

class CaptureFlowFragmentFactory(
private val giniCaptureFragmentListener: GiniCaptureFragmentListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import net.gini.android.capture.document.QRCodeDocument
import net.gini.android.capture.network.model.GiniCaptureCompoundExtraction
import net.gini.android.capture.network.model.GiniCaptureReturnReason
import net.gini.android.capture.network.model.GiniCaptureSpecificExtraction
import net.gini.android.capture.review.multipage.MultiPageReviewActivity
import net.gini.android.capture.review.multipage.MultiPageReviewFragment
import net.gini.android.capture.review.multipage.MultiPageReviewFragmentDirections
import net.gini.android.capture.review.multipage.MultiPageReviewFragmentListener

class GiniCaptureFragment(private val analysisIntent: Intent? = null) : Fragment(), CameraFragmentListener, MultiPageReviewFragmentListener,
Expand Down Expand Up @@ -102,7 +104,7 @@ class GiniCaptureFragment(private val analysisIntent: Intent? = null) : Fragment
//new listener onFinishedWithResult -> returns the result to the client

override fun onProceedToAnalysisScreen(document: Document) {
//navController.navigate(CameraFragmentDirections.toAnalysisFragment(document, ""))
navController.navigate(CameraFragmentDirections.toAnalysisFragment(document, ""))
}

override fun onProceedToMultiPageReviewScreen(
Expand All @@ -113,18 +115,18 @@ class GiniCaptureFragment(private val analysisIntent: Intent? = null) : Fragment
if (addPages) {
// In case we returned to take more images
// Let the app know if it should scroll to the last position
// val intent: Intent = Intent(this, MultiPageReviewActivity::class.java)
// val intent: Intent = Intent(requireActivity(), MultiPageReviewActivity::class.java)
// intent.putExtra(MultiPageReviewActivity.SHOULD_SCROLL_TO_LAST_PAGE, shouldScrollToLastPage)
// setResult(MultiPageReviewActivity.RESULT_SCROLL_TO_LAST_PAGE, intent)
// requireActivity().setResult(MultiPageReviewActivity.RESULT_SCROLL_TO_LAST_PAGE, intent)

// For subsequent images a new CameraActivity was launched from the MultiPageReviewActivity
// and so we can simply finish to return to the review activity
//navController.popBackStack()
navController.popBackStack()
} else {
// For the first image navigate to the review fragment by replacing the camera fragment to make
// the review fragment the new start destination
//val intent = MultiPageReviewActivity.createIntent(this, shouldScrollToLastPage)
//navController.navigate(CameraFragmentDirections.toReviewFragmentForFirstPage())
// val intent = MultiPageReviewActivity.createIntent(requireActivity(), shouldScrollToLastPage)
navController.navigate(CameraFragmentDirections.toReviewFragmentForFirstPage())
}
} else {
throw UnsupportedOperationException("Unsupported multi-page document type.")
Expand All @@ -139,18 +141,18 @@ class GiniCaptureFragment(private val analysisIntent: Intent? = null) : Fragment
}

override fun onProceedToAnalysisScreen(document: GiniCaptureMultiPageDocument<*, *>) {
//navController.navigate(MultiPageReviewFragmentDirections.toAnalysisFragment(document, ""))
navController.navigate(MultiPageReviewFragmentDirections.toAnalysisFragment(document, ""))
}

override fun onReturnToCameraScreenToAddPages() {
// When returning to the camera screen for adding pages we navigate to a new CameraFragment instance
//navController.navigate(MultiPageReviewFragmentDirections.toCameraFragmentForAddingPages())
navController.navigate(MultiPageReviewFragmentDirections.toCameraFragmentForAddingPages())
addPages = true
}

override fun onReturnToCameraScreenForFirstPage() {
// When returning to the camera screen for adding the first page we navigate back to the first CameraFragment instance
//navController.navigate(MultiPageReviewFragmentDirections.toCameraFragmentForFirstPage())
navController.navigate(MultiPageReviewFragmentDirections.toCameraFragmentForFirstPage())
addPages = false
}

Expand All @@ -170,29 +172,13 @@ class GiniCaptureFragment(private val analysisIntent: Intent? = null) : Fragment
returnReasons: MutableList<GiniCaptureReturnReason>
) {
Log.d("analysis", "extractions received: $extractions")

// if (GiniBank.getCaptureConfiguration()?.returnAssistantEnabled == true) {
// try {
// LineItemsValidator.validate(compoundExtractions)
// // TODO: launch the digital invoice fragment
// } catch (notUsed: DigitalInvoiceException) {
// captureFlowFragmentListener.onFinishedWithResult(
// CaptureResult.Success(
// extractions,
// emptyMap(),
// emptyList()
// )
// )
// }
// } else {
giniCaptureFragmentListener.onFinishedWithResult(
CaptureResult.Success(
extractions,
emptyMap(),
emptyList()
)
)
//}
}

override fun onProceedToNoExtractionsScreen(document: Document) {
Expand Down
1 change: 1 addition & 0 deletions capture-sdk/sdk/src/main/res/navigation/gc_nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@
</fragment>



</navigation>

0 comments on commit f686f78

Please sign in to comment.