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
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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue