Skip to content

Instantly share code, notes, and snippets.

@PiotrPrus
Last active May 31, 2019 13:11
Show Gist options
  • Save PiotrPrus/50f56cac94bb88bb31291ac17754112c to your computer and use it in GitHub Desktop.
Save PiotrPrus/50f56cac94bb88bb31291ac17754112c to your computer and use it in GitHub Desktop.
koin module with multiple shared preferences
val preferencesModule = module {
single(named("settingsPrefs")) { provideSettingsPreferences(androidApplication()) }
single(named("securePrefs")) { provideSecurePreferences(androidApplication()) }
}
private const val PREFERENCES_FILE_KEY = "com.example.settings_preferences"
private const val SECURE_PREFS_FILE_KEY = "com.example.secure_preferences"
private fun provideSettingsPreferences(app: Application): SharedPreferences =
app.getSharedPreferences(PREFERENCES_FILE_KEY, Context.MODE_PRIVATE)
private fun provideSecurePreferences(app: Application): SharedPreferences =
app.getSharedPreferences(SECURE_PREFS_FILE_KEY, Context.MODE_PRIVATE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment