Skip to content

Upgrade dependencies. Migrate to Kodein 7 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security
- No security issues fixed!

## [1.4.0] - 2020-12-15
### Added
- Upgrade Kotlin to 1.4.21 and Kodein to 7.1.0, apart from other Android dependencies.

## [1.3.3] - 2020-08-13
### Added
- Add proguard rules for most modules that need them.
Expand Down Expand Up @@ -105,8 +109,9 @@ state (`success` or `failure`)
### Added
- Initial architecture release.

[Unreleased]: https://github.com/bq/mini-kotlin/compare/1.3.3...HEAD
[1.3.3]: https://github.com/bq/mini-kotlin/compare/1.3.1...1.3.2
[Unreleased]: https://github.com/bq/mini-kotlin/compare/1.4.0...HEAD
[1.4.0]: https://github.com/bq/mini-kotlin/compare/1.3.3...1.4.0
[1.3.3]: https://github.com/bq/mini-kotlin/compare/1.3.2...1.3.3
[1.3.2]: https://github.com/bq/mini-kotlin/compare/1.3.1...1.3.2
[1.3.1]: https://github.com/bq/mini-kotlin/compare/1.3.0...1.3.1
[1.3.0]: https://github.com/bq/mini-kotlin/compare/1.2.0...1.3.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Add the following dependencies to your app's `build.gradle`:

```groovy
dependencies {
def mini_version = "1.3.3"
def mini_version = "1.4.0"
// Minimum working dependencies
implementation "com.github.bq.mini-kotlin:mini-android:$mini_version"
kapt "com.github.bq.mini-kotlin:mini-processor:$mini_version"
Expand Down
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ repositories {
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

//Android
android {
Expand All @@ -24,6 +23,10 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
viewBinding = true
}

buildTypes {
release {
minifyEnabled false
Expand Down Expand Up @@ -71,8 +74,8 @@ dependencies {
implementation "io.reactivex.rxjava2:rxjava:$rx_version"

//Support
implementation "androidx.core:core:1.2.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.core:core:1.3.2"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

//Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/org/sample/SampleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ import android.os.Bundle
import com.mini.android.FluxActivity
import com.minikorp.grove.ConsoleLogTree
import com.minikorp.grove.Grove
import kotlinx.android.synthetic.main.home_activity.*
import mini.LoggerInterceptor
import mini.MiniGen
import org.sample.databinding.HomeActivityBinding

class SampleActivity : FluxActivity() {

private val dispatcher = MiniGen.newDispatcher()
private val dummyStore = DummyStore()

private lateinit var binding: HomeActivityBinding

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

val stores = listOf(dummyStore)
MiniGen.subscribe(dispatcher, stores).track()
stores.forEach { it.initialize() }

dummyStore.subscribe {
demo_text.text = it.text
binding.demoText.text = it.text
}

Grove.plant(ConsoleLogTree())
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/org/sample/SampleRxActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,31 @@ package org.sample
import android.os.Bundle
import com.minikorp.grove.ConsoleLogTree
import com.minikorp.grove.Grove
import kotlinx.android.synthetic.main.home_activity.*
import mini.LoggerInterceptor
import mini.MiniGen
import mini.rx.android.activities.FluxRxActivity
import mini.rx.flowable
import org.sample.databinding.HomeActivityBinding

class SampleRxActivity : FluxRxActivity() {

private val dispatcher = MiniGen.newDispatcher()
private val dummyStore = DummyStore()

private lateinit var binding: HomeActivityBinding

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

val stores = listOf(dummyStore)
MiniGen.subscribe(dispatcher, stores)
stores.forEach { it.initialize() }

dummyStore.flowable()
.subscribe {
demo_text.text = it.text
binding.demoText.text = it.text
}
.track()

Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ apply plugin: 'com.gladed.androidgitversion'

buildscript {
ext {
kotlin_version = "1.3.72"
kotlin_version = "1.4.21"

android_compile_sdk = 29
android_target_sdk = 29
android_build_tools_version = "29.0.1"
android_compile_sdk = 30
android_target_sdk = 30
android_build_tools_version = "30.0.2"

lifecycle_version = "2.2.0"
rx_version = "2.2.6"
coroutines_version = "1.3.3"
coroutines_version = "1.4.2"
}

repositories {
Expand All @@ -22,7 +22,7 @@ buildscript {
}

dependencies {
classpath "com.android.tools.build:gradle:3.6.3"
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.junit.platform:junit-platform-gradle-plugin:1.2.0"
classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Jul 22 11:10:54 CEST 2019
#Mon Dec 14 20:31:47 CET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
6 changes: 3 additions & 3 deletions mini-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ dependencies {
api project(":mini-common")

api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
api "androidx.appcompat:appcompat:1.1.0"
api "androidx.appcompat:appcompat:1.2.0"
api "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"

testImplementation "junit:junit:4.13"
androidTestImplementation "androidx.test:runner:1.2.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"
androidTestImplementation "androidx.test:runner:1.3.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
}

apply from: "../jitpack-android.gradle"
4 changes: 2 additions & 2 deletions mini-kodein-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ dependencies {
api "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

testImplementation "junit:junit:4.13"
androidTestImplementation "androidx.test:runner:1.2.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"
androidTestImplementation "androidx.test:runner:1.3.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
}

apply from: "../jitpack-android.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import org.kodein.di.DKodein
import org.kodein.di.Kodein
import org.kodein.di.KodeinAware
import org.kodein.di.bindings.BindingKodein
import org.kodein.di.bindings.NoArgBindingKodein
import org.kodein.di.direct
import org.kodein.di.generic.*
import org.kodein.di.*
import org.kodein.di.bindings.BindingDI
import org.kodein.di.bindings.NoArgBindingDI

/**
* Binds a ViewModel to a Kotlin module, assuming that it's a provided dependency.
*/
inline fun <reified VM : ViewModel> Kodein.Builder.bindViewModel(overrides: Boolean? = null,
noinline creator: NoArgBindingKodein<*>.() -> VM) {
inline fun <reified VM : ViewModel> DI.Builder.bindViewModel(overrides: Boolean? = null,
noinline creator: NoArgBindingDI<*>.() -> VM) {
bind<VM>(VM::class.java.simpleName, overrides) with provider(creator)
}

/**
* Binds a ViewModel factory to a Kotlin module in order to create new ViewModels.
*/
inline fun <reified VM : ViewModel, reified F : ViewModelProvider.Factory> Kodein.Builder.bindViewModelFactory(overrides: Boolean? = null,
noinline creator: BindingKodein<*>.(Any) -> F) {
inline fun <reified VM : ViewModel, reified F : ViewModelProvider.Factory> DI.Builder.bindViewModelFactory(overrides: Boolean? = null,
noinline creator: BindingDI<*>.(Any) -> F) {
bind<F>(VM::class.java, overrides) with factory(creator = creator)
}

Expand All @@ -37,7 +33,7 @@ inline fun <reified VM : ViewModel, reified F : ViewModelProvider.Factory> Kodei
* if you allow creating new instances of them via [Class.newInstance] with [allowNewInstance].
* The default is true to mimic the default behaviour of [ViewModelProvider].
*/
class KodeinViewModelFactory(private val injector: DKodein,
class DIViewModelFactory(private val injector: DirectDI,
private val allowNewInstance: Boolean = true) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
Expand All @@ -51,71 +47,72 @@ class KodeinViewModelFactory(private val injector: DKodein,
}

/**
* Injects a [ViewModel] into a [FragmentActivity] that implements [KodeinAware].
* Injects a [ViewModel] into a [FragmentActivity] that implements [DIAware].
*/
@MainThread
inline fun <reified VM : ViewModel, A> A.viewModel(): Lazy<VM> where A : KodeinAware, A : FragmentActivity {
inline fun <reified VM : ViewModel, A> A.viewModel(): Lazy<VM> where A : DIAware, A : FragmentActivity {
return lazy {
ViewModelProvider(this, direct.instance()).get(VM::class.java)
}
}

/**
* Injects a [ViewModel] into a [Fragment] that implements [KodeinAware].
* Injects a [ViewModel] into a [Fragment] that implements [DIAware].
*/
@MainThread
inline fun <reified VM : ViewModel, F> F.viewModel(): Lazy<VM> where F : KodeinAware, F : Fragment {
inline fun <reified VM : ViewModel, F> F.viewModel(): Lazy<VM> where F : DIAware, F : Fragment {
return lazy {
ViewModelProvider(this, direct.instance()).get(VM::class.java)
}
}

/**
* Injects a [ViewModel] into a [FragmentActivity] that implements [KodeinAware].
* Injects a [ViewModel] into a [FragmentActivity] that implements [DIAware].
*
* Requires previous [ViewModelProvider.Factory] injection for the [ViewModel] via [bindViewModelFactory]
* to work and a [TypedViewModel] to be used.
*/
@MainThread
inline fun <reified T, reified VM : TypedViewModel<T>, A> A.viewModel(params: T): Lazy<VM> where A : KodeinAware, A : FragmentActivity {
inline fun <reified T : Any, reified VM : TypedViewModel<T>, A> A.viewModel(params: T): Lazy<VM> where A : DIAware, A : FragmentActivity {
return lazy {
ViewModelProvider(this, direct.instance(VM::class.java, params)).get(VM::class.java)
}
}

/**
* Injects a [ViewModel] into a [Fragment] that implements [KodeinAware].
* Injects a [ViewModel] into a [Fragment] that implements [DIAware].
*
* Requires previous [ViewModelProvider.Factory] injection for the [ViewModel] via [bindViewModelFactory]
* to work and a [TypedViewModel] to be used.
*/
@MainThread
inline fun <reified T, reified VM : TypedViewModel<T>, F> F.viewModel(params: T): Lazy<VM> where F : KodeinAware, F : Fragment {
inline fun <reified T : Any, reified VM : TypedViewModel<T>, F> F.viewModel(params: T): Lazy<VM> where F : DIAware, F : Fragment {
return lazy {
ViewModelProvider(this, direct.instance(VM::class.java, params)).get(VM::class.java)
}
}

/**
* Injects a [ViewModel] with an [Activity] context that implements [KodeinAware], in order to share it between
* Injects a [ViewModel] with an [Activity] context that implements [DIAware
* ], in order to share it between
* different fragments hosted by that same [Activity].
*/
@MainThread
inline fun <reified VM : ViewModel, F> F.sharedActivityViewModel(): Lazy<VM> where F : KodeinAware, F : Fragment {
inline fun <reified VM : ViewModel, F> F.sharedActivityViewModel(): Lazy<VM> where F : DIAware, F : Fragment {
return lazy {
ViewModelProvider(this.requireActivity(), direct.instance()).get(VM::class.java)
}
}

/**
* Injects a [ViewModel] with an [Activity] context that implements [KodeinAware], in order to share it between
* Injects a [ViewModel] with an [Activity] context that implements [DIAware], in order to share it between
* different fragments hosted by that same [Activity].
*
* Requires previous [ViewModelProvider.Factory] injection for the [ViewModel] via [bindViewModelFactory]
* to work and a [TypedViewModel] to be used.
*/
@MainThread
inline fun <reified T, reified VM : TypedViewModel<T>, F> F.sharedActivityViewModel(params: T): Lazy<VM> where F : KodeinAware, F : Fragment {
inline fun <reified T: Any, reified VM : TypedViewModel<T>, F> F.sharedActivityViewModel(params: T): Lazy<VM> where F : DIAware, F : Fragment {
return lazy {
ViewModelProvider(this.requireActivity(), direct.instance(VM::class.java, params)).get(VM::class.java)
}
Expand All @@ -125,4 +122,4 @@ inline fun <reified T, reified VM : TypedViewModel<T>, F> F.sharedActivityViewMo
* Generic [ViewModel] that adds support for adding a single [params] object to ease parameter
* injection.
*/
open class TypedViewModel<T>(private val params: T) : ViewModel()
open class TypedViewModel<T>(private val params: T) : ViewModel()
4 changes: 2 additions & 2 deletions mini-kodein/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

def kodein_version = "6.5.5"
api "org.kodein.di:kodein-di-generic-jvm:$kodein_version"
def kodein_version = "7.1.0"
api "org.kodein.di:kodein-di-jvm:$kodein_version"
api "org.kodein.di:kodein-di-framework-android-x:$kodein_version"
}
10 changes: 3 additions & 7 deletions mini-kodein/src/main/java/mini/kodein/KodeinUtils.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package mini.kodein

import mini.Store
import org.kodein.di.Kodein
import org.kodein.di.bindings.NoArgSimpleBindingKodein
import org.kodein.di.generic.bind
import org.kodein.di.generic.inSet
import org.kodein.di.generic.instance
import org.kodein.di.generic.singleton
import org.kodein.di.*
import org.kodein.di.bindings.NoArgBindingDI

/**
* Work based on: https://proandroiddev.com/android-viewmodel-dependency-injection-with-kodein-249f80f083c9
Expand All @@ -15,7 +11,7 @@ import org.kodein.di.generic.singleton
/**
* Binds a store in a Kodein module, assuming that it's a singleton dependency.
*/
inline fun <reified T : Store<*>> Kodein.Builder.bindStore(noinline creator: NoArgSimpleBindingKodein<*>.() -> T) {
inline fun <reified T : Store<*>> DI.Builder.bindStore(noinline creator: NoArgBindingDI<*>.() -> T) {
bind<T>() with singleton(creator = creator)
bind<Store<*>>().inSet() with singleton { instance<T>() }
}
6 changes: 3 additions & 3 deletions mini-rx2-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ dependencies {
api project(":mini-android")

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'

api "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
api "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

apply from: "../jitpack-android.gradle"