Skip to content

Instantly share code, notes, and snippets.

@IvanShafran
Last active August 16, 2019 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IvanShafran/2da9211045d8e59692107898e8d0da54 to your computer and use it in GitHub Desktop.
Save IvanShafran/2da9211045d8e59692107898e8d0da54 to your computer and use it in GitHub Desktop.
class BuyPreferencesImpl(context: Context) : BuyPreferences {
companion object {
private val PREFERENCES_FILENAME = "BUY_PREFERENCES"
private val BUY_COUNT_KEY = "BUY_COUNT_KEY"
}
private val sharedPreferences = context.getSharedPreferences(
PREFERENCES_FILENAME,
Context.MODE_PRIVATE
)
override fun incrementBuyCount() {
val count = getBuyCount()
sharedPreferences.edit().putInt(BUY_COUNT_KEY, count + 1).apply()
}
override fun getBuyCount(): Int {
return sharedPreferences.getInt(BUY_COUNT_KEY, 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment