File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
app/src/main/java/com/github/odaridavid/designpatterns Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -28,9 +28,8 @@ internal class RatingManager(private val sharedPreferences: SharedPreferences) :
28
28
override fun hasGivenRating (): Boolean = sharedPreferences.getBoolean(RATING_PREF_KEY , false )
29
29
30
30
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 )
34
33
}
35
34
}
36
35
@@ -41,8 +40,15 @@ internal class RatingManager(private val sharedPreferences: SharedPreferences) :
41
40
42
41
override fun updatePromptForRatingCounter () {
43
42
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 ) {
44
50
with (sharedPreferences.edit()) {
45
- putInt( PROMPT_COUNTER_PREF_KEY , counter )
51
+ block( this )
46
52
apply ()
47
53
}
48
54
}
You can’t perform that action at this time.
0 commit comments