Pixelcat-App-Android/app/src/main/kotlin/at/connyduck/pixelcat/dagger/AppModule.kt

43 lines
1.1 KiB
Kotlin
Raw Normal View History

2020-06-12 15:44:45 +02:00
package at.connyduck.pixelcat.dagger
import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import androidx.preference.PreferenceManager
import androidx.room.Room
import at.connyduck.pixelcat.PixelcatApplication
import at.connyduck.pixelcat.db.AccountManager
import at.connyduck.pixelcat.db.AppDatabase
import dagger.Module
import dagger.Provides
import javax.inject.Singleton
@Module
class AppModule {
@Provides
2020-06-12 19:58:15 +02:00
fun providesApp(app: PixelcatApplication): Application = app
2020-06-12 15:44:45 +02:00
@Provides
fun providesContext(app: Application): Context = app
@Provides
fun providesSharedPreferences(app: Application): SharedPreferences {
return PreferenceManager.getDefaultSharedPreferences(app)
}
@Provides
@Singleton
fun providesDatabase(app: PixelcatApplication): AppDatabase {
return Room
.databaseBuilder(app, AppDatabase::class.java, "pixelcat.db")
.build()
}
@Provides
@Singleton
fun providesAccountManager(db: AppDatabase): AccountManager {
return AccountManager(db)
}
2020-06-12 19:58:15 +02:00
}