Created
July 13, 2019 14:11
-
-
Save harmittaa/de507de3c1e22b973b41846e77d47c4d to your computer and use it in GitHub Desktop.
Koin 2.0 example module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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