Skip to content

Commit

Permalink
feature(bank-sdk): Transaction Docs. Code refactor
Browse files Browse the repository at this point in the history
PP-747
  • Loading branch information
ndubkov-distcotech committed Sep 24, 2024
1 parent 8384f0c commit 261913a
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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.PermissionHandler
import net.gini.android.bank.sdk.transactiondocs.TransactionDocsConfiguration
import net.gini.android.capture.DocumentImportEnabledFileTypes
import net.gini.android.capture.network.GiniCaptureDefaultNetworkService
import net.gini.android.core.api.DocumentMetadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import net.gini.android.bank.sdk.exampleapp.ui.adapters.CustomReviewNavigationBa
import net.gini.android.bank.sdk.exampleapp.ui.adapters.CustomSkontoHelpNavigationBarBottomAdapter
import net.gini.android.bank.sdk.exampleapp.ui.adapters.CustomSkontoNavigationBarBottomAdapter
import net.gini.android.bank.sdk.exampleapp.ui.data.Configuration
import net.gini.android.bank.sdk.transactiondocs.TransactionDocsConfiguration
import net.gini.android.capture.GiniCaptureDebug
import net.gini.android.capture.help.HelpItem
import net.gini.android.capture.internal.util.FileImportValidator
Expand Down
22 changes: 8 additions & 14 deletions bank-sdk/sdk/src/main/java/net/gini/android/bank/sdk/GiniBank.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import net.gini.android.bank.sdk.invoice.InvoicePreviewFragmentArgs
import net.gini.android.bank.sdk.pay.getBusinessIntent
import net.gini.android.bank.sdk.pay.getRequestId
import net.gini.android.bank.sdk.transactiondocs.TransactionDocs
import net.gini.android.bank.sdk.transactiondocs.TransactionDocsConfiguration
import net.gini.android.bank.sdk.transactiondocs.internal.GiniBankTransactionDocs
import net.gini.android.bank.sdk.transactiondocs.internal.GiniTransactionDocsSettings
import net.gini.android.bank.sdk.util.parseAmountToBackendFormat
Expand Down Expand Up @@ -191,6 +190,11 @@ object GiniBank {
GiniBank.captureConfiguration = captureConfiguration
GiniCapture.newInstance(context).applyConfiguration(captureConfiguration).build()
giniCapture = GiniCapture.getInstance()

releaseTransactionDocsFeature(context)
BankSdkIsolatedKoinContext.init(context)
getGiniCaptureKoin().loadModules(listOf(captureSdkDiBridge))
this.giniBankTransactionDocs = GiniBankTransactionDocs()
}


Expand Down Expand Up @@ -262,6 +266,7 @@ object GiniBank {
paymentRecipient, paymentReference, paymentPurpose, iban, bic, amount
)
releaseCapture(context)
releaseTransactionDocsFeature(context)
BankSdkIsolatedKoinContext.clean()
}

Expand Down Expand Up @@ -292,6 +297,7 @@ object GiniBank {
)

digitalInvoiceNavigationBarBottomAdapter = DefaultDigitalInvoiceNavigationBarBottomAdapter()
releaseTransactionDocsFeature(context)
BankSdkIsolatedKoinContext.clean()
}

Expand Down Expand Up @@ -576,20 +582,8 @@ object GiniBank {
)
}

fun initializeTransactionDocsFeature(
context: Context,
transactionDocsConfiguration: TransactionDocsConfiguration
) {
releaseTransactionDocsFeature(context)
BankSdkIsolatedKoinContext.init(context)
getGiniCaptureKoin().loadModules(listOf(captureSdkDiBridge))
this.giniBankTransactionDocs = GiniBankTransactionDocs(
configuration = transactionDocsConfiguration,
)
}

@Suppress("UnusedParameter")
fun releaseTransactionDocsFeature(context: Context) {
private fun releaseTransactionDocsFeature(context: Context) {
giniBankTransactionDocs = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ class CaptureFlowFragment(private val openWithDocument: Document? = null) :
tryShowingSkontoScreen(result)
return
}

else -> {
finishWithResult(interceptSuccessResult(result).toCaptureResult())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import net.gini.android.bank.sdk.transactiondocs.model.extractions.TransactionDo

interface TransactionDocs {

val configuration: TransactionDocsConfiguration

val transactionDocsSettings: TransactionDocsSettings

val extractionDocumentsFlow: Flow<List<TransactionDoc>>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net.gini.android.bank.sdk.transactiondocs.di
import net.gini.android.bank.sdk.GiniBank
import net.gini.android.bank.sdk.transactiondocs.internal.GiniBankTransactionDocs
import net.gini.android.bank.sdk.transactiondocs.internal.GiniTransactionDocsSettings
import net.gini.android.bank.sdk.transactiondocs.internal.TransactionDocInvoicePreviewInfoLinesFactory
import net.gini.android.bank.sdk.transactiondocs.internal.factory.TransactionDocInvoicePreviewInfoLinesFactory
import net.gini.android.capture.analysis.transactiondoc.AttachedToTransactionDocumentProvider
import net.gini.android.capture.di.getGiniCaptureKoin
import net.gini.android.capture.provider.LastExtractionsProvider
Expand All @@ -22,7 +22,9 @@ internal val transactionListModule = module {

factory {
TransactionDocInvoicePreviewInfoLinesFactory(
resources = androidContext().resources
resources = androidContext().resources,
lastExtractionsProvider = get<LastExtractionsProvider>(),
amountFormatter = get(),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package net.gini.android.bank.sdk.transactiondocs.internal

import kotlinx.coroutines.flow.map
import net.gini.android.bank.sdk.GiniBank
import net.gini.android.bank.sdk.di.getGiniBankKoin
import net.gini.android.bank.sdk.transactiondocs.TransactionDocs
import net.gini.android.bank.sdk.transactiondocs.TransactionDocsConfiguration
import net.gini.android.bank.sdk.transactiondocs.model.extractions.TransactionDoc
import net.gini.android.capture.analysis.transactiondoc.AttachedToTransactionDocumentProvider

internal class GiniBankTransactionDocs internal constructor(
override val configuration: TransactionDocsConfiguration,
override val transactionDocsSettings: GiniTransactionDocsSettings =
getGiniBankKoin().get(),
private val attachedToTransactionDocumentProvider: AttachedToTransactionDocumentProvider =
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.gini.android.bank.sdk.transactiondocs.internal.factory

import android.content.res.Resources
import net.gini.android.bank.sdk.R
import net.gini.android.bank.sdk.capture.skonto.formatter.AmountFormatter
import net.gini.android.capture.Amount
import net.gini.android.capture.provider.LastExtractionsProvider

internal class TransactionDocInvoicePreviewInfoLinesFactory(
private val resources: Resources,
private val lastExtractionsProvider: LastExtractionsProvider,
private val amountFormatter: AmountFormatter,
) {

fun create(
) = listOfNotNull(
lastExtractionsProvider.provide()["iban"]?.value?.let {
resources.getString(
R.string.gbs_td_invoice_preview_info_text_iban,
it
)
},
lastExtractionsProvider.provide()["amountToPay"]?.value?.let { Amount.parse(it) }?.let {
resources.getString(
R.string.gbs_td_invoice_preview_info_text_amount, amountFormatter.format(it)
)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import kotlinx.coroutines.runBlocking
import net.gini.android.bank.sdk.GiniBank
import net.gini.android.bank.sdk.R
import net.gini.android.bank.sdk.di.getGiniBankKoin
Expand All @@ -46,10 +47,6 @@ fun AttachDocumentToTransactionDialog(

var alwaysAttachChecked by remember { mutableStateOf(true) }

LaunchedEffect(alwaysAttachChecked) {
giniTransactionDocsSettings.setAlwaysAttachSetting(alwaysAttachChecked)
}

Dialog(
onDismissRequest = onDismiss,
properties = DialogProperties(
Expand Down Expand Up @@ -110,6 +107,9 @@ fun AttachDocumentToTransactionDialog(
}
TextButton(
onClick = {
runBlocking {
giniTransactionDocsSettings.setAlwaysAttachSetting(alwaysAttachChecked)
}
onConfirm(alwaysAttachChecked)
}) {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import net.gini.android.bank.sdk.GiniBank
import net.gini.android.bank.sdk.di.getGiniBankKoin
import net.gini.android.bank.sdk.transactiondocs.ui.extractions.colors.TransactionDocsWidgetColors
import net.gini.android.bank.sdk.transactiondocs.internal.GiniBankTransactionDocs
import net.gini.android.bank.sdk.transactiondocs.internal.TransactionDocInvoicePreviewInfoLinesFactory
import net.gini.android.bank.sdk.transactiondocs.internal.factory.TransactionDocInvoicePreviewInfoLinesFactory
import net.gini.android.bank.sdk.transactiondocs.model.extractions.TransactionDoc
import net.gini.android.capture.provider.LastExtractionsProvider
import net.gini.android.capture.ui.theme.GiniTheme
Expand All @@ -33,10 +32,6 @@ fun TransactionDocs(
val transactionDocInvoicePreviewInfoLinesFactory: TransactionDocInvoicePreviewInfoLinesFactory =
remember { getGiniBankKoin().get() }

val lastExtractionsProvider : LastExtractionsProvider = remember { getGiniBankKoin().get() }
val iban = lastExtractionsProvider.provide()["iban"]?.value
val amount = lastExtractionsProvider.provide()["amountToPay"]?.value

Card(
modifier = modifier,
colors = CardDefaults.cardColors(
Expand All @@ -59,10 +54,7 @@ fun TransactionDocs(
onDocumentClick = {
onDocumentClick(
it,
transactionDocInvoicePreviewInfoLinesFactory.create(
iban ?: "Unknown IBAN",
amount ?: "Unknown amount"
)
transactionDocInvoicePreviewInfoLinesFactory.create()
)
}
)
Expand Down

0 comments on commit 261913a

Please sign in to comment.