From 63bf0cc74ed7db115ed3b6a70b1de99274ceff2e Mon Sep 17 00:00:00 2001 From: Mahdi Abolfazli Date: Mon, 16 Oct 2023 11:31:04 +0200 Subject: [PATCH 1/6] feat(capture-sdk): Extract transfer summary and clean up into two separate methods PIA-4595 --- .../net/gini/android/capture/GiniCapture.java | 148 ++++++++++++++---- 1 file changed, 121 insertions(+), 27 deletions(-) diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java index f950b3381b..4c1d07724d 100644 --- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java +++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java @@ -1,13 +1,12 @@ package net.gini.android.capture; -import static net.gini.android.capture.internal.util.FileImportValidator.FILE_SIZE_LIMIT; - -import static java.util.Collections.emptyList; -import static java.util.Collections.emptyMap; - import android.content.Context; import android.content.Intent; -import net.gini.android.capture.analysis.AnalysisActivity; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; + import net.gini.android.capture.camera.view.CameraNavigationBarBottomAdapter; import net.gini.android.capture.camera.view.DefaultCameraNavigationBarBottomAdapter; import net.gini.android.capture.help.HelpItem; @@ -22,21 +21,15 @@ import net.gini.android.capture.logging.ErrorLoggerListener; import net.gini.android.capture.network.Error; import net.gini.android.capture.network.GiniCaptureNetworkCallback; +import net.gini.android.capture.network.GiniCaptureNetworkService; +import net.gini.android.capture.network.model.GiniCaptureCompoundExtraction; import net.gini.android.capture.network.model.GiniCaptureSpecificExtraction; +import net.gini.android.capture.onboarding.OnboardingPage; import net.gini.android.capture.onboarding.view.DefaultOnboardingNavigationBarBottomAdapter; import net.gini.android.capture.onboarding.view.OnboardingIllustrationAdapter; import net.gini.android.capture.onboarding.view.OnboardingNavigationBarBottomAdapter; import net.gini.android.capture.review.multipage.view.DefaultReviewNavigationBarBottomAdapter; import net.gini.android.capture.review.multipage.view.ReviewNavigationBarBottomAdapter; -import net.gini.android.capture.view.CustomLoadingIndicatorAdapter; -import net.gini.android.capture.view.DefaultLoadingIndicatorAdapter; -import net.gini.android.capture.view.DefaultOnButtonLoadingIndicatorAdapter; -import net.gini.android.capture.view.InjectedViewAdapterInstance; -import net.gini.android.capture.view.NavigationBarTopAdapter; -import net.gini.android.capture.view.DefaultNavigationBarTopAdapter; -import net.gini.android.capture.network.GiniCaptureNetworkService; -import net.gini.android.capture.network.model.GiniCaptureCompoundExtraction; -import net.gini.android.capture.onboarding.OnboardingPage; import net.gini.android.capture.tracking.AnalysisScreenEvent; import net.gini.android.capture.tracking.CameraScreenEvent; import net.gini.android.capture.tracking.Event; @@ -44,6 +37,12 @@ import net.gini.android.capture.tracking.OnboardingScreenEvent; import net.gini.android.capture.tracking.ReviewScreenEvent; import net.gini.android.capture.util.CancellationToken; +import net.gini.android.capture.view.CustomLoadingIndicatorAdapter; +import net.gini.android.capture.view.DefaultLoadingIndicatorAdapter; +import net.gini.android.capture.view.DefaultNavigationBarTopAdapter; +import net.gini.android.capture.view.DefaultOnButtonLoadingIndicatorAdapter; +import net.gini.android.capture.view.InjectedViewAdapterInstance; +import net.gini.android.capture.view.NavigationBarTopAdapter; import net.gini.android.capture.view.OnButtonLoadingIndicatorAdapter; import org.jetbrains.annotations.NotNull; @@ -55,9 +54,9 @@ import java.util.List; import java.util.Map; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.VisibleForTesting; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; +import static net.gini.android.capture.internal.util.FileImportValidator.FILE_SIZE_LIMIT; /** * Created by Alpar Szotyori on 22.02.2018. @@ -71,14 +70,20 @@ *

To create and configure a singleton instance use the {@link #newInstance(Context)} method and the * returned {@link Builder}. * - *

Use the {@link #cleanup(Context, String, String, String, String, String, Amount)} method to clean up the SDK - * while also providing the required extraction feedback to improve the future extraction accuracy. + *

Use the {@link #cleanup(Context)} method to clean up the SDK + * Please follow the recommendations below: + * + *

+ * + *

Use the {@link #transferSummary(String, String, String, String, String, Amount)} method to + * provide the required extraction feedback to improve the future extraction accuracy. * Please follow the recommendations below: * *

*/ public class GiniCapture { @@ -154,10 +159,10 @@ public static synchronized boolean hasInstance() { * Configure and create a new instance using the returned {@link Builder}. * * @return a new {@link Builder} - * @throws IllegalStateException when an instance already exists. Call {@link #cleanup(Context, String, String, String, String, String, Amount)} + * @throws IllegalStateException when an instance already exists. Call {@link #cleanup(Context)} * before trying to create a new instance * @deprecated Please use {@link #newInstance(Context)} which allows instance recreation without having to - * call {@link #cleanup(Context, String, String, String, String, String, Amount)} first. + * call {@link #cleanup(Context)} first. */ @NonNull @Deprecated @@ -181,10 +186,93 @@ public static synchronized Builder newInstance(final Context context) { if (sInstance.mNetworkRequestsManager != null) { sInstance.mNetworkRequestsManager.cleanup(); } - doActualCleanUp(context); + cleanup(context); } return new Builder(); } + + /** + * Provides transfer summary to Gini. + * + *

Please provide the required extraction feedback to improve the future extraction accuracy. + * Please follow the recommendations below: + * + *

+ * + * @param paymentRecipient payment receiver + * @param paymentReference ID based on Client ID (Kundennummer) and invoice ID (Rechnungsnummer) + * @param paymentPurpose statement what this payment is for + * @param iban international bank account + * @param bic bank identification code + * @param amount accepts extracted amount and currency + * + */ + public static synchronized void transferSummary( + @NonNull final String paymentRecipient, + @NonNull final String paymentReference, + @NonNull final String paymentPurpose, + @NonNull final String iban, + @NonNull final String bic, + @NonNull final Amount amount) { + + if (sInstance == null) { + return; + } + + Map extractionMap = new HashMap<>(); + + extractionMap.put("amountToPay", new GiniCaptureSpecificExtraction("amountToPay", amount.amountToPay(), + "amount", null, emptyList())); + + extractionMap.put("paymentRecipient", new GiniCaptureSpecificExtraction("paymentRecipient", paymentRecipient, + "companyname", null, emptyList())); + + extractionMap.put("paymentReference", new GiniCaptureSpecificExtraction("paymentReference", paymentReference, + "reference", null, emptyList())); + + extractionMap.put("paymentPurpose", new GiniCaptureSpecificExtraction("paymentPurpose", paymentPurpose, + "reference", null, emptyList())); + + extractionMap.put("iban", new GiniCaptureSpecificExtraction("iban", iban, + "iban", null, emptyList())); + + extractionMap.put("bic", new GiniCaptureSpecificExtraction("bic", bic, + "bic", null, emptyList())); + + + // Test fails here if for some reason mGiniCaptureNetworkService is null + // Added null checking to fix test fail -> or figure out something else + final GiniCapture oldInstance = sInstance; + if (oldInstance.mGiniCaptureNetworkService != null) + oldInstance.mGiniCaptureNetworkService.sendFeedback(extractionMap, + oldInstance.mInternal.getCompoundExtractions(), new GiniCaptureNetworkCallback() { + @Override + public void failure(Error error) { + if (oldInstance.mNetworkRequestsManager != null) { + oldInstance.mNetworkRequestsManager.cleanup(); + } + } + + @Override + public void success(Void result) { + if (oldInstance.mNetworkRequestsManager != null) { + oldInstance.mNetworkRequestsManager.cleanup(); + } + } + + @Override + public void cancelled() { + if (oldInstance.mNetworkRequestsManager != null) { + oldInstance.mNetworkRequestsManager.cleanup(); + } + } + }); + } + + /** * Destroys the {@link GiniCapture} instance and frees up used resources. * @@ -204,7 +292,11 @@ public static synchronized Builder newInstance(final Context context) { * @param iban international bank account * @param bic bank identification code * @param amount accepts extracted amount and currency + * + * @deprecated Please use {@link #cleanup(Context)} which does not require transfer summary parameters. */ + + @Deprecated public static synchronized void cleanup(@NonNull final Context context, @NonNull final String paymentRecipient, @NonNull final String paymentReference, @@ -266,11 +358,13 @@ public void cancelled() { } }); - doActualCleanUp(context); + cleanup(context); } - - private static void doActualCleanUp(Context context) { + /** + * Destroys the {@link GiniCapture} instance and frees up used resources. + */ + public static void cleanup(Context context) { sInstance.mDocumentDataMemoryCache.clear(); sInstance.mPhotoMemoryCache.clear(); sInstance.mInternal.setUpdatedCompoundExtractions(emptyMap()); From ed33921f2080580cf5b20bbc2e18a9d44b1d9835 Mon Sep 17 00:00:00 2001 From: Mahdi Abolfazli Date: Mon, 16 Oct 2023 13:17:08 +0200 Subject: [PATCH 2/6] feat(bank-sdk): Extract feedback and cleanup methods into two separate methods PIA-4595 --- .../sdk/exampleapp/ui/ExtractionsActivity.kt | 64 +++++++++++------ .../net/gini/android/bank/sdk/GiniBank.kt | 68 +++++++++++++++++-- .../net/gini/android/capture/GiniCapture.java | 59 ++-------------- 3 files changed, 110 insertions(+), 81 deletions(-) diff --git a/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt b/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt index cbd3728cbd..38fa2bbee6 100644 --- a/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt +++ b/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt @@ -19,7 +19,7 @@ import com.google.android.material.textfield.TextInputLayout import dagger.hilt.android.AndroidEntryPoint import net.gini.android.bank.sdk.GiniBank import net.gini.android.bank.sdk.exampleapp.R -import net.gini.android.bank.sdk.exampleapp.core.di.GiniCaptureNetworkServiceDebugDisabled +import net.gini.android.bank.sdk.exampleapp.core.di.GiniCaptureNetworkServiceRelease import net.gini.android.bank.sdk.exampleapp.databinding.ActivityExtractionsBinding import net.gini.android.capture.Amount import net.gini.android.capture.AmountCurrency @@ -40,12 +40,16 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA private var mExtractions: MutableMap = hashMapOf() private lateinit var mExtractionsAdapter: ExtractionsAdapter - @Inject @GiniCaptureNetworkServiceDebugDisabled + + @Inject + @GiniCaptureNetworkServiceRelease lateinit var defaultNetworkService: GiniCaptureDefaultNetworkService // {extraction name} to it's {entity name} - private val editableSpecificExtractions = hashMapOf("paymentRecipient" to "companyname", "paymentReference" to "reference", - "paymentPurpose" to "text", "iban" to "iban", "bic" to "bic", "amountToPay" to "amount") + private val editableSpecificExtractions = hashMapOf( + "paymentRecipient" to "companyname", "paymentReference" to "reference", + "paymentPurpose" to "text", "iban" to "iban", "bic" to "bic", "amountToPay" to "amount" + ) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -98,23 +102,30 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA editableSpecificExtractions.forEach { if (!mExtractions.containsKey(it.key)) { mExtractions[it.key] = GiniCaptureSpecificExtraction( - it.key, "", - it.value, null, emptyList()) + it.key, "", + it.value, null, emptyList() + ) } } - adapter = ExtractionsAdapter(getSortedExtractions(mExtractions), this@ExtractionsActivity, editableSpecificExtractions.keys.toList()).also { + adapter = ExtractionsAdapter( + getSortedExtractions(mExtractions), + this@ExtractionsActivity, + editableSpecificExtractions.keys.toList() + ).also { mExtractionsAdapter = it } setOnTouchListener { _, _ -> performClick() - val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager + val inputMethodManager = + getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.hideSoftInputFromWindow(windowToken, 0) } } } - private fun getSortedExtractions(extractions: Map): List = extractions.toSortedMap().values.toList() + private fun getSortedExtractions(extractions: Map): List = + extractions.toSortedMap().values.toList() private fun sendFeedbackAndClose(binding: ActivityExtractionsBinding) { // Feedback should be sent only for the user visible fields. Non-visible fields should be filtered out. @@ -131,10 +142,14 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA amount = Amount.EMPTY.amountToPay() } - GiniBank.releaseCapture(applicationContext, paymentRecipient, paymentReference, paymentPurpose, iban, bic, Amount( - BigDecimal(amount.removeSuffix(":EUR")), AmountCurrency.EUR) + GiniBank.transferSummary( + paymentRecipient, paymentReference, paymentPurpose, iban, bic, Amount( + BigDecimal(amount.removeSuffix(":EUR")), AmountCurrency.EUR + ) ) + GiniBank.releaseCapture(applicationContext) + finish() } @@ -151,25 +166,32 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA companion object { const val EXTRA_IN_EXTRACTIONS = "EXTRA_IN_EXTRACTIONS" - fun getStartIntent(context: Context, extractionsBundle: Map): Intent = - Intent(context, ExtractionsActivity::class.java).apply { - putExtra(EXTRA_IN_EXTRACTIONS, Bundle().apply { - extractionsBundle.map { putParcelable(it.key, it.value) } - }) - } + fun getStartIntent( + context: Context, + extractionsBundle: Map + ): Intent = + Intent(context, ExtractionsActivity::class.java).apply { + putExtra(EXTRA_IN_EXTRACTIONS, Bundle().apply { + extractionsBundle.map { putParcelable(it.key, it.value) } + }) + } } } -private class ExtractionsAdapter(var extractions: List, - var listener: ExtractionsAdapterInterface? = null, - val editableSpecificExtractions: List) : RecyclerView.Adapter() { +private class ExtractionsAdapter( + var extractions: List, + var listener: ExtractionsAdapterInterface? = null, + val editableSpecificExtractions: List +) : RecyclerView.Adapter() { interface ExtractionsAdapterInterface { fun valueChanged(key: String, value: String) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExtractionsViewHolder { - val holder = ExtractionsViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_extraction, parent, false)) + val holder = ExtractionsViewHolder( + LayoutInflater.from(parent.context).inflate(R.layout.item_extraction, parent, false) + ) holder.mTextValue.addTextChangedListener { listener?.valueChanged(holder.mTextInputLayout.hint.toString(), it.toString()) } diff --git a/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt b/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt index ce45c53030..350bec5a21 100644 --- a/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt +++ b/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt @@ -34,9 +34,7 @@ import net.gini.android.capture.onboarding.view.OnboardingIllustrationAdapter import net.gini.android.capture.requirements.GiniCaptureRequirements import net.gini.android.capture.requirements.RequirementsReport import net.gini.android.capture.util.CancellationToken -import net.gini.android.capture.view.DefaultNavigationBarTopAdapter import net.gini.android.capture.view.InjectedViewAdapterInstance -import net.gini.android.capture.view.NavigationBarTopAdapter import net.gini.android.core.api.Resource import net.gini.android.core.api.models.PaymentRequest @@ -133,6 +131,45 @@ object GiniBank { giniCapture = GiniCapture.getInstance() } + + /** + * Provides transfer summary to Gini. + * + * + * Please provide the required extraction feedback to improve the future extraction accuracy. + * Please follow the recommendations below: + * + * Please make sure to call this method before calling [releaseCapture]. + * + * Please provide values for all necessary fields, including those that were not extracted. + * Provide the final data approved by the user (and not the initially extracted only). + * + * + * @param paymentRecipient payment receiver + * @param paymentReference ID based on Client ID (Kundennummer) and invoice ID (Rechnungsnummer) + * @param paymentPurpose statement what this payment is for + * @param iban international bank account + * @param bic bank identification code + * @param amount accepts extracted amount and currency + */ + fun transferSummary( + paymentRecipient: String, + paymentReference: String, + paymentPurpose: String, + iban: String, + bic: String, + amount: Amount + ) { + GiniCapture.transferSummary( + paymentRecipient, + paymentReference, + paymentPurpose, + iban, + bic, + amount + ) + } + /** * Frees up resources used by the capture flow. * @@ -150,7 +187,13 @@ object GiniBank { * @param iban international bank account * @param bic bank identification code * @param amount accepts extracted amount and currency + * + * @deprecated Please use {@link #releaseCapture(Context)} which does not require transfer summary parameters. */ + @Deprecated( + "Please use releaseCapture(Context) which does not require transfer summary parameters.", + ReplaceWith("releaseCapture(context)") + ) fun releaseCapture( context: Context, paymentRecipient: String, @@ -160,8 +203,7 @@ object GiniBank { bic: String, amount: Amount ) { - GiniCapture.cleanup( - context, + transferSummary( paymentRecipient, paymentReference, paymentPurpose, @@ -169,6 +211,22 @@ object GiniBank { bic, amount ) + releaseCapture(context) + } + + + /** + * Frees up resources used by the capture flow. + * + * @param context Android context + * + */ + fun releaseCapture( + context: Context + ) { + GiniCapture.cleanup( + context + ) captureConfiguration = null giniCapture = null @@ -176,7 +234,7 @@ object GiniBank { digitalInvoiceHelpNavigationBarBottomAdapter = DefaultDigitalInvoiceHelpNavigationBarBottomAdapter() digitalInvoiceOnboardingIllustrationAdapter = ImageOnboardingIllustrationAdapter(R.drawable.gbs_digital_invoice_list_image, - R.string.gbs_digital_invoice_onboarding_text_1) + R.string.gbs_digital_invoice_onboarding_text_1) digitalInvoiceNavigationBarBottomAdapter = DefaultDigitalInvoiceNavigationBarBottomAdapter() } diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java index 4c1d07724d..de7e32cb8c 100644 --- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java +++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java @@ -198,6 +198,7 @@ public static synchronized Builder newInstance(final Context context) { * Please follow the recommendations below: * *
    + *
  • Please call this method before calling the {@link #cleanup(Context)} method
  • *
  • Please provide values for all necessary fields, including those that were not extracted.
  • *
  • Provide the final data approved by the user (and not the initially extracted only).
  • *
@@ -270,6 +271,7 @@ public void cancelled() { } } }); + } @@ -293,7 +295,7 @@ public void cancelled() { * @param bic bank identification code * @param amount accepts extracted amount and currency * - * @deprecated Please use {@link #cleanup(Context)} which does not require transfer summary parameters. + * @deprecated Please use {@link #cleanup(Context)} to cleanup and {@link #transferSummary(String, String, String, String, String, Amount)} to provide the required extraction feedback. */ @Deprecated @@ -304,60 +306,7 @@ public static synchronized void cleanup(@NonNull final Context context, @NonNull final String iban, @NonNull final String bic, @NonNull final Amount amount) { - - if (sInstance == null) { - return; - } - - Map extractionMap = new HashMap<>(); - - extractionMap.put("amountToPay", new GiniCaptureSpecificExtraction("amountToPay", amount.amountToPay(), - "amount", null, emptyList())); - - extractionMap.put("paymentRecipient", new GiniCaptureSpecificExtraction("paymentRecipient", paymentRecipient, - "companyname", null, emptyList())); - - extractionMap.put("paymentReference", new GiniCaptureSpecificExtraction("paymentReference", paymentReference, - "reference", null, emptyList())); - - extractionMap.put("paymentPurpose", new GiniCaptureSpecificExtraction("paymentPurpose", paymentPurpose, - "reference", null, emptyList())); - - extractionMap.put("iban", new GiniCaptureSpecificExtraction("iban", iban, - "iban", null, emptyList())); - - extractionMap.put("bic", new GiniCaptureSpecificExtraction("bic", bic, - "bic", null, emptyList())); - - - // Test fails here if for some reason mGiniCaptureNetworkService is null - // Added null checking to fix test fail -> or figure out something else - final GiniCapture oldInstance = sInstance; - if (oldInstance.mGiniCaptureNetworkService != null) - oldInstance.mGiniCaptureNetworkService.sendFeedback(extractionMap, - oldInstance.mInternal.getCompoundExtractions(), new GiniCaptureNetworkCallback() { - @Override - public void failure(Error error) { - if (oldInstance.mNetworkRequestsManager != null) { - oldInstance.mNetworkRequestsManager.cleanup(); - } - } - - @Override - public void success(Void result) { - if (oldInstance.mNetworkRequestsManager != null) { - oldInstance.mNetworkRequestsManager.cleanup(); - } - } - - @Override - public void cancelled() { - if (oldInstance.mNetworkRequestsManager != null) { - oldInstance.mNetworkRequestsManager.cleanup(); - } - } - }); - + transferSummary(paymentRecipient, paymentReference, paymentPurpose, iban, bic, amount); cleanup(context); } From f37c1381241f3cc1871ee9c9c7d0d3870f004b4f Mon Sep 17 00:00:00 2001 From: Mahdi Abolfazli Date: Mon, 16 Oct 2023 13:19:44 +0200 Subject: [PATCH 3/6] refactor(): Reformat code and remove unused imports PIA-4595 --- .../sdk/exampleapp/ui/ExtractionsActivity.kt | 25 ++-- .../net/gini/android/bank/sdk/GiniBank.kt | 66 ++++----- .../net/gini/android/capture/GiniCapture.java | 137 +++++++----------- 3 files changed, 93 insertions(+), 135 deletions(-) diff --git a/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt b/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt index 38fa2bbee6..c01ebdc7ad 100644 --- a/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt +++ b/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt @@ -47,8 +47,12 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA // {extraction name} to it's {entity name} private val editableSpecificExtractions = hashMapOf( - "paymentRecipient" to "companyname", "paymentReference" to "reference", - "paymentPurpose" to "text", "iban" to "iban", "bic" to "bic", "amountToPay" to "amount" + "paymentRecipient" to "companyname", + "paymentReference" to "reference", + "paymentPurpose" to "text", + "iban" to "iban", + "bic" to "bic", + "amountToPay" to "amount" ) override fun onCreate(savedInstanceState: Bundle?) { @@ -102,8 +106,7 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA editableSpecificExtractions.forEach { if (!mExtractions.containsKey(it.key)) { mExtractions[it.key] = GiniCaptureSpecificExtraction( - it.key, "", - it.value, null, emptyList() + it.key, "", it.value, null, emptyList() ) } } @@ -167,14 +170,12 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA const val EXTRA_IN_EXTRACTIONS = "EXTRA_IN_EXTRACTIONS" fun getStartIntent( - context: Context, - extractionsBundle: Map - ): Intent = - Intent(context, ExtractionsActivity::class.java).apply { - putExtra(EXTRA_IN_EXTRACTIONS, Bundle().apply { - extractionsBundle.map { putParcelable(it.key, it.value) } - }) - } + context: Context, extractionsBundle: Map + ): Intent = Intent(context, ExtractionsActivity::class.java).apply { + putExtra(EXTRA_IN_EXTRACTIONS, Bundle().apply { + extractionsBundle.map { putParcelable(it.key, it.value) } + }) + } } } diff --git a/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt b/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt index 350bec5a21..2f0beecfd0 100644 --- a/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt +++ b/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt @@ -66,7 +66,8 @@ object GiniBank { InjectedViewAdapterInstance(DefaultDigitalInvoiceOnboardingNavigationBarBottomAdapter()) var digitalInvoiceOnboardingNavigationBarBottomAdapter: DigitalInvoiceOnboardingNavigationBarBottomAdapter set(value) { - digitalInvoiceOnboardingNavigationBarBottomAdapterInstance = InjectedViewAdapterInstance(value) + digitalInvoiceOnboardingNavigationBarBottomAdapterInstance = + InjectedViewAdapterInstance(value) } get() = digitalInvoiceOnboardingNavigationBarBottomAdapterInstance.viewAdapter @@ -74,12 +75,18 @@ object GiniBank { InjectedViewAdapterInstance(DefaultDigitalInvoiceHelpNavigationBarBottomAdapter()) var digitalInvoiceHelpNavigationBarBottomAdapter: DigitalInvoiceHelpNavigationBarBottomAdapter set(value) { - digitalInvoiceHelpNavigationBarBottomAdapterInstance = InjectedViewAdapterInstance(value) + digitalInvoiceHelpNavigationBarBottomAdapterInstance = + InjectedViewAdapterInstance(value) } get() = digitalInvoiceHelpNavigationBarBottomAdapterInstance.viewAdapter internal var digitalInvoiceOnboardingIllustrationAdapterInstance: InjectedViewAdapterInstance = - InjectedViewAdapterInstance(ImageOnboardingIllustrationAdapter(R.drawable.gbs_digital_invoice_list_image, R.string.gbs_digital_invoice_onboarding_text_1)) + InjectedViewAdapterInstance( + ImageOnboardingIllustrationAdapter( + R.drawable.gbs_digital_invoice_list_image, + R.string.gbs_digital_invoice_onboarding_text_1 + ) + ) var digitalInvoiceOnboardingIllustrationAdapter: OnboardingIllustrationAdapter set(value) { digitalInvoiceOnboardingIllustrationAdapterInstance = InjectedViewAdapterInstance(value) @@ -114,9 +121,7 @@ object GiniBank { fun setCaptureConfiguration(captureConfiguration: CaptureConfiguration) { check(giniCapture == null) { "Gini Capture already configured. Call releaseCapture() before setting a new configuration." } GiniBank.captureConfiguration = captureConfiguration - GiniCapture.newInstance() - .applyConfiguration(captureConfiguration) - .build() + GiniCapture.newInstance().applyConfiguration(captureConfiguration).build() giniCapture = GiniCapture.getInstance() } @@ -125,9 +130,7 @@ object GiniBank { */ fun setCaptureConfiguration(context: Context, captureConfiguration: CaptureConfiguration) { GiniBank.captureConfiguration = captureConfiguration - GiniCapture.newInstance(context) - .applyConfiguration(captureConfiguration) - .build() + GiniCapture.newInstance(context).applyConfiguration(captureConfiguration).build() giniCapture = GiniCapture.getInstance() } @@ -161,12 +164,7 @@ object GiniBank { amount: Amount ) { GiniCapture.transferSummary( - paymentRecipient, - paymentReference, - paymentPurpose, - iban, - bic, - amount + paymentRecipient, paymentReference, paymentPurpose, iban, bic, amount ) } @@ -204,12 +202,7 @@ object GiniBank { amount: Amount ) { transferSummary( - paymentRecipient, - paymentReference, - paymentPurpose, - iban, - bic, - amount + paymentRecipient, paymentReference, paymentPurpose, iban, bic, amount ) releaseCapture(context) } @@ -230,11 +223,15 @@ object GiniBank { captureConfiguration = null giniCapture = null - digitalInvoiceOnboardingNavigationBarBottomAdapter = DefaultDigitalInvoiceOnboardingNavigationBarBottomAdapter() - digitalInvoiceHelpNavigationBarBottomAdapter = DefaultDigitalInvoiceHelpNavigationBarBottomAdapter() + digitalInvoiceOnboardingNavigationBarBottomAdapter = + DefaultDigitalInvoiceOnboardingNavigationBarBottomAdapter() + digitalInvoiceHelpNavigationBarBottomAdapter = + DefaultDigitalInvoiceHelpNavigationBarBottomAdapter() - digitalInvoiceOnboardingIllustrationAdapter = ImageOnboardingIllustrationAdapter(R.drawable.gbs_digital_invoice_list_image, - R.string.gbs_digital_invoice_onboarding_text_1) + digitalInvoiceOnboardingIllustrationAdapter = ImageOnboardingIllustrationAdapter( + R.drawable.gbs_digital_invoice_list_image, + R.string.gbs_digital_invoice_onboarding_text_1 + ) digitalInvoiceNavigationBarBottomAdapter = DefaultDigitalInvoiceNavigationBarBottomAdapter() } @@ -271,16 +268,12 @@ object GiniBank { * @throws IllegalStateException if the capture feature was not configured. */ fun startCaptureFlowForIntent( - resultLauncher: ActivityResultLauncher, - context: Context, - intent: Intent + resultLauncher: ActivityResultLauncher, context: Context, intent: Intent ): CancellationToken { giniCapture.let { capture -> check(capture != null) { "Capture feature is not configured. Call setCaptureConfiguration before starting the flow." } return capture.createIntentForImportedFiles( - intent, - context, - getImportFileCallback(resultLauncher) + intent, context, getImportFileCallback(resultLauncher) ) } } @@ -313,9 +306,9 @@ object GiniBank { return when (val paymentRequestResource = api.documentManager.getPaymentRequest(id)) { is Resource.Cancelled -> throw Exception("Cancelled") is Resource.Error -> throw Exception( - paymentRequestResource.message, - paymentRequestResource.exception + paymentRequestResource.message, paymentRequestResource.exception ) + is Resource.Success -> paymentRequestResource.data } } @@ -333,8 +326,7 @@ object GiniBank { * @throws AmountParsingException If the amount string could not be parsed */ suspend fun resolvePaymentRequest( - requestId: String, - resolvePaymentInput: ResolvePaymentInput + requestId: String, resolvePaymentInput: ResolvePaymentInput ): ResolvedPayment { val api = giniApi check(api != null) { "Gini Api is not set" } @@ -344,9 +336,9 @@ object GiniBank { )) { is Resource.Cancelled -> throw Exception("Cancelled") is Resource.Error -> throw Exception( - resolvedPaymentResource.message, - resolvedPaymentResource.exception + resolvedPaymentResource.message, resolvedPaymentResource.exception ) + is Resource.Success -> resolvedPaymentResource.data } } diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java index de7e32cb8c..8b461d20b4 100644 --- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java +++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java @@ -168,8 +168,7 @@ public static synchronized boolean hasInstance() { @Deprecated public static synchronized Builder newInstance() { if (sInstance != null) { - throw new IllegalStateException("An instance was already created. " - + "Call GiniCapture.cleanup() before creating a new instance."); + throw new IllegalStateException("An instance was already created. " + "Call GiniCapture.cleanup() before creating a new instance."); } return new Builder(); } @@ -177,8 +176,8 @@ public static synchronized Builder newInstance() { /** * Configure and create a new instance using the returned {@link Builder}. * - * @return a new {@link Builder} * @param context Android context + * @return a new {@link Builder} */ @NonNull public static synchronized Builder newInstance(final Context context) { @@ -205,19 +204,12 @@ public static synchronized Builder newInstance(final Context context) { * * @param paymentRecipient payment receiver * @param paymentReference ID based on Client ID (Kundennummer) and invoice ID (Rechnungsnummer) - * @param paymentPurpose statement what this payment is for - * @param iban international bank account - * @param bic bank identification code - * @param amount accepts extracted amount and currency - * + * @param paymentPurpose statement what this payment is for + * @param iban international bank account + * @param bic bank identification code + * @param amount accepts extracted amount and currency */ - public static synchronized void transferSummary( - @NonNull final String paymentRecipient, - @NonNull final String paymentReference, - @NonNull final String paymentPurpose, - @NonNull final String iban, - @NonNull final String bic, - @NonNull final Amount amount) { + public static synchronized void transferSummary(@NonNull final String paymentRecipient, @NonNull final String paymentReference, @NonNull final String paymentPurpose, @NonNull final String iban, @NonNull final String bic, @NonNull final Amount amount) { if (sInstance == null) { return; @@ -225,52 +217,45 @@ public static synchronized void transferSummary( Map extractionMap = new HashMap<>(); - extractionMap.put("amountToPay", new GiniCaptureSpecificExtraction("amountToPay", amount.amountToPay(), - "amount", null, emptyList())); + extractionMap.put("amountToPay", new GiniCaptureSpecificExtraction("amountToPay", amount.amountToPay(), "amount", null, emptyList())); - extractionMap.put("paymentRecipient", new GiniCaptureSpecificExtraction("paymentRecipient", paymentRecipient, - "companyname", null, emptyList())); + extractionMap.put("paymentRecipient", new GiniCaptureSpecificExtraction("paymentRecipient", paymentRecipient, "companyname", null, emptyList())); - extractionMap.put("paymentReference", new GiniCaptureSpecificExtraction("paymentReference", paymentReference, - "reference", null, emptyList())); + extractionMap.put("paymentReference", new GiniCaptureSpecificExtraction("paymentReference", paymentReference, "reference", null, emptyList())); - extractionMap.put("paymentPurpose", new GiniCaptureSpecificExtraction("paymentPurpose", paymentPurpose, - "reference", null, emptyList())); + extractionMap.put("paymentPurpose", new GiniCaptureSpecificExtraction("paymentPurpose", paymentPurpose, "reference", null, emptyList())); - extractionMap.put("iban", new GiniCaptureSpecificExtraction("iban", iban, - "iban", null, emptyList())); + extractionMap.put("iban", new GiniCaptureSpecificExtraction("iban", iban, "iban", null, emptyList())); - extractionMap.put("bic", new GiniCaptureSpecificExtraction("bic", bic, - "bic", null, emptyList())); + extractionMap.put("bic", new GiniCaptureSpecificExtraction("bic", bic, "bic", null, emptyList())); // Test fails here if for some reason mGiniCaptureNetworkService is null // Added null checking to fix test fail -> or figure out something else final GiniCapture oldInstance = sInstance; if (oldInstance.mGiniCaptureNetworkService != null) - oldInstance.mGiniCaptureNetworkService.sendFeedback(extractionMap, - oldInstance.mInternal.getCompoundExtractions(), new GiniCaptureNetworkCallback() { - @Override - public void failure(Error error) { - if (oldInstance.mNetworkRequestsManager != null) { - oldInstance.mNetworkRequestsManager.cleanup(); - } - } - - @Override - public void success(Void result) { - if (oldInstance.mNetworkRequestsManager != null) { - oldInstance.mNetworkRequestsManager.cleanup(); - } - } - - @Override - public void cancelled() { - if (oldInstance.mNetworkRequestsManager != null) { - oldInstance.mNetworkRequestsManager.cleanup(); - } - } - }); + oldInstance.mGiniCaptureNetworkService.sendFeedback(extractionMap, oldInstance.mInternal.getCompoundExtractions(), new GiniCaptureNetworkCallback() { + @Override + public void failure(Error error) { + if (oldInstance.mNetworkRequestsManager != null) { + oldInstance.mNetworkRequestsManager.cleanup(); + } + } + + @Override + public void success(Void result) { + if (oldInstance.mNetworkRequestsManager != null) { + oldInstance.mNetworkRequestsManager.cleanup(); + } + } + + @Override + public void cancelled() { + if (oldInstance.mNetworkRequestsManager != null) { + oldInstance.mNetworkRequestsManager.cleanup(); + } + } + }); } @@ -287,25 +272,18 @@ public void cancelled() { *
  • Do cleanup after TAN verification.to clean up and provide the extraction values the user has used.
  • * * - * @param context Android context + * @param context Android context * @param paymentRecipient payment receiver * @param paymentReference ID based on Client ID (Kundennummer) and invoice ID (Rechnungsnummer) - * @param paymentPurpose statement what this payment is for - * @param iban international bank account - * @param bic bank identification code - * @param amount accepts extracted amount and currency - * + * @param paymentPurpose statement what this payment is for + * @param iban international bank account + * @param bic bank identification code + * @param amount accepts extracted amount and currency * @deprecated Please use {@link #cleanup(Context)} to cleanup and {@link #transferSummary(String, String, String, String, String, Amount)} to provide the required extraction feedback. */ @Deprecated - public static synchronized void cleanup(@NonNull final Context context, - @NonNull final String paymentRecipient, - @NonNull final String paymentReference, - @NonNull final String paymentPurpose, - @NonNull final String iban, - @NonNull final String bic, - @NonNull final Amount amount) { + public static synchronized void cleanup(@NonNull final Context context, @NonNull final String paymentRecipient, @NonNull final String paymentReference, @NonNull final String paymentPurpose, @NonNull final String iban, @NonNull final String bic, @NonNull final Amount amount) { transferSummary(paymentRecipient, paymentReference, paymentPurpose, iban, bic, amount); cleanup(context); } @@ -339,8 +317,7 @@ private GiniCapture(@NonNull final Builder builder) { mDocumentDataMemoryCache = new DocumentDataMemoryCache(); mPhotoMemoryCache = new PhotoMemoryCache(mDocumentDataMemoryCache); mImageDiskStore = new ImageDiskStore(); - mNetworkRequestsManager = mGiniCaptureNetworkService != null ? new NetworkRequestsManager( - mGiniCaptureNetworkService, mDocumentDataMemoryCache) : null; + mNetworkRequestsManager = mGiniCaptureNetworkService != null ? new NetworkRequestsManager(mGiniCaptureNetworkService, mDocumentDataMemoryCache) : null; mImageMultiPageDocumentMemoryStore = new ImageMultiPageDocumentMemoryStore(); mGiniCaptureFileImport = new GiniCaptureFileImport(this); mInternal = new Internal(this); @@ -350,9 +327,7 @@ private GiniCapture(@NonNull final Builder builder) { mIsFlashOnByDefault = builder.isFlashOnByDefault(); mEventTracker = builder.getEventTracker(); mCustomHelpItems = builder.getCustomHelpItems(); - mErrorLogger = new ErrorLogger(builder.getGiniErrorLoggerIsOn(), - builder.getGiniCaptureNetworkService(), - builder.getCustomErrorLoggerListener()); + mErrorLogger = new ErrorLogger(builder.getGiniErrorLoggerIsOn(), builder.getGiniCaptureNetworkService(), builder.getCustomErrorLoggerListener()); mImportedFileSizeBytesLimit = builder.getImportedFileSizeBytesLimit(); navigationBarTopAdapterInstance = builder.getNavigationBarTopAdapterInstance(); onboardingNavigationBarBottomAdapterInstance = builder.getOnboardingNavigationBarBottomAdapterInstance(); @@ -538,9 +513,7 @@ public boolean isFlashOnByDefault() { * @return a {@link CancellationToken} for cancelling the import process */ @NonNull - public CancellationToken createIntentForImportedFiles(@NonNull final Intent intent, - @NonNull final Context context, - @NonNull final AsyncCallback callback) { + public CancellationToken createIntentForImportedFiles(@NonNull final Intent intent, @NonNull final Context context, @NonNull final AsyncCallback callback) { return mGiniCaptureFileImport.createIntentForImportedFiles(intent, context, callback); } @@ -692,8 +665,7 @@ public EntryPoint getEntryPoint() { public static class Builder { private GiniCaptureNetworkService mGiniCaptureNetworkService; - private DocumentImportEnabledFileTypes mDocumentImportEnabledFileTypes = - DocumentImportEnabledFileTypes.NONE; + private DocumentImportEnabledFileTypes mDocumentImportEnabledFileTypes = DocumentImportEnabledFileTypes.NONE; private boolean mFileImportEnabled; private boolean mQRCodeScanningEnabled; private boolean mOnlyQRCodeScanningEnabled; @@ -703,7 +675,7 @@ public static class Builder { private boolean mMultiPageEnabled; private boolean mIsSupportedFormatsHelpScreenEnabled = true; private boolean mFlashButtonEnabled; - + private boolean mIsFlashOnByDefault = true; private EventTracker mEventTracker = new EventTracker() { @@ -752,10 +724,7 @@ public void build() { private void checkNetworkingImplementations() { if (mGiniCaptureNetworkService == null) { - LOG.warn("GiniCaptureNetworkService instance not set. " - + "Relying on client to perform network calls." - + "You may provide a GiniCaptureNetworkService instance with " - + "GiniCapture.newInstance().setGiniCaptureNetworkService()"); + LOG.warn("GiniCaptureNetworkService instance not set. " + "Relying on client to perform network calls." + "You may provide a GiniCaptureNetworkService instance with " + "GiniCapture.newInstance().setGiniCaptureNetworkService()"); } } @@ -772,8 +741,7 @@ private void checkNetworkingImplementations() { * @return the {@link Builder} instance */ @NonNull - public Builder setShouldShowOnboardingAtFirstRun( - final boolean shouldShowOnboardingAtFirstRun) { + public Builder setShouldShowOnboardingAtFirstRun(final boolean shouldShowOnboardingAtFirstRun) { mShouldShowOnboardingAtFirstRun = shouldShowOnboardingAtFirstRun; return this; } @@ -785,8 +753,7 @@ public Builder setShouldShowOnboardingAtFirstRun( * @return the {@link Builder} instance */ @NonNull - public Builder setCustomOnboardingPages( - @NonNull final ArrayList onboardingPages) { // NOPMD - ArrayList required (Bundle) + public Builder setCustomOnboardingPages(@NonNull final ArrayList onboardingPages) { // NOPMD - ArrayList required (Bundle) mOnboardingPages = onboardingPages; return this; } @@ -847,8 +814,7 @@ GiniCaptureNetworkService getGiniCaptureNetworkService() { * @return the {@link Builder} instance */ @NonNull - public Builder setGiniCaptureNetworkService( - @NonNull final GiniCaptureNetworkService giniCaptureNetworkService) { + public Builder setGiniCaptureNetworkService(@NonNull final GiniCaptureNetworkService giniCaptureNetworkService) { mGiniCaptureNetworkService = giniCaptureNetworkService; return this; } @@ -868,8 +834,7 @@ DocumentImportEnabledFileTypes getDocumentImportEnabledFileTypes() { * @return the {@link Builder} instance */ @NonNull - public Builder setDocumentImportEnabledFileTypes( - @NonNull final DocumentImportEnabledFileTypes documentImportEnabledFileTypes) { + public Builder setDocumentImportEnabledFileTypes(@NonNull final DocumentImportEnabledFileTypes documentImportEnabledFileTypes) { mDocumentImportEnabledFileTypes = documentImportEnabledFileTypes; return this; } From 625c28aa26ebd36b0d773f88a392b3826d5e0ebe Mon Sep 17 00:00:00 2001 From: Mahdi Abolfazli Date: Mon, 16 Oct 2023 18:04:10 +0200 Subject: [PATCH 4/6] feat(): Rename method from transferSummary to sendTransferSummary - rename ExtractionFeedbackIntegrationTest to TransferSummaryIntegrationTest - rename feedback to transfer summary in comments and menu items - add some information about how to use sendTransferSummary method - enhance Kotlin and Java docs PIA-4595 --- ...t.kt => TransferSummaryIntegrationTest.kt} | 2 +- .../sdk/exampleapp/ui/ExtractionsActivity.kt | 12 +++---- .../src/main/res/menu/menu_extractions.xml | 2 +- ...t.kt => TransferSummaryIntegrationTest.kt} | 11 ++++--- .../net/gini/android/bank/sdk/GiniBank.kt | 24 +++++++------- ...t.kt => TransferSummaryIntegrationTest.kt} | 10 +++--- .../net/gini/android/capture/GiniCapture.java | 33 +++++++++---------- 7 files changed, 47 insertions(+), 47 deletions(-) rename bank-api-library/library/src/androidTest/java/net/gini/android/bank/api/{ExtractionFeedbackIntegrationTest.kt => TransferSummaryIntegrationTest.kt} (98%) rename bank-sdk/sdk/src/androidTest/java/net/gini/android/bank/sdk/{ExtractionFeedbackIntegrationTest.kt => TransferSummaryIntegrationTest.kt} (97%) rename capture-sdk/default-network/src/androidTest/java/net/gini/android/capture/network/{ExtractionFeedbackIntegrationTest.kt => TransferSummaryIntegrationTest.kt} (97%) diff --git a/bank-api-library/library/src/androidTest/java/net/gini/android/bank/api/ExtractionFeedbackIntegrationTest.kt b/bank-api-library/library/src/androidTest/java/net/gini/android/bank/api/TransferSummaryIntegrationTest.kt similarity index 98% rename from bank-api-library/library/src/androidTest/java/net/gini/android/bank/api/ExtractionFeedbackIntegrationTest.kt rename to bank-api-library/library/src/androidTest/java/net/gini/android/bank/api/TransferSummaryIntegrationTest.kt index 96a523e7b6..c3acf2dfce 100644 --- a/bank-api-library/library/src/androidTest/java/net/gini/android/bank/api/ExtractionFeedbackIntegrationTest.kt +++ b/bank-api-library/library/src/androidTest/java/net/gini/android/bank/api/TransferSummaryIntegrationTest.kt @@ -22,7 +22,7 @@ import java.util.* @OptIn(ExperimentalCoroutinesApi::class) @RunWith(AndroidJUnit4::class) -class ExtractionFeedbackIntegrationTest { +class TransferSummaryIntegrationTest { private lateinit var giniBankAPI: GiniBankAPI private val moshi = Moshi.Builder().build() diff --git a/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt b/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt index c01ebdc7ad..e162c9eaf6 100644 --- a/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt +++ b/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt @@ -31,7 +31,7 @@ import javax.inject.Inject /** * Displays the Pay5 extractions: paymentRecipient, iban, bic, amount and paymentReference. * - * A menu item is added to send feedback. + * A menu item is added to send transfer summary. */ @AndroidEntryPoint @@ -76,8 +76,8 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA } override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) { - R.id.feedback -> { - sendFeedbackAndClose(binding) + R.id.transfer_summary -> { + sendTransferSummaryAndClose(binding) true } @@ -130,8 +130,8 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA private fun getSortedExtractions(extractions: Map): List = extractions.toSortedMap().values.toList() - private fun sendFeedbackAndClose(binding: ActivityExtractionsBinding) { - // Feedback should be sent only for the user visible fields. Non-visible fields should be filtered out. + private fun sendTransferSummaryAndClose(binding: ActivityExtractionsBinding) { + // Transfer summary should be sent only for the user visible fields. Non-visible fields should be filtered out. // In a real application the user input should be used as the new value. var amount = mExtractions["amountToPay"]?.value ?: "" @@ -145,7 +145,7 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA amount = Amount.EMPTY.amountToPay() } - GiniBank.transferSummary( + GiniBank.sendTransferSummary( paymentRecipient, paymentReference, paymentPurpose, iban, bic, Amount( BigDecimal(amount.removeSuffix(":EUR")), AmountCurrency.EUR ) diff --git a/bank-sdk/example-app/src/main/res/menu/menu_extractions.xml b/bank-sdk/example-app/src/main/res/menu/menu_extractions.xml index 636224fc8e..aba6b7720d 100644 --- a/bank-sdk/example-app/src/main/res/menu/menu_extractions.xml +++ b/bank-sdk/example-app/src/main/res/menu/menu_extractions.xml @@ -2,7 +2,7 @@ @@ -186,10 +184,10 @@ object GiniBank { * @param bic bank identification code * @param amount accepts extracted amount and currency * - * @deprecated Please use {@link #releaseCapture(Context)} which does not require transfer summary parameters. + * @deprecated Please use [sendTransferSummary] to provide the required transfer summary first (if the user has completed TAN verification) and then [releaseCapture] to let the SDK free up used resources. */ @Deprecated( - "Please use releaseCapture(Context) which does not require transfer summary parameters.", + "Please use sendTransferSummary() to provide the required transfer summary first (if the user has completed TAN verification) and then releaseCapture() to let the SDK free up used resources.", ReplaceWith("releaseCapture(context)") ) fun releaseCapture( @@ -201,7 +199,7 @@ object GiniBank { bic: String, amount: Amount ) { - transferSummary( + sendTransferSummary( paymentRecipient, paymentReference, paymentPurpose, iban, bic, amount ) releaseCapture(context) diff --git a/capture-sdk/default-network/src/androidTest/java/net/gini/android/capture/network/ExtractionFeedbackIntegrationTest.kt b/capture-sdk/default-network/src/androidTest/java/net/gini/android/capture/network/TransferSummaryIntegrationTest.kt similarity index 97% rename from capture-sdk/default-network/src/androidTest/java/net/gini/android/capture/network/ExtractionFeedbackIntegrationTest.kt rename to capture-sdk/default-network/src/androidTest/java/net/gini/android/capture/network/TransferSummaryIntegrationTest.kt index e4d5a283ef..e4da8da0d9 100644 --- a/capture-sdk/default-network/src/androidTest/java/net/gini/android/capture/network/ExtractionFeedbackIntegrationTest.kt +++ b/capture-sdk/default-network/src/androidTest/java/net/gini/android/capture/network/TransferSummaryIntegrationTest.kt @@ -22,7 +22,6 @@ import net.gini.android.capture.network.model.GiniCaptureSpecificExtraction import net.gini.android.capture.network.test.ExtractionsFixture import net.gini.android.capture.network.test.bankAPIDocumentWithId import net.gini.android.capture.network.test.fromJsonAsset -import org.junit.After import org.junit.Assert import org.junit.Before import org.junit.Test @@ -39,7 +38,7 @@ import kotlin.coroutines.resumeWithException */ @RunWith(AndroidJUnit4::class) -class ExtractionFeedbackIntegrationTest { +class TransferSummaryIntegrationTest { private lateinit var networkService: GiniCaptureDefaultNetworkService private lateinit var giniBankAPI: GiniBankAPI @@ -98,12 +97,12 @@ class ExtractionFeedbackIntegrationTest { val amountToPay = extractionsBundle.getParcelable("amountToPay") amountToPay!!.value = "950.00:EUR" - // When releasing capture we need to provide the values the user has used for + // Before cleaning up the capture we need to provide the values the user has used for // creating the transaction. // Supposing the user changed the amountToPay from "995.00:EUR" to "950.00:EUR" // we need to pass in the changed value. For the other extractions we can pass in // the original values since the user did not edit them. - GiniCapture.cleanup(getApplicationContext(), + GiniCapture.sendTransferSummary( extractionsBundle.getParcelable("paymentRecipient")!!.value, "", // Payment reference was not shown to the user and can be left empty extractionsBundle.getParcelable("paymentPurpose")!!.value, @@ -112,6 +111,9 @@ class ExtractionFeedbackIntegrationTest { Amount(BigDecimal("950.00"), AmountCurrency.EUR) ) + // Now we can clean up the capture + GiniCapture.cleanup(getApplicationContext()) + // Wait a little for the feedback sending to complete delay(2_000) diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java index 8b461d20b4..643aecec22 100644 --- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java +++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java @@ -70,20 +70,15 @@ *

    To create and configure a singleton instance use the {@link #newInstance(Context)} method and the * returned {@link Builder}. * - *

    Use the {@link #cleanup(Context)} method to clean up the SDK - * Please follow the recommendations below: - * - *

      - *
    • Do cleanup after TAN verification.to clean up.
    • - *
    + *

    Please first provide the transfer summary via the {@link #sendTransferSummary(String, String, String, String, String, Amount)} method. + * The transfer summary is used to improve the future extraction accuracy. + * Then, use the {@link #cleanup(Context)} method to clean up the SDK. * - *

    Use the {@link #transferSummary(String, String, String, String, String, Amount)} method to - * provide the required extraction feedback to improve the future extraction accuracy. * Please follow the recommendations below: * *

      - *
    • Please provide values for all necessary fields, including those that were not extracted.
    • *
    • Provide the final data approved by the user (and not the initially extracted only).
    • + *
    • Send the transfer summary after TAN verification and provide the extraction values the user has used.
    • *
    */ public class GiniCapture { @@ -168,7 +163,7 @@ public static synchronized boolean hasInstance() { @Deprecated public static synchronized Builder newInstance() { if (sInstance != null) { - throw new IllegalStateException("An instance was already created. " + "Call GiniCapture.cleanup() before creating a new instance."); + throw new IllegalStateException("An instance was already created. Call GiniCapture.cleanup() before creating a new instance."); } return new Builder(); } @@ -193,13 +188,13 @@ public static synchronized Builder newInstance(final Context context) { /** * Provides transfer summary to Gini. * - *

    Please provide the required extraction feedback to improve the future extraction accuracy. + *

    Please provide the required transfer summary to improve the future extraction accuracy. * Please follow the recommendations below: - * *

      - *
    • Please call this method before calling the {@link #cleanup(Context)} method
    • + *
    • Please make sure to call this method before calling {@link #cleanup(Context)} if the user has completed TAN verification.
    • *
    • Please provide values for all necessary fields, including those that were not extracted.
    • *
    • Provide the final data approved by the user (and not the initially extracted only).
    • + *
    • Send the transfer summary after TAN verification and provide the extraction values the user has used.
    • *
    * * @param paymentRecipient payment receiver @@ -209,7 +204,7 @@ public static synchronized Builder newInstance(final Context context) { * @param bic bank identification code * @param amount accepts extracted amount and currency */ - public static synchronized void transferSummary(@NonNull final String paymentRecipient, @NonNull final String paymentReference, @NonNull final String paymentPurpose, @NonNull final String iban, @NonNull final String bic, @NonNull final Amount amount) { + public static synchronized void sendTransferSummary(@NonNull final String paymentRecipient, @NonNull final String paymentReference, @NonNull final String paymentPurpose, @NonNull final String iban, @NonNull final String bic, @NonNull final Amount amount) { if (sInstance == null) { return; @@ -233,7 +228,7 @@ public static synchronized void transferSummary(@NonNull final String paymentRec // Test fails here if for some reason mGiniCaptureNetworkService is null // Added null checking to fix test fail -> or figure out something else final GiniCapture oldInstance = sInstance; - if (oldInstance.mGiniCaptureNetworkService != null) + if (oldInstance.mGiniCaptureNetworkService != null) { oldInstance.mGiniCaptureNetworkService.sendFeedback(extractionMap, oldInstance.mInternal.getCompoundExtractions(), new GiniCaptureNetworkCallback() { @Override public void failure(Error error) { @@ -256,6 +251,7 @@ public void cancelled() { } } }); + } } @@ -263,7 +259,7 @@ public void cancelled() { /** * Destroys the {@link GiniCapture} instance and frees up used resources. * - *

    Please provide the required extraction feedback to improve the future extraction accuracy. + *

    Please provide the required transfer summary to improve the future extraction accuracy. * Please follow the recommendations below: * *

      @@ -279,12 +275,13 @@ public void cancelled() { * @param iban international bank account * @param bic bank identification code * @param amount accepts extracted amount and currency - * @deprecated Please use {@link #cleanup(Context)} to cleanup and {@link #transferSummary(String, String, String, String, String, Amount)} to provide the required extraction feedback. + * @deprecated Please use {@link #sendTransferSummary(String, String, String, String, String, Amount)} to provide the required transfer summary first (if the user has completed TAN verification) and then {@link #cleanup(Context)} to let the SDK free up used resources. + * */ @Deprecated public static synchronized void cleanup(@NonNull final Context context, @NonNull final String paymentRecipient, @NonNull final String paymentReference, @NonNull final String paymentPurpose, @NonNull final String iban, @NonNull final String bic, @NonNull final Amount amount) { - transferSummary(paymentRecipient, paymentReference, paymentPurpose, iban, bic, amount); + sendTransferSummary(paymentRecipient, paymentReference, paymentPurpose, iban, bic, amount); cleanup(context); } From b2188781524d605461867bdd4355a477e34c1cd1 Mon Sep 17 00:00:00 2001 From: Mahdi Abolfazli Date: Mon, 30 Oct 2023 17:17:51 +0100 Subject: [PATCH 5/6] docs: Remove repetitive `please` from GiniBank and GiniCapture docs PIA-4595 --- .../main/java/net/gini/android/bank/sdk/GiniBank.kt | 12 ++++++------ .../java/net/gini/android/capture/GiniCapture.java | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt b/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt index 8773920a96..e40bc827a6 100644 --- a/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt +++ b/bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt @@ -140,9 +140,9 @@ object GiniBank { * * Please provide the required transfer summary to improve the future extraction accuracy. * - * Please follow the recommendations below: - * - Please make sure to call this method before calling [releaseCapture] if the user has completed TAN verification. - * - Please provide values for all necessary fields, including those that were not extracted. + * Follow the recommendations below: + * - Make sure to call this method before calling [releaseCapture] if the user has completed TAN verification. + * - Provide values for all necessary fields, including those that were not extracted. * - Provide the final data approved by the user (and not the initially extracted only). * - Send the transfer summary after TAN verification and provide the extraction values the user has used. * @@ -170,9 +170,9 @@ object GiniBank { * Frees up resources used by the capture flow. * * Please provide the required transfer summary to improve the future extraction accuracy. - * Please follow the recommendations below: + * Follow the recommendations below: * - * - Please provide values for all necessary fields, including those that were not extracted. + * - Provide values for all necessary fields, including those that were not extracted. * - Provide the final data approved by the user (and not the initially extracted only). * - Do cleanup after TAN verification.to clean up and provide the extraction values the user has used. * @@ -184,7 +184,7 @@ object GiniBank { * @param bic bank identification code * @param amount accepts extracted amount and currency * - * @deprecated Please use [sendTransferSummary] to provide the required transfer summary first (if the user has completed TAN verification) and then [releaseCapture] to let the SDK free up used resources. + * @deprecated Use [sendTransferSummary] to provide the required transfer summary first (if the user has completed TAN verification) and then [releaseCapture] to let the SDK free up used resources. */ @Deprecated( "Please use sendTransferSummary() to provide the required transfer summary first (if the user has completed TAN verification) and then releaseCapture() to let the SDK free up used resources.", diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java index 643aecec22..cc142f3e86 100644 --- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java +++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/GiniCapture.java @@ -189,10 +189,10 @@ public static synchronized Builder newInstance(final Context context) { * Provides transfer summary to Gini. * *

      Please provide the required transfer summary to improve the future extraction accuracy. - * Please follow the recommendations below: + * Follow the recommendations below: *

        - *
      • Please make sure to call this method before calling {@link #cleanup(Context)} if the user has completed TAN verification.
      • - *
      • Please provide values for all necessary fields, including those that were not extracted.
      • + *
      • Make sure to call this method before calling {@link #cleanup(Context)} if the user has completed TAN verification.
      • + *
      • Provide values for all necessary fields, including those that were not extracted.
      • *
      • Provide the final data approved by the user (and not the initially extracted only).
      • *
      • Send the transfer summary after TAN verification and provide the extraction values the user has used.
      • *
      @@ -260,10 +260,10 @@ public void cancelled() { * Destroys the {@link GiniCapture} instance and frees up used resources. * *

      Please provide the required transfer summary to improve the future extraction accuracy. - * Please follow the recommendations below: + * Follow the recommendations below: * *

        - *
      • Please provide values for all necessary fields, including those that were not extracted.
      • + *
      • Provide values for all necessary fields, including those that were not extracted.
      • *
      • Provide the final data approved by the user (and not the initially extracted only).
      • *
      • Do cleanup after TAN verification.to clean up and provide the extraction values the user has used.
      • *
      @@ -275,7 +275,7 @@ public void cancelled() { * @param iban international bank account * @param bic bank identification code * @param amount accepts extracted amount and currency - * @deprecated Please use {@link #sendTransferSummary(String, String, String, String, String, Amount)} to provide the required transfer summary first (if the user has completed TAN verification) and then {@link #cleanup(Context)} to let the SDK free up used resources. + * @deprecated Use {@link #sendTransferSummary(String, String, String, String, String, Amount)} to provide the required transfer summary first (if the user has completed TAN verification) and then {@link #cleanup(Context)} to let the SDK free up used resources. * */ From a32ba4614ccb08ef4135f40ddb5b187e85b0398c Mon Sep 17 00:00:00 2001 From: Mahdi Abolfazli Date: Mon, 30 Oct 2023 17:54:05 +0100 Subject: [PATCH 6/6] refactor: Resolve rebase conflicts PIA-4595 --- RELEASE-ORDER.md | 1 + .../android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/RELEASE-ORDER.md b/RELEASE-ORDER.md index 541f9b678e..337e78cb88 100644 --- a/RELEASE-ORDER.md +++ b/RELEASE-ORDER.md @@ -32,3 +32,4 @@ Release order for :bank-sdk:sdk 3.6.0: 3. :capture-sdk:sdk 3.6.0 4. :capture-sdk:default-network 3.6.0 5. :bank-sdk:sdk 3.6.0 + diff --git a/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt b/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt index e162c9eaf6..4d5de5e14f 100644 --- a/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt +++ b/bank-sdk/example-app/src/main/java/net/gini/android/bank/sdk/exampleapp/ui/ExtractionsActivity.kt @@ -19,7 +19,7 @@ import com.google.android.material.textfield.TextInputLayout import dagger.hilt.android.AndroidEntryPoint import net.gini.android.bank.sdk.GiniBank import net.gini.android.bank.sdk.exampleapp.R -import net.gini.android.bank.sdk.exampleapp.core.di.GiniCaptureNetworkServiceRelease +import net.gini.android.bank.sdk.exampleapp.core.di.GiniCaptureNetworkServiceDebugEnabled import net.gini.android.bank.sdk.exampleapp.databinding.ActivityExtractionsBinding import net.gini.android.capture.Amount import net.gini.android.capture.AmountCurrency @@ -42,7 +42,7 @@ class ExtractionsActivity : AppCompatActivity(), ExtractionsAdapter.ExtractionsA private lateinit var mExtractionsAdapter: ExtractionsAdapter @Inject - @GiniCaptureNetworkServiceRelease + @GiniCaptureNetworkServiceDebugEnabled lateinit var defaultNetworkService: GiniCaptureDefaultNetworkService // {extraction name} to it's {entity name}