@@ -25,10 +25,10 @@ public class SharedPrefsRepo {
25
25
private static final String SAVED_CARDS_PREFIX = "EXTRA_SAVED_CARDS" ;
26
26
private static final String PHONE_NUMBER = "phone_number" ;
27
27
public Context context ;
28
- SharedPreferences sharedPreferences ;
29
- SharedPreferences .Editor editor ;
30
- String FLW_REF_KEY = "flw_ref_key" ;
31
- Gson gson ;
28
+ private SharedPreferences sharedPreferences ;
29
+ private SharedPreferences .Editor editor ;
30
+ private String FLW_REF_KEY = "flw_ref_key" ;
31
+ private Gson gson ;
32
32
33
33
@ SuppressLint ("CommitPrefEdits" )
34
34
@ Inject
@@ -56,8 +56,6 @@ public void saveCardToSharedPreference(List<SavedCard> cardsToSave, String phone
56
56
savedCards .removeAll (repeatedCards );
57
57
savedCards .addAll (cardsToSave );
58
58
59
- init ();
60
- Gson gson = new Gson ();
61
59
Type type = new TypeToken <List <SavedCard >>() {}.getType ();
62
60
String savedCardsJson = gson .toJson (savedCards , type );
63
61
@@ -66,12 +64,10 @@ public void saveCardToSharedPreference(List<SavedCard> cardsToSave, String phone
66
64
67
65
68
66
public List <SavedCard > getSavedCards (String phoneNumber , String publicKey ) {
69
- init ();
70
67
String savedCardsJson = sharedPreferences .getString (
71
68
SAVED_CARDS_PREFIX + phoneNumber + publicKey , "[]" );
72
69
73
70
try {
74
- Gson gson = new Gson ();
75
71
Type type = new TypeToken <List <SavedCard >>() {
76
72
}.getType ();
77
73
return gson .fromJson (savedCardsJson , type );
@@ -81,37 +77,23 @@ public List<SavedCard> getSavedCards(String phoneNumber, String publicKey) {
81
77
return new ArrayList <>();
82
78
}
83
79
}
84
-
85
- private void init () {
86
-
87
- if (sharedPreferences == null ) {
88
- sharedPreferences = context .getSharedPreferences (
89
- RAVEPAY , Context .MODE_PRIVATE );
90
- editor = sharedPreferences .edit ();
91
- }
92
- }
93
-
94
80
95
81
public void saveFlwRef (String flwRef ) {
96
- init ();
97
82
editor .putString (FLW_REF_KEY , flwRef ).apply ();
98
83
}
99
84
100
85
101
86
public String fetchFlwRef () {
102
- init ();
103
87
return sharedPreferences .getString (FLW_REF_KEY , "" );
104
88
}
105
89
106
90
107
- public void savePhoneNumber (String phoneNumber ) {
108
- init ();
91
+ private void savePhoneNumber (String phoneNumber ) {
109
92
editor .putString (PHONE_NUMBER , phoneNumber ).apply ();
110
93
}
111
94
112
95
113
96
public String fetchPhoneNumber () {
114
- init ();
115
97
return sharedPreferences .getString (PHONE_NUMBER , "" );
116
98
}
117
99
}
0 commit comments