-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reproducible scenario for Koin issue InsertKoinIO/koin#1434
- Loading branch information
Marek Defeciński
committed
Oct 5, 2022
1 parent
9c024f9
commit 3ea7078
Showing
44 changed files
with
1,069 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "pl.senordeveloper.insertkoinsharedviewmodel" | ||
minSdk 26 | ||
targetSdk 32 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
buildFeatures { | ||
viewBinding true | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.9.0' | ||
implementation 'androidx.appcompat:appcompat:1.5.1' | ||
implementation 'com.google.android.material:material:1.6.1' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
implementation "io.insert-koin:koin-android:3.2.0" | ||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
...c/androidTest/java/pl/senordeveloper/insertkoinsharedviewmodel/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package pl.senordeveloper.insertkoinsharedviewmodel | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("pl.senordeveloper.insertkoinsharedviewmodel", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="pl.senordeveloper.insertkoinsharedviewmodel"> | ||
|
||
<application | ||
android:name=".MainApplication" | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.InsertKoinSharedViewModel" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/pl/senordeveloper/insertkoinsharedviewmodel/Fragment1.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package pl.senordeveloper.insertkoinsharedviewmodel | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.FrameLayout | ||
import androidx.fragment.app.Fragment | ||
import org.koin.androidx.viewmodel.ext.android.getSharedStateViewModel | ||
import org.koin.androidx.viewmodel.ext.android.sharedStateViewModel | ||
import pl.senordeveloper.insertkoinsharedviewmodel.databinding.SimpleFragmentBinding | ||
|
||
class Fragment1 : Fragment() { | ||
val viewModel: MainViewModel by lazy { | ||
getSharedStateViewModel( | ||
// owner = {requireParentFragment()} | ||
) | ||
} | ||
|
||
private lateinit var simpleFragmentBinding: SimpleFragmentBinding | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
simpleFragmentBinding = SimpleFragmentBinding.inflate(inflater, container, false) | ||
return simpleFragmentBinding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
simpleFragmentBinding.button.setOnClickListener { | ||
viewModel.random() | ||
} | ||
|
||
viewModel.random.observe(viewLifecycleOwner) { | ||
simpleFragmentBinding.textView.text = it.toString() | ||
|
||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/pl/senordeveloper/insertkoinsharedviewmodel/Fragment2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package pl.senordeveloper.insertkoinsharedviewmodel | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import org.koin.androidx.viewmodel.ext.android.getSharedStateViewModel | ||
import org.koin.androidx.viewmodel.ext.android.sharedStateViewModel | ||
import pl.senordeveloper.insertkoinsharedviewmodel.databinding.SimpleFragmentBinding | ||
|
||
class Fragment2 : Fragment() { | ||
val viewModel: MainViewModel by lazy { | ||
getSharedStateViewModel( | ||
// owner = {requireParentFragment()} | ||
) | ||
} | ||
|
||
private lateinit var simpleFragmentBinding: SimpleFragmentBinding | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
simpleFragmentBinding = SimpleFragmentBinding.inflate(inflater, container, false) | ||
return simpleFragmentBinding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
viewModel.random.observe(viewLifecycleOwner) { | ||
simpleFragmentBinding.textView.text = it.toString() | ||
simpleFragmentBinding.button.setOnClickListener { | ||
viewModel.random() | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/java/pl/senordeveloper/insertkoinsharedviewmodel/Fragment3.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package pl.senordeveloper.insertkoinsharedviewmodel | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.FrameLayout | ||
import androidx.fragment.app.Fragment | ||
import org.koin.androidx.viewmodel.ext.android.getSharedStateViewModel | ||
import org.koin.androidx.viewmodel.ext.android.sharedStateViewModel | ||
import pl.senordeveloper.insertkoinsharedviewmodel.databinding.SimpleFragmentBinding | ||
|
||
class Fragment3 : Fragment() { | ||
val viewModel: MainViewModel by lazy { | ||
getSharedStateViewModel( | ||
// owner = {requireParentFragment()} | ||
// clazz = MainViewModel::class | ||
) | ||
} | ||
|
||
private lateinit var simpleFragmentBinding: SimpleFragmentBinding | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
simpleFragmentBinding = SimpleFragmentBinding.inflate(inflater, container, false) | ||
return simpleFragmentBinding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
viewModel.random.observe(viewLifecycleOwner) { | ||
simpleFragmentBinding.textView.text = it.toString() | ||
simpleFragmentBinding.button.setOnClickListener { | ||
viewModel.random() | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/pl/senordeveloper/insertkoinsharedviewmodel/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package pl.senordeveloper.insertkoinsharedviewmodel | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import org.koin.androidx.viewmodel.ext.android.stateViewModel | ||
import pl.senordeveloper.insertkoinsharedviewmodel.databinding.ActivityMainBinding | ||
|
||
class MainActivity : AppCompatActivity() { | ||
private val viewModel by stateViewModel<MainViewModel>() | ||
|
||
private val activityMainBinding by lazy { | ||
ActivityMainBinding.inflate(layoutInflater) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(activityMainBinding.root) | ||
|
||
viewModel.random.observe(this) { | ||
activityMainBinding.textView.text = it.toString() | ||
} | ||
|
||
activityMainBinding.button.setOnClickListener { | ||
viewModel.random() | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/pl/senordeveloper/insertkoinsharedviewmodel/MainApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package pl.senordeveloper.insertkoinsharedviewmodel | ||
|
||
import android.app.Application | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.android.ext.koin.androidLogger | ||
import org.koin.core.context.GlobalContext.startKoin | ||
import org.koin.core.logger.Level | ||
|
||
class MainApplication: Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
startKoin{ | ||
androidLogger(level = Level.DEBUG) | ||
androidContext(this@MainApplication) | ||
modules(appModule) | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/pl/senordeveloper/insertkoinsharedviewmodel/MainFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package pl.senordeveloper.insertkoinsharedviewmodel | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import org.koin.androidx.viewmodel.ext.android.getSharedStateViewModel | ||
import org.koin.androidx.viewmodel.ext.android.sharedStateViewModel | ||
import pl.senordeveloper.insertkoinsharedviewmodel.databinding.MainFragmentBinding | ||
|
||
class MainFragment: Fragment() { | ||
private lateinit var mainFragmentBinding: MainFragmentBinding | ||
|
||
val viewModel: MainViewModel by lazy { | ||
getSharedStateViewModel( | ||
// owner = {this}, | ||
clazz = MainViewModel::class | ||
) | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
mainFragmentBinding = MainFragmentBinding.inflate(inflater, container, false) | ||
return mainFragmentBinding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
viewModel.random.observe(viewLifecycleOwner){ | ||
mainFragmentBinding.textView.text = it.toString() | ||
} | ||
mainFragmentBinding.button.setOnClickListener { | ||
viewModel.random() | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/pl/senordeveloper/insertkoinsharedviewmodel/MainViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package pl.senordeveloper.insertkoinsharedviewmodel | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModel | ||
import kotlin.random.Random | ||
|
||
class MainViewModel( | ||
savedStateHandle: SavedStateHandle | ||
): ViewModel() { | ||
private val _random = MutableLiveData<Int>() | ||
val random: LiveData<Int> = _random | ||
|
||
fun random() { | ||
_random.value = Random.nextInt() | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/pl/senordeveloper/insertkoinsharedviewmodel/appModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package pl.senordeveloper.insertkoinsharedviewmodel | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import org.koin.androidx.viewmodel.dsl.viewModel | ||
import org.koin.dsl.module | ||
|
||
val appModule = module { | ||
viewModel { | ||
MainViewModel(savedStateHandle = get()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="108" | ||
android:viewportHeight="108"> | ||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:endX="85.84757" | ||
android:endY="92.4963" | ||
android:startX="42.9492" | ||
android:startY="49.59793" | ||
android:type="linear"> | ||
<item | ||
android:color="#44000000" | ||
android:offset="0.0" /> | ||
<item | ||
android:color="#00000000" | ||
android:offset="1.0" /> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:fillType="nonZero" | ||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" | ||
android:strokeWidth="1" | ||
android:strokeColor="#00000000" /> | ||
</vector> |
Oops, something went wrong.