Skip to content

Commit

Permalink
refactor(bank-sdk): Skonto feature. Implement koin (#513)
Browse files Browse the repository at this point in the history
PP-673
  • Loading branch information
ndubkov-distcotech authored Aug 5, 2024
1 parent 005e345 commit 555d6eb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
4 changes: 4 additions & 0 deletions bank-sdk/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ dependencies {
implementation(libs.accompanist.themeAdapter)
debugImplementation(libs.compose.tools.uiTooling)

implementation(platform(libs.koin.bom))
implementation(libs.koin.core)
implementation(libs.koin.android)
implementation(libs.koin.androidx.compose)

testImplementation(libs.junit)
testImplementation(libs.mockk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.findNavController
import androidx.navigation.fragment.navArgs
import net.gini.android.bank.sdk.GiniBank
Expand All @@ -81,6 +79,7 @@ import net.gini.android.bank.sdk.capture.skonto.colors.section.SkontoSectionColo
import net.gini.android.bank.sdk.capture.skonto.colors.section.WithoutSkontoSectionColors
import net.gini.android.bank.sdk.capture.skonto.model.SkontoData
import net.gini.android.bank.sdk.capture.util.currencyFormatterWithoutSymbol
import net.gini.android.bank.sdk.di.getGiniKoin
import net.gini.android.bank.sdk.util.disallowScreenshots
import net.gini.android.capture.GiniCapture
import net.gini.android.capture.internal.util.ActivityHelper.forcePortraitOrientationOnPhones
Expand All @@ -96,6 +95,7 @@ import net.gini.android.capture.ui.theme.GiniTheme
import net.gini.android.capture.ui.theme.modifier.tabletMaxWidth
import net.gini.android.capture.ui.theme.typography.bold
import net.gini.android.capture.view.InjectedViewAdapterInstance
import org.koin.core.parameter.parametersOf
import java.math.BigDecimal
import java.math.RoundingMode
import java.time.LocalDate
Expand All @@ -105,6 +105,10 @@ class SkontoFragment : Fragment() {

private val args: SkontoFragmentArgs by navArgs<SkontoFragmentArgs>()

private val viewModel: SkontoFragmentViewModel by getGiniKoin().inject {
parametersOf(args.data)
}

lateinit var cancelListener: CancelListener

var skontoFragmentListener: SkontoFragmentListener? = null
Expand Down Expand Up @@ -138,11 +142,6 @@ class SkontoFragment : Fragment() {
customBottomNavigationBarView =
container?.let { customBottomNavBarAdapter?.viewAdapter?.onCreateView(it) }

val viewModel = ViewModelProvider(
factory = ViewModelFactory(args.data),
owner = this
)[SkontoFragmentViewModel::class.java]

viewModel.setListener(skontoFragmentListener)

return ComposeView(requireContext()).apply {
Expand All @@ -162,16 +161,6 @@ class SkontoFragment : Fragment() {
}
}
}

internal class ViewModelFactory(
private val args: SkontoData,
) : ViewModelProvider.Factory {

override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
return SkontoFragmentViewModel(args) as T
}
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.gini.android.bank.sdk.capture.skonto

import net.gini.android.bank.sdk.capture.skonto.model.SkontoData
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

val skontoScreenModule = module {
viewModel { (data: SkontoData) ->
SkontoFragmentViewModel(data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.gini.android.bank.sdk.di

import net.gini.android.bank.sdk.capture.skonto.skontoScreenModule
import org.koin.dsl.koinApplication

object IsolatedKoinContext {

private val koinApp = koinApplication {
modules(skontoScreenModule)
}

val koin = koinApp.koin
}

fun getGiniKoin() = IsolatedKoinContext.koin
7 changes: 6 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ navigation_component = "2.7.6"
compose-bom = "2024.06.00"
accompanist-themeAdapter = "1.1.1"
compose-activity = "1.9.0"
koin-bom = "3.5.6"

[libraries]
android-gradle = { module = "com.android.tools.build:gradle", version.ref = "android-gradle-plugin" }
Expand Down Expand Up @@ -119,4 +120,8 @@ compose-material3 = { module = "androidx.compose.material3:material3" }
compose-activity = { module = "androidx.activity:activity-compose", version.ref = "compose-activity" }
compose-tools-uiTooling = { module = "androidx.compose.ui:ui-tooling" }
compose-tools-uiToolingPreview = { module = "androidx.compose.ui:ui-tooling-preview" }
accompanist-themeAdapter = { module = "com.google.android.material:compose-theme-adapter-3", version.ref = "accompanist-themeAdapter" }
accompanist-themeAdapter = { module = "com.google.android.material:compose-theme-adapter-3", version.ref = "accompanist-themeAdapter" }
koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin-bom" }
koin-core = { module = "io.insert-koin:koin-core" }
koin-android = { module = "io.insert-koin:koin-android" }
koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose" }

0 comments on commit 555d6eb

Please sign in to comment.