-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify di, normalize strings when filtering (#41)
1 parent
ba441c9
commit 7190f38
Showing
7 changed files
with
72 additions
and
75 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
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
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
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
42 changes: 0 additions & 42 deletions
42
utils/src/main/java/com/jcaique/dialetus/utils/extensions/dependency_injection.kt
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
utils/src/main/java/com/jcaique/dialetus/utils/extensions/di_ktx.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,42 @@ | ||
package com.jcaique.dialetus.utils.extensions | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.FragmentActivity | ||
import com.jcaique.dialetus.utils.KodeinTags.hostActivity | ||
import com.jcaique.dialetus.utils.dataflow.ConfigChangesAwareStateContainer | ||
import com.jcaique.dialetus.utils.dataflow.StateContainer | ||
import com.jcaique.dialetus.utils.dataflow.StateMachine | ||
import com.jcaique.dialetus.utils.dataflow.TaskExecutor | ||
import org.kodein.di.Kodein | ||
import org.kodein.di.KodeinAware | ||
import org.kodein.di.bindings.NoArgBindingKodein | ||
import org.kodein.di.generic.bind | ||
import org.kodein.di.generic.instance | ||
import org.kodein.di.generic.provider | ||
|
||
fun AppCompatActivity.selfInject(bindings: Kodein.MainBuilder.() -> Unit = {}) = Kodein.lazy { | ||
|
||
val parentKodein = (applicationContext as KodeinAware).kodein | ||
|
||
extend(parentKodein) | ||
|
||
bind<FragmentActivity>(tag = hostActivity) with provider { | ||
this@selfInject | ||
} | ||
|
||
bindings.invoke(this) | ||
} | ||
|
||
fun <T> NoArgBindingKodein<*>.newStateContainer(tag: String) = | ||
ConfigChangesAwareStateContainer<T>( | ||
host = instance(tag) | ||
) | ||
|
||
fun <T> NoArgBindingKodein<*>.newStateMachine(stateContainer: StateContainer<T>) = | ||
StateMachine( | ||
container = stateContainer, | ||
executor = TaskExecutor.Concurrent( | ||
scope = stateContainer.emissionScope, | ||
dispatcher = instance() | ||
) | ||
) |
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