simplify dagger setup/AppModule

This commit is contained in:
Konrad Pozniak 2020-10-15 19:09:20 +02:00
parent 7df890efef
commit 7c14af603e
2 changed files with 8 additions and 15 deletions

View File

@ -19,13 +19,11 @@
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 at.connyduck.pixelcat.db.RoomConverter
import dagger.Module
@ -36,14 +34,12 @@ import javax.inject.Singleton
class AppModule {
@Provides
fun providesApp(app: PixelcatApplication): Application = app
fun providesContext(app: PixelcatApplication): Context = app
@Provides
fun providesContext(app: Application): Context = app
@Provides
fun providesSharedPreferences(app: Application): SharedPreferences {
return PreferenceManager.getDefaultSharedPreferences(app)
@Singleton
fun providesSharedPreferences(context: Context): SharedPreferences {
return PreferenceManager.getDefaultSharedPreferences(context)
}
@Provides
@ -54,10 +50,4 @@ class AppModule {
.addTypeConverter(converter)
.build()
}
@Provides
@Singleton
fun providesAccountManager(db: AppDatabase): AccountManager {
return AccountManager(db)
}
}

View File

@ -23,6 +23,8 @@ import android.util.Log
import at.connyduck.pixelcat.db.entitity.AccountAuthData
import at.connyduck.pixelcat.db.entitity.AccountEntity
import at.connyduck.pixelcat.model.Account
import javax.inject.Inject
import javax.inject.Singleton
/**
* This class caches the account database and handles all account related operations
@ -30,7 +32,8 @@ import at.connyduck.pixelcat.model.Account
private const val TAG = "AccountManager"
class AccountManager(db: AppDatabase) {
@Singleton
class AccountManager @Inject constructor(db: AppDatabase) {
private var activeAccount: AccountEntity? = null