Skip to content

Commit

Permalink
add sharedVM test with params
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgiuliani committed Jun 11, 2024
1 parent dc6f348 commit 9902222
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 8 deletions.
6 changes: 4 additions & 2 deletions examples/android-perfs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
namespace = "org.koin.sample.android"

compileSdk android_target_version
buildToolsVersion android_build_tools_version
// buildToolsVersion android_build_tools_version

defaultConfig {
minSdkVersion 21
Expand All @@ -23,7 +25,7 @@ android {
dependencies {
// Koin
implementation "io.insert-koin:koin-core:$koin_version"
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "androidx.appcompat:appcompat:1.7.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation project(":jvm-perfs")

Expand Down
3 changes: 2 additions & 1 deletion examples/androidx-samples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
namespace = "org.koin.sample.sandbox"
compileSdk android_target_version
buildToolsVersion android_build_tools_version

Expand Down Expand Up @@ -56,7 +57,7 @@ android {
dependencies {

implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.work:work-runtime-ktx:2.8.1"
implementation "androidx.work:work-runtime-ktx:2.9.0"
implementation 'com.squareup.leakcanary:leakcanary-android:2.7'
testImplementation 'androidx.arch.core:core-testing:2.2.0'
testImplementation "junit:junit:4.13.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.koin.sample.sandbox.components.mvvm

import androidx.lifecycle.ViewModel
import org.koin.sample.sandbox.components.scope.Session

class SharedVM(val session: Session) : ViewModel()
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ val mvvmModule = lazyModule {

viewModelOf(::SavedStateViewModel) { named("vm2") }

viewModel { (s : Session) -> SharedVM(s)}
scope<MVVMActivity> {
scopedOf(::Session)
fragmentOf(::MVVMFragment) // { MVVMFragment(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class MVVMActivity : ScopeActivity(contentLayoutId = R.layout.mvvm_activity) {

val presenter : FactoryPresenter by inject { parametersOf("_MVVMActivity_id_") }

val session : Session by inject()
val sharedVM : SharedVM by viewModel { parametersOf(session) }

override fun onCreate(savedInstanceState: Bundle?) {
// should set `lifecycleScope` here because we're
// using MVVMActivity with scope in mvvmModule (AppModule)
Expand Down Expand Up @@ -81,5 +84,7 @@ class MVVMActivity : ScopeActivity(contentLayoutId = R.layout.mvvm_activity) {
assert(scopeVm2.session.id == scopeVm2.scope.get<Session>().id)
assert(scopeVm2.scope.get<SessionConsumer>().getSessionId() == scopeVm2.scope.get<Session>().id)
assert(scopeVm1.session.id != scopeVm2.session.id)

println("activity sharedVM.session:${sharedVM.session}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.koin.core.scope.Scope
import org.koin.sample.sandbox.R
import org.koin.sample.sandbox.components.ID
import org.koin.sample.sandbox.components.mvvm.SavedStateViewModel
import org.koin.sample.sandbox.components.mvvm.SharedVM
import org.koin.sample.sandbox.components.mvvm.SimpleViewModel
import org.koin.sample.sandbox.components.scope.Session

Expand All @@ -29,6 +30,8 @@ class MVVMFragment(private val session: Session) : Fragment(R.layout.mvvm_fragme
val saved by viewModel<SavedStateViewModel> { parametersOf(ID) }
val saved2 by viewModel<SavedStateViewModel> { parametersOf(ID) }

val sharedVM : SharedVM by activityViewModel()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand All @@ -50,5 +53,7 @@ class MVVMFragment(private val session: Session) : Fragment(R.layout.mvvm_fragme

assert(requireScopeActivity<MVVMActivity>().get<Session>().id == getKoin().getProperty("session_id"))
assert(scope.get<Session>().id == requireScopeActivity<MVVMActivity>().get<Session>().id)

println("fragment sharedVM.session:${sharedVM.session}")
}
}
4 changes: 2 additions & 2 deletions examples/gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ ext {
// build Tools
android_min_version = 14
android_target_version = 34
android_build_tools_version = '33.0.1'
android_gradle_version = '7.4.2'
android_build_tools_version = '34.0.0'
android_gradle_version = '8.4.0'
}
2 changes: 1 addition & 1 deletion examples/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions examples/jvm-perfs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ tasks.getByName<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>("compileKotlin"

val jmhVersion = "1.36"
//TODO get from existing version.gradle file
val koin_version = "3.5.3"
val coroutines_version = "1.7.3"
val koin_version = "3.6.0-Beta4"
val coroutines_version = "1.8.0"

dependencies {
api("io.insert-koin:koin-core:$koin_version")
Expand Down
1 change: 1 addition & 0 deletions examples/sample-android-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply plugin: 'kotlin-android'
apply from: "../gradle/versions.gradle"

android {
namespace = "org.koin.sample.androidx.compose"
compileSdk android_target_version
buildToolsVersion '30.0.3'

Expand Down

0 comments on commit 9902222

Please sign in to comment.