Migrate Modules
This commit is contained in:
parent
fc6e53b7ab
commit
6453ea49cb
14 changed files with 60 additions and 249 deletions
|
@ -1,28 +0,0 @@
|
|||
package dev.lucasnlm.antimine.di
|
||||
|
||||
import dev.lucasnlm.antimine.GameActivity
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import dev.lucasnlm.antimine.TvGameActivity
|
||||
import dev.lucasnlm.antimine.core.scope.ActivityScope
|
||||
import dev.lucasnlm.antimine.history.views.HistoryFragment
|
||||
import dev.lucasnlm.antimine.stats.StatsActivity
|
||||
|
||||
@Module
|
||||
interface ActivityModule {
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
fun contributeGameActivityInjector(): GameActivity
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
fun contributeHistoryFragmentInjector(): HistoryFragment
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
fun contributeStatsActivityInjector(): StatsActivity
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
fun contributeTvGameActivityInjector(): TvGameActivity
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package dev.lucasnlm.antimine.di
|
||||
|
||||
import android.app.Application
|
||||
import dagger.BindsInstance
|
||||
import dagger.Component
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.support.AndroidSupportInjectionModule
|
||||
import dev.lucasnlm.antimine.MainApplication
|
||||
import dev.lucasnlm.antimine.common.level.di.LevelModule
|
||||
import dev.lucasnlm.antimine.core.di.CommonModule
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Component(
|
||||
modules = [
|
||||
AndroidSupportInjectionModule::class,
|
||||
AppModule::class,
|
||||
LevelModule::class,
|
||||
ActivityModule::class,
|
||||
FragmentModule::class,
|
||||
CommonModule::class
|
||||
]
|
||||
)
|
||||
@Singleton
|
||||
interface AppComponent : AndroidInjector<MainApplication> {
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
@BindsInstance
|
||||
fun application(application: Application): Builder
|
||||
|
||||
fun levelModule(application: LevelModule): Builder
|
||||
|
||||
fun appModule(module: AppModule): Builder
|
||||
|
||||
fun build(): AppComponent
|
||||
}
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
package dev.lucasnlm.antimine.di
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ApplicationComponent
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dev.lucasnlm.antimine.instant.InstantAppManager
|
||||
|
||||
@Module
|
||||
class AppModule(
|
||||
private val application: Application
|
||||
) {
|
||||
@InstallIn(ApplicationComponent::class)
|
||||
class AppModule {
|
||||
@Provides
|
||||
fun provideContext(): Context = application.applicationContext
|
||||
|
||||
@Provides
|
||||
fun provideInstantAppManager(): InstantAppManager = InstantAppManager(application.applicationContext)
|
||||
fun provideInstantAppManager(
|
||||
@ApplicationContext context: Context
|
||||
): InstantAppManager = InstantAppManager(context)
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package dev.lucasnlm.antimine.di
|
||||
|
||||
import dev.lucasnlm.antimine.level.view.CustomLevelDialogFragment
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import dev.lucasnlm.antimine.core.scope.ActivityScope
|
||||
import dev.lucasnlm.antimine.level.view.EndGameDialogFragment
|
||||
import dev.lucasnlm.antimine.level.view.LevelFragment
|
||||
|
||||
@Module
|
||||
interface FragmentModule {
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
fun contributeLevelFragmentInjector(): LevelFragment
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
fun contributeCustomLevelDialogFragmentInjector(): CustomLevelDialogFragment
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
fun contributeGameOverDialogFragmentInjector(): EndGameDialogFragment
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package dev.lucasnlm.antimine.di
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dev.lucasnlm.antimine.common.level.di.LevelModule
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ActivityComponent
|
||||
import dev.lucasnlm.antimine.common.level.models.Event
|
||||
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
|
||||
import dev.lucasnlm.antimine.common.level.repository.IMinefieldRepository
|
||||
|
@ -23,17 +23,16 @@ import dev.lucasnlm.antimine.mocks.FixedDimensionRepository
|
|||
import dev.lucasnlm.antimine.mocks.FixedMinefieldRepository
|
||||
|
||||
@Module
|
||||
class TestLevelModule(
|
||||
application: Application
|
||||
) : LevelModule(application) {
|
||||
@InstallIn(ActivityComponent::class)
|
||||
class TestLevelModule {
|
||||
@Provides
|
||||
override fun provideGameEventObserver(): MutableLiveData<Event> = MutableLiveData()
|
||||
fun provideGameEventObserver(): MutableLiveData<Event> = MutableLiveData()
|
||||
|
||||
@Provides
|
||||
override fun provideClock(): Clock = Clock()
|
||||
fun provideClock(): Clock = Clock()
|
||||
|
||||
@Provides
|
||||
override fun provideGameViewModelFactory(
|
||||
fun provideGameViewModelFactory(
|
||||
application: Application,
|
||||
eventObserver: MutableLiveData<Event>,
|
||||
savesRepository: ISavesRepository,
|
||||
|
@ -58,23 +57,17 @@ class TestLevelModule(
|
|||
)
|
||||
|
||||
@Provides
|
||||
override fun provideDimensionRepository(
|
||||
context: Context,
|
||||
preferencesRepository: IPreferencesRepository
|
||||
): IDimensionRepository = FixedDimensionRepository()
|
||||
fun provideDimensionRepository(): IDimensionRepository = FixedDimensionRepository()
|
||||
|
||||
@Provides
|
||||
override fun provideSavesRepository(): ISavesRepository = MemorySavesRepository()
|
||||
fun provideSavesRepository(): ISavesRepository = MemorySavesRepository()
|
||||
|
||||
@Provides
|
||||
override fun provideStatsRepository(): IStatsRepository = MemoryStatsRepository()
|
||||
fun provideStatsRepository(): IStatsRepository = MemoryStatsRepository()
|
||||
|
||||
@Provides
|
||||
override fun provideMinefieldRepository(): IMinefieldRepository = FixedMinefieldRepository()
|
||||
fun provideMinefieldRepository(): IMinefieldRepository = FixedMinefieldRepository()
|
||||
|
||||
@Provides
|
||||
override fun provideHapticFeedbackInteractor(
|
||||
application: Application,
|
||||
preferencesRepository: IPreferencesRepository
|
||||
): IHapticFeedbackInteractor = DisabledHapticFeedbackInteractor()
|
||||
fun provideHapticFeedbackInteractor(): IHapticFeedbackInteractor = DisabledHapticFeedbackInteractor()
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package dev.lucasnlm.antimine.common.level.di
|
||||
|
||||
import dagger.Component
|
||||
import dagger.android.support.AndroidSupportInjectionModule
|
||||
|
||||
@Component(
|
||||
modules = [
|
||||
AndroidSupportInjectionModule::class,
|
||||
LevelModule::class
|
||||
]
|
||||
)
|
||||
abstract class LevelComponent {
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
fun levelModule(levelModule: LevelModule): Builder
|
||||
fun build(): LevelComponent
|
||||
}
|
||||
}
|
|
@ -6,8 +6,13 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.room.Room
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ActivityComponent
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dev.lucasnlm.antimine.common.level.models.Event
|
||||
import dev.lucasnlm.antimine.common.level.database.AppDataBase
|
||||
import dev.lucasnlm.antimine.common.level.database.dao.SaveDao
|
||||
import dev.lucasnlm.antimine.common.level.database.dao.StatsDao
|
||||
import dev.lucasnlm.antimine.common.level.repository.DimensionRepository
|
||||
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
|
||||
import dev.lucasnlm.antimine.common.level.repository.IMinefieldRepository
|
||||
|
@ -24,30 +29,26 @@ import dev.lucasnlm.antimine.core.analytics.AnalyticsManager
|
|||
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
|
||||
|
||||
@Module
|
||||
open class LevelModule(
|
||||
private val application: Application
|
||||
) {
|
||||
private val appDataBase by lazy {
|
||||
Room.databaseBuilder(application, AppDataBase::class.java, DATA_BASE_NAME)
|
||||
@InstallIn(ActivityComponent::class)
|
||||
open class LevelModule {
|
||||
@Provides
|
||||
fun provideAppDataBase(
|
||||
@ApplicationContext context: Context
|
||||
): AppDataBase {
|
||||
return Room.databaseBuilder(context, AppDataBase::class.java, DATA_BASE_NAME)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
|
||||
private val savesDao by lazy {
|
||||
appDataBase.saveDao()
|
||||
}
|
||||
@Provides
|
||||
fun provideSavesDao(
|
||||
appDataBase: AppDataBase
|
||||
): SaveDao = appDataBase.saveDao()
|
||||
|
||||
private val statsDao by lazy {
|
||||
appDataBase.statsDao()
|
||||
}
|
||||
|
||||
private val savesRepository by lazy {
|
||||
SavesRepository(savesDao)
|
||||
}
|
||||
|
||||
private val statsRepository by lazy {
|
||||
StatsRepository(statsDao)
|
||||
}
|
||||
@Provides
|
||||
fun provideStatsDao(
|
||||
appDataBase: AppDataBase
|
||||
): StatsDao = appDataBase.statsDao()
|
||||
|
||||
@Provides
|
||||
open fun provideGameEventObserver(): MutableLiveData<Event> = MutableLiveData()
|
||||
|
@ -88,10 +89,14 @@ open class LevelModule(
|
|||
DimensionRepository(context, preferencesRepository)
|
||||
|
||||
@Provides
|
||||
open fun provideSavesRepository(): ISavesRepository = savesRepository
|
||||
open fun provideSavesRepository(
|
||||
savesDao: SaveDao
|
||||
): ISavesRepository = SavesRepository(savesDao)
|
||||
|
||||
@Provides
|
||||
open fun provideStatsRepository(): IStatsRepository = statsRepository
|
||||
open fun provideStatsRepository(
|
||||
statsDao: StatsDao
|
||||
): IStatsRepository = StatsRepository(statsDao)
|
||||
|
||||
@Provides
|
||||
open fun provideMinefieldRepository(): IMinefieldRepository = MinefieldRepository()
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package dev.lucasnlm.antimine.core.di
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ApplicationComponent
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dev.lucasnlm.antimine.core.analytics.AnalyticsManager
|
||||
import dev.lucasnlm.antimine.core.analytics.DebugAnalyticsManager
|
||||
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
|
||||
|
@ -11,6 +14,7 @@ import dev.lucasnlm.antimine.core.preferences.PreferencesRepository
|
|||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(ApplicationComponent::class)
|
||||
class CommonModule {
|
||||
@Singleton
|
||||
@Provides
|
||||
|
@ -21,8 +25,8 @@ class CommonModule {
|
|||
@Singleton
|
||||
@Provides
|
||||
fun providePreferencesInteractor(
|
||||
application: Application
|
||||
): PreferencesInteractor = PreferencesInteractor(application)
|
||||
@ApplicationContext context: Context
|
||||
): PreferencesInteractor = PreferencesInteractor(context)
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package dev.lucasnlm.antimine.core.di
|
||||
|
||||
import dagger.Component
|
||||
import dagger.android.support.AndroidSupportInjectionModule
|
||||
|
||||
@Component(
|
||||
modules = [
|
||||
AndroidSupportInjectionModule::class,
|
||||
CommonModule::class
|
||||
]
|
||||
)
|
||||
abstract class LevelComponent {
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
fun levelModule(levelModule: CommonModule): Builder
|
||||
fun build(): LevelComponent
|
||||
}
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
package dev.lucasnlm.antimine.core.preferences
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.preference.PreferenceManager
|
||||
import dev.lucasnlm.antimine.common.level.models.Minefield
|
||||
import javax.inject.Inject
|
||||
|
||||
class PreferencesInteractor @Inject constructor(
|
||||
private val application: Application
|
||||
private val context: Context
|
||||
) {
|
||||
private val preferences by lazy {
|
||||
PreferenceManager.getDefaultSharedPreferences(application)
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
}
|
||||
|
||||
fun getCustomMode() = Minefield(
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package dev.lucasnlm.antimine.wear.di
|
||||
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import dev.lucasnlm.antimine.core.scope.ActivityScope
|
||||
import dev.lucasnlm.antimine.wear.WatchGameActivity
|
||||
|
||||
@Module
|
||||
interface ActivityModule {
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
fun contributeWatchGameActivityInjector(): WatchGameActivity
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package dev.lucasnlm.antimine.wear.di
|
||||
|
||||
import android.app.Application
|
||||
import dagger.BindsInstance
|
||||
import dagger.Component
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.support.AndroidSupportInjectionModule
|
||||
import dev.lucasnlm.antimine.common.level.di.LevelModule
|
||||
import dev.lucasnlm.antimine.core.di.CommonModule
|
||||
import dev.lucasnlm.antimine.wear.MainApplication
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Component(
|
||||
modules = [
|
||||
AndroidSupportInjectionModule::class,
|
||||
AppModule::class,
|
||||
LevelModule::class,
|
||||
ActivityModule::class,
|
||||
FragmentModule::class,
|
||||
CommonModule::class
|
||||
]
|
||||
)
|
||||
@Singleton
|
||||
interface AppComponent : AndroidInjector<MainApplication> {
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
@BindsInstance
|
||||
fun application(application: Application): Builder
|
||||
|
||||
fun levelModule(application: LevelModule): Builder
|
||||
|
||||
fun appModule(module: AppModule): Builder
|
||||
|
||||
fun build(): AppComponent
|
||||
}
|
||||
}
|
|
@ -1,14 +1,9 @@
|
|||
package dev.lucasnlm.antimine.wear.di
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ApplicationComponent
|
||||
|
||||
@Module
|
||||
class AppModule(
|
||||
private val application: Application
|
||||
) {
|
||||
@Provides
|
||||
fun provideContext(): Context = application.applicationContext
|
||||
}
|
||||
@InstallIn(ApplicationComponent::class)
|
||||
class AppModule
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package dev.lucasnlm.antimine.wear.di
|
||||
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import dev.lucasnlm.antimine.core.scope.ActivityScope
|
||||
import dev.lucasnlm.antimine.wear.WatchLevelFragment
|
||||
|
||||
@Module
|
||||
interface FragmentModule {
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
fun contributeWatchLevelFragmentInjector(): WatchLevelFragment
|
||||
}
|
Loading…
Reference in a new issue