implements
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/analysis/AnalysisScreenPresenter.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/analysis/AnalysisScreenPresenter.java
index e89ef5579a..6738c68c84 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/analysis/AnalysisScreenPresenter.java
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/analysis/AnalysisScreenPresenter.java
@@ -1,8 +1,6 @@
package net.gini.android.capture.analysis;
import android.app.Activity;
-import android.content.DialogInterface;
-import android.graphics.Bitmap;
import android.net.Uri;
import androidx.annotation.NonNull;
@@ -18,7 +16,6 @@
import net.gini.android.capture.document.GiniCaptureDocumentError;
import net.gini.android.capture.document.GiniCaptureMultiPageDocument;
import net.gini.android.capture.document.PdfDocument;
-import net.gini.android.capture.error.ErrorActivity;
import net.gini.android.capture.error.ErrorType;
import net.gini.android.capture.internal.camera.photo.ParcelableMemoryCache;
import net.gini.android.capture.internal.document.DocumentRenderer;
@@ -53,7 +50,7 @@
/**
* Created by Alpar Szotyori on 08.05.2019.
- *
+ *
* Copyright (c) 2019 Gini GmbH.
*/
@@ -268,32 +265,17 @@ String getPdfFilename(final PdfDocument pdfDocument) {
@VisibleForTesting
void analyzeDocument() {
showAlertIfOpenWithDocumentAndAppIsDefault(mMultiPageDocument,
- new FileImportHelper.ShowAlertCallback() {
- @Override
- public void showAlertDialog(@NonNull final String message,
- @NonNull final String positiveButtonTitle,
- @NonNull final DialogInterface.OnClickListener
- positiveButtonClickListener,
- @Nullable final String negativeButtonTitle,
- @Nullable final DialogInterface.OnClickListener
- negativeButtonClickListener,
- @Nullable final DialogInterface.OnCancelListener cancelListener) {
- getView().showAlertDialog(message, positiveButtonTitle,
- positiveButtonClickListener, negativeButtonTitle,
- negativeButtonClickListener, cancelListener);
- }
- })
- .handle(new CompletableFuture.BiFun() {
- @Override
- public Void apply(final Void aVoid, final Throwable throwable) {
- if (throwable != null) {
- getAnalysisFragmentListenerOrNoOp()
- .onDefaultPDFAppAlertDialogCancelled();
- } else {
- showErrorIfAvailableAndAnalyzeDocument();
- }
- return null;
+ (message, positiveButtonTitle, positiveButtonClickListener, negativeButtonTitle, negativeButtonClickListener, cancelListener) -> getView().showAlertDialog(message, positiveButtonTitle,
+ positiveButtonClickListener, negativeButtonTitle,
+ negativeButtonClickListener, cancelListener))
+ .handle((CompletableFuture.BiFun) (aVoid, throwable) -> {
+ if (throwable != null) {
+ getAnalysisFragmentListenerOrNoOp()
+ .onDefaultPDFAppAlertDialogCancelled();
+ } else {
+ showErrorIfAvailableAndAnalyzeDocument();
}
+ return null;
});
}
@@ -432,21 +414,17 @@ private void showPdfInfoForPdfDocument() {
private void showDocument() {
LOG.debug("Rendering the document");
mDocumentRenderer.toBitmap(getActivity(), getView().getPdfPreviewSize(),
- new DocumentRenderer.Callback() {
- @Override
- public void onBitmapReady(@Nullable final Bitmap bitmap,
- final int rotationForDisplay) {
- LOG.debug("Document rendered");
- if (isStopped()) {
- return;
- }
-
- if (mMultiPageDocument.getType() == Document.Type.IMAGE_MULTI_PAGE || mMultiPageDocument.getType() == Document.Type.IMAGE) {
- return;
- }
+ (bitmap, rotationForDisplay) -> {
+ LOG.debug("Document rendered");
+ if (isStopped()) {
+ return;
+ }
- getView().showBitmap(bitmap, rotationForDisplay);
+ if (mMultiPageDocument.getType() == Document.Type.IMAGE_MULTI_PAGE || mMultiPageDocument.getType() == Document.Type.IMAGE) {
+ return;
}
+
+ getView().showBitmap(bitmap, rotationForDisplay);
});
}
@@ -463,7 +441,7 @@ private void showErrorIfAvailableAndAnalyzeDocument() {
}
}
- ErrorActivity.startErrorActivity(getActivity(), mDocumentAnalysisErrorMessage, mMultiPageDocument);
+ getView().showError(mDocumentAnalysisErrorMessage, mMultiPageDocument);
} else {
doAnalyzeDocument();
}
@@ -482,6 +460,6 @@ private void handleAnalysisError(final Throwable throwable) {
} else {
errorType = ErrorType.GENERAL;
}
- ErrorActivity.startErrorActivity(getActivity(), errorType, mMultiPageDocument);
+ getView().showError(errorType, mMultiPageDocument);
}
}
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraActivity.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraActivity.java
index 34a93f7a86..c23d2040ec 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraActivity.java
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraActivity.java
@@ -33,7 +33,6 @@
import java.util.Map;
import static net.gini.android.capture.analysis.AnalysisActivity.RESULT_NO_EXTRACTIONS;
-import static net.gini.android.capture.error.ErrorActivity.ERROR_SCREEN_REQUEST;
import static net.gini.android.capture.internal.util.ActivityHelper.interceptOnBackPressed;
import static net.gini.android.capture.internal.util.FeatureConfiguration.shouldShowOnboarding;
import static net.gini.android.capture.internal.util.FeatureConfiguration.shouldShowOnboardingAtFirstRun;
@@ -357,7 +356,6 @@ protected void onActivityResult(final int requestCode, final int resultCode,
case REVIEW_DOCUMENT_REQUEST:
case ANALYSE_DOCUMENT_REQUEST:
case MULTI_PAGE_REVIEW_REQUEST:
- case ERROR_SCREEN_REQUEST:
case NO_RESULT_REQUEST:
// The first CameraActivity instance is invisible to the user
// after we navigate to the review or analysis activity.
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraFragmentImpl.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraFragmentImpl.java
index 9dcc931569..600ee42fae 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraFragmentImpl.java
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraFragmentImpl.java
@@ -47,9 +47,8 @@
import net.gini.android.capture.document.ImageDocument;
import net.gini.android.capture.document.ImageMultiPageDocument;
import net.gini.android.capture.document.QRCodeDocument;
-import net.gini.android.capture.error.ErrorActivity;
+import net.gini.android.capture.error.ErrorFragment;
import net.gini.android.capture.error.ErrorType;
-import net.gini.android.capture.help.HelpFragment;
import net.gini.android.capture.internal.camera.api.CameraException;
import net.gini.android.capture.internal.camera.api.CameraInterface;
import net.gini.android.capture.internal.camera.api.OldCameraController;
@@ -336,6 +335,7 @@ public void onCreate(final Bundle savedInstanceState) {
if (savedInstanceState != null) {
restoreSavedState(savedInstanceState);
}
+
}
private void initFlashState() {
@@ -1016,9 +1016,15 @@ private void handleAnalysisError(Throwable throwable, Document document) {
final FailureException failureException = FailureException.tryCastFromCompletableFutureThrowable(throwable);
trackAnalysisScreenEvent(AnalysisScreenEvent.ERROR);
if (failureException != null) {
- ErrorActivity.startErrorActivity(mFragment.getActivity(), failureException.getErrorType(), document);
+ ErrorFragment.Companion.navigateToErrorFragment(
+ mFragment.findNavController(),
+ CameraFragmentDirections.toErrorFragment(failureException.getErrorType(), document)
+ );
} else {
- ErrorActivity.startErrorActivity(mFragment.getActivity(), ErrorType.GENERAL, document);
+ ErrorFragment.Companion.navigateToErrorFragment(
+ mFragment.findNavController(),
+ CameraFragmentDirections.toErrorFragment(ErrorType.GENERAL, document)
+ );
}
}
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorActivity.kt b/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorActivity.kt
deleted file mode 100644
index 1bf011d81f..0000000000
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorActivity.kt
+++ /dev/null
@@ -1,172 +0,0 @@
-package net.gini.android.capture.error
-
-import android.app.Activity
-import android.content.Intent
-import android.os.Bundle
-import android.os.Parcelable
-import android.view.MenuItem
-import androidx.activity.OnBackPressedCallback
-import androidx.appcompat.app.AppCompatActivity
-import net.gini.android.capture.*
-import net.gini.android.capture.camera.CameraActivity.RESULT_CAMERA_SCREEN
-import net.gini.android.capture.camera.CameraActivity.RESULT_ENTER_MANUALLY
-import net.gini.android.capture.internal.ui.IntervalClickListener
-import net.gini.android.capture.internal.util.ActivityHelper
-import net.gini.android.capture.noresults.NoResultsActivity
-import net.gini.android.capture.noresults.NoResultsActivity.EXTRA_IN_DOCUMENT
-import net.gini.android.capture.view.InjectedViewAdapterHolder
-import net.gini.android.capture.view.InjectedViewContainer
-import net.gini.android.capture.view.NavButtonType
-import net.gini.android.capture.view.NavigationBarTopAdapter
-
-/**
- * Internal use only
- */
-class ErrorActivity : AppCompatActivity(),
- ImageRetakeOptionsListener, ErrorFragmentListener {
-
- private var mDocument: Document? = null
- private var mErrorType: ErrorType? = null
- private var mCustomError: String? = null
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.gc_activity_error)
-
- readExtras()
-
- setInjectedTopBarContainer()
- if (savedInstanceState == null) {
- initFragment()
- }
-
- handleOnBackPressed()
- }
-
- private fun setInjectedTopBarContainer() {
- val topBarContainer =
- findViewById>(R.id.gc_injected_navigation_bar_container_top)
- if (GiniCapture.hasInstance()) {
- topBarContainer.injectedViewAdapterHolder = InjectedViewAdapterHolder(GiniCapture.getInstance().internal().navigationBarTopAdapterInstance) { injectedViewAdapter ->
- injectedViewAdapter.apply {
- setTitle(getString(R.string.gc_title_error))
-
- setNavButtonType(NavButtonType.CLOSE)
- setOnNavButtonClickListener(IntervalClickListener {
- onBackPressed()
- })
- }
- }
- }
- }
-
- override fun onBackToCameraPressed() {
- setResult(RESULT_CAMERA_SCREEN)
- finish()
- }
-
- override fun onEnterManuallyPressed() {
- setResult(RESULT_ENTER_MANUALLY)
- finish()
- }
-
- override fun onOptionsItemSelected(item: MenuItem): Boolean {
- if (item.itemId == android.R.id.home) {
- finish()
- return true
- }
- return super.onOptionsItemSelected(item)
- }
-
- private fun initFragment() {
- val errorFragment = ErrorFragmentCompat.createInstance(mErrorType, mDocument, mCustomError)
- supportFragmentManager
- .beginTransaction()
- .add(R.id.gc_fragment_error, errorFragment)
- .commit()
- }
-
- private fun readExtras() {
- val extras = intent.extras
- if (extras != null) {
- mDocument = extras.getParcelable(NoResultsActivity.EXTRA_IN_DOCUMENT)
- mErrorType = extras.getSerializable(EXTRA_IN_ERROR) as? ErrorType
- mCustomError = extras.getString(EXTRA_ERROR_STRING)
- }
- }
-
- private fun handleOnBackPressed() {
- ActivityHelper.interceptOnBackPressed(this, object : OnBackPressedCallback(true) {
- override fun handleOnBackPressed() {
- val noResultsIntent = Intent()
- noResultsIntent.putExtra(NoResultsActivity.NO_RESULT_CANCEL_KEY, true)
- setResult(RESULT_CANCELED, noResultsIntent)
- finish()
- }
- })
- }
-
- override fun onDestroy() {
- super.onDestroy()
- isActivityShown = false
- }
-
- override fun onError(error: GiniCaptureError) {
- val result = Intent()
- result.putExtra(EXTRA_OUT_ERROR, error)
- setResult(RESULT_ERROR, result)
- finish()
- }
-
- companion object {
- /**
- * Internal use only.
- *
- * @suppress
- */
- const val ERROR_REQUEST = 999
-
- const val ERROR_SCREEN_REQUEST = 111
-
- const val EXTRA_IN_ERROR = "GC_EXTRA_IN_ERROR"
-
- const val EXTRA_OUT_ERROR = "GC_EXTRA_OUT_ERROR"
-
- const val EXTRA_ERROR_STRING = "GC_EXTRA_ERROR_STRING"
-
- const val RESULT_ERROR = RESULT_FIRST_USER + 1
-
- var isActivityShown: Boolean = false
-
- @JvmStatic
- fun startErrorActivity(context: Activity, errorType: ErrorType, document: Parcelable?) {
-
- //Error activity is already shown don't start new one
- if (isActivityShown)
- return
-
- isActivityShown = true
-
- val intent = Intent(context, ErrorActivity::class.java)
- intent.putExtra(EXTRA_IN_ERROR, errorType)
- intent.putExtra(EXTRA_IN_DOCUMENT, document)
- context.startActivityForResult(intent, ERROR_SCREEN_REQUEST)
- }
-
- @JvmStatic
- fun startErrorActivity(context: Activity, errorMessage: String, document: Parcelable?) {
-
- //Error activity is already shown don't start new one
- if (isActivityShown)
- return
-
- isActivityShown = true
-
- val intent = Intent(context, ErrorActivity::class.java)
- intent.putExtra(EXTRA_ERROR_STRING, errorMessage)
- intent.putExtra(EXTRA_IN_DOCUMENT, document)
- context.startActivityForResult(intent, ERROR_SCREEN_REQUEST)
- }
-
- }
-}
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentCompat.kt b/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragment.kt
similarity index 54%
rename from capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentCompat.kt
rename to capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragment.kt
index 2f84d06de0..b9a3178049 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentCompat.kt
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragment.kt
@@ -7,10 +7,11 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
+import androidx.navigation.NavDirections
import androidx.navigation.fragment.NavHostFragment
import net.gini.android.capture.Document
-import net.gini.android.capture.GiniCapture
-import net.gini.android.capture.GiniCaptureError
+import net.gini.android.capture.EnterManuallyButtonListener
+import net.gini.android.capture.R
import net.gini.android.capture.internal.ui.FragmentImplCallback
import net.gini.android.capture.internal.util.AlertDialogHelperCompat
@@ -32,22 +33,19 @@ import net.gini.android.capture.internal.util.AlertDialogHelperCompat
* Your Activity is automatically set as the listener in {@link ErrorFragmentCompat#onCreate(Bundle)}.
*
*/
-class ErrorFragmentCompat : Fragment(), FragmentImplCallback {
+class ErrorFragment : Fragment(), FragmentImplCallback,
+ EnterManuallyButtonListener {
private lateinit var fragmentImpl: ErrorFragmentImpl
- private var errorListener: ErrorFragmentListener? = null
+ private lateinit var listener: EnterManuallyButtonListener
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- fragmentImpl = ErrorFragmentHelper.createFragmentImpl(this, arguments)
- activity?.let {
- ErrorFragmentHelper.setListener(fragmentImpl, it)
- if (it is ErrorFragmentListener) errorListener = it
- }
+ fragmentImpl = createFragmentImpl(this, arguments)
+ fragmentImpl.setListener(listener)
fragmentImpl.onCreate(savedInstanceState)
- checkGiniCaptureInstance()
}
override fun onCreateView(
@@ -58,6 +56,13 @@ class ErrorFragmentCompat : Fragment(), FragmentImplCallback {
return fragmentImpl.onCreateView(inflater, container, savedInstanceState)
}
+ fun setListener(
+ listener: EnterManuallyButtonListener
+ ) {
+ this.listener = listener
+
+ }
+
override fun showAlertDialog(
message: String,
positiveButtonTitle: String,
@@ -67,8 +72,15 @@ class ErrorFragmentCompat : Fragment(), FragmentImplCallback {
cancelListener: DialogInterface.OnCancelListener?
) {
activity?.let {
- AlertDialogHelperCompat.showAlertDialog(it, message, positiveButtonTitle,
- positiveButtonClickListener, negativeButtonTitle, negativeButtonClickListener, cancelListener)
+ AlertDialogHelperCompat.showAlertDialog(
+ it,
+ message,
+ positiveButtonTitle,
+ positiveButtonClickListener,
+ negativeButtonTitle,
+ negativeButtonClickListener,
+ cancelListener
+ )
}
}
@@ -76,30 +88,39 @@ class ErrorFragmentCompat : Fragment(), FragmentImplCallback {
return NavHostFragment.findNavController(this)
}
- private fun checkGiniCaptureInstance() {
- if (!GiniCapture.hasInstance()) {
- errorListener?.onError(GiniCaptureError(
- GiniCaptureError.ErrorCode.MISSING_GINI_CAPTURE_INSTANCE,
- "Missing GiniCapture instance. It was not created or there was an application process restart."
- ))
- }
+ fun createFragmentImpl(
+ fragment: FragmentImplCallback,
+ arguments: Bundle?
+ ): ErrorFragmentImpl {
+ val document = arguments?.getParcelable(ARGS_DOCUMENT)
+ val error = arguments?.getSerializable(ARGS_ERROR) as? ErrorType
+ val customError = arguments?.getString(ARGS_CUSTOM_ERROR)
+ return ErrorFragmentImpl(fragment, document, error, customError)
}
companion object {
- /**
- *
- *
- * Factory method for creating a new instance of the Fragment.
- *
- *
- * @param document a [Document] for which no valid extractions were received
- *
- * @return a new instance of the Fragment
- */
- fun createInstance(errorType: ErrorType?, document: Document?, customError: String?): ErrorFragmentCompat {
- val fragment = ErrorFragmentCompat()
- fragment.arguments = ErrorFragmentHelper.createArguments(errorType, document, customError)
- return fragment
+ private const val ARGS_ERROR = "GC_ARGS_ERROR"
+ private const val ARGS_DOCUMENT = "ARGS_DOCUMENT"
+ private const val ARGS_CUSTOM_ERROR = "ARGS_CUSTOM_ERROR"
+
+
+ fun navigateToErrorFragment(
+ navController: NavController,
+ direction: NavDirections
+ ) {
+ if (navController.currentDestination?.id == R.id.gc_destination_error_fragment) {
+ return
+ }
+ navController.navigate(direction)
}
+
+
+ }
+
+
+ override fun onEnterManuallyPressed() {
+
}
+
+
}
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentHelper.kt b/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentHelper.kt
deleted file mode 100644
index e9d1a784c7..0000000000
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentHelper.kt
+++ /dev/null
@@ -1,52 +0,0 @@
-package net.gini.android.capture.error
-
-import android.content.Context
-import android.os.Bundle
-import net.gini.android.capture.Document
-import net.gini.android.capture.internal.ui.FragmentImplCallback
-import net.gini.android.capture.ImageRetakeOptionsListener
-
-/**
- * Helper class for setting arguments to error fragment.
- * Internal use only.
- */
-class ErrorFragmentHelper {
-
- companion object {
- private const val ARGS_ERROR = "GC_ARGS_ERROR"
- private const val ARGS_DOCUMENT = "ARGS_DOCUMENT"
- private const val ARGS_CUSTOM_ERROR = "ARGS_CUSTOM_ERROR"
-
-
- fun createArguments(errorType: ErrorType?, document: Document?, customError: String?): Bundle {
- val arguments = Bundle()
- arguments.putSerializable(ARGS_ERROR, errorType)
- arguments.putParcelable(ARGS_DOCUMENT, document)
- arguments.putString(ARGS_CUSTOM_ERROR, customError)
- return arguments
- }
-
- fun createFragmentImpl(
- fragment: FragmentImplCallback,
- arguments: Bundle?
- ): ErrorFragmentImpl {
- val document = arguments?.getParcelable(ARGS_DOCUMENT)
- val error = arguments?.getSerializable(ARGS_ERROR) as? ErrorType
- val customError = arguments?.getString(ARGS_CUSTOM_ERROR)
- return ErrorFragmentImpl(fragment, document, error, customError)
- }
-
- fun setListener(
- fragmentImpl: ErrorFragmentImpl,
- context: Context
- ) {
- if (context is ImageRetakeOptionsListener) {
- fragmentImpl.setListener(context as ImageRetakeOptionsListener)
- } else {
- throw IllegalStateException(
- "Hosting activity must implement ImageRetakeOptionsListener."
- )
- }
- }
- }
-}
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentImpl.kt b/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentImpl.kt
index fc8c0eaeeb..83f2e6c91b 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentImpl.kt
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentImpl.kt
@@ -8,7 +8,7 @@ import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import net.gini.android.capture.Document
-import net.gini.android.capture.ImageRetakeOptionsListener
+import net.gini.android.capture.EnterManuallyButtonListener
import net.gini.android.capture.R
import net.gini.android.capture.document.ImageMultiPageDocument
import net.gini.android.capture.internal.ui.FragmentImplCallback
@@ -28,13 +28,9 @@ class ErrorFragmentImpl(
private val customError: String?
) {
- private val defaultListener: ImageRetakeOptionsListener = object :
- ImageRetakeOptionsListener {
- override fun onBackToCameraPressed() {}
- override fun onEnterManuallyPressed() {}
- }
+ private val defaultListener: EnterManuallyButtonListener = EnterManuallyButtonListener { }
- private var imageRetakeOptionsListener: ImageRetakeOptionsListener? = null
+ private var enterManuallyButtonListener: EnterManuallyButtonListener? = null
private lateinit var retakeImagesButton: Button
fun onCreate(savedInstanceState: Bundle?) {
@@ -52,19 +48,22 @@ class ErrorFragmentImpl(
if (shouldAllowRetakeImages()) {
retakeImagesButton.setIntervalClickListener {
EventTrackingHelper.trackAnalysisScreenEvent(AnalysisScreenEvent.RETRY)
- imageRetakeOptionsListener?.onBackToCameraPressed()
}
} else {
retakeImagesButton.visibility = View.GONE
}
val enterManuallyButton = view.findViewById(R.id.gc_button_error_enter_manually)
- enterManuallyButton.setIntervalClickListener { imageRetakeOptionsListener?.onEnterManuallyPressed() }
+ enterManuallyButton.setIntervalClickListener { enterManuallyButtonListener?.onEnterManuallyPressed() }
customError?.let {
view.findViewById(R.id.gc_error_header).text = it
}
+ view.findViewById(R.id.gc_button_error_retake_images).setOnClickListener {
+ fragment.findNavController().navigate(ErrorFragmentDirections.toCameraFragment())
+ }
+
errorType?.let {
view.findViewById(R.id.gc_error_header).text =
fragment.activity?.getString(it.titleTextResource)
@@ -77,8 +76,8 @@ class ErrorFragmentImpl(
return view
}
- fun setListener(imageRetakeOptionsListener: ImageRetakeOptionsListener?) {
- this.imageRetakeOptionsListener = imageRetakeOptionsListener ?: defaultListener
+ fun setListener(enterManuallyButtonListener: EnterManuallyButtonListener?) {
+ this.enterManuallyButtonListener = enterManuallyButtonListener ?: defaultListener
}
private fun shouldAllowRetakeImages(): Boolean {
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentListener.kt b/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentListener.kt
deleted file mode 100644
index 3b64b971e9..0000000000
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/error/ErrorFragmentListener.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package net.gini.android.capture.error
-
-import net.gini.android.capture.GiniCaptureError
-
-/**
- * Internal use only.
- *
- * Interface used by the {@link ErrorFragmentCompat} to dispatch events to the hosting activity.
- */
-interface ErrorFragmentListener {
-
- /**
- * Called when an error occurred.
- *
- * @param error details about what went wrong
- */
- fun onError(error: GiniCaptureError)
-}
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/internal/util/ActivityHelper.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/internal/util/ActivityHelper.java
index 3a9d4cd3c8..b2ef74d5ee 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/internal/util/ActivityHelper.java
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/internal/util/ActivityHelper.java
@@ -1,21 +1,10 @@
package net.gini.android.capture.internal.util;
-import static net.gini.android.capture.error.ErrorActivity.ERROR_SCREEN_REQUEST;
-import static net.gini.android.capture.error.ErrorActivity.EXTRA_IN_ERROR;
-import static net.gini.android.capture.internal.util.ContextHelper.isTablet;
-import static net.gini.android.capture.noresults.NoResultsActivity.EXTRA_IN_DOCUMENT;
-import static net.gini.android.capture.tracking.EventTrackingHelper.trackAnalysisScreenEvent;
-
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.os.Parcelable;
-import android.view.Display;
-import android.view.WindowManager;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
@@ -23,6 +12,8 @@
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
+import static net.gini.android.capture.internal.util.ContextHelper.isTablet;
+
/**
* Internal use only.
*
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsActivity.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsActivity.java
index 63c0864795..b2ac5838fb 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsActivity.java
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsActivity.java
@@ -6,18 +6,15 @@
import android.os.Bundle;
import android.view.MenuItem;
-import net.gini.android.capture.Document;
-import net.gini.android.capture.GiniCaptureError;
-import net.gini.android.capture.ImageRetakeOptionsListener;
-import net.gini.android.capture.R;
-
import androidx.activity.OnBackPressedCallback;
-import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
-import static net.gini.android.capture.camera.CameraActivity.RESULT_CAMERA_SCREEN;
+import net.gini.android.capture.Document;
+import net.gini.android.capture.EnterManuallyButtonListener;
+import net.gini.android.capture.R;
+
import static net.gini.android.capture.camera.CameraActivity.RESULT_ENTER_MANUALLY;
import static net.gini.android.capture.internal.util.ActivityHelper.interceptOnBackPressed;
@@ -26,7 +23,7 @@
*
* The {@code NoResultsActivity} displays hints that show how to best use the SDK.
*/
-public class NoResultsActivity extends AppCompatActivity implements ImageRetakeOptionsListener, NoResultsFragmentListener {
+public class NoResultsActivity extends AppCompatActivity implements EnterManuallyButtonListener {
/**
* Internal use only.
@@ -47,12 +44,6 @@ public class NoResultsActivity extends AppCompatActivity implements ImageRetakeO
private Document mDocument;
- @Override
- public void onBackToCameraPressed() {
- setResult(RESULT_CAMERA_SCREEN);
- finish();
- }
-
@Override
public void onEnterManuallyPressed() {
setResult(RESULT_ENTER_MANUALLY);
@@ -121,11 +112,4 @@ public boolean onOptionsItemSelected(final MenuItem item) {
return super.onOptionsItemSelected(item);
}
- @Override
- public void onError(@NonNull GiniCaptureError error) {
- Intent noResultsIntent = new Intent();
- noResultsIntent.putExtra(EXTRA_OUT_ERROR, true);
- setResult(RESULT_ERROR, noResultsIntent);
- finish();
- }
}
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentCompat.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentCompat.java
index 0a873064b5..aa01796011 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentCompat.java
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentCompat.java
@@ -8,20 +8,15 @@
import android.view.View;
import android.view.ViewGroup;
-import net.gini.android.capture.Document;
-import net.gini.android.capture.GiniCapture;
-import net.gini.android.capture.GiniCaptureError;
-import net.gini.android.capture.ImageRetakeOptionsListener;
-import net.gini.android.capture.internal.ui.FragmentImplCallback;
-import net.gini.android.capture.internal.util.AlertDialogHelperCompat;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;
-import static net.gini.android.capture.GiniCaptureError.ErrorCode.MISSING_GINI_CAPTURE_INSTANCE;
+import net.gini.android.capture.Document;
+import net.gini.android.capture.internal.ui.FragmentImplCallback;
+import net.gini.android.capture.internal.util.AlertDialogHelperCompat;
/**
* Internal use only.
@@ -29,19 +24,14 @@
public class NoResultsFragmentCompat extends Fragment implements FragmentImplCallback {
private NoResultsFragmentImpl mFragmentImpl;
- private NoResultsFragmentListener errorListener;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mFragmentImpl = NoResultsFragmentHelper.createFragmentImpl(this, getArguments());
NoResultsFragmentHelper.setListener(mFragmentImpl, getActivity());
- if (getActivity() instanceof NoResultsFragmentListener) {
- errorListener = (NoResultsFragmentListener) getActivity();
- }
mFragmentImpl.onCreate(savedInstanceState);
- checkGiniCaptureInstance();
}
@Nullable
@@ -88,10 +78,4 @@ public NavController findNavController() {
return NavHostFragment.findNavController(this);
}
- private void checkGiniCaptureInstance() {
- if (!GiniCapture.hasInstance()) {
- errorListener.onError(new GiniCaptureError(MISSING_GINI_CAPTURE_INSTANCE,
- "Missing GiniCapture instance. It was not created or there was an application process restart."));
- }
- }
}
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentHelper.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentHelper.java
index f59d22b319..d69c04c3a6 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentHelper.java
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentHelper.java
@@ -3,12 +3,12 @@
import android.content.Context;
import android.os.Bundle;
+import androidx.annotation.NonNull;
+
import net.gini.android.capture.Document;
-import net.gini.android.capture.ImageRetakeOptionsListener;
+import net.gini.android.capture.EnterManuallyButtonListener;
import net.gini.android.capture.internal.ui.FragmentImplCallback;
-import androidx.annotation.NonNull;
-
/**
* Helper class for setting arguments to analysis fragment.
* Internal use only.
@@ -36,8 +36,8 @@ static NoResultsFragmentImpl createFragmentImpl(@NonNull final FragmentImplCallb
public static void setListener(@NonNull final NoResultsFragmentImpl fragmentImpl,
@NonNull final Context context) {
- if (context instanceof ImageRetakeOptionsListener) {
- fragmentImpl.setListener((ImageRetakeOptionsListener) context);
+ if (context instanceof EnterManuallyButtonListener) {
+ fragmentImpl.setListener((EnterManuallyButtonListener) context);
} else {
throw new IllegalStateException(
"Hosting activity must implement NoResultsFragmentListener.");
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentImpl.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentImpl.java
index 72ecd9fedb..5e22101f32 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentImpl.java
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentImpl.java
@@ -13,7 +13,7 @@
import net.gini.android.capture.Document;
import net.gini.android.capture.GiniCapture;
-import net.gini.android.capture.ImageRetakeOptionsListener;
+import net.gini.android.capture.EnterManuallyButtonListener;
import net.gini.android.capture.R;
import net.gini.android.capture.document.ImageMultiPageDocument;
import net.gini.android.capture.help.PhotoTipsAdapter;
@@ -37,18 +37,12 @@
*/
class NoResultsFragmentImpl {
- private static final ImageRetakeOptionsListener NO_OP_LISTENER =
- new ImageRetakeOptionsListener() {
- @Override
- public void onBackToCameraPressed() {}
-
- @Override
- public void onEnterManuallyPressed() {}
- };
+ private static final EnterManuallyButtonListener NO_OP_LISTENER =
+ () -> {};
private final FragmentImplCallback mFragment;
private final Document mDocument;
- private ImageRetakeOptionsListener mListener;
+ private EnterManuallyButtonListener mListener;
private TextView mTitleTextView;
private InjectedViewContainer topAdapterInjectedViewContainer;
@@ -59,7 +53,7 @@ public void onEnterManuallyPressed() {}
mDocument = document;
}
- void setListener(@Nullable final ImageRetakeOptionsListener listener) {
+ void setListener(@Nullable final EnterManuallyButtonListener listener) {
if (listener == null) {
mListener = NO_OP_LISTENER;
} else {
@@ -78,7 +72,6 @@ View onCreateView(final LayoutInflater inflater, final ViewGroup container,
if (shouldAllowRetakeImages()) {
ClickListenerExtKt.setIntervalClickListener(retakeImagesButton, v -> {
trackAnalysisScreenEvent(AnalysisScreenEvent.RETRY);
- mListener.onBackToCameraPressed();
});
} else {
retakeImagesButton.setVisibility(GONE);
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentListener.kt b/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentListener.kt
deleted file mode 100644
index da397b5d3e..0000000000
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/noresults/NoResultsFragmentListener.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package net.gini.android.capture.noresults
-
-import net.gini.android.capture.GiniCaptureError
-
-/**
- * Internal use only.
- *
- * Interface used by the {@link NoResultsFragmentCompat} to dispatch events to the hosting activity.
- */
-interface NoResultsFragmentListener {
-
- /**
- * Called when an error occurred.
- *
- * @param error details about what went wrong
- */
- fun onError(error: GiniCaptureError)
-}
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/review/multipage/MultiPageReviewActivity.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/review/multipage/MultiPageReviewActivity.java
index a8bc7bf7c6..738ef9ba7b 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/review/multipage/MultiPageReviewActivity.java
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/review/multipage/MultiPageReviewActivity.java
@@ -1,14 +1,5 @@
package net.gini.android.capture.review.multipage;
-import static net.gini.android.capture.analysis.AnalysisActivity.RESULT_NO_EXTRACTIONS;
-import static net.gini.android.capture.camera.CameraActivity.RESULT_CAMERA_SCREEN;
-import static net.gini.android.capture.camera.CameraActivity.RESULT_ENTER_MANUALLY;
-import static net.gini.android.capture.error.ErrorActivity.ERROR_SCREEN_REQUEST;
-import static net.gini.android.capture.internal.util.ActivityHelper.enableHomeAsUp;
-import static net.gini.android.capture.internal.util.ActivityHelper.interceptOnBackPressed;
-import static net.gini.android.capture.noresults.NoResultsActivity.NO_RESULT_CANCEL_KEY;
-import static net.gini.android.capture.tracking.EventTrackingHelper.trackReviewScreenEvent;
-
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -16,7 +7,10 @@
import android.os.Bundle;
import android.view.MenuItem;
-import net.gini.android.capture.GiniCapture;
+import androidx.activity.OnBackPressedCallback;
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+
import net.gini.android.capture.GiniCaptureError;
import net.gini.android.capture.R;
import net.gini.android.capture.analysis.AnalysisActivity;
@@ -26,9 +20,11 @@
import java.util.List;
-import androidx.activity.OnBackPressedCallback;
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
+import static net.gini.android.capture.camera.CameraActivity.RESULT_CAMERA_SCREEN;
+import static net.gini.android.capture.internal.util.ActivityHelper.enableHomeAsUp;
+import static net.gini.android.capture.internal.util.ActivityHelper.interceptOnBackPressed;
+import static net.gini.android.capture.noresults.NoResultsActivity.NO_RESULT_CANCEL_KEY;
+import static net.gini.android.capture.tracking.EventTrackingHelper.trackReviewScreenEvent;
/**
* Created by Alpar Szotyori on 16.02.2018.
@@ -213,18 +209,6 @@ protected void onActivityResult(final int requestCode, final int resultCode,
finish();
}
- if (requestCode == ERROR_SCREEN_REQUEST) {
- if (resultCode == RESULT_CAMERA_SCREEN) {
- if (GiniCapture.hasInstance()) {
- GiniCapture.getInstance().internal().getImageMultiPageDocumentMemoryStore().clear();
- }
- setResult(resultCode);
- } else if (resultCode == RESULT_ENTER_MANUALLY) {
- setResult(RESULT_ENTER_MANUALLY, data);
- }
- finish();
- }
-
if (requestCode == REQUEST_SCROLL_TO_LAST_PAGE) {
if (resultCode == RESULT_SCROLL_TO_LAST_PAGE && data != null) {
if (data.hasExtra(SHOULD_SCROLL_TO_LAST_PAGE)) {
diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/review/multipage/MultiPageReviewFragment.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/review/multipage/MultiPageReviewFragment.java
index c68ae5a858..0cd4f8e72c 100644
--- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/review/multipage/MultiPageReviewFragment.java
+++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/review/multipage/MultiPageReviewFragment.java
@@ -2,7 +2,6 @@
import android.app.Activity;
import android.content.DialogInterface;
-import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -18,6 +17,7 @@
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
+import androidx.navigation.Navigation;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SnapHelper;
@@ -33,13 +33,12 @@
import net.gini.android.capture.document.GiniCaptureDocumentError;
import net.gini.android.capture.document.ImageDocument;
import net.gini.android.capture.document.ImageMultiPageDocument;
-import net.gini.android.capture.error.ErrorActivity;
+import net.gini.android.capture.error.ErrorFragment;
import net.gini.android.capture.error.ErrorType;
import net.gini.android.capture.internal.network.FailureException;
import net.gini.android.capture.internal.network.NetworkRequestResult;
import net.gini.android.capture.internal.network.NetworkRequestsManager;
import net.gini.android.capture.internal.ui.ClickListenerExtKt;
-import net.gini.android.capture.internal.ui.FragmentImplCallback;
import net.gini.android.capture.internal.ui.IntervalClickListener;
import net.gini.android.capture.internal.util.AlertDialogHelperCompat;
import net.gini.android.capture.internal.util.FileImportHelper;
@@ -387,11 +386,11 @@ private void setInjectedLoadingIndicatorContainer() {
if (GiniCapture.hasInstance() && !GiniCapture.getInstance().isBottomNavigationBarEnabled()) {
injectedLoadingIndicatorContainer.setInjectedViewAdapterHolder(new InjectedViewAdapterHolder<>(
GiniCapture.getInstance().internal().getOnButtonLoadingIndicatorAdapterInstance(), injectedViewAdapter -> {
- if (isOnButtonLoadingIndicatorActive) {
- injectedViewAdapter.onVisible();
- } else {
- injectedViewAdapter.onHidden();
- }
+ if (isOnButtonLoadingIndicatorActive) {
+ injectedViewAdapter.onVisible();
+ } else {
+ injectedViewAdapter.onHidden();
+ }
}));
}
}
@@ -687,6 +686,7 @@ public void run() {
}
private void uploadDocuments() {
+
for (final ImageDocument imageDocument : mMultiPageDocument.getDocuments()) {
if (!mMultiPageDocument.hasDocumentError(imageDocument)) {
// Documents with a an error should not be uploaded automatically
@@ -696,7 +696,7 @@ private void uploadDocuments() {
if (documentError != null) {
trackAnalysisScreenEvent(AnalysisScreenEvent.ERROR);
ErrorType errorType = ErrorType.typeFromDocumentErrorCode(documentError.getErrorCode());
- ErrorActivity.startErrorActivity(requireActivity(), errorType, imageDocument);
+ Navigation.findNavController(this.getView()).navigate(MultiPageReviewFragmentDirections.toErrorFragment(errorType, imageDocument));
}
}
}
@@ -722,30 +722,24 @@ void uploadDocument(final ImageDocument document) {
mMultiPageDocument.removeErrorForDocument(document);
mDocumentUploadResults.put(document.getId(), false);
networkRequestsManager.upload(activity, document)
- .handle(new CompletableFuture.BiFun,
- Throwable, Void>() {
- @Override
- public Void apply(
- final NetworkRequestResult requestResult,
- final Throwable throwable) {
- if (throwable != null
- && !NetworkRequestsManager.isCancellation(throwable)) {
+ .handle((CompletableFuture.BiFun, Throwable, Void>) (requestResult, throwable) -> {
+ if (throwable != null
+ && !NetworkRequestsManager.isCancellation(throwable)) {
- hideIndicator();
+ hideIndicator();
- trackUploadError(throwable);
+ trackUploadError(throwable);
- if (getActivity() != null) {
- handleError(throwable, document);
- }
-
- } else if (requestResult != null) {
- hideIndicator();
- mDocumentUploadResults.put(document.getId(), true);
+ if (getActivity() != null) {
+ handleError(throwable, document);
}
- updateNextButtonVisibility();
- return null;
+
+ } else if (requestResult != null) {
+ hideIndicator();
+ mDocumentUploadResults.put(document.getId(), true);
}
+ updateNextButtonVisibility();
+ return null;
});
}
@@ -761,9 +755,15 @@ private void handleError(Throwable throwable, Document document) {
final FailureException failureException = FailureException.tryCastFromCompletableFutureThrowable(throwable);
trackAnalysisScreenEvent(AnalysisScreenEvent.ERROR);
if (failureException != null) {
- ErrorActivity.startErrorActivity(requireActivity(), failureException.getErrorType(), document);
+ ErrorFragment.Companion.navigateToErrorFragment(
+ Navigation.findNavController(this.getView()),
+ MultiPageReviewFragmentDirections.toErrorFragment(failureException.getErrorType(), document)
+ );
} else {
- ErrorActivity.startErrorActivity(requireActivity(), ErrorType.GENERAL, document);
+ ErrorFragment.Companion.navigateToErrorFragment(
+ Navigation.findNavController(this.getView()),
+ MultiPageReviewFragmentDirections.toErrorFragment(ErrorType.GENERAL, document)
+ );
}
}
}
diff --git a/capture-sdk/sdk/src/main/res/navigation/gc_nav_graph.xml b/capture-sdk/sdk/src/main/res/navigation/gc_nav_graph.xml
index 513659d590..886267a1ec 100644
--- a/capture-sdk/sdk/src/main/res/navigation/gc_nav_graph.xml
+++ b/capture-sdk/sdk/src/main/res/navigation/gc_nav_graph.xml
@@ -5,6 +5,86 @@
android:id="@+id/gc_nav_graph"
app:startDestination="@id/gc_destination_camera_fragment">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ app:popUpToInclusive="true" />
-
-
-
-
-
-
-
-
-
+ android:name="GC_ARGS_ERROR"
+ app:argType="net.gini.android.capture.error.ErrorType" />
+ android:name="ARGS_DOCUMENT"
+ app:argType="net.gini.android.capture.Document" />
+
+
+
-
-
-
-
-
-
-
+ tools:layout="@layout/gc_fragment_file_import_help">
-
+ tools:layout="@layout/gc_fragment_photo_tips_help">
+ tools:layout="@layout/gc_fragment_supported_formats_help">
+
+
+
+
+
+