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
|
2024-04-06 17:39:46 -07:00
|
|
|
import com.anthonyla.paperize.feature.wallpaper.data.data_source.SelectedAlbumDatabase
|
2023-10-17 16:07:27 -07:00
|
|
|
import com.anthonyla.paperize.feature.wallpaper.data.repository.AlbumRepositoryImpl
|
2024-04-06 17:39:46 -07:00
|
|
|
import com.anthonyla.paperize.feature.wallpaper.data.repository.SelectedAlbumRepositoryImpl
|
2023-10-17 16:07:27 -07:00
|
|
|
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
2024-04-06 17:39:46 -07:00
|
|
|
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
|
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(
|
|
|
|
|
app,
|
2023-10-17 16:07:27 -07:00
|
|
|
AlbumDatabase::class.java,
|
|
|
|
|
AlbumDatabase.DATABASE_NAME
|
2023-08-11 10:29:32 -07:00
|
|
|
).build()
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-06 17:39:46 -07:00
|
|
|
@Provides
|
|
|
|
|
@Singleton
|
|
|
|
|
fun provideSelectedAlbumDatabase(app: Application): SelectedAlbumDatabase {
|
|
|
|
|
return Room.databaseBuilder(
|
|
|
|
|
app,
|
|
|
|
|
SelectedAlbumDatabase::class.java,
|
|
|
|
|
SelectedAlbumDatabase.DATABASE_NAME
|
|
|
|
|
).build()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
|
|
2024-04-06 17:39:46 -07:00
|
|
|
@Provides
|
|
|
|
|
@Singleton
|
|
|
|
|
fun provideSelectedAlbumDao(db: SelectedAlbumDatabase) = db.selectedAlbumDao
|
|
|
|
|
|
|
|
|
|
@Provides
|
|
|
|
|
@Singleton
|
|
|
|
|
fun provideSelectedAlbumRepository(
|
|
|
|
|
db: SelectedAlbumDatabase
|
|
|
|
|
): SelectedAlbumRepository {
|
|
|
|
|
return SelectedAlbumRepositoryImpl(db.selectedAlbumDao)
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 10:29:32 -07:00
|
|
|
@Provides
|
|
|
|
|
@Singleton
|
|
|
|
|
fun provideSettingsDataStore (
|
|
|
|
|
@ApplicationContext context: Context
|
|
|
|
|
): SettingsDataStore = SettingsDataStoreImpl(context)
|
|
|
|
|
|
|
|
|
|
@Provides
|
|
|
|
|
fun provideContext(
|
|
|
|
|
@ApplicationContext context: Context,
|
2023-10-17 16:07:27 -07:00
|
|
|
): Context { return context }
|
2023-08-11 10:29:32 -07:00
|
|
|
}
|