Guest User

Untitled

a guest
Feb 27th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.88 KB | None | 0 0
  1. @Module
  2. class AppModule(private val app: SeezApp) {
  3.     @Provides
  4.     @Singleton
  5.     fun provideApp() = app
  6.  
  7.     @Provides
  8.     @Singleton
  9.     fun provideContext(): Context = app.applicationContext
  10.  
  11.     @Provides
  12.     @Singleton
  13.     fun provideSharedPreferences(): SharedPreferences = app.getSharedPreferences(
  14.         SHARED_PREFERENCES_TITLE,
  15.         Context.MODE_PRIVATE
  16.     )
  17.  
  18.     //Needs sharedPrefs
  19.     @Provides
  20.     @Singleton
  21.     fun provideApiService() = ApiManager.initApiService(provideSharedPreferences())
  22.  
  23.     @Provides
  24.     @Singleton
  25.     fun provideNumberFormatter(): NumberFormat = NumberFormat.getInstance(Locale.getDefault())
  26.  
  27.     @Provides
  28.     @Singleton
  29.     fun providesDBHelper(): AppDatabase = Room.databaseBuilder(
  30.         app,
  31.         AppDatabase::class.java,
  32.         SEEZ_APP_DB_NAME
  33.     )
  34.         .fallbackToDestructiveMigration()
  35.         .build()
  36. }
Advertisement
Add Comment
Please, Sign In to add comment