3
3
import android .content .Context ;
4
4
import android .content .SharedPreferences ;
5
5
6
+ import androidx .preference .PreferenceManager ;
7
+
6
8
import com .codedead .deadhash .R ;
7
9
8
10
public class SettingsContainer {
@@ -16,7 +18,7 @@ public class SettingsContainer {
16
18
private boolean calculateSha512 ;
17
19
private boolean calculateCrc32 ;
18
20
private int reviewTimes ;
19
- private int theme ;
21
+ private String theme ;
20
22
21
23
/**
22
24
* Initialize a new SettingsContainer
@@ -34,15 +36,6 @@ public String getLanguageCode() {
34
36
return languageCode ;
35
37
}
36
38
37
- /**
38
- * Set the language code
39
- *
40
- * @param languageCode The language code
41
- */
42
- public void setLanguageCode (final String languageCode ) {
43
- this .languageCode = languageCode ;
44
- }
45
-
46
39
/**
47
40
* Get whether MD5 hashes should be calculated
48
41
*
@@ -52,15 +45,6 @@ public boolean isCalculateMd5() {
52
45
return calculateMd5 ;
53
46
}
54
47
55
- /**
56
- * Set whether MD5 hashes should be calculated
57
- *
58
- * @param calculateMd5 True if MD5 hashes should be calculated, otherwise false
59
- */
60
- public void setCalculateMd5 (final boolean calculateMd5 ) {
61
- this .calculateMd5 = calculateMd5 ;
62
- }
63
-
64
48
/**
65
49
* Get whether SHA1 hashes should be calculated
66
50
*
@@ -70,15 +54,6 @@ public boolean isCalculateSha1() {
70
54
return calculateSha1 ;
71
55
}
72
56
73
- /**
74
- * Set whether SHA1 hashes should be calculated
75
- *
76
- * @param calculateSha1 True if SHA1 hashes should be calculated, otherwise false
77
- */
78
- public void setCalculateSha1 (final boolean calculateSha1 ) {
79
- this .calculateSha1 = calculateSha1 ;
80
- }
81
-
82
57
/**
83
58
* Get whether SHA224 hashes should be calculated
84
59
*
@@ -88,15 +63,6 @@ public boolean isCalculateSha224() {
88
63
return calculateSha224 ;
89
64
}
90
65
91
- /**
92
- * Set whether SHA224 hashes should be calculated
93
- *
94
- * @param calculateSha224 True if SHA224 hashes should be calculated, otherwise false
95
- */
96
- public void setCalculateSha224 (final boolean calculateSha224 ) {
97
- this .calculateSha224 = calculateSha224 ;
98
- }
99
-
100
66
/**
101
67
* Get whether SHA256 hashes should be calculated
102
68
*
@@ -106,15 +72,6 @@ public boolean isCalculateSha256() {
106
72
return calculateSha256 ;
107
73
}
108
74
109
- /**
110
- * Set whether SHA256 hashes should be calculated
111
- *
112
- * @param calculateSha256 True if SHA256 hashes should be calculated, otherwise false
113
- */
114
- public void setCalculateSha256 (final boolean calculateSha256 ) {
115
- this .calculateSha256 = calculateSha256 ;
116
- }
117
-
118
75
/**
119
76
* Get whether SHA384 hashes should be calculated
120
77
*
@@ -124,15 +81,6 @@ public boolean isCalculateSha384() {
124
81
return calculateSha384 ;
125
82
}
126
83
127
- /**
128
- * Set whether SHA384 hashes should be calculated
129
- *
130
- * @param calculateSha384 True if SHA384 hashes should be calculated, otherwise false
131
- */
132
- public void setCalculateSha384 (final boolean calculateSha384 ) {
133
- this .calculateSha384 = calculateSha384 ;
134
- }
135
-
136
84
/**
137
85
* Get whether SHA512 hashes should be calculated
138
86
*
@@ -142,15 +90,6 @@ public boolean isCalculateSha512() {
142
90
return calculateSha512 ;
143
91
}
144
92
145
- /**
146
- * Set whether SHA512 hashes should be calculated
147
- *
148
- * @param calculateSha512 True if SHA512 hashes should be calculated, otherwise false
149
- */
150
- public void setCalculateSha512 (final boolean calculateSha512 ) {
151
- this .calculateSha512 = calculateSha512 ;
152
- }
153
-
154
93
/**
155
94
* Get whether CRC32 values should be calculated
156
95
*
@@ -160,15 +99,6 @@ public boolean isCalculateCrc32() {
160
99
return calculateCrc32 ;
161
100
}
162
101
163
- /**
164
- * Set whether CRC32 values should be calculated
165
- *
166
- * @param calculateCrc32 True if CRC32 values should be calculated, otherwise false
167
- */
168
- public void setCalculateCrc32 (final boolean calculateCrc32 ) {
169
- this .calculateCrc32 = calculateCrc32 ;
170
- }
171
-
172
102
/**
173
103
* Get the amount of times a user has been asked to review the application
174
104
*
@@ -195,28 +125,20 @@ public void setReviewTimes(final int reviewTimes) {
195
125
*
196
126
* @return The theme index
197
127
*/
198
- public int getTheme () {
128
+ public String getTheme () {
199
129
return theme ;
200
130
}
201
131
202
- /**
203
- * Set the theme index
204
- *
205
- * @param theme The theme index
206
- */
207
- public void setTheme (final int theme ) {
208
- this .theme = theme ;
209
- }
210
-
211
132
/**
212
133
* Load the settings
213
134
*
214
135
* @param context The Context that can be used to load the settings
215
136
*/
216
137
public void loadSettings (final Context context ) {
217
- if (context == null ) throw new NullPointerException ("Context cannot be null!" );
138
+ if (context == null )
139
+ throw new NullPointerException ("Context cannot be null!" );
218
140
219
- final SharedPreferences sharedPreferences = context . getSharedPreferences (context .getString ( R . string . preferences_file_key ), Context . MODE_PRIVATE );
141
+ final SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences (context .getApplicationContext () );
220
142
221
143
languageCode = sharedPreferences .getString ("language" , "en" );
222
144
calculateMd5 = sharedPreferences .getBoolean ("md5" , true );
@@ -227,7 +149,7 @@ public void loadSettings(final Context context) {
227
149
calculateSha512 = sharedPreferences .getBoolean ("sha512" , true );
228
150
calculateCrc32 = sharedPreferences .getBoolean ("crc32" , true );
229
151
reviewTimes = sharedPreferences .getInt ("reviewTimes" , 0 );
230
- theme = sharedPreferences .getInt ("theme" , 0 );
152
+ theme = sharedPreferences .getString ("theme" , "2" );
231
153
}
232
154
233
155
/**
@@ -250,7 +172,7 @@ public void saveSettings(final Context context) {
250
172
edit .putBoolean ("sha512" , isCalculateSha512 ());
251
173
edit .putBoolean ("crc32" , isCalculateCrc32 ());
252
174
edit .putInt ("reviewTimes" , getReviewTimes ());
253
- edit .putInt ("theme" , getTheme ());
175
+ edit .putString ("theme" , getTheme ());
254
176
255
177
edit .apply ();
256
178
}
0 commit comments