atlantis210
03/18/2021, 10:12 AMatlantis210
03/22/2021, 9:57 AMatlantis210
03/23/2021, 9:09 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 Autoatlantis210
03/23/2021, 9:58 AMarnaud.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 AMatlantis210
03/23/2021, 1:37 PMarnaud.giuliani
03/23/2021, 3:42 PMkoin.declare() APIarnaud.giuliani
03/23/2021, 3:42 PMarnaud.giuliani
03/23/2021, 3:42 PMarnaud.giuliani
03/23/2021, 3:42 PMatlantis210
03/23/2021, 3:51 PMScreen component to implements KoinComponent with it whereas it has a lifecycleatlantis210
03/23/2021, 3:58 PMkoin.rootScope.beanRegistry.findDefinition(clazz = CarContext::class) ?: koin.declare(carContext)atlantis210
03/23/2021, 3:58 PMDefinitionOverrideExceptionatlantis210
03/23/2021, 4:01 PMScope.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 flyarnaud.giuliani
03/23/2021, 4:14 PMoverride=truearnaud.giuliani
03/23/2021, 4:15 PMarnaud.giuliani
03/23/2021, 4:15 PMatlantis210
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 idealatlantis210
03/23/2021, 4:24 PMatlantis210
03/23/2021, 4:25 PMarnaud.giuliani
03/23/2021, 4:27 PMatlantis210
03/23/2021, 4:27 PMatlantis210
03/23/2021, 4:28 PMatlantis210
03/23/2021, 4:30 PMarnaud.giuliani
03/23/2021, 5:58 PMatlantis210
03/23/2021, 5:58 PM