Skip to content

Commit

Permalink
refactor(): Replace ErrorActivity with ErrorFragment
Browse files Browse the repository at this point in the history
BSDK-258
  • Loading branch information
abolfazlimahdi committed Jan 18, 2024
1 parent c8a22ea commit 46cdb60
Show file tree
Hide file tree
Showing 27 changed files with 350 additions and 609 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import net.gini.android.bank.sdk.capture.CaptureFlowFragmentListener
import net.gini.android.bank.sdk.capture.CaptureResult
import net.gini.android.bank.sdk.capture.ResultError
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.capture.CaptureSDKResultError
import net.gini.android.capture.DocumentImportEnabledFileTypes
Expand Down Expand Up @@ -142,21 +143,21 @@ class ClientGiniCaptureFragment :

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

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

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

CaptureResult.EnterManually -> {
Expand All @@ -165,9 +166,9 @@ class ClientGiniCaptureFragment :
"Scan exited for manual enter mode",
Toast.LENGTH_SHORT
).show()
// if (isIntentActionViewOrSend(requireActivity().intent)) {
// requireActivity().finish()
// }
if (isIntentActionViewOrSend(requireActivity().intent)) {
requireActivity().finish()
}
}
}
}
Expand All @@ -178,7 +179,6 @@ class ClientGiniCaptureFragment :
}



}


Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import net.gini.android.bank.sdk.exampleapp.core.PermissionHandler
import net.gini.android.bank.sdk.exampleapp.databinding.ActivityMainBinding
import net.gini.android.bank.sdk.exampleapp.ui.data.Configuration
import net.gini.android.capture.EntryPoint
import net.gini.android.capture.requirements.RequirementsReport
import net.gini.android.capture.util.CancellationToken


Expand Down Expand Up @@ -215,26 +214,6 @@ class MainActivity : AppCompatActivity() {
configurationViewModel.configureGiniBank(this)
}

private fun showUnfulfilledRequirementsToast(report: RequirementsReport) {
val stringBuilder = StringBuilder()
val requirementReports = report.requirementReports
for (i in requirementReports.indices) {
val requirementReport = requirementReports[i]
if (!requirementReport.isFulfilled) {
if (stringBuilder.isNotEmpty()) {
stringBuilder.append("\n")
}
stringBuilder.append(requirementReport.requirementId)
if (requirementReport.details.isNotEmpty()) {
stringBuilder.append(": ")
stringBuilder.append(requirementReport.details)
}
}
}
Toast.makeText(
this, "Requirements not fulfilled:\n$stringBuilder", Toast.LENGTH_LONG
).show()
}

override fun onActivityResult(
requestCode: Int, resultCode: Int, data: Intent?
Expand Down
5 changes: 0 additions & 5 deletions capture-sdk/sdk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
<uses-permission android:name="android.permission.VIBRATE" />

<application>
<activity
android:name="net.gini.android.capture.error.ErrorActivity"
android:exported="false"
android:label="@string/gc_title_error"
android:theme="@style/GiniCaptureTheme"/>
<activity
android:name="net.gini.android.capture.camera.CameraActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.gini.android.capture;

import net.gini.android.capture.error.ErrorFragment;
import net.gini.android.capture.noresults.NoResultsFragmentCompat;
/**
* <p>
* Interface used by {@link NoResultsFragmentCompat} and {@link ErrorFragment} to dispatch events to the hosting Activity.
* </p>
*/
public interface EnterManuallyButtonListener {


/**
* <p>
* Called when the button on the bottom of the No Results/Error Screen was pressed. This button
* should lead the user to the manual data input form/site.
* </p>
*/
void onEnterManuallyPressed();
}
Original file line number Diff line number Diff line change
Expand Up @@ -664,30 +664,30 @@ public static GiniCaptureFragment createGiniCaptureFragment() {
return GiniCaptureFragment.Companion.createInstance(null);
}

public CancellationToken createGiniCaptureFragmentForIntent(Context context, Intent intent, TheCallback the) {
public CancellationToken createGiniCaptureFragmentForIntent(Context context, Intent intent, GiniCaptureIntentCallback captureIntentCallback) {
return createIntentForImportedFiles(intent, context, new AsyncCallback<Intent, ImportedFileValidationException>() {
@Override
public void onSuccess(Intent result) {
if (result.getComponent().getClassName().equals(AnalysisActivity.class.getName())) {
the.callback(new CreateCaptureFlowFragmentForIntentResult.Success(GiniCaptureFragment.Companion.createInstance(result)));
captureIntentCallback.callback(new CreateCaptureFlowFragmentForIntentResult.Success(GiniCaptureFragment.Companion.createInstance(result)));
} else {
the.callback(new CreateCaptureFlowFragmentForIntentResult.Error(new ImportedFileValidationException("Unknown activity class: ${result.component?.className}")));
captureIntentCallback.callback(new CreateCaptureFlowFragmentForIntentResult.Error(new ImportedFileValidationException("Unknown activity class: ${result.component?.className}")));
}
}

@Override
public void onError(ImportedFileValidationException exception) {
the.callback(new CreateCaptureFlowFragmentForIntentResult.Error(exception));
captureIntentCallback.callback(new CreateCaptureFlowFragmentForIntentResult.Error(exception));
}

@Override
public void onCancelled() {
the.callback(new CreateCaptureFlowFragmentForIntentResult.Cancelled());
captureIntentCallback.callback(new CreateCaptureFlowFragmentForIntentResult.Cancelled());
}
});
}

interface TheCallback {
interface GiniCaptureIntentCallback {
void callback(CreateCaptureFlowFragmentForIntentResult result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import net.gini.android.capture.camera.CameraFragmentListener
import net.gini.android.capture.document.GiniCaptureDocumentError
import net.gini.android.capture.document.GiniCaptureMultiPageDocument
import net.gini.android.capture.document.QRCodeDocument
import net.gini.android.capture.error.ErrorFragment
import net.gini.android.capture.network.model.GiniCaptureCompoundExtraction
import net.gini.android.capture.network.model.GiniCaptureReturnReason
import net.gini.android.capture.network.model.GiniCaptureSpecificExtraction
Expand All @@ -30,7 +31,8 @@ class GiniCaptureFragment(private val analysisIntent: Intent? = null) :
Fragment(),
CameraFragmentListener,
MultiPageReviewFragmentListener,
AnalysisFragmentListener {
AnalysisFragmentListener,
EnterManuallyButtonListener {

internal companion object {
fun createInstance(intent: Intent? = null): GiniCaptureFragment {
Expand Down Expand Up @@ -76,7 +78,7 @@ class GiniCaptureFragment(private val analysisIntent: Intent? = null) :
}

override fun onCreate(savedInstanceState: Bundle?) {
childFragmentManager.fragmentFactory = CaptureFragmentFactory(this, this, this)
childFragmentManager.fragmentFactory = CaptureFragmentFactory(this, this, this, this)
super.onCreate(savedInstanceState)
}

Expand Down Expand Up @@ -219,12 +221,17 @@ class GiniCaptureFragment(private val analysisIntent: Intent? = null) :
// TODO("Not yet implemented")
}

override fun onEnterManuallyPressed() {
giniCaptureFragmentListener.onFinishedWithResult(CaptureSDKResult.EnterManually)
}

}

class CaptureFragmentFactory(
private val cameraListener: CameraFragmentListener,
private val multiPageReviewFragmentListener: MultiPageReviewFragmentListener,
private val analysisFragmentListener: AnalysisFragmentListener
private val analysisFragmentListener: AnalysisFragmentListener,
private val enterManuallyButtonListener: EnterManuallyButtonListener
) : FragmentFactory() {
override fun instantiate(classLoader: ClassLoader, className: String): Fragment {
when (className) {
Expand All @@ -245,6 +252,11 @@ class CaptureFragmentFactory(
analysisFragmentListener
)
}
ErrorFragment::class.java.name -> return ErrorFragment().apply {
setListener(
enterManuallyButtonListener
)
}

else -> return super.instantiate(classLoader, className)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AppCompatActivity;

import net.gini.android.capture.Document;
import net.gini.android.capture.GiniCapture;
Expand All @@ -21,15 +26,8 @@
import java.util.List;
import java.util.Map;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AppCompatActivity;

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;
Expand Down Expand Up @@ -252,7 +250,7 @@ public void onDefaultPDFAppAlertDialogCancelled() {

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if ((requestCode == NO_RESULT_REQUEST || requestCode == ERROR_SCREEN_REQUEST) &&
if ((requestCode == NO_RESULT_REQUEST) &&
((resultCode == RESULT_CANCELED && data != null && data.hasExtra(NO_RESULT_CANCEL_KEY)) || resultCode == RESULT_ENTER_MANUALLY || resultCode == RESULT_CAMERA_SCREEN)) {
if (resultCode == RESULT_CAMERA_SCREEN) {
if (GiniCapture.hasInstance()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import net.gini.android.capture.Document;
import net.gini.android.capture.GiniCapture;
import net.gini.android.capture.R;
import net.gini.android.capture.error.ErrorFragment;
import net.gini.android.capture.error.ErrorType;
import net.gini.android.capture.internal.ui.FragmentImplCallback;
import net.gini.android.capture.internal.ui.IntervalClickListener;
import net.gini.android.capture.internal.util.Size;
Expand Down Expand Up @@ -159,6 +161,22 @@ void showHints(final List<AnalysisHint> hints) {
mHintsAnimator.start();
}

@Override
void showError(String error, Document document) {
ErrorFragment.Companion.navigateToErrorFragment(
mFragment.findNavController(),
AnalysisFragmentCompatDirections.toErrorFragmentWithErrorMessage(error, document)
);
}

@Override
void showError(ErrorType errorType, Document document) {
ErrorFragment.Companion.navigateToErrorFragment(
mFragment.findNavController(),
AnalysisFragmentCompatDirections.toErrorFragmentWithErrorType(errorType, document)
);
}

private void rotateDocumentImageView(final int rotationForDisplay) {
if (rotationForDisplay == 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import android.content.DialogInterface;
import android.graphics.Bitmap;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import net.gini.android.capture.Document;
import net.gini.android.capture.GiniCaptureBasePresenter;
import net.gini.android.capture.GiniCaptureBaseView;
import net.gini.android.capture.error.ErrorType;
import net.gini.android.capture.internal.util.Size;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import jersey.repackaged.jsr166e.CompletableFuture;

/**
Expand Down Expand Up @@ -57,6 +60,9 @@ abstract void showAlertDialog(@NonNull final String message,
@Nullable final DialogInterface.OnCancelListener cancelListener);

abstract void showHints(List<AnalysisHint> hints);

abstract void showError(String errorMessage, Document document);
abstract void showError(ErrorType errorType, Document document);
}

abstract class Presenter extends GiniCaptureBasePresenter<View> implements
Expand Down
Loading

0 comments on commit 46cdb60

Please sign in to comment.