Skip to content

Instantly share code, notes, and snippets.

@harmittaa
Created July 13, 2019 14:11
Show Gist options
  • Save harmittaa/de507de3c1e22b973b41846e77d47c4d to your computer and use it in GitHub Desktop.
Save harmittaa/de507de3c1e22b973b41846e77d47c4d to your computer and use it in GitHub Desktop.
Koin 2.0 example module
import android.content.Context
import android.content.SharedPreferences
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module
val prefModule = module {
single { ExamplePreferences(androidContext()) }
}
class ExamplePreferences(context: Context) {
private val preferences: SharedPreferences = context.getSharedPreferences("prefs", Context.MODE_PRIVATE)
private val showFragmentKey = "showFragment"
fun storeShouldShowFragment(shouldShow: Boolean) {
preferences.edit().putBoolean(showFragmentKey, shouldShow).apply()
}
fun getShouldShowFragment() {
preferences.getBoolean(showFragmentKey, false)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment