2023-08-11 10:29:32 -07:00
|
|
|
package com.anthonyla.paperize.di
|
|
|
|
|
|
|
|
|
|
import android.app.Application
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import androidx.room.Room
|
|
|
|
|
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
|
|
|
|
import com.anthonyla.paperize.data.settings.SettingsDataStoreImpl
|
2023-10-17 16:07:27 -07:00
|
|
|
import com.anthonyla.paperize.feature.wallpaper.data.data_source.AlbumDatabase
|
|
|
|
|
import com.anthonyla.paperize.feature.wallpaper.data.repository.AlbumRepositoryImpl
|
|
|
|
|
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
2023-08-11 10:29:32 -07:00
|
|
|
import dagger.Module
|
|
|
|
|
import dagger.Provides
|
|
|
|
|
import dagger.hilt.InstallIn
|
|
|
|
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
|
|
|
import dagger.hilt.components.SingletonComponent
|
|
|
|
|
import javax.inject.Singleton
|
|
|
|
|
|
2024-04-07 14:48:26 -07:00
|
|
|
/**
|
|
|
|
|
* AppModule provides dependencies for the application for Dagger Hilt to inject
|
|
|
|
|
*/
|
2023-08-11 10:29:32 -07:00
|
|
|
@Module
|
|
|
|
|
@InstallIn(SingletonComponent::class)
|
|
|
|
|
object AppModule {
|
|
|
|
|
@Provides
|
|
|
|
|
@Singleton
|
2023-10-17 16:07:27 -07:00
|
|
|
fun provideAlbumDatabase(app: Application): AlbumDatabase {
|
2023-08-11 10:29:32 -07:00
|
|
|
return Room.databaseBuilder(
|
2025-03-07 18:01:56 -08:00
|
|
|
app,
|
|
|
|
|
AlbumDatabase::class.java,
|
|
|
|
|
AlbumDatabase.DATABASE_NAME
|
|
|
|
|
).fallbackToDestructiveMigration(true).addMigrations().build()
|
2023-08-11 10:29:32 -07:00
|
|
|
}
|
|
|
|
|
|
2024-04-06 17:39:46 -07:00
|
|
|
@Provides
|
|
|
|
|
@Singleton
|
|
|
|
|
fun provideAlbumDao(db: AlbumDatabase) = db.albumDao
|
|
|
|
|
|
2023-08-11 10:29:32 -07:00
|
|
|
@Provides
|
|
|
|
|
@Singleton
|
2023-10-17 16:07:27 -07:00
|
|
|
fun provideAlbumRepository(
|
|
|
|
|
db: AlbumDatabase
|
|
|
|
|
): AlbumRepository {
|
|
|
|
|
return AlbumRepositoryImpl(db.albumDao)
|
2023-08-11 10:29:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Provides
|
|
|
|
|
@Singleton
|
|
|
|
|
fun provideSettingsDataStore (
|
|
|
|
|
@ApplicationContext context: Context
|
|
|
|
|
): SettingsDataStore = SettingsDataStoreImpl(context)
|
|
|
|
|
|
|
|
|
|
@Provides
|
2024-04-26 10:36:45 -07:00
|
|
|
@Singleton
|
2023-08-11 10:29:32 -07:00
|
|
|
fun provideContext(
|
|
|
|
|
@ApplicationContext context: Context,
|
2023-10-17 16:07:27 -07:00
|
|
|
): Context { return context }
|
2023-08-11 10:29:32 -07:00
|
|
|
}
|