atlantis210
03/18/2021, 10:12 AMarnaud.giuliani
03/23/2021, 9:11 AMKoinComponent
? is there any missing API ?atlantis210
03/23/2021, 9:20 AMabstract class MyScreen(carContext: CarContext): Screen(carContext), KoinComponent
whereas Screen has lifecycle and add a function for settings the carContext as you did for the Android Context
fun KoinApplication.carContext(carContext: CarContext): KoinApplication {
if (KoinApplication.logger.isAt(<http://Level.INFO|Level.INFO>)) {
<http://KoinApplication.logger.info|KoinApplication.logger.info>("[init] declare CarContext")
}
koin.rootScope.beanRegistry.findDefinition(clazz = CarContext::class) ?:
koin.rootScope.beanRegistry.saveDefinition(DefinitionFactory.createSingle { carContext })
return this
}
and also
fun Scope.carContext(): CarContext = try {
get()
} catch (e: Exception) {
throw MissingAndroidContextException("$e")
}
So if this could be inside a library koin-android-auto or something like that, I think it would be easier for other people to continue using koin when on Android Autoarnaud.giuliani
03/23/2021, 10:17 AMandroidContext()
DSL keywordatlantis210
03/23/2021, 10:29 AMCarContext
has to be set only when connected to Android Auto. And when unplugged the Context
has to be back to the standard Android Context.arnaud.giuliani
03/23/2021, 10:45 AMatlantis210
03/23/2021, 10:50 AMarnaud.giuliani
03/23/2021, 3:42 PMkoin.declare()
APIatlantis210
03/23/2021, 3:51 PMScreen
component to implements KoinComponent with it whereas it has a lifecyclekoin.rootScope.beanRegistry.findDefinition(clazz = CarContext::class) ?: koin.declare(carContext)
DefinitionOverrideException
Scope.carContext()
but I like to use it the same way you did for androidContext()
. But I'll still have to use`koin.declare()` or saveDefinition()
and override the Screen
componentarnaud.giuliani
03/23/2021, 4:14 PMI’ll still have to docheck thekoin.rootScope.beanRegistry.findDefinition(clazz = CarContext::class) ?: koin.declare(carContext)
declare()
function from Koin. You can declare things on the flyoverride=true
atlantis210
03/23/2021, 4:16 PMimplementation '<http://androidx.car.app:app:1.0.0-beta01|androidx.car.app:app:1.0.0-beta01>'
And yes, there is no ViewModel in Android Auto since there is no layouts nor viewsarnaud.giuliani
03/23/2021, 4:22 PMatlantis210
03/23/2021, 4:24 PMdeclare()
function from Koin. You can declare things on the fly and specify `override=true`". I could do that but that's not idealarnaud.giuliani
03/23/2021, 4:27 PMatlantis210
03/23/2021, 4:27 PMarnaud.giuliani
03/23/2021, 5:58 PMatlantis210
03/23/2021, 5:58 PM