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
|
|
@ -2,6 +2,8 @@ plugins {
|
|||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'kotlin-kapt'
|
||||
// hilt specific
|
||||
id 'dagger.hilt.android.plugin'
|
||||
}
|
||||
|
||||
android {
|
||||
|
|
@ -25,6 +27,17 @@ android {
|
|||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
flavorDimensions 'di'
|
||||
productFlavors {
|
||||
hilt {
|
||||
dimension 'di'
|
||||
applicationId "org.fnives.test.showcase.hilt"
|
||||
}
|
||||
koin {
|
||||
dimension 'di'
|
||||
applicationId "org.fnives.test.showcase.koin"
|
||||
}
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
|
|
@ -49,10 +62,17 @@ android {
|
|||
}
|
||||
}
|
||||
|
||||
hilt {
|
||||
enableAggregatingTask = true
|
||||
enableExperimentalClasspathAggregation = true
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
// making sure the :mockserver is assembled after :clean when running tests
|
||||
testDebugUnitTest.dependsOn tasks.getByPath(':mockserver:assemble')
|
||||
testReleaseUnitTest.dependsOn tasks.getByPath(':mockserver:assemble')
|
||||
testKoinDebugUnitTest.dependsOn tasks.getByPath(':mockserver:assemble')
|
||||
testKoinReleaseUnitTest.dependsOn tasks.getByPath(':mockserver:assemble')
|
||||
testHiltDebugUnitTest.dependsOn tasks.getByPath(':mockserver:assemble')
|
||||
testHiltReleaseUnitTest.dependsOn tasks.getByPath(':mockserver:assemble')
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
@ -66,7 +86,14 @@ dependencies {
|
|||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:$androidx_swiperefreshlayout_version"
|
||||
|
||||
// Koin
|
||||
implementation "io.insert-koin:koin-android:$koin_version"
|
||||
koinImplementation "io.insert-koin:koin-android:$koin_version"
|
||||
|
||||
// Hilt
|
||||
// hiltImplementation "com.google.dagger:hilt-android:$hilt_version"
|
||||
implementation "com.google.dagger:hilt-android:$hilt_version"
|
||||
// implementation "com.google.dagger:hilt-core:$hilt_version"
|
||||
kaptHilt "com.google.dagger:hilt-compiler:$hilt_version"
|
||||
hiltImplementation "androidx.activity:activity-ktx:$activity_ktx_version"
|
||||
|
||||
implementation "androidx.room:room-runtime:$androidx_room_version"
|
||||
kapt "androidx.room:room-compiler:$androidx_room_version"
|
||||
|
|
@ -98,6 +125,8 @@ dependencies {
|
|||
testImplementation "com.jakewharton.espresso:okhttp3-idling-resource:$testing_okhttp3_idling_resource_version"
|
||||
testImplementation "androidx.arch.core:core-testing:$testing_androidx_arch_core_version"
|
||||
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$testing_junit5_version"
|
||||
testImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
|
||||
kaptTest "com.google.dagger:hilt-compiler:$hilt_version"
|
||||
|
||||
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
|
||||
androidTestImplementation "io.insert-koin:koin-test-junit4:$koin_version"
|
||||
|
|
@ -111,4 +140,6 @@ dependencies {
|
|||
androidTestImplementation "com.jakewharton.espresso:okhttp3-idling-resource:$testing_okhttp3_idling_resource_version"
|
||||
androidTestImplementation "androidx.arch.core:core-testing:$testing_androidx_arch_core_version"
|
||||
androidTestRuntimeOnly "org.junit.vintage:junit-vintage-engine:$testing_junit5_version"
|
||||
androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
|
||||
kaptAndroidTest "com.google.dagger:hilt-compiler:$hilt_version"
|
||||
}
|
||||
22
app/src/hilt/AndroidManifest.xml
Normal file
22
app/src/hilt/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="org.fnives.test.showcase">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application>
|
||||
<activity
|
||||
android:name=".ui.splash.HiltSplashActivity"
|
||||
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.HiltMainActivity" />
|
||||
<activity android:name=".ui.auth.HiltAuthActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.fnives.test.showcase
|
||||
|
||||
import android.app.Application
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
|
||||
@HiltAndroidApp
|
||||
class TestShowcaseApplication : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
}
|
||||
}
|
||||
53
app/src/hilt/java/org/fnives/test/showcase/di/AppModule.kt
Normal file
53
app/src/hilt/java/org/fnives/test/showcase/di/AppModule.kt
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package org.fnives.test.showcase.di
|
||||
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import org.fnives.test.showcase.core.session.SessionExpirationListener
|
||||
import org.fnives.test.showcase.core.storage.UserDataLocalStorage
|
||||
import org.fnives.test.showcase.core.storage.content.FavouriteContentLocalStorage
|
||||
import org.fnives.test.showcase.session.SessionExpirationListenerImpl
|
||||
import org.fnives.test.showcase.storage.SharedPreferencesManagerImpl
|
||||
import org.fnives.test.showcase.storage.database.DatabaseInitialization
|
||||
import org.fnives.test.showcase.storage.favourite.FavouriteContentLocalStorageImpl
|
||||
import javax.inject.Singleton
|
||||
|
||||
@InstallIn(SingletonComponent::class)
|
||||
@Module
|
||||
object AppModule {
|
||||
|
||||
@Provides
|
||||
fun provideBaseUrl(): String = BaseUrlProvider.get().baseUrl
|
||||
|
||||
@Provides
|
||||
fun enableLogging(): Boolean = true
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideFavouriteDao(@ApplicationContext context: Context) =
|
||||
DatabaseInitialization.create(context).favouriteDao
|
||||
|
||||
@Provides
|
||||
fun provideSharedPreferencesManagerImpl(@ApplicationContext context: Context) =
|
||||
SharedPreferencesManagerImpl.create(context)
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideUserDataLocalStorage(
|
||||
sharedPreferencesManagerImpl: SharedPreferencesManagerImpl
|
||||
): UserDataLocalStorage = sharedPreferencesManagerImpl
|
||||
|
||||
@Provides
|
||||
fun provideFavouriteContentLocalStorage(
|
||||
favouriteContentLocalStorageImpl: FavouriteContentLocalStorageImpl
|
||||
): FavouriteContentLocalStorage = favouriteContentLocalStorageImpl
|
||||
|
||||
@Provides
|
||||
internal fun bindSessionExpirationListener(
|
||||
sessionExpirationListenerImpl: SessionExpirationListenerImpl
|
||||
) : SessionExpirationListener = sessionExpirationListenerImpl
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package org.fnives.test.showcase.ui
|
||||
|
||||
import android.content.Context
|
||||
import org.fnives.test.showcase.ui.auth.HiltAuthActivity
|
||||
import org.fnives.test.showcase.ui.home.HiltMainActivity
|
||||
|
||||
object IntentCoordinator {
|
||||
|
||||
fun mainActivitygetStartIntent(context: Context) =
|
||||
HiltMainActivity.getStartIntent(context)
|
||||
|
||||
fun authActivitygetStartIntent(context: Context) =
|
||||
HiltAuthActivity.getStartIntent(context)
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package org.fnives.test.showcase.ui
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelStoreOwner
|
||||
import androidx.activity.viewModels as androidxViewModel
|
||||
|
||||
inline fun <reified T : ViewModel> ViewModelStoreOwner.viewModels(): Lazy<T> =
|
||||
when (this) {
|
||||
is ComponentActivity -> androidxViewModel()
|
||||
else -> throw IllegalStateException("Only supports activity viewModel for now")
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package org.fnives.test.showcase.ui.auth
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class HiltAuthActivity : AuthActivity() {
|
||||
companion object {
|
||||
fun getStartIntent(context: Context): Intent = Intent(context, HiltAuthActivity::class.java)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package org.fnives.test.showcase.ui.home
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class HiltMainActivity : MainActivity() {
|
||||
companion object {
|
||||
fun getStartIntent(context: Context): Intent = Intent(context, HiltMainActivity::class.java)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package org.fnives.test.showcase.ui.splash
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class HiltSplashActivity : SplashActivity()
|
||||
21
app/src/koin/AndroidManifest.xml
Normal file
21
app/src/koin/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.fnives.test.showcase">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application>
|
||||
<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>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.fnives.test.showcase.di
|
||||
|
||||
import org.fnives.test.showcase.core.di.createCoreModule
|
||||
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
|
||||
|
|
@ -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()
|
||||
|
|
@ -6,24 +6,13 @@
|
|||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:name=".TestShowcaseApplication"
|
||||
android:allowBackup="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:name=".TestShowcaseApplication"
|
||||
android:theme="@style/Theme.TestShowCase"
|
||||
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>
|
||||
tools:ignore="AllowBackup"/>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -4,15 +4,20 @@ 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.auth.AuthActivity
|
||||
import org.fnives.test.showcase.ui.IntentCoordinator
|
||||
import javax.inject.Inject
|
||||
|
||||
class SessionExpirationListenerImpl(private val context: Context) : SessionExpirationListener {
|
||||
class SessionExpirationListenerImpl @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context
|
||||
) : SessionExpirationListener {
|
||||
|
||||
override fun onSessionExpired() {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
context.startActivity(
|
||||
AuthActivity.getStartIntent(context)
|
||||
IntentCoordinator.authActivitygetStartIntent(context)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import org.fnives.test.showcase.model.session.Session
|
|||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class SharedPreferencesManagerImpl(private val sharedPreferences: SharedPreferences) : UserDataLocalStorage {
|
||||
class SharedPreferencesManagerImpl constructor(private val sharedPreferences: SharedPreferences) : UserDataLocalStorage {
|
||||
|
||||
override var session: Session? by SessionDelegate(SESSION_KEY)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ 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(private val favouriteDao: FavouriteDao) : FavouriteContentLocalStorage {
|
||||
class FavouriteContentLocalStorageImpl @Inject constructor(private val favouriteDao: FavouriteDao) : FavouriteContentLocalStorage {
|
||||
override fun observeFavourites(): Flow<List<ContentId>> =
|
||||
favouriteDao.get().map { it.map(FavouriteEntity::contentId).map(::ContentId) }
|
||||
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import androidx.core.widget.doAfterTextChanged
|
|||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.fnives.test.showcase.R
|
||||
import org.fnives.test.showcase.databinding.ActivityAuthenticationBinding
|
||||
import org.fnives.test.showcase.ui.home.MainActivity
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.fnives.test.showcase.ui.IntentCoordinator
|
||||
import org.fnives.test.showcase.ui.viewModels
|
||||
|
||||
class AuthActivity : AppCompatActivity() {
|
||||
open class AuthActivity : AppCompatActivity() {
|
||||
|
||||
private val viewModel by viewModel<AuthViewModel>()
|
||||
private val viewModel by viewModels<AuthViewModel>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -35,7 +35,7 @@ class AuthActivity : AppCompatActivity() {
|
|||
}
|
||||
viewModel.navigateToHome.observe(this) {
|
||||
it.consume() ?: return@observe
|
||||
startActivity(MainActivity.getStartIntent(this))
|
||||
startActivity(IntentCoordinator.mainActivitygetStartIntent(this))
|
||||
finishAffinity()
|
||||
}
|
||||
setContentView(binding.root)
|
||||
|
|
|
|||
|
|
@ -4,14 +4,17 @@ 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
|
||||
|
||||
class AuthViewModel(private val loginUseCase: LoginUseCase) : ViewModel() {
|
||||
@HiltViewModel
|
||||
class AuthViewModel @Inject constructor(private val loginUseCase: LoginUseCase) : ViewModel() {
|
||||
|
||||
private val _username = MutableLiveData<String>()
|
||||
val username: LiveData<String> = _username
|
||||
|
|
|
|||
|
|
@ -6,17 +6,18 @@ import android.os.Bundle
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.fnives.test.showcase.R
|
||||
import org.fnives.test.showcase.databinding.ActivityMainBinding
|
||||
import org.fnives.test.showcase.model.content.ContentId
|
||||
import org.fnives.test.showcase.ui.auth.AuthActivity
|
||||
import org.fnives.test.showcase.ui.IntentCoordinator
|
||||
import org.fnives.test.showcase.ui.shared.VerticalSpaceItemDecoration
|
||||
import org.fnives.test.showcase.ui.shared.getThemePrimaryColor
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.fnives.test.showcase.ui.viewModels
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
open class MainActivity : AppCompatActivity() {
|
||||
|
||||
private val viewModel by viewModel<MainViewModel>()
|
||||
private val viewModel by viewModels<MainViewModel>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -45,7 +46,7 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
viewModel.navigateToAuth.observe(this) {
|
||||
it.consume() ?: return@observe
|
||||
startActivity(AuthActivity.getStartIntent(this))
|
||||
startActivity(IntentCoordinator.authActivitygetStartIntent(this))
|
||||
finishAffinity()
|
||||
}
|
||||
viewModel.loading.observe(this) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.lifecycle.ViewModel
|
||||
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
|
||||
|
|
@ -16,8 +17,10 @@ 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
|
||||
|
||||
class MainViewModel(
|
||||
@HiltViewModel
|
||||
class MainViewModel @Inject constructor(
|
||||
private val getAllContentUseCase: GetAllContentUseCase,
|
||||
private val logoutUseCase: LogoutUseCase,
|
||||
private val fetchContentUseCase: FetchContentUseCase,
|
||||
|
|
|
|||
|
|
@ -3,21 +3,20 @@ package org.fnives.test.showcase.ui.splash
|
|||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import org.fnives.test.showcase.R
|
||||
import org.fnives.test.showcase.ui.auth.AuthActivity
|
||||
import org.fnives.test.showcase.ui.home.MainActivity
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.fnives.test.showcase.ui.IntentCoordinator
|
||||
import org.fnives.test.showcase.ui.viewModels
|
||||
|
||||
class SplashActivity : AppCompatActivity() {
|
||||
open class SplashActivity : AppCompatActivity() {
|
||||
|
||||
private val viewModel by viewModel<SplashViewModel>()
|
||||
private val viewModel by viewModels<SplashViewModel>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_splash)
|
||||
viewModel.navigateTo.observe(this) {
|
||||
val intent = when (it.consume()) {
|
||||
SplashViewModel.NavigateTo.HOME -> MainActivity.getStartIntent(this)
|
||||
SplashViewModel.NavigateTo.AUTHENTICATION -> AuthActivity.getStartIntent(this)
|
||||
SplashViewModel.NavigateTo.HOME -> IntentCoordinator.mainActivitygetStartIntent(this)
|
||||
SplashViewModel.NavigateTo.AUTHENTICATION -> IntentCoordinator.authActivitygetStartIntent(this)
|
||||
null -> return@observe
|
||||
}
|
||||
startActivity(intent)
|
||||
|
|
|
|||
|
|
@ -4,12 +4,15 @@ 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
|
||||
|
||||
class SplashViewModel(isUserLoggedInUseCase: IsUserLoggedInUseCase) : ViewModel() {
|
||||
@HiltViewModel
|
||||
class SplashViewModel @Inject constructor(isUserLoggedInUseCase: IsUserLoggedInUseCase) : ViewModel() {
|
||||
|
||||
private val _navigateTo = MutableLiveData<Event<NavigateTo>>()
|
||||
val navigateTo: LiveData<Event<NavigateTo>> = _navigateTo
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue