Issue#31 Remove hilt completely
This commit is contained in:
parent
e3bf7fd3e2
commit
b29870c90c
84 changed files with 75 additions and 1875 deletions
|
|
@ -13,6 +13,18 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.TestShowCase"
|
||||
tools:ignore="AllowBackup"/>
|
||||
tools:ignore="AllowBackup">
|
||||
<activity
|
||||
android:name=".ui.splash.SplashActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".ui.home.MainActivity" />
|
||||
<activity android:name=".ui.auth.AuthActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package org.fnives.test.showcase
|
||||
|
||||
import android.app.Application
|
||||
import org.fnives.test.showcase.di.BaseUrlProvider
|
||||
import org.fnives.test.showcase.di.createAppModules
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.core.context.startKoin
|
||||
|
||||
class TestShowcaseApplication : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
startKoin {
|
||||
androidContext(this@TestShowcaseApplication)
|
||||
modules(createAppModules(BaseUrlProvider.get()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package org.fnives.test.showcase.di
|
||||
|
||||
import org.fnives.test.showcase.core.di.koin.createCoreModule
|
||||
import org.fnives.test.showcase.model.network.BaseUrl
|
||||
import org.fnives.test.showcase.session.SessionExpirationListenerImpl
|
||||
import org.fnives.test.showcase.storage.LocalDatabase
|
||||
import org.fnives.test.showcase.storage.SharedPreferencesManagerImpl
|
||||
import org.fnives.test.showcase.storage.database.DatabaseInitialization
|
||||
import org.fnives.test.showcase.storage.favourite.FavouriteContentLocalStorageImpl
|
||||
import org.fnives.test.showcase.ui.auth.AuthViewModel
|
||||
import org.fnives.test.showcase.ui.home.MainViewModel
|
||||
import org.fnives.test.showcase.ui.splash.SplashViewModel
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.dsl.module
|
||||
|
||||
fun createAppModules(baseUrl: BaseUrl): List<Module> {
|
||||
return createCoreModule(
|
||||
baseUrl = baseUrl,
|
||||
true,
|
||||
userDataLocalStorageProvider = { get<SharedPreferencesManagerImpl>() },
|
||||
sessionExpirationListenerProvider = { get<SessionExpirationListenerImpl>() },
|
||||
favouriteContentLocalStorageProvider = { get<FavouriteContentLocalStorageImpl>() }
|
||||
)
|
||||
.plus(storageModule())
|
||||
.plus(authModule())
|
||||
.plus(appModule())
|
||||
.plus(favouriteModule())
|
||||
.plus(splashModule())
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun storageModule() = module {
|
||||
single { SharedPreferencesManagerImpl.create(androidContext()) }
|
||||
single { DatabaseInitialization.create(androidContext()) }
|
||||
}
|
||||
|
||||
fun authModule() = module {
|
||||
viewModel { AuthViewModel(get()) }
|
||||
}
|
||||
|
||||
fun appModule() = module {
|
||||
single { SessionExpirationListenerImpl(androidContext()) }
|
||||
}
|
||||
|
||||
fun splashModule() = module {
|
||||
viewModel { SplashViewModel(get()) }
|
||||
}
|
||||
|
||||
fun favouriteModule() = module {
|
||||
single { get<LocalDatabase>().favouriteDao }
|
||||
viewModel { MainViewModel(get(), get(), get(), get(), get()) }
|
||||
single { FavouriteContentLocalStorageImpl(get()) }
|
||||
}
|
||||
|
|
@ -4,15 +4,10 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import org.fnives.test.showcase.core.session.SessionExpirationListener
|
||||
import org.fnives.test.showcase.ui.IntentCoordinator
|
||||
import javax.inject.Inject
|
||||
|
||||
class SessionExpirationListenerImpl @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context
|
||||
) : SessionExpirationListener {
|
||||
class SessionExpirationListenerImpl(private val context: Context) : SessionExpirationListener {
|
||||
|
||||
override fun onSessionExpired() {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ import kotlinx.coroutines.flow.Flow
|
|||
import kotlinx.coroutines.flow.map
|
||||
import org.fnives.test.showcase.core.storage.content.FavouriteContentLocalStorage
|
||||
import org.fnives.test.showcase.model.content.ContentId
|
||||
import javax.inject.Inject
|
||||
|
||||
class FavouriteContentLocalStorageImpl @Inject constructor(
|
||||
class FavouriteContentLocalStorageImpl(
|
||||
private val favouriteDao: FavouriteDao
|
||||
) : FavouriteContentLocalStorage {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package org.fnives.test.showcase.ui
|
||||
|
||||
import android.content.Context
|
||||
import org.fnives.test.showcase.ui.auth.AuthActivity
|
||||
import org.fnives.test.showcase.ui.home.MainActivity
|
||||
|
||||
object IntentCoordinator {
|
||||
|
||||
fun mainActivitygetStartIntent(context: Context) =
|
||||
MainActivity.getStartIntent(context)
|
||||
|
||||
fun authActivitygetStartIntent(context: Context) =
|
||||
AuthActivity.getStartIntent(context)
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.fnives.test.showcase.ui
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelStoreOwner
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
|
||||
inline fun <reified T : ViewModel> ViewModelStoreOwner.viewModels(): Lazy<T> =
|
||||
viewModel()
|
||||
|
|
@ -4,17 +4,14 @@ import androidx.lifecycle.LiveData
|
|||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import org.fnives.test.showcase.core.login.LoginUseCase
|
||||
import org.fnives.test.showcase.model.auth.LoginCredentials
|
||||
import org.fnives.test.showcase.model.auth.LoginStatus
|
||||
import org.fnives.test.showcase.model.shared.Answer
|
||||
import org.fnives.test.showcase.ui.shared.Event
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class AuthViewModel @Inject constructor(private val loginUseCase: LoginUseCase) : ViewModel() {
|
||||
class AuthViewModel(private val loginUseCase: LoginUseCase) : ViewModel() {
|
||||
|
||||
private val _username = MutableLiveData<String>()
|
||||
val username: LiveData<String> = _username
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.distinctUntilChanged
|
||||
import androidx.lifecycle.liveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
import org.fnives.test.showcase.core.content.AddContentToFavouriteUseCase
|
||||
import org.fnives.test.showcase.core.content.FetchContentUseCase
|
||||
|
|
@ -18,10 +16,8 @@ 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 org.fnives.test.showcase.ui.shared.Event
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class MainViewModel @Inject constructor(
|
||||
class MainViewModel(
|
||||
private val getAllContentUseCase: GetAllContentUseCase,
|
||||
private val logoutUseCase: LogoutUseCase,
|
||||
private val fetchContentUseCase: FetchContentUseCase,
|
||||
|
|
|
|||
|
|
@ -4,15 +4,12 @@ import androidx.lifecycle.LiveData
|
|||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.fnives.test.showcase.core.login.IsUserLoggedInUseCase
|
||||
import org.fnives.test.showcase.ui.shared.Event
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class SplashViewModel @Inject constructor(isUserLoggedInUseCase: IsUserLoggedInUseCase) : ViewModel() {
|
||||
class SplashViewModel(isUserLoggedInUseCase: IsUserLoggedInUseCase) : ViewModel() {
|
||||
|
||||
private val _navigateTo = MutableLiveData<Event<NavigateTo>>()
|
||||
val navigateTo: LiveData<Event<NavigateTo>> = _navigateTo
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<resources>
|
||||
<string name="app_name">Test ShowCase</string>
|
||||
<string name="login">Login</string>
|
||||
<string name="username">Username</string>
|
||||
<string name="password">Password</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue