Skip to content

Commit

Permalink
refactor(health-sdk): Updated InvoicesActivity and `InoicesViewMode…
Browse files Browse the repository at this point in the history
…l` to be able to run the app

- Changed `ReviewFragment` implementation to use `internal-payment-sdk`

IPC-327
  • Loading branch information
danicretu committed Oct 8, 2024
1 parent ece6a86 commit 698b091
Show file tree
Hide file tree
Showing 24 changed files with 744 additions and 695 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import net.gini.android.health.sdk.exampleapp.databinding.ActivityMainBinding
import net.gini.android.health.sdk.exampleapp.invoices.ui.AppCompatThemeInvoicesActivity
import net.gini.android.health.sdk.exampleapp.invoices.ui.InvoicesActivity
import net.gini.android.health.sdk.exampleapp.pager.PagerAdapter
import net.gini.android.health.sdk.exampleapp.review.ReviewActivity
import net.gini.android.health.sdk.exampleapp.upload.UploadActivity
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.slf4j.LoggerFactory
Expand All @@ -44,7 +43,7 @@ class MainActivity : AppCompatActivity() {
binding.importFile.setOnClickListener {
if (useTestDocument) {
viewModel.setDocumentForReview(testDocumentId)
startActivity(ReviewActivity.getStartIntent(this, paymentComponentConfiguration = viewModel.getPaymentComponentConfiguration()))
// startActivity(ReviewActivity.getStartIntent(this, paymentComponentConfiguration = viewModel.getPaymentComponentConfiguration()))
} else {
importFile()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package net.gini.android.health.sdk.exampleapp.di

import net.gini.android.health.sdk.GiniHealth
import net.gini.android.health.sdk.util.getGiniApi
import net.gini.android.internal.payment.GiniInternalPaymentModule
import org.koin.dsl.module

val giniModule = module {
single { getGiniApi(get(), getProperty("clientId"), getProperty("clientSecret"), "example.com") }
single { GiniHealth(get(), get()) }
single { GiniInternalPaymentModule(context = get(), giniHealthAPI = get())}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import net.gini.android.health.sdk.exampleapp.invoices.data.InvoicesRepository
import net.gini.android.health.sdk.exampleapp.invoices.ui.InvoicesViewModel
import net.gini.android.health.sdk.exampleapp.review.ReviewViewModel
import net.gini.android.health.sdk.exampleapp.upload.UploadViewModel
import net.gini.android.internal.payment.paymentComponent.PaymentComponent
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

Expand All @@ -19,5 +18,4 @@ val viewModelModule = module {
factory { InvoicesRepository(get(), get(), get(), get()) }
factory { InvoicesLocalDataSource(get()) }
factory { HardcodedInvoicesLocalDataSource(get()) }
factory { PaymentComponent(get(), get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import net.gini.android.internal.payment.moreinformation.MoreInformationFragment
import net.gini.android.internal.payment.paymentComponent.PaymentComponent
import net.gini.android.internal.payment.paymentComponent.PaymentComponentConfiguration
import net.gini.android.internal.payment.paymentComponent.PaymentComponentView
import net.gini.android.internal.payment.paymentComponent.PaymentProviderAppsState
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -69,7 +70,7 @@ open class InvoicesActivity : AppCompatActivity() {
launch {
viewModel.uploadHardcodedInvoicesStateFlow.combine(viewModel.paymentProviderAppsFlow) { a, b -> a to b }
.collect { (uploadState, bankAppsState) ->
if (uploadState == Loading || bankAppsState == LoadingBankApp) {
if (uploadState == Loading || bankAppsState == PaymentProviderAppsState.Loading) {
showLoadingIndicator(binding)
} else {
hideLoadingIndicator(binding)
Expand All @@ -90,7 +91,7 @@ open class InvoicesActivity : AppCompatActivity() {
}
launch {
viewModel.paymentProviderAppsFlow.collect { paymentProviderAppsState ->
if (paymentProviderAppsState is Error) {
if (paymentProviderAppsState is PaymentProviderAppsState.Error) {
AlertDialog.Builder(this@InvoicesActivity)
.setTitle(R.string.failed_to_load_bank_apps)
.setMessage(paymentProviderAppsState.throwable.message)
Expand Down Expand Up @@ -124,12 +125,12 @@ open class InvoicesActivity : AppCompatActivity() {
viewModel.loadPaymentProviderApps()

binding.invoicesList.layoutManager = LinearLayoutManager(this)
binding.invoicesList.adapter = InvoicesAdapter(emptyList(), viewModel.paymentComponent)
binding.invoicesList.adapter = InvoicesAdapter(emptyList(), viewModel.giniPaymentModule.paymentComponent)
binding.invoicesList.addItemDecoration(DividerItemDecoration(this, LinearLayout.VERTICAL))

viewModel.paymentComponent.listener = object: PaymentComponent.Listener {
viewModel.giniPaymentModule.paymentComponent.listener = object: PaymentComponent.Listener {
override fun onMoreInformationClicked() {
MoreInformationFragment.newInstance(viewModel.paymentComponent).apply {
MoreInformationFragment.newInstance(viewModel.giniPaymentModule.paymentComponent).apply {
supportFragmentManager.beginTransaction()
.add(R.id.fragment_container,this, this::class.java.simpleName)
.addToBackStack(this::class.java.simpleName)
Expand All @@ -138,12 +139,12 @@ open class InvoicesActivity : AppCompatActivity() {
}

override fun onBankPickerClicked() {
BankSelectionBottomSheet.newInstance(viewModel.paymentComponent).apply {
BankSelectionBottomSheet.newInstance(viewModel.giniPaymentModule.paymentComponent).apply {
show(supportFragmentManager, BankSelectionBottomSheet::class.simpleName)
}
}

override fun onPayInvoiceClicked(documentId: String) {
override fun onPayInvoiceClicked(documentId: String?) {
LOG.debug("Pay invoice clicked")

viewModel.getPaymentReviewFragment(documentId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import net.gini.android.health.sdk.exampleapp.invoices.data.InvoicesRepository
import net.gini.android.health.sdk.exampleapp.invoices.ui.model.InvoiceItem
import net.gini.android.health.sdk.paymentcomponent.PaymentComponent
import net.gini.android.health.sdk.review.ReviewConfiguration
import net.gini.android.health.sdk.review.ReviewFragment
import net.gini.android.health.sdk.review.model.ResultWrapper
import net.gini.android.internal.payment.GiniInternalPaymentModule
import net.gini.android.internal.payment.paymentComponent.PaymentComponentConfiguration
import net.gini.android.internal.payment.review.ReviewConfiguration
import org.slf4j.LoggerFactory

class InvoicesViewModel(
private val invoicesRepository: InvoicesRepository,
val paymentComponent: PaymentComponent
val giniPaymentModule: GiniInternalPaymentModule
) : ViewModel() {

val uploadHardcodedInvoicesStateFlow = invoicesRepository.uploadHardcodedInvoicesStateFlow
Expand All @@ -24,7 +25,7 @@ class InvoicesViewModel(
InvoiceItem.fromInvoice(invoice)
}
}
val paymentProviderAppsFlow = paymentComponent.paymentProviderAppsFlow
val paymentProviderAppsFlow = giniPaymentModule.paymentComponent.paymentProviderAppsFlow

val openBankState = invoicesRepository.giniHealth.openBankState

Expand All @@ -51,18 +52,19 @@ class InvoicesViewModel(

fun loadPaymentProviderApps() {
viewModelScope.launch {
paymentComponent.loadPaymentProviderApps()
giniPaymentModule.paymentComponent.loadPaymentProviderApps()
}
}

fun getPaymentReviewFragment(documentId: String): Result<ReviewFragment> {
fun getPaymentReviewFragment(documentId: String?): Result<ReviewFragment> {
val documentWithExtractions =
invoicesRepository.invoicesFlow.value.find { it.documentId == documentId }

return if (documentWithExtractions != null) {
return try {
val paymentReviewFragment = paymentComponent.getPaymentReviewFragment(
val paymentReviewFragment = invoicesRepository.giniHealth.getPaymentReviewFragment(
documentWithExtractions.documentId,
giniPaymentModule.paymentComponent,
ReviewConfiguration(showCloseButton = true)
)
Result.success(paymentReviewFragment)
Expand All @@ -77,7 +79,7 @@ class InvoicesViewModel(
}

fun setPaymentComponentConfig(paymentComponentConfiguration: PaymentComponentConfiguration) {
paymentComponent.paymentComponentConfiguration = paymentComponentConfiguration
giniPaymentModule.paymentComponent.paymentComponentConfiguration = paymentComponentConfiguration
}

companion object {
Expand Down
Loading

0 comments on commit 698b091

Please sign in to comment.