Skip to content

Commit f75274e

Browse files
committed
feat: Gradle upgrade, dependency upgrades, refactoring, added toast for permissions, updated min and target sdk
1 parent b11d361 commit f75274e

38 files changed

+128
-124
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ This library is maintained by CodeDead. You can find more about us using the fol
3131
* [Twitter](https://twitter.com/C0DEDEAD)
3232
* [Facebook](https://facebook.com/deadlinecodedead)
3333

34-
Copyright © 2022 CodeDead
34+
Copyright © 2023 CodeDead

app/build.gradle

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 31
5-
buildToolsVersion '30.0.3'
4+
compileSdk 34
65
defaultConfig {
76
applicationId "com.codedead.deadhash"
8-
minSdkVersion 24
9-
targetSdkVersion 31
7+
minSdk 28
8+
targetSdk 34
109
versionName '1.7.8'
1110
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1211
versionCode 9
@@ -20,20 +19,21 @@ android {
2019
productFlavors {
2120
}
2221
compileOptions {
23-
sourceCompatibility JavaVersion.VERSION_1_8
24-
targetCompatibility JavaVersion.VERSION_1_8
22+
sourceCompatibility JavaVersion.VERSION_17
23+
targetCompatibility JavaVersion.VERSION_17
2524
}
25+
namespace 'com.codedead.deadhash'
2626
}
2727

2828
dependencies {
2929
implementation fileTree(include: ['*.jar'], dir: 'libs')
30-
androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0', {
30+
androidTestImplementation('androidx.test.espresso:espresso-core:3.5.1', {
3131
exclude group: 'com.android.support', module: 'support-annotations'
3232
})
33-
implementation 'androidx.appcompat:appcompat:1.4.1'
34-
implementation 'com.google.android.material:material:1.5.0'
35-
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
33+
implementation 'androidx.appcompat:appcompat:1.6.1'
34+
implementation 'com.google.android.material:material:1.10.0'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
3636
implementation 'androidx.cardview:cardview:1.0.0'
37-
implementation "androidx.preference:preference:1.2.0"
37+
implementation 'androidx.preference:preference:1.2.1'
3838
testImplementation 'junit:junit:4.13.2'
3939
}

app/src/main/AndroidManifest.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
4-
package="com.codedead.deadhash">
3+
xmlns:tools="http://schemas.android.com/tools">
54

6-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
5+
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
6+
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
7+
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
78

89
<application
910
android:name=".main.Runner"
-1.26 KB
Loading

app/src/main/ic_launcher-web.png

-13.7 KB
Binary file not shown.
-22.5 KB
Binary file not shown.

app/src/main/java/com/codedead/deadhash/domain/objects/hashgenerator/HashData.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class HashData implements Parcelable {
1010

1111
private final String compareCheck;
1212

13-
public static final Creator<HashData> CREATOR = new Creator<HashData>() {
13+
public static final Creator<HashData> CREATOR = new Creator<>() {
1414
@Override
1515
public HashData createFromParcel(final Parcel in) {
1616
return new HashData(in);

app/src/main/java/com/codedead/deadhash/domain/objects/hashgenerator/HashGenerator.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -78,37 +78,37 @@ private byte[] readFileToBytes(final File file) throws IOException {
7878
* Generate the List of HashData for the given input data
7979
* @return The List of HashData for the given input data
8080
*/
81-
public final List<HashData> generateHashes() {
81+
public List<HashData> generateHashes() {
8282
for (final HashAlgorithm algorithm : hashAlgorithms) {
8383
switch (algorithm) {
84-
case md5:
84+
case md5 -> {
8585
final String md5 = HashUtil.calculateHash(data, "MD5");
8686
hashData.add(new HashData("MD5", md5, compare));
87-
break;
88-
case sha1:
87+
}
88+
case sha1 -> {
8989
final String sha1 = HashUtil.calculateHash(data, "SHA-1");
9090
hashData.add(new HashData("SHA-1", sha1, compare));
91-
break;
92-
case sha224:
91+
}
92+
case sha224 -> {
9393
final String sha224 = HashUtil.calculateHash(data, "SHA-224");
9494
hashData.add(new HashData("SHA-224", sha224, compare));
95-
break;
96-
case sha256:
95+
}
96+
case sha256 -> {
9797
final String sha256 = HashUtil.calculateHash(data, "SHA-256");
9898
hashData.add(new HashData("SHA-256", sha256, compare));
99-
break;
100-
case sha384:
99+
}
100+
case sha384 -> {
101101
final String sha384 = HashUtil.calculateHash(data, "SHA-384");
102102
hashData.add(new HashData("SHA-384", sha384, compare));
103-
break;
104-
case sha512:
103+
}
104+
case sha512 -> {
105105
final String sha512 = HashUtil.calculateHash(data, "SHA-512");
106106
hashData.add(new HashData("SHA-512", sha512, compare));
107-
break;
108-
case crc32:
107+
}
108+
case crc32 -> {
109109
final String crc32 = HashUtil.calculateCRC32(data);
110110
hashData.add(new HashData("CRC32", crc32, compare));
111-
break;
111+
}
112112
}
113113
}
114114

app/src/main/java/com/codedead/deadhash/gui/MainActivity.java

+50-50
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import android.content.pm.PackageManager;
77
import android.content.res.Configuration;
88
import android.net.Uri;
9+
import android.os.Build;
910
import android.os.Bundle;
1011
import android.os.CountDownTimer;
11-
import android.os.Handler;
1212

1313
import androidx.activity.result.ActivityResultLauncher;
1414
import androidx.activity.result.contract.ActivityResultContracts;
@@ -33,11 +33,11 @@
3333
import androidx.appcompat.app.AppCompatActivity;
3434
import androidx.appcompat.widget.Toolbar;
3535

36-
import android.os.Looper;
3736
import android.text.method.LinkMovementMethod;
3837
import android.view.Menu;
3938
import android.view.MenuInflater;
4039
import android.view.MenuItem;
40+
import android.view.SubMenu;
4141
import android.view.View;
4242
import android.widget.Button;
4343
import android.widget.EditText;
@@ -63,7 +63,6 @@
6363
import java.util.concurrent.CompletableFuture;
6464

6565
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
66-
private boolean doubleBackToExitPressedOnce;
6766

6867
private ViewFlipper viewFlipper;
6968
private EditText edtFileCompare;
@@ -125,16 +124,27 @@ protected void onCreate(final Bundle savedInstanceState) {
125124
viewFlipper.setDisplayedChild(flipperPosition);
126125

127126
if (flipperPosition > 1) {
128-
navigationView.setCheckedItem(navigationView.getMenu().getItem(1).getSubMenu().getItem(flipperPosition - 2).getItemId());
127+
final SubMenu menu = navigationView.getMenu().getItem(1).getSubMenu();
128+
if (menu != null) {
129+
navigationView.setCheckedItem(menu.getItem(flipperPosition - 2).getItemId());
130+
}
129131
} else {
130-
navigationView.setCheckedItem(navigationView.getMenu().getItem(0).getSubMenu().getItem(flipperPosition).getItemId());
132+
final SubMenu menu = navigationView.getMenu().getItem(0).getSubMenu();
133+
if (menu != null) {
134+
navigationView.setCheckedItem(menu.getItem(flipperPosition).getItemId());
135+
}
131136
}
132137

133138
if (!savedInstanceState.getBoolean("KEEP_FILE")) {
134139
deleteTempFile();
135140
}
136141
} else {
137-
navigationView.setCheckedItem(navigationView.getMenu().getItem(0).getSubMenu().getItem(0).getItemId());
142+
final SubMenu menu = navigationView.getMenu().getItem(0).getSubMenu();
143+
144+
if (menu != null) {
145+
navigationView.setCheckedItem(menu.getItem(0).getItemId());
146+
}
147+
138148
deleteTempFile();
139149
}
140150

@@ -180,15 +190,10 @@ protected void onCreate(final Bundle savedInstanceState) {
180190
*/
181191
private void loadTheme() {
182192
switch (settingsContainer.getTheme()) {
183-
case "0":
184-
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
185-
break;
186-
case "1":
187-
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
188-
break;
189-
case "2":
190-
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
191-
break;
193+
case "0" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
194+
case "1" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
195+
case "2" ->
196+
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
192197
}
193198
}
194199

@@ -309,10 +314,6 @@ protected void onPause() {
309314
* @param savedInstance The Bundle that contains saved information
310315
*/
311316
private void loadFileHashContent(final Bundle savedInstance) {
312-
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
313-
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
314-
}
315-
316317
pgbFile = findViewById(R.id.PgbFile);
317318
mRecyclerViewFile = findViewById(R.id.file_recycler);
318319
mRecyclerViewFile.setHasFixedSize(true);
@@ -342,18 +343,8 @@ private void loadFileHashContent(final Bundle savedInstance) {
342343

343344
mRecyclerViewFile.setAdapter(mAdapterFile);
344345

345-
btnOpenFile.setOnClickListener(v -> {
346-
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
347-
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
348-
} else {
349-
final Intent intent = new Intent()
350-
.setType("*/*")
351-
.setAction(Intent.ACTION_GET_CONTENT)
352-
.addCategory(Intent.CATEGORY_OPENABLE);
353-
354-
activityResultLauncher.launch(Intent.createChooser(intent, getString(R.string.dialog_select_file)));
355-
}
356-
});
346+
btnOpenFile.setOnClickListener(this::onClickSelectFile);
347+
edtFilePath.setOnClickListener(this::onClickSelectFile);
357348

358349
btnGenerate.setOnClickListener(v -> {
359350
if (fileLoading) return;
@@ -511,7 +502,7 @@ private void loadHelpContent() {
511502

512503
btnSupport.setOnClickListener(v -> new ShareCompat.IntentBuilder(MainActivity.this)
513504
.setType("message/rfc822")
514-
.addEmailTo("admin@codedead.com")
505+
.addEmailTo("support@codedead.com")
515506
.setSubject("DeadHash - Android")
516507
.setText("")
517508
.setChooserTitle(R.string.text_send_mail)
@@ -557,24 +548,6 @@ protected void attachBaseContext(final Context base) {
557548
super.attachBaseContext(LocaleHelper.onAttach(base));
558549
}
559550

560-
@Override
561-
public void onBackPressed() {
562-
final DrawerLayout drawer = findViewById(R.id.drawer_layout);
563-
if (drawer.isDrawerOpen(GravityCompat.START)) {
564-
drawer.closeDrawer(GravityCompat.START);
565-
} else {
566-
if (doubleBackToExitPressedOnce) {
567-
super.onBackPressed();
568-
return;
569-
}
570-
571-
this.doubleBackToExitPressedOnce = true;
572-
Toast.makeText(this, R.string.toast_back_again, Toast.LENGTH_SHORT).show();
573-
574-
new Handler(Looper.getMainLooper()).postDelayed(() -> doubleBackToExitPressedOnce = false, 2000);
575-
}
576-
}
577-
578551
@Override
579552
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
580553
int page = 0;
@@ -594,4 +567,31 @@ public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
594567
drawer.closeDrawer(GravityCompat.START);
595568
return true;
596569
}
570+
571+
private void onClickSelectFile(final View v) {
572+
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_MEDIA_AUDIO) != PackageManager.PERMISSION_GRANTED
573+
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_MEDIA_IMAGES) != PackageManager.PERMISSION_GRANTED
574+
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_MEDIA_VIDEO) != PackageManager.PERMISSION_GRANTED) {
575+
Toast.makeText(getApplicationContext(), R.string.toast_no_permissions, Toast.LENGTH_LONG).show();
576+
577+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
578+
ActivityCompat.requestPermissions(MainActivity.this, new String[]{
579+
Manifest.permission.READ_MEDIA_AUDIO,
580+
Manifest.permission.READ_MEDIA_IMAGES,
581+
Manifest.permission.READ_MEDIA_VIDEO
582+
}, 0);
583+
} else {
584+
ActivityCompat.requestPermissions(MainActivity.this, new String[]{
585+
Manifest.permission.READ_EXTERNAL_STORAGE
586+
}, 0);
587+
}
588+
} else {
589+
final Intent intent = new Intent()
590+
.setType("*/*")
591+
.setAction(Intent.ACTION_OPEN_DOCUMENT)
592+
.addCategory(Intent.CATEGORY_OPENABLE);
593+
594+
activityResultLauncher.launch(Intent.createChooser(intent, getString(R.string.dialog_select_file)));
595+
}
596+
}
597597
}

app/src/main/java/com/codedead/deadhash/gui/SettingsActivity.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,19 @@ protected void onCreate(final Bundle savedInstanceState) {
5151
}
5252

5353
private final SharedPreferences.OnSharedPreferenceChangeListener listener = (prefs, key) -> {
54+
if (key == null)
55+
return;
56+
5457
if (key.equals("language")) {
5558
LocaleHelper.setLocale(getApplicationContext(), prefs.getString("language", "en"));
5659
recreate();
5760
} else if (key.equals("theme")) {
5861
final String theme = prefs.getString("theme", "0");
5962
switch (theme) {
60-
case "0":
61-
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
62-
break;
63-
case "1":
64-
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
65-
break;
66-
case "2":
67-
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
68-
break;
63+
case "0" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
64+
case "1" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
65+
case "2" ->
66+
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
6967
}
7068
}
7169
};
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
22
android:width="108dp"
33
android:height="108dp"
4-
android:viewportWidth="108"
5-
android:viewportHeight="108"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
66
android:tint="#FFFFFF">
7-
<group android:scaleX="2.8188"
8-
android:scaleY="2.8188"
9-
android:translateX="20.1744"
10-
android:translateY="20.1744">
7+
<group android:scaleX="0.58"
8+
android:scaleY="0.58"
9+
android:translateX="5.04"
10+
android:translateY="5.04">
1111
<path
1212
android:fillColor="@android:color/white"
13-
android:pathData="M12.65,10C11.83,7.67 9.61,6 7,6c-3.31,0 -6,2.69 -6,6s2.69,6 6,6c2.61,0 4.83,-1.67 5.65,-4H17v4h4v-4h2v-4H12.65zM7,14c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z"/>
13+
android:pathData="M9.4,16.6L4.8,12l4.6,-4.6L8,6l-6,6 6,6 1.4,-1.4zM14.6,16.6l4.6,-4.6 -4.6,-4.6L16,6l6,6 -6,6 -1.4,-1.4z"/>
1414
</group>
1515
</vector>

app/src/main/res/layout/content_file.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
android:id="@+id/EdtFile_name"
3535
android:layout_width="wrap_content"
3636
android:layout_height="wrap_content"
37-
android:layout_weight="0.85"
37+
android:layout_weight="0.90"
38+
android:lines="1"
3839
android:clickable="false"
3940
android:cursorVisible="false"
4041
android:focusable="false"
@@ -44,10 +45,10 @@
4445
android:inputType="none" />
4546

4647
<ImageButton
47-
android:layout_weight="1"
4848
android:id="@+id/ImgBtnFileData"
4949
android:layout_width="wrap_content"
5050
android:layout_height="wrap_content"
51+
android:layout_weight="1"
5152
android:contentDescription="@string/card_open_folder"
5253
android:src="@drawable/ic_open_folder" />
5354
</TableRow>

app/src/main/res/layout/content_text.xml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
android:paddingTop="5dp">
3131

3232
<TableRow>
33+
3334
<TextView
3435
android:layout_width="wrap_content"
3536
android:layout_height="wrap_content"

app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml renamed to app/src/main/res/mipmap-anydpi/ic_launcher.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
33
<background android:drawable="@color/ic_launcher_background"/>
44
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
5-
</adaptive-icon>
5+
</adaptive-icon>

0 commit comments

Comments
 (0)