Skip to content

Commit a642e22

Browse files
committed
* Make use of CompletableFuture
* Make use of Lambda expressions * Refactoring * Bump Android requirements
1 parent c1aa255 commit a642e22

File tree

7 files changed

+153
-271
lines changed

7 files changed

+153
-271
lines changed

app/build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android {
55
buildToolsVersion '29.0.3'
66
defaultConfig {
77
applicationId "com.codedead.deadhash"
8-
minSdkVersion 21
8+
minSdkVersion 24
99
targetSdkVersion 30
1010
versionName '1.7.3'
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -19,17 +19,21 @@ android {
1919
}
2020
productFlavors {
2121
}
22+
compileOptions {
23+
sourceCompatibility JavaVersion.VERSION_1_8
24+
targetCompatibility JavaVersion.VERSION_1_8
25+
}
2226
}
2327

2428
dependencies {
2529
implementation fileTree(include: ['*.jar'], dir: 'libs')
26-
androidTestImplementation('androidx.test.espresso:espresso-core:3.2.0', {
30+
androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0', {
2731
exclude group: 'com.android.support', module: 'support-annotations'
2832
})
2933
implementation 'androidx.appcompat:appcompat:1.2.0'
3034
implementation 'com.google.android.material:material:1.2.1'
3135
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
32-
testImplementation 'junit:junit:4.12'
36+
testImplementation 'junit:junit:4.13.1'
3337
implementation 'androidx.cardview:cardview:1.0.0'
3438
implementation "androidx.preference:preference:1.1.1"
3539
}

app/src/main/java/com/codedead/deadhash/domain/interfaces/hashgenerator/IHashResponse.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.codedead.deadhash.domain.objects.hashgenerator;
22

3-
import android.os.AsyncTask;
4-
5-
import com.codedead.deadhash.domain.interfaces.hashgenerator.IHashResponse;
63
import com.codedead.deadhash.domain.utils.HashUtil;
74

85
import java.io.File;
@@ -11,23 +8,21 @@
118
import java.util.ArrayList;
129
import java.util.List;
1310

14-
public abstract class HashGenerator extends AsyncTask<Void, Void, List<HashData>> {
11+
public final class HashGenerator {
1512

1613
private final byte[] data;
1714
private final List<HashAlgorithm> hashAlgorithms;
1815
private final List<HashData> hashData;
1916
private final String compare;
2017

21-
public IHashResponse hashResponse = null;
22-
2318
/**
2419
* Initialize a new HashGenerator
2520
*
2621
* @param data The byte array that should be hashed
2722
* @param hashAlgorithms The List of HashingAlgorithm enums that should be used to calculate hashes
2823
* @param compare The compare String for the calculated hashes
2924
*/
30-
HashGenerator(final byte[] data, final List<HashAlgorithm> hashAlgorithms, final String compare) {
25+
public HashGenerator(final byte[] data, final List<HashAlgorithm> hashAlgorithms, final String compare) {
3126
hashData = new ArrayList<>();
3227
this.data = data;
3328

@@ -43,7 +38,7 @@ public abstract class HashGenerator extends AsyncTask<Void, Void, List<HashData>
4338
* @param compare The compare String for the calculated hashes
4439
* @throws IOException When the File could not be read
4540
*/
46-
HashGenerator(final File data, final List<HashAlgorithm> hashAlgorithms, final String compare) throws IOException {
41+
public HashGenerator(final File data, final List<HashAlgorithm> hashAlgorithms, final String compare) throws IOException {
4742
hashData = new ArrayList<>();
4843
this.data = readFileToBytes(data);
4944
this.hashAlgorithms = hashAlgorithms;
@@ -76,8 +71,11 @@ private byte[] readFileToBytes(final File file) throws IOException {
7671
return bytes;
7772
}
7873

79-
@Override
80-
protected List<HashData> doInBackground(Void... params) {
74+
/**
75+
* Generate the List of HashData for the given input data
76+
* @return The List of HashData for the given input data
77+
*/
78+
public final List<HashData> generateHashes() {
8179
for (final HashAlgorithm algorithm : hashAlgorithms) {
8280
switch (algorithm) {
8381
case md5:

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

Lines changed: 0 additions & 22 deletions
This file was deleted.

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,12 @@ static class DataHolder extends RecyclerView.ViewHolder implements View.OnClickL
7474
final ImageButton copyData = v.findViewById(R.id.Copy_Data);
7575

7676
copyData.setOnClickListener(this);
77-
compareData.setOnClickListener(new View.OnClickListener() {
78-
@Override
79-
public void onClick(final View v) {
80-
if (originalCompare == null || originalCompare.length() == 0) return;
81-
if (originalCompare.equals(encryptionData.getText().toString())) {
82-
Toast.makeText(v.getContext(), R.string.toast_hash_match, Toast.LENGTH_SHORT).show();
83-
} else {
84-
Toast.makeText(v.getContext(), R.string.toast_hash_mismatch, Toast.LENGTH_SHORT).show();
85-
}
77+
compareData.setOnClickListener(v1 -> {
78+
if (originalCompare == null || originalCompare.length() == 0) return;
79+
if (originalCompare.equals(encryptionData.getText().toString())) {
80+
Toast.makeText(v1.getContext(), R.string.toast_hash_match, Toast.LENGTH_SHORT).show();
81+
} else {
82+
Toast.makeText(v1.getContext(), R.string.toast_hash_mismatch, Toast.LENGTH_SHORT).show();
8683
}
8784
});
8885
}

0 commit comments

Comments
 (0)