Skip to content

Commit

Permalink
feature(bank-sdk): Transaction List. Invoice Preview integration. Att…
Browse files Browse the repository at this point in the history
…ach Invoice from PP

PP-747
  • Loading branch information
ndubkov-distcotech committed Sep 19, 2024
1 parent 7dffe88 commit f1447cf
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 83 deletions.
3 changes: 2 additions & 1 deletion bank-sdk/example-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
android:theme="@style/AppTheme">
<activity
android:name=".ui.InvoicePreviewActivity"
android:exported="false" />
android:exported="false"
android:theme="@style/Root.GiniCaptureTheme.Internal" />
<activity
android:name=".ui.MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ package net.gini.android.bank.sdk.exampleapp.ui
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.navigation.fragment.NavHostFragment
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.databinding.ActivityInvoicePreviewBinding

@AndroidEntryPoint
class InvoicePreviewActivity : AppCompatActivity() {

lateinit var binding: ActivityInvoicePreviewBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_invoice_preview)
binding = ActivityInvoicePreviewBinding.inflate(layoutInflater)
setContentView(binding.root)

val documentId =
intent.getStringExtra(EXTRA_DOCUMENT_ID) ?: error("Missing $EXTRA_DOCUMENT_ID extra")

val fragment = GiniBank.createInvoicePreviewFragment(documentId)
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
val navController = navHostFragment.navController

supportFragmentManager.beginTransaction().replace(R.id.container, fragment).commit()
navController.setGraph(
R.navigation.invoice_preview_nav_graph,
GiniBank.createInvoicePreviewFragmentArgs(documentId).toBundle()
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
android:layout_height="match_parent"
tools:context=".ui.InvoicePreviewActivity">

<FrameLayout
<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
Expand All @@ -20,5 +21,5 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

</FrameLayout>
</androidx.fragment.app.FragmentContainerView>
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@id/invoicePreviewFragment">


<fragment
android:id="@+id/invoicePreviewFragment"
android:name="net.gini.android.bank.sdk.invoice.InvoicePreviewFragment"
android:label="InvoicePreviewFragment" />
</navigation>
15 changes: 11 additions & 4 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 @@ -3,7 +3,6 @@ package net.gini.android.bank.sdk
import android.content.Context
import android.content.Intent
import androidx.activity.result.ActivityResultLauncher
import kotlinx.coroutines.Dispatchers
import net.gini.android.bank.api.GiniBankAPI
import net.gini.android.bank.api.models.ResolvePaymentInput
import net.gini.android.bank.api.models.ResolvedPayment
Expand Down Expand Up @@ -31,6 +30,7 @@ import net.gini.android.bank.sdk.capture.skonto.help.SkontoHelpNavigationBarBott
import net.gini.android.bank.sdk.di.BankSdkIsolatedKoinContext
import net.gini.android.bank.sdk.error.AmountParsingException
import net.gini.android.bank.sdk.invoice.InvoicePreviewFragment
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
Expand Down Expand Up @@ -541,10 +541,17 @@ object GiniBank {
return CaptureFlowFragment.createInstance(document)
}

fun createInvoicePreviewFragment(giniApiDocumentId: String) : InvoicePreviewFragment {
fun createInvoicePreviewFragment(giniApiDocumentId: String): InvoicePreviewFragment {
return InvoicePreviewFragment.createInstance(
createInvoicePreviewFragmentArgs(giniApiDocumentId)
)
}

fun createInvoicePreviewFragmentArgs(giniApiDocumentId: String): InvoicePreviewFragmentArgs {
check(giniApiDocumentId.isNotBlank() && giniApiDocumentId.isNotEmpty()) {
"Gini Api Document Id should not be empty or blank" }
return InvoicePreviewFragment.createInstance(giniApiDocumentId)
"Gini Api Document Id should not be empty or blank"
}
return InvoicePreviewFragmentArgs(giniApiDocumentId, arrayOf(), arrayOf())
}

fun startInvoicePreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class CaptureFlowFragment(private val openWithDocument: Document? = null) :

private val skontoInvoiceHighlightsExtractor: SkontoInvoiceHighlightsExtractor
by getGiniBankKoin().inject()
private val skontoDataExtractor : SkontoDataExtractor
private val skontoDataExtractor: SkontoDataExtractor
by getGiniBankKoin().inject()
private val skontoExtractionsHandler : SkontoExtractionsHandler
private val skontoExtractionsHandler: SkontoExtractionsHandler
by getGiniBankKoin().inject()

// Remember the original primary navigation fragment so that we can restore it when this fragment is detached
Expand Down Expand Up @@ -293,23 +293,27 @@ class CaptureFlowFragment(private val openWithDocument: Document? = null) :
specificExtractions: Map<String, GiniCaptureSpecificExtraction>,
compoundExtractions: Map<String, GiniCaptureCompoundExtraction>
) {
finishWithResult(CaptureResult.Success(
specificExtractions,
compoundExtractions,
emptyList()
))
finishWithResult(
CaptureResult.Success(
specificExtractions,
compoundExtractions,
emptyList()
)
)
}


override fun onPayInvoiceWithSkonto(
specificExtractions: Map<String, GiniCaptureSpecificExtraction>,
compoundExtractions: Map<String, GiniCaptureCompoundExtraction>
) {
finishWithResult(CaptureResult.Success(
specificExtractions,
compoundExtractions,
emptyList()
))
finishWithResult(
CaptureResult.Success(
specificExtractions,
compoundExtractions,
emptyList()
)
)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ internal class DigitalInvoiceSkontoViewModel(
fun onInvoiceClicked() = viewModelScope.launch {
val currentState =
stateFlow.value as? DigitalInvoiceSkontoScreenState.Ready ?: return@launch
val documentId = lastAnalyzedDocumentProvider.provide()?.first ?: return@launch
val documentId = lastAnalyzedDocumentProvider.provide()?.giniApiDocumentId ?: return@launch
sideEffectFlow.emit(DigitalInvoiceSkontoSideEffect.OpenInvoiceScreen(
documentId,
SkontoData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ internal class SkontoFragmentViewModel(
fun onInvoiceClicked() = viewModelScope.launch {
val currentState =
stateFlow.value as? SkontoFragmentContract.State.Ready ?: return@launch
val documentId = lastAnalyzedDocumentProvider.provide()?.first ?: return@launch
val documentId = lastAnalyzedDocumentProvider.provide()?.giniApiDocumentId ?: return@launch
sideEffectFlow.emit(
SkontoFragmentContract.SideEffect.OpenInvoiceScreen(
documentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,27 @@ class InvoicePreviewFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {

val navigateBack = { requireActivity().onBackPressedDispatcher.onBackPressed() }

return ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
GiniTheme {
InvoicePreviewScreen(
modifier = Modifier,
viewModel = viewModel,
navigateBack = {
findNavController().navigateUp()
}
navigateBack = navigateBack
)
}
}
}
}

companion object {
fun createInstance(documentId: String): InvoicePreviewFragment {
fun createInstance(args: InvoicePreviewFragmentArgs): InvoicePreviewFragment {
return InvoicePreviewFragment().apply {
arguments = InvoicePreviewFragmentArgs(
documentId = documentId,
infoTextLines = arrayOf(),
highlightBoxes = arrayOf()
).toBundle()
arguments = args.toBundle()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ internal class GiniBankTransactionDocs internal constructor(

override val extractionDocumentsFlow = lastAnalyzedDocumentProvider
.data
.filterNotNull()
.map {
listOf(
listOfNotNull(it?.let {
TransactionDoc(
giniApiDocumentId = it.first,
it.second
giniApiDocumentId = it.giniApiDocumentId,
documentFileName = it.filename
)
)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.gini.android.bank.sdk.transactiondocs.ui.extractions
import android.content.res.Configuration
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
Expand All @@ -28,6 +29,9 @@ fun TransactionDocs(

Card(
modifier = modifier,
colors = CardDefaults.cardColors(
containerColor = colors.containerColor
),
shape = RectangleShape
) {
if (transactionDocs == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.gini.android.bank.sdk.transactiondocs.ui.extractions

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -12,6 +13,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand Down Expand Up @@ -45,26 +47,30 @@ internal fun TransactionDocsContent(
onDocumentClick: (TransactionDoc) -> Unit = {},
onDocumentDelete: (TransactionDoc) -> Unit = {},
) {

Card(
modifier = modifier,
shape = RectangleShape
) {
Column {
Text(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
text = stringResource(id = R.string.gbs_tl_extraction_result_documents_section_title),
style = GiniTheme.typography.subtitle2,
AnimatedVisibility(visible = documents.isNotEmpty()) {
Card(
modifier = modifier,
shape = RectangleShape,
colors = CardDefaults.cardColors(
containerColor = colors.containerColor,
)
Column(
modifier = Modifier.padding(start = 8.dp, end = 8.dp, top = 4.dp),
) {
DocumentList(
documents = documents,
colors = colors,
onDocumentClick = onDocumentClick,
onDocumentDelete = onDocumentDelete,
) {
Column {
Text(
text = stringResource(id = R.string.gbs_tl_extraction_result_documents_section_title),
style = GiniTheme.typography.subtitle2,
color = colors.titleColor
)
Column(
modifier = Modifier.padding(start = 8.dp, end = 8.dp, top = 4.dp),
) {
DocumentList(
documents = documents,
colors = colors,
onDocumentClick = onDocumentClick,
onDocumentDelete = onDocumentDelete,
)
}
}
}
}
Expand All @@ -76,7 +82,7 @@ private fun DocumentList(
onDocumentClick: (TransactionDoc) -> Unit,
onDocumentDelete: (TransactionDoc) -> Unit,
modifier: Modifier = Modifier,
colors: TransactionDocsWidgetColors = TransactionDocsWidgetColors.colors(),
colors: TransactionDocsWidgetColors,
) {
Column(
modifier = modifier.fillMaxWidth(),
Expand All @@ -99,8 +105,7 @@ private fun Document(
onDocumentClick: (TransactionDoc) -> Unit,
onDocumentDelete: (TransactionDoc) -> Unit,
modifier: Modifier = Modifier,
colors: TransactionDocsWidgetColors.DocumentItemColors =
TransactionDocsWidgetColors.DocumentItemColors.colors(),
colors: TransactionDocsWidgetColors.DocumentItemColors,
) {

var menuVisible by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -242,7 +247,7 @@ private fun ExtractionResultDocumentsSectionPreviewDark() {
private fun PreviewContent() {
GiniTheme {
Surface(modifier = Modifier.fillMaxSize()) {
DocumentList(
TransactionDocsContent(
documents = listOf(
TransactionDoc("id", "document1.jpg"),
TransactionDoc("id", "document2.jpg"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import net.gini.android.capture.ui.theme.GiniTheme

@Immutable
data class TransactionDocsWidgetColors(
val titleColor: Color,
val containerColor: Color,
val documentItemColors: DocumentItemColors,
) {

Expand Down Expand Up @@ -57,9 +59,13 @@ data class TransactionDocsWidgetColors(

@Composable
fun colors(
titleColor: Color = GiniTheme.colorScheme.text.primary,
containerColor: Color = Color.Transparent,
documentItemColors: DocumentItemColors = DocumentItemColors.colors(),
) = TransactionDocsWidgetColors(
containerColor = containerColor,
documentItemColors = documentItemColors,
titleColor = titleColor
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import android.widget.FrameLayout
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import net.gini.android.bank.sdk.transactiondocs.ui.extractions.TransactionDocs
import net.gini.android.bank.sdk.transactiondocs.model.extractions.TransactionDoc
import net.gini.android.bank.sdk.transactiondocs.ui.extractions.colors.TransactionDocsWidgetColors
import net.gini.android.capture.ui.theme.GiniTheme

class TransactionDocsView @JvmOverloads constructor(
Expand Down
Loading

0 comments on commit f1447cf

Please sign in to comment.