Separate Hilt and Koin into their own product flavours
This commit is contained in:
parent
682fd71c2d
commit
1b8d0e836c
56 changed files with 496 additions and 72 deletions
|
|
@ -1,6 +1,7 @@
|
|||
plugins {
|
||||
id 'java-library'
|
||||
id 'kotlin'
|
||||
id 'kotlin-kapt'
|
||||
}
|
||||
|
||||
java {
|
||||
|
|
@ -14,12 +15,22 @@ compileKotlin {
|
|||
}
|
||||
}
|
||||
|
||||
kapt {
|
||||
correctErrorTypes = true
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
|
||||
|
||||
api project(":model")
|
||||
implementation project(":network")
|
||||
|
||||
// hilt
|
||||
implementation "com.google.dagger:hilt-core:$hilt_version"
|
||||
kapt "com.google.dagger:hilt-compiler:$hilt_version"
|
||||
implementation "org.fnives.library.reloadable.module:annotation:$reloadable_module_version"
|
||||
kapt "org.fnives.library.reloadable.module:annotation-processor:$reloadable_module_version"
|
||||
|
||||
testImplementation "io.insert-koin:koin-test-junit5:$koin_version"
|
||||
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
|
||||
testImplementation "org.mockito.kotlin:mockito-kotlin:$testing_kotlin_mockito_version"
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ package org.fnives.test.showcase.core.content
|
|||
|
||||
import org.fnives.test.showcase.core.storage.content.FavouriteContentLocalStorage
|
||||
import org.fnives.test.showcase.model.content.ContentId
|
||||
import javax.inject.Inject
|
||||
|
||||
class AddContentToFavouriteUseCase internal constructor(
|
||||
class AddContentToFavouriteUseCase @Inject internal constructor(
|
||||
private val favouriteContentLocalStorage: FavouriteContentLocalStorage
|
||||
) {
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
|
|||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import org.fnives.test.showcase.core.di.hilt.LoggedInModuleInject
|
||||
import org.fnives.test.showcase.core.shared.Optional
|
||||
import org.fnives.test.showcase.core.shared.mapIntoResource
|
||||
import org.fnives.test.showcase.core.shared.wrapIntoAnswer
|
||||
|
|
@ -14,7 +15,7 @@ import org.fnives.test.showcase.model.content.Content
|
|||
import org.fnives.test.showcase.model.shared.Resource
|
||||
import org.fnives.test.showcase.network.content.ContentRemoteSource
|
||||
|
||||
internal class ContentRepository(private val contentRemoteSource: ContentRemoteSource) {
|
||||
internal class ContentRepository @LoggedInModuleInject constructor(private val contentRemoteSource: ContentRemoteSource) {
|
||||
|
||||
private val mutableContentFlow = MutableStateFlow(Optional<List<Content>>(null))
|
||||
private val requestFlow: Flow<Resource<List<Content>>> = flow {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package org.fnives.test.showcase.core.content
|
||||
|
||||
class FetchContentUseCase internal constructor(private val contentRepository: ContentRepository) {
|
||||
import javax.inject.Inject
|
||||
|
||||
class FetchContentUseCase @Inject internal constructor(private val contentRepository: ContentRepository) {
|
||||
|
||||
fun invoke() = contentRepository.fetch()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ import org.fnives.test.showcase.model.content.Content
|
|||
import org.fnives.test.showcase.model.content.ContentId
|
||||
import org.fnives.test.showcase.model.content.FavouriteContent
|
||||
import org.fnives.test.showcase.model.shared.Resource
|
||||
import javax.inject.Inject
|
||||
|
||||
class GetAllContentUseCase internal constructor(
|
||||
class GetAllContentUseCase @Inject internal constructor(
|
||||
private val contentRepository: ContentRepository,
|
||||
private val favouriteContentLocalStorage: FavouriteContentLocalStorage
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ package org.fnives.test.showcase.core.content
|
|||
|
||||
import org.fnives.test.showcase.core.storage.content.FavouriteContentLocalStorage
|
||||
import org.fnives.test.showcase.model.content.ContentId
|
||||
import javax.inject.Inject
|
||||
|
||||
class RemoveContentFromFavouritesUseCase internal constructor(
|
||||
class RemoveContentFromFavouritesUseCase @Inject internal constructor(
|
||||
private val favouriteContentLocalStorage: FavouriteContentLocalStorage
|
||||
) {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
package org.fnives.test.showcase.core.di.hilt
|
||||
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import org.fnives.test.showcase.core.login.LogoutUseCase
|
||||
import org.fnives.test.showcase.core.session.SessionExpirationAdapter
|
||||
import org.fnives.test.showcase.core.storage.NetworkSessionLocalStorageAdapter
|
||||
import org.fnives.test.showcase.core.storage.UserDataLocalStorage
|
||||
import org.fnives.test.showcase.network.session.NetworkSessionExpirationListener
|
||||
import org.fnives.test.showcase.network.session.NetworkSessionLocalStorage
|
||||
import org.fnives.test.showcase.core.di.hilt.ReloadLoggedInModuleInjectModule
|
||||
|
||||
@InstallIn(SingletonComponent::class)
|
||||
@Module
|
||||
object CoreModule {
|
||||
|
||||
@Provides
|
||||
internal fun bindNetworkSessionLocalStorageAdapter(
|
||||
networkSessionLocalStorageAdapter: NetworkSessionLocalStorageAdapter
|
||||
): NetworkSessionLocalStorage = networkSessionLocalStorageAdapter
|
||||
|
||||
@Provides
|
||||
internal fun bindNetworkSessionExpirationListener(
|
||||
sessionExpirationAdapter: SessionExpirationAdapter
|
||||
): NetworkSessionExpirationListener = sessionExpirationAdapter
|
||||
|
||||
@Provides
|
||||
fun provideLogoutUseCase(
|
||||
storage: UserDataLocalStorage,
|
||||
reloadLoggedInModuleInjectModule: ReloadLoggedInModuleInjectModule
|
||||
) : LogoutUseCase = LogoutUseCase(storage, reloadLoggedInModuleInjectModule)
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.fnives.test.showcase.core.di.hilt
|
||||
|
||||
import org.fnives.library.reloadable.module.annotation.ReloadableModule
|
||||
|
||||
@ReloadableModule
|
||||
@Target(AnnotationTarget.CONSTRUCTOR)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class LoggedInModuleInject
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.fnives.test.showcase.core.di
|
||||
package org.fnives.test.showcase.core.di.koin
|
||||
|
||||
import org.fnives.test.showcase.core.content.AddContentToFavouriteUseCase
|
||||
import org.fnives.test.showcase.core.content.ContentRepository
|
||||
|
|
@ -14,7 +14,7 @@ import org.fnives.test.showcase.core.storage.NetworkSessionLocalStorageAdapter
|
|||
import org.fnives.test.showcase.core.storage.UserDataLocalStorage
|
||||
import org.fnives.test.showcase.core.storage.content.FavouriteContentLocalStorage
|
||||
import org.fnives.test.showcase.model.network.BaseUrl
|
||||
import org.fnives.test.showcase.network.di.createNetworkModules
|
||||
import org.fnives.test.showcase.network.di.koin.createNetworkModules
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.core.scope.Scope
|
||||
import org.koin.dsl.module
|
||||
|
|
@ -42,7 +42,7 @@ fun repositoryModule() = module {
|
|||
|
||||
fun useCaseModule() = module {
|
||||
factory { LoginUseCase(get(), get()) }
|
||||
factory { LogoutUseCase(get()) }
|
||||
factory { LogoutUseCase(get(), null) }
|
||||
factory { GetAllContentUseCase(get(), get()) }
|
||||
factory { AddContentToFavouriteUseCase(get()) }
|
||||
factory { RemoveContentFromFavouritesUseCase(get()) }
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
package org.fnives.test.showcase.core.login
|
||||
|
||||
import org.fnives.test.showcase.core.storage.UserDataLocalStorage
|
||||
import javax.inject.Inject
|
||||
|
||||
class IsUserLoggedInUseCase(private val userDataLocalStorage: UserDataLocalStorage) {
|
||||
class IsUserLoggedInUseCase @Inject constructor(
|
||||
private val userDataLocalStorage: UserDataLocalStorage
|
||||
) {
|
||||
|
||||
fun invoke(): Boolean = userDataLocalStorage.session != null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ import org.fnives.test.showcase.model.auth.LoginStatus
|
|||
import org.fnives.test.showcase.model.shared.Answer
|
||||
import org.fnives.test.showcase.network.auth.LoginRemoteSource
|
||||
import org.fnives.test.showcase.network.auth.model.LoginStatusResponses
|
||||
import javax.inject.Inject
|
||||
|
||||
class LoginUseCase internal constructor(
|
||||
class LoginUseCase @Inject internal constructor(
|
||||
private val loginRemoteSource: LoginRemoteSource,
|
||||
private val userDataLocalStorage: UserDataLocalStorage
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,22 @@
|
|||
package org.fnives.test.showcase.core.login
|
||||
|
||||
import org.fnives.test.showcase.core.di.repositoryModule
|
||||
import org.fnives.test.showcase.core.di.koin.repositoryModule
|
||||
import org.fnives.test.showcase.core.storage.UserDataLocalStorage
|
||||
import org.koin.core.context.loadKoinModules
|
||||
import org.koin.mp.KoinPlatformTools
|
||||
import org.fnives.test.showcase.core.di.hilt.ReloadLoggedInModuleInjectModule
|
||||
|
||||
class LogoutUseCase(private val storage: UserDataLocalStorage) {
|
||||
class LogoutUseCase(
|
||||
private val storage: UserDataLocalStorage,
|
||||
private val reloadLoggedInModuleInjectModule: ReloadLoggedInModuleInjectModule?
|
||||
) {
|
||||
|
||||
suspend fun invoke() {
|
||||
loadKoinModules(repositoryModule())
|
||||
if (KoinPlatformTools.defaultContext().getOrNull() == null) {
|
||||
reloadLoggedInModuleInjectModule?.reload()
|
||||
} else {
|
||||
loadKoinModules(repositoryModule())
|
||||
}
|
||||
storage.session = null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
package org.fnives.test.showcase.core.session
|
||||
|
||||
import org.fnives.test.showcase.network.session.NetworkSessionExpirationListener
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class SessionExpirationAdapter(
|
||||
internal class SessionExpirationAdapter @Inject constructor(
|
||||
private val sessionExpirationListener: SessionExpirationListener
|
||||
) :
|
||||
NetworkSessionExpirationListener {
|
||||
) : NetworkSessionExpirationListener {
|
||||
|
||||
override fun onSessionExpired() = sessionExpirationListener.onSessionExpired()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ package org.fnives.test.showcase.core.storage
|
|||
|
||||
import org.fnives.test.showcase.model.session.Session
|
||||
import org.fnives.test.showcase.network.session.NetworkSessionLocalStorage
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class NetworkSessionLocalStorageAdapter(
|
||||
internal class NetworkSessionLocalStorageAdapter @Inject constructor(
|
||||
private val userDataLocalStorage: UserDataLocalStorage
|
||||
) : NetworkSessionLocalStorage {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package org.fnives.test.showcase.core.login
|
|||
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
import org.fnives.test.showcase.core.content.ContentRepository
|
||||
import org.fnives.test.showcase.core.di.createCoreModule
|
||||
import org.fnives.test.showcase.core.di.koin.createCoreModule
|
||||
import org.fnives.test.showcase.core.storage.UserDataLocalStorage
|
||||
import org.fnives.test.showcase.model.network.BaseUrl
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue