Skip to content

Commit 9ce9154

Browse files
committed
cleanup
1 parent 6adb555 commit 9ce9154

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

app/src/main/java/com/github/odaridavid/designpatterns/RatingManager.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ internal class RatingManager(private val sharedPreferences: SharedPreferences) :
2828
override fun hasGivenRating(): Boolean = sharedPreferences.getBoolean(RATING_PREF_KEY, false)
2929

3030
override fun giveRating() {
31-
with(sharedPreferences.edit()) {
32-
putBoolean(RATING_PREF_KEY, true)
33-
apply()
31+
setPreferenceValue { editor ->
32+
editor.putBoolean(RATING_PREF_KEY, true)
3433
}
3534
}
3635

@@ -41,8 +40,15 @@ internal class RatingManager(private val sharedPreferences: SharedPreferences) :
4140

4241
override fun updatePromptForRatingCounter() {
4342
val counter = sharedPreferences.getInt(PROMPT_COUNTER_PREF_KEY, 0) + 1
43+
setPreferenceValue { editor ->
44+
editor.putInt(PROMPT_COUNTER_PREF_KEY, counter)
45+
}
46+
}
47+
48+
49+
private fun setPreferenceValue(block: (SharedPreferences.Editor) -> Unit) {
4450
with(sharedPreferences.edit()) {
45-
putInt(PROMPT_COUNTER_PREF_KEY, counter)
51+
block(this)
4652
apply()
4753
}
4854
}

0 commit comments

Comments
 (0)