WaheedNazir/Kotlin-MVVM-Architecture

PreferencesModule sample

pritam2102 opened this issue · 3 comments

Hello.

I have read your mvvm architecure i.e. very good. can you please provide how to use sharedPreference in your sample

@Module
class PreferencesModule {
   /**
     * Provides Preferences object with MODE_PRIVATE
     */
    @Provides
    @Singleton
    fun provideSharedPreference(app: Application):
            SharedPreferences = app.getSharedPreferences("SharedPreferences", Context.MODE_PRIVATE)

}

after R and D sample code found and implemented

please share an example of using this in activity or fragment

You can inject like this in activity / fragment

@Inject
lateinit var sharedPreferences: SharedPreferences

To save
sharedPreferences.edit().putString("YOUR_KEY","123456").apply()

To retrieve
sharedPreferences.getString("YOUR_KEY","defaultValue")