Skip to content

Commit d13c6b0

Browse files
committed
* Make use of a SettingsContainer
* Added code doc
1 parent 79149ef commit d13c6b0

File tree

2 files changed

+323
-44
lines changed

2 files changed

+323
-44
lines changed
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
package com.codedead.deadhash.domain.objects.settings;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
6+
import com.codedead.deadhash.R;
7+
8+
public class SettingsContainer {
9+
10+
private String languageCode;
11+
private boolean calculateMd5;
12+
private boolean calculateSha1;
13+
private boolean calculateSha224;
14+
private boolean calculateSha256;
15+
private boolean calculateSha384;
16+
private boolean calculateSha512;
17+
private boolean calculateCrc32;
18+
private int reviewTimes;
19+
20+
/**
21+
* Initialize a new SettingsContainer
22+
*/
23+
public SettingsContainer() {
24+
25+
}
26+
27+
/**
28+
* Get the language code
29+
*
30+
* @return The language code
31+
*/
32+
public String getLanguageCode() {
33+
return languageCode;
34+
}
35+
36+
/**
37+
* Set the language code
38+
*
39+
* @param languageCode The language code
40+
*/
41+
public void setLanguageCode(final String languageCode) {
42+
this.languageCode = languageCode;
43+
}
44+
45+
/**
46+
* Get whether MD5 hashes should be calculated
47+
*
48+
* @return True if MD5 hashes should be calculated, otherwise false
49+
*/
50+
public boolean isCalculateMd5() {
51+
return calculateMd5;
52+
}
53+
54+
/**
55+
* Set whether MD5 hashes should be calculated
56+
*
57+
* @param calculateMd5 True if MD5 hashes should be calculated, otherwise false
58+
*/
59+
public void setCalculateMd5(final boolean calculateMd5) {
60+
this.calculateMd5 = calculateMd5;
61+
}
62+
63+
/**
64+
* Get whether SHA1 hashes should be calculated
65+
*
66+
* @return True if SHA1 hashes should be calculated, otherwise false
67+
*/
68+
public boolean isCalculateSha1() {
69+
return calculateSha1;
70+
}
71+
72+
/**
73+
* Set whether SHA1 hashes should be calculated
74+
*
75+
* @param calculateSha1 True if SHA1 hashes should be calculated, otherwise false
76+
*/
77+
public void setCalculateSha1(final boolean calculateSha1) {
78+
this.calculateSha1 = calculateSha1;
79+
}
80+
81+
/**
82+
* Get whether SHA224 hashes should be calculated
83+
*
84+
* @return True if SHA224 hashes should be calculated, otherwise false
85+
*/
86+
public boolean isCalculateSha224() {
87+
return calculateSha224;
88+
}
89+
90+
/**
91+
* Set whether SHA224 hashes should be calculated
92+
*
93+
* @param calculateSha224 True if SHA224 hashes should be calculated, otherwise false
94+
*/
95+
public void setCalculateSha224(final boolean calculateSha224) {
96+
this.calculateSha224 = calculateSha224;
97+
}
98+
99+
/**
100+
* Get whether SHA256 hashes should be calculated
101+
*
102+
* @return True if SHA256 hashes should be calculated, otherwise false
103+
*/
104+
public boolean isCalculateSha256() {
105+
return calculateSha256;
106+
}
107+
108+
/**
109+
* Set whether SHA256 hashes should be calculated
110+
*
111+
* @param calculateSha256 True if SHA256 hashes should be calculated, otherwise false
112+
*/
113+
public void setCalculateSha256(final boolean calculateSha256) {
114+
this.calculateSha256 = calculateSha256;
115+
}
116+
117+
/**
118+
* Get whether SHA384 hashes should be calculated
119+
*
120+
* @return True if SHA384 hashes should be calculated, otherwise false
121+
*/
122+
public boolean isCalculateSha384() {
123+
return calculateSha384;
124+
}
125+
126+
/**
127+
* Set whether SHA384 hashes should be calculated
128+
*
129+
* @param calculateSha384 True if SHA384 hashes should be calculated, otherwise false
130+
*/
131+
public void setCalculateSha384(final boolean calculateSha384) {
132+
this.calculateSha384 = calculateSha384;
133+
}
134+
135+
/**
136+
* Get whether SHA512 hashes should be calculated
137+
*
138+
* @return True if SHA512 hashes should be calculated, otherwise false
139+
*/
140+
public boolean isCalculateSha512() {
141+
return calculateSha512;
142+
}
143+
144+
/**
145+
* Set whether SHA512 hashes should be calculated
146+
*
147+
* @param calculateSha512 True if SHA512 hashes should be calculated, otherwise false
148+
*/
149+
public void setCalculateSha512(final boolean calculateSha512) {
150+
this.calculateSha512 = calculateSha512;
151+
}
152+
153+
/**
154+
* Get whether CRC32 values should be calculated
155+
*
156+
* @return True if CRC32 values should be calculated, otherwise false
157+
*/
158+
public boolean isCalculateCrc32() {
159+
return calculateCrc32;
160+
}
161+
162+
/**
163+
* Set whether CRC32 values should be calculated
164+
*
165+
* @param calculateCrc32 True if CRC32 values should be calculated, otherwise false
166+
*/
167+
public void setCalculateCrc32(final boolean calculateCrc32) {
168+
this.calculateCrc32 = calculateCrc32;
169+
}
170+
171+
/**
172+
* Get the amount of times a user has been asked to review the application
173+
*
174+
* @return The amount of times a user has been asked to review the application
175+
*/
176+
public int getReviewTimes() {
177+
return reviewTimes;
178+
}
179+
180+
/**
181+
* Set the amount of times a user has been asked to review the application
182+
*
183+
* @param reviewTimes The amount of times a user has been asked to review the application
184+
*/
185+
public void setReviewTimes(final int reviewTimes) {
186+
if (reviewTimes < 0)
187+
throw new IllegalArgumentException("reviewTimes cannot be smaller than zero!");
188+
189+
this.reviewTimes = reviewTimes;
190+
}
191+
192+
/**
193+
* Load the settings
194+
*
195+
* @param context The Context that can be used to load the settings
196+
*/
197+
public void loadSettings(final Context context) {
198+
if (context == null) throw new NullPointerException("Context cannot be null!");
199+
200+
final SharedPreferences sharedPreferences = context.getSharedPreferences(context.getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
201+
202+
languageCode = sharedPreferences.getString("language", "en");
203+
calculateMd5 = sharedPreferences.getBoolean("md5", true);
204+
calculateSha1 = sharedPreferences.getBoolean("sha1", true);
205+
calculateSha224 = sharedPreferences.getBoolean("sha224", true);
206+
calculateSha256 = sharedPreferences.getBoolean("sha256", true);
207+
calculateSha384 = sharedPreferences.getBoolean("sha384", true);
208+
calculateSha512 = sharedPreferences.getBoolean("sha512", true);
209+
calculateCrc32 = sharedPreferences.getBoolean("crc32", true);
210+
reviewTimes = sharedPreferences.getInt("reviewTimes", 0);
211+
}
212+
213+
/**
214+
* Save the settings
215+
*
216+
* @param context The Context that can be used to save the settings
217+
*/
218+
public void saveSettings(final Context context) {
219+
if (context == null) throw new NullPointerException("Context cannot be null!");
220+
221+
final SharedPreferences sharedPreferences = context.getSharedPreferences(context.getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
222+
final SharedPreferences.Editor edit = sharedPreferences.edit();
223+
224+
edit.putString("language", getLanguageCode());
225+
edit.putBoolean("md5", isCalculateMd5());
226+
edit.putBoolean("sha1", isCalculateSha1());
227+
edit.putBoolean("sha224", isCalculateSha224());
228+
edit.putBoolean("sha256", isCalculateSha256());
229+
edit.putBoolean("sha384", isCalculateSha384());
230+
edit.putBoolean("sha512", isCalculateSha512());
231+
edit.putBoolean("crc32", isCalculateCrc32());
232+
edit.putInt("reviewTimes", getReviewTimes());
233+
234+
edit.apply();
235+
}
236+
}

0 commit comments

Comments
 (0)