Skip to content

Commit

Permalink
refactor(capture-sdk): Move navigation into MultiPageReviewFragment
Browse files Browse the repository at this point in the history
BSDK-258
  • Loading branch information
a-szotyori committed Jan 22, 2024
1 parent ba5f41f commit f9b70f2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,6 @@ class GiniCaptureFragment(private val openWithDocument: Document? = null) :
giniCaptureFragmentListener.onCheckImportedDocument(document, callback)
}

override fun onProceedToAnalysisScreen(document: GiniCaptureMultiPageDocument<*, *>) {
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())
}

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())
}

override fun onImportedDocumentReviewCancelled() {
// TODO: not needed anymore because this was called when the user deleted the last image imported via "open with"
// and since version 3.x we upload "open with" images directly (like PDFs) and users can't delete them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.navigation.Navigation;
import androidx.navigation.fragment.NavHostFragment;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SnapHelper;
Expand Down Expand Up @@ -435,7 +436,9 @@ private void setReviewNavigationBarBottomAdapter(View view) {
mReviewNavigationBarBottomAdapter.setInjectedViewAdapterHolder(new InjectedViewAdapterHolder<>(
GiniCapture.getInstance().internal().getReviewNavigationBarBottomAdapterInstance(),
injectedViewAdapter -> {
injectedViewAdapter.setOnAddPageButtonClickListener(new IntervalClickListener(v -> mListener.onReturnToCameraScreenToAddPages()));
injectedViewAdapter.setOnAddPageButtonClickListener(new IntervalClickListener(v -> {
NavHostFragment.findNavController(this).navigate(MultiPageReviewFragmentDirections.toCameraFragmentForAddingPages());
}));

boolean isMultiPage = GiniCapture.getInstance().isMultiPageEnabled();

Expand Down Expand Up @@ -528,7 +531,9 @@ private void setInputHandlers() {
mAddPagesButton.setVisibility(GiniCapture.getInstance().isMultiPageEnabled() ? View.VISIBLE : View.GONE);
}

ClickListenerExtKt.setIntervalClickListener(mAddPagesButton, v -> mListener.onReturnToCameraScreenToAddPages());
ClickListenerExtKt.setIntervalClickListener(mAddPagesButton, v -> {
NavHostFragment.findNavController(this).navigate(MultiPageReviewFragmentDirections.toCameraFragmentForAddingPages());
});
}


Expand All @@ -551,7 +556,7 @@ private void deleteDocumentAndUpdateUI(@NonNull final ImageDocument document) {
.create().show();
} else {
doDeleteDocumentAndUpdateUI(document);
mListener.onReturnToCameraScreenForFirstPage();
NavHostFragment.findNavController(this).navigate(MultiPageReviewFragmentDirections.toCameraFragmentForFirstPage());
}
} else {
doDeleteDocumentAndUpdateUI(document);
Expand Down Expand Up @@ -667,7 +672,7 @@ private void setNextButtonEnabled(final boolean enabled) {
void onNextButtonClicked() {
trackReviewScreenEvent(ReviewScreenEvent.NEXT);
mNextClicked = true;
mListener.onProceedToAnalysisScreen(mMultiPageDocument);
NavHostFragment.findNavController(this).navigate(MultiPageReviewFragmentDirections.toAnalysisFragment(mMultiPageDocument, ""));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,6 @@
*/
public interface MultiPageReviewFragmentListener {

/**
* Called when all pages were uploaded successfully and the user tapped on the "next" button.
*
* <p> If you use the Screen API you should start the {@link AnalysisFragment} and
*
* <p> If you use the Component API you should start the {@link AnalysisFragment}
* and pass the document when creating it with {@link
* AnalysisFragment#createInstance(Document, String)}.
*
* @param document contains the reviewed image (can be the original one or a modified image)
*/
void onProceedToAnalysisScreen(@NonNull GiniCaptureMultiPageDocument document);

/**
* Called when the user wants to add a picture of another page. Also called when the user has
* deleted every page and the document consisted of images taken with the Camera Screen or
* imported using the Camera Screen.
*
* <p> If you host the {@link MultiPageReviewFragment} in its own Activity, then you should
* simply finish the Activity.
*
* <p> If you use one Activity to host all the Gini Capture fragments, then you should display the
* {@link CameraFragment} again.
*/
void onReturnToCameraScreenToAddPages();

/**
* Called when user deletes the last taken or imported image from {@link MultiPageReviewFragment}
*/
void onReturnToCameraScreenForFirstPage();

/**
* Called when the user deleted all the pages of a document received from another app.
*
Expand Down

0 comments on commit f9b70f2

Please sign in to comment.