Skip to content

Commit

Permalink
refactor(capture-sdk): Replace NoResultsActivity with NoResultsFragment
Browse files Browse the repository at this point in the history
- move the logic from NoResultsActivity into NoResultsFragment
- delete NoResultsActivity

BSDK-258
  • Loading branch information
abolfazlimahdi committed Jan 19, 2024
1 parent ff2cd70 commit e2fa698
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 301 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.gini.android.capture;

import net.gini.android.capture.error.ErrorFragment;
import net.gini.android.capture.noresults.NoResultsFragmentCompat;
import net.gini.android.capture.noresults.NoResultsFragment;
/**
* <p>
* Interface used by {@link NoResultsFragmentCompat} and {@link ErrorFragment} to dispatch events to the hosting Activity.
* Interface used by {@link NoResultsFragment} and {@link ErrorFragment} to dispatch events to the hosting Activity.
* </p>
*/
public interface EnterManuallyButtonListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import net.gini.android.capture.analysis.AnalysisActivity
import net.gini.android.capture.analysis.AnalysisFragmentCompat
import net.gini.android.capture.analysis.AnalysisFragmentCompatDirections
import net.gini.android.capture.analysis.AnalysisFragmentListener
import net.gini.android.capture.camera.CameraFragment
import net.gini.android.capture.camera.CameraFragmentDirections
Expand All @@ -24,6 +25,7 @@ import net.gini.android.capture.internal.util.FeatureConfiguration.shouldShowOnb
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.noresults.NoResultsFragment
import net.gini.android.capture.review.multipage.MultiPageReviewFragment
import net.gini.android.capture.review.multipage.MultiPageReviewFragmentDirections
import net.gini.android.capture.review.multipage.MultiPageReviewFragmentListener
Expand Down Expand Up @@ -203,8 +205,10 @@ class GiniCaptureFragment(private val analysisIntent: Intent? = null) :
}

override fun onProceedToNoExtractionsScreen(document: Document) {
// TODO: launch the no results fragment for the document
// TODO("Not yet implemented")
NoResultsFragment.navigateToNoResultsFragment(
navController,
AnalysisFragmentCompatDirections.toNoResultsFragment(document)
)
}

override fun onDefaultPDFAppAlertDialogCancelled() {
Expand Down Expand Up @@ -260,12 +264,20 @@ class CaptureFragmentFactory(
analysisFragmentListener
)
}

ErrorFragment::class.java.name -> return ErrorFragment().apply {
setListener(
enterManuallyButtonListener
)
}

NoResultsFragment::class.java.name -> return NoResultsFragment()
.apply {
setListener(
enterManuallyButtonListener
)
}

else -> return super.instantiate(classLoader, className)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
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.noresults.NoResultsActivity;
import net.gini.android.capture.tracking.AnalysisScreenEvent;

import java.util.ArrayList;
Expand All @@ -29,7 +28,6 @@
import static net.gini.android.capture.camera.CameraActivity.RESULT_ENTER_MANUALLY;
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.trackAnalysisScreenEvent;

/**
Expand Down Expand Up @@ -226,24 +224,7 @@ public void onExtractionsAvailable(

@Override
public void onProceedToNoExtractionsScreen(@NonNull final Document document) {
if (shouldShowGiniCaptureNoResultsScreen(mDocument)) {
final Intent noResultsActivity = new Intent(this, NoResultsActivity.class);
noResultsActivity.putExtra(NoResultsActivity.EXTRA_IN_DOCUMENT, mDocument);
noResultsActivity.setExtrasClassLoader(AnalysisActivity.class.getClassLoader());
startActivityForResult(noResultsActivity, NO_RESULT_REQUEST);
setResult(RESULT_NO_EXTRACTIONS);
if (GiniCapture.hasInstance()) {
GiniCapture.getInstance().internal().getImageMultiPageDocumentMemoryStore().clear();
}
} else {
final Intent result = new Intent();
setResult(RESULT_OK, result);
finish();
}
}

public static boolean shouldShowGiniCaptureNoResultsScreen(final Document document) {
return document.getType() != Document.Type.QRCode && document.getType() != Document.Type.QR_CODE_MULTI_PAGE;
}

@Override
Expand All @@ -254,7 +235,7 @@ public void onDefaultPDFAppAlertDialogCancelled() {
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if ((requestCode == NO_RESULT_REQUEST) &&
((resultCode == RESULT_CANCELED && data != null && data.hasExtra(NO_RESULT_CANCEL_KEY)) || resultCode == RESULT_ENTER_MANUALLY || resultCode == RESULT_CAMERA_SCREEN)) {
((resultCode == RESULT_CANCELED && data != null) || resultCode == RESULT_ENTER_MANUALLY || resultCode == RESULT_CAMERA_SCREEN)) {
if (resultCode == RESULT_CAMERA_SCREEN) {
if (GiniCapture.hasInstance()) {
GiniCapture.getInstance().internal().getImageMultiPageDocumentMemoryStore().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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.noresults.NoResultsFragmentCompat;
import net.gini.android.capture.noresults.NoResultsFragment;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -38,7 +38,7 @@ void onExtractionsAvailable(
/**
* Called when the document has been analyzed and no extractions were received.
* <p>
* You should show the {@link NoResultsFragmentCompat}.
* You should show the {@link NoResultsFragment}.
*
* @param document contains the reviewed document
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@
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.noresults.NoResultsActivity;
import net.gini.android.capture.review.multipage.MultiPageReviewActivity;
import net.gini.android.capture.tracking.AnalysisScreenEvent;
import net.gini.android.capture.tracking.CameraScreenEvent;

import java.util.Map;

import static net.gini.android.capture.analysis.AnalysisActivity.RESULT_NO_EXTRACTIONS;
import static net.gini.android.capture.internal.util.ActivityHelper.interceptOnBackPressed;
import static net.gini.android.capture.review.multipage.MultiPageReviewActivity.RESULT_SCROLL_TO_LAST_PAGE;
import static net.gini.android.capture.review.multipage.MultiPageReviewActivity.SHOULD_SCROLL_TO_LAST_PAGE;
import static net.gini.android.capture.tracking.EventTrackingHelper.trackAnalysisScreenEvent;
import static net.gini.android.capture.tracking.EventTrackingHelper.trackCameraScreenEvent;

/**
Expand Down Expand Up @@ -300,15 +296,6 @@ public void onExtractionsAvailable(

@Override
public void noExtractionsFromQRCode(QRCodeDocument qrCodeDocument) {
trackAnalysisScreenEvent(AnalysisScreenEvent.NO_RESULTS);
final Intent noResultsActivity = new Intent(this, NoResultsActivity.class);
noResultsActivity.putExtra(NoResultsActivity.EXTRA_IN_DOCUMENT, qrCodeDocument);
noResultsActivity.setExtrasClassLoader(CameraActivity.class.getClassLoader());
startActivityForResult(noResultsActivity, NO_RESULT_REQUEST);
setResult(RESULT_NO_EXTRACTIONS);
if (GiniCapture.hasInstance()) {
GiniCapture.getInstance().internal().getImageMultiPageDocumentMemoryStore().clear();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import net.gini.android.capture.internal.util.AlertDialogHelperCompat
* Your Activity is automatically set as the listener in {@link ErrorFragmentCompat#onCreate(Bundle)}.
* </p>
*/
class ErrorFragment : Fragment(), FragmentImplCallback,
EnterManuallyButtonListener {
class ErrorFragment : Fragment(), FragmentImplCallback {

private lateinit var fragmentImpl: ErrorFragmentImpl
private lateinit var listener: EnterManuallyButtonListener
Expand Down Expand Up @@ -118,9 +117,4 @@ class ErrorFragment : Fragment(), FragmentImplCallback,
}


override fun onEnterManuallyPressed() {

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ErrorFragmentImpl(
if (shouldAllowRetakeImages()) {
retakeImagesButton.setIntervalClickListener {
EventTrackingHelper.trackAnalysisScreenEvent(AnalysisScreenEvent.RETRY)
fragment.findNavController().navigate(ErrorFragmentDirections.toCameraFragment())
}
} else {
retakeImagesButton.visibility = View.GONE
Expand All @@ -60,9 +61,6 @@ class ErrorFragmentImpl(
view.findViewById<TextView>(R.id.gc_error_header).text = it
}

view.findViewById<Button>(R.id.gc_button_error_retake_images).setOnClickListener {
fragment.findNavController().navigate(ErrorFragmentDirections.toCameraFragment())
}

errorType?.let {
view.findViewById<TextView>(R.id.gc_error_header).text =
Expand Down

This file was deleted.

Loading

0 comments on commit e2fa698

Please sign in to comment.