Last active
August 16, 2019 09:43
-
-
Save IvanShafran/2da9211045d8e59692107898e8d0da54 to your computer and use it in GitHub Desktop.
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
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