Last active
August 22, 2019 09:49
-
-
Save IvanShafran/42c14e95783f386c1ff90894127847c2 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
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