forked from az4521/TachiyomiAZ
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch Injekt to Koin-Injekt bridge and implement InjektRegistrar bridge
- Loading branch information
Showing
11 changed files
with
115 additions
and
54 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
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
64 changes: 64 additions & 0 deletions
64
app/src/main/java/eu/kanade/tachiyomi/di/InjektKoinBridge.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,64 @@ | ||
package eu.kanade.tachiyomi.di | ||
|
||
import android.content.Context | ||
import logcat.LogPriority | ||
import logcat.logcat | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.core.context.startKoin | ||
import org.koin.core.logger.Level | ||
import org.koin.core.logger.Logger | ||
import org.koin.core.logger.MESSAGE | ||
import org.koin.core.module.Module | ||
import org.koin.core.scope.Scope | ||
import uy.kohesive.injekt.api.InjektRegistrar | ||
import uy.kohesive.injekt.api.InjektScope | ||
|
||
object InjektKoinBridge { | ||
private val modules = mutableMapOf<InjektModule, Module>() | ||
fun getModule(injektModule: InjektModule) = modules.getOrPut(injektModule) { Module() } | ||
|
||
fun startKoin(context: Context) { | ||
startKoin { | ||
logger( | ||
object : Logger() { | ||
override fun display(level: Level, msg: MESSAGE) { | ||
logcat( | ||
when (level) { | ||
Level.DEBUG -> LogPriority.DEBUG | ||
Level.INFO -> LogPriority.INFO | ||
Level.WARNING -> LogPriority.WARN | ||
Level.ERROR -> LogPriority.ERROR | ||
Level.NONE -> LogPriority.VERBOSE | ||
}, | ||
) { msg } | ||
} | ||
}, | ||
) | ||
androidContext(context) | ||
modules(modules.values.toList()) | ||
} | ||
} | ||
} | ||
|
||
interface InjektModule { | ||
fun InjektRegistrar.registerInjectables() | ||
} | ||
|
||
inline fun <reified T> InjektModule.addSingleton(instance: T) { | ||
val module = InjektKoinBridge.getModule(this) | ||
module.single<T> { instance } | ||
} | ||
|
||
inline fun <reified T> InjektModule.addSingletonFactory(crossinline instance: Scope.() -> T) { | ||
val module = InjektKoinBridge.getModule(this) | ||
module.single<T> { instance() } | ||
} | ||
|
||
inline fun <reified T> InjektModule.addFactory(crossinline instance: Scope.() -> T) { | ||
val module = InjektKoinBridge.getModule(this) | ||
module.factory<T> { instance() } | ||
} | ||
|
||
fun InjektScope.importModule(injektModule: InjektModule) { | ||
with(injektModule) { registrar.registerInjectables() } | ||
} |
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