simplify dagger setup/AppModule
This commit is contained in:
parent
7df890efef
commit
7c14af603e
|
@ -19,13 +19,11 @@
|
||||||
|
|
||||||
package at.connyduck.pixelcat.dagger
|
package at.connyduck.pixelcat.dagger
|
||||||
|
|
||||||
import android.app.Application
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import at.connyduck.pixelcat.PixelcatApplication
|
import at.connyduck.pixelcat.PixelcatApplication
|
||||||
import at.connyduck.pixelcat.db.AccountManager
|
|
||||||
import at.connyduck.pixelcat.db.AppDatabase
|
import at.connyduck.pixelcat.db.AppDatabase
|
||||||
import at.connyduck.pixelcat.db.RoomConverter
|
import at.connyduck.pixelcat.db.RoomConverter
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
|
@ -36,14 +34,12 @@ import javax.inject.Singleton
|
||||||
class AppModule {
|
class AppModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun providesApp(app: PixelcatApplication): Application = app
|
fun providesContext(app: PixelcatApplication): Context = app
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun providesContext(app: Application): Context = app
|
@Singleton
|
||||||
|
fun providesSharedPreferences(context: Context): SharedPreferences {
|
||||||
@Provides
|
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
fun providesSharedPreferences(app: Application): SharedPreferences {
|
|
||||||
return PreferenceManager.getDefaultSharedPreferences(app)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -54,10 +50,4 @@ class AppModule {
|
||||||
.addTypeConverter(converter)
|
.addTypeConverter(converter)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun providesAccountManager(db: AppDatabase): AccountManager {
|
|
||||||
return AccountManager(db)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import android.util.Log
|
||||||
import at.connyduck.pixelcat.db.entitity.AccountAuthData
|
import at.connyduck.pixelcat.db.entitity.AccountAuthData
|
||||||
import at.connyduck.pixelcat.db.entitity.AccountEntity
|
import at.connyduck.pixelcat.db.entitity.AccountEntity
|
||||||
import at.connyduck.pixelcat.model.Account
|
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
|
* 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"
|
private const val TAG = "AccountManager"
|
||||||
|
|
||||||
class AccountManager(db: AppDatabase) {
|
@Singleton
|
||||||
|
class AccountManager @Inject constructor(db: AppDatabase) {
|
||||||
|
|
||||||
private var activeAccount: AccountEntity? = null
|
private var activeAccount: AccountEntity? = null
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue