Skip to content

Instantly share code, notes, and snippets.

@IvanShafran
Last active August 22, 2019 09:49
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/42c14e95783f386c1ff90894127847c2 to your computer and use it in GitHub Desktop.
Save IvanShafran/42c14e95783f386c1ff90894127847c2 to your computer and use it in GitHub Desktop.
interface BuyPreferences {
fun incrementBuyCount()
fun getBuyCount(): Int
}
class BuyPreferencesImpl(context: Context) : BuyPreferences {
// ...
private val sharedPreferences: SharedPreferences = context.getSharedPreferences(...)
override fun incrementBuyCount() {
val count = getBuyCount()
sharedPreferences.edit().putInt(BUY_COUNT_KEY, count + 1).apply()
}
override fun getBuyCount() = sharedPreferences.getInt(BUY_COUNT_KEY, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment