Skip to content

Commit cce829d

Browse files
authored
Merge pull request #24 from CodeDead/feature/settings
feature/settings
2 parents 081c18b + 1a116f3 commit cce829d

34 files changed

+427
-583
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
android:supportsRtl="true"
1818
android:theme="@style/Theme.DeadHash"
1919
tools:ignore="GoogleAppIndexingWarning">
20+
<activity
21+
android:name=".gui.SettingsActivity"
22+
android:exported="false"
23+
android:label="@string/nav_settings"
24+
android:theme="@style/Theme.DeadHash.NoActionBar" />
2025
<activity
2126
android:name=".gui.MainActivity"
2227
android:exported="true"

app/src/main/java/com/codedead/deadhash/domain/objects/settings/SettingsContainer.java

Lines changed: 9 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.content.Context;
44
import android.content.SharedPreferences;
55

6+
import androidx.preference.PreferenceManager;
7+
68
import com.codedead.deadhash.R;
79

810
public class SettingsContainer {
@@ -16,7 +18,7 @@ public class SettingsContainer {
1618
private boolean calculateSha512;
1719
private boolean calculateCrc32;
1820
private int reviewTimes;
19-
private int theme;
21+
private String theme;
2022

2123
/**
2224
* Initialize a new SettingsContainer
@@ -34,15 +36,6 @@ public String getLanguageCode() {
3436
return languageCode;
3537
}
3638

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-
4639
/**
4740
* Get whether MD5 hashes should be calculated
4841
*
@@ -52,15 +45,6 @@ public boolean isCalculateMd5() {
5245
return calculateMd5;
5346
}
5447

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-
6448
/**
6549
* Get whether SHA1 hashes should be calculated
6650
*
@@ -70,15 +54,6 @@ public boolean isCalculateSha1() {
7054
return calculateSha1;
7155
}
7256

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-
8257
/**
8358
* Get whether SHA224 hashes should be calculated
8459
*
@@ -88,15 +63,6 @@ public boolean isCalculateSha224() {
8863
return calculateSha224;
8964
}
9065

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-
10066
/**
10167
* Get whether SHA256 hashes should be calculated
10268
*
@@ -106,15 +72,6 @@ public boolean isCalculateSha256() {
10672
return calculateSha256;
10773
}
10874

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-
11875
/**
11976
* Get whether SHA384 hashes should be calculated
12077
*
@@ -124,15 +81,6 @@ public boolean isCalculateSha384() {
12481
return calculateSha384;
12582
}
12683

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-
13684
/**
13785
* Get whether SHA512 hashes should be calculated
13886
*
@@ -142,15 +90,6 @@ public boolean isCalculateSha512() {
14290
return calculateSha512;
14391
}
14492

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-
15493
/**
15594
* Get whether CRC32 values should be calculated
15695
*
@@ -160,15 +99,6 @@ public boolean isCalculateCrc32() {
16099
return calculateCrc32;
161100
}
162101

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-
172102
/**
173103
* Get the amount of times a user has been asked to review the application
174104
*
@@ -195,28 +125,20 @@ public void setReviewTimes(final int reviewTimes) {
195125
*
196126
* @return The theme index
197127
*/
198-
public int getTheme() {
128+
public String getTheme() {
199129
return theme;
200130
}
201131

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-
211132
/**
212133
* Load the settings
213134
*
214135
* @param context The Context that can be used to load the settings
215136
*/
216137
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!");
218140

219-
final SharedPreferences sharedPreferences = context.getSharedPreferences(context.getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
141+
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
220142

221143
languageCode = sharedPreferences.getString("language", "en");
222144
calculateMd5 = sharedPreferences.getBoolean("md5", true);
@@ -227,7 +149,7 @@ public void loadSettings(final Context context) {
227149
calculateSha512 = sharedPreferences.getBoolean("sha512", true);
228150
calculateCrc32 = sharedPreferences.getBoolean("crc32", true);
229151
reviewTimes = sharedPreferences.getInt("reviewTimes", 0);
230-
theme = sharedPreferences.getInt("theme", 0);
152+
theme = sharedPreferences.getString("theme", "2");
231153
}
232154

233155
/**
@@ -250,7 +172,7 @@ public void saveSettings(final Context context) {
250172
edit.putBoolean("sha512", isCalculateSha512());
251173
edit.putBoolean("crc32", isCalculateCrc32());
252174
edit.putInt("reviewTimes", getReviewTimes());
253-
edit.putInt("theme", getTheme());
175+
edit.putString("theme", getTheme());
254176

255177
edit.apply();
256178
}

app/src/main/java/com/codedead/deadhash/domain/utils/IntentUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import android.net.Uri;
66
import android.widget.Toast;
77

8+
import androidx.appcompat.app.AlertDialog;
9+
810
import com.codedead.deadhash.R;
911

1012
public final class IntentUtils {
@@ -56,4 +58,23 @@ public static void openPlayStore(final Context context) {
5658
Toast.makeText(context, context.getString(R.string.error_playstore), Toast.LENGTH_SHORT).show();
5759
}
5860
}
61+
62+
/**
63+
* Display an alert to the user
64+
*
65+
* @param context The context that can be used to display the alert
66+
* @param message The message that needs to be displayed to the user
67+
*/
68+
public static void showAlert(final Context context, final String message) {
69+
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
70+
builder.setMessage(message);
71+
builder.setCancelable(true);
72+
73+
builder.setPositiveButton(
74+
android.R.string.ok,
75+
(dialog, id) -> dialog.cancel());
76+
77+
final AlertDialog alert = builder.create();
78+
alert.show();
79+
}
5980
}

app/src/main/java/com/codedead/deadhash/domain/utils/LocaleHelper.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import android.content.res.Configuration;
66
import android.content.res.Resources;
77

8-
import androidx.preference.PreferenceManager;
9-
108
import java.util.Locale;
119

1210
public final class LocaleHelper {
@@ -42,7 +40,6 @@ public static Context onAttach(final Context context, final String defaultLangua
4240
* @return The Context that contains the correct locale
4341
*/
4442
public static Context setLocale(final Context context, final String language) {
45-
persist(context, language);
4643
return updateResourcesLegacy(context, language);
4744
}
4845

@@ -58,20 +55,6 @@ private static String getPersistedData(final Context context, final String defau
5855
return preferences.getString("language", defaultLanguage);
5956
}
6057

61-
/**
62-
* Persist the language code
63-
*
64-
* @param context The Context that can be used to persist the data
65-
* @param language The language code that should be persisted
66-
*/
67-
private static void persist(final Context context, final String language) {
68-
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
69-
SharedPreferences.Editor editor = preferences.edit();
70-
71-
editor.putString("language", language);
72-
editor.apply();
73-
}
74-
7558
/**
7659
* Update the resources of a specific Context
7760
*
@@ -86,7 +69,7 @@ private static Context updateResourcesLegacy(final Context context, final String
8669
final Resources resources = context.getResources();
8770

8871
final Configuration configuration = resources.getConfiguration();
89-
configuration.locale = locale;
72+
configuration.setLocale(locale);
9073

9174
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
9275

0 commit comments

Comments
 (0)