Skip to content

Commit

Permalink
* Added an error message when no file was selected
Browse files Browse the repository at this point in the history
* Fixed an issue that could cause the file hash utility to not generate hashes
  • Loading branch information
CodeDead committed Mar 19, 2020
1 parent d13c6b0 commit 1e5b26d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
31 changes: 22 additions & 9 deletions app/src/main/java/com/codedead/deadhash/gui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ protected void onCreate(final Bundle savedInstanceState) {
} else {
navigationView.setCheckedItem(navigationView.getMenu().getItem(0).getSubMenu().getItem(flipperPosition).getItemId());
}

if (!savedInstanceState.getBoolean("KEEP_FILE")) {
deleteTempFile();
}
} else {
navigationView.setCheckedItem(navigationView.getMenu().getItem(0).getSubMenu().getItem(0).getItemId());
deleteTempFile();
}

spnLanguages = findViewById(R.id.SpnLanguages);
Expand All @@ -150,8 +155,12 @@ protected void onCreate(final Bundle savedInstanceState) {
loadSettingsContent();

loadAlertContent();
}

// Cleanup of previous runs, if applicable
/**
* Delete the temporary file to save storage
*/
private void deleteTempFile() {
final File f = new File(getApplicationContext().getCacheDir(), tmpFile);
if (f.exists()) {
//noinspection ResultOfMethodCallIgnored
Expand Down Expand Up @@ -296,9 +305,12 @@ public void onClick(View v) {

btnGenerate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
public void onClick(final View v) {
if (fileLoading) return;
if (!new File(getApplicationContext().getCacheDir(), tmpFile).exists()) return;
if (!new File(getBaseContext().getCacheDir(), tmpFile).exists()) {
Toast.makeText(getApplicationContext(), R.string.error_no_file, Toast.LENGTH_LONG).show();
return;
}

mRecyclerViewFile.setAdapter(null);

Expand Down Expand Up @@ -593,25 +605,26 @@ private void saveSettings(final String lang, final boolean md5, final boolean sh
}

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
public void onSaveInstanceState(final Bundle savedInstanceState) {
savedInstanceState.putInt("TAB_NUMBER", viewFlipper.getDisplayedChild());
savedInstanceState.putString("FILE_PATH", edtFilePath.getText().toString());
savedInstanceState.putString("FILE_COMPARE", edtFileCompare.getText().toString());
savedInstanceState.putParcelableArrayList("FILE_KEY", fileDataArrayList);
savedInstanceState.putString("TEXT_DATA", edtTextData.getText().toString());
savedInstanceState.putString("TEXT_COMPARE", edtTextCompare.getText().toString());
savedInstanceState.putParcelableArrayList("TEXT_KEY", textDataArrayList);
savedInstanceState.putBoolean("KEEP_FILE", true);
super.onSaveInstanceState(savedInstanceState);
}

@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
public void onConfigurationChanged(@NonNull final Configuration newConfig) {
super.onConfigurationChanged(newConfig);
LocaleHelper.onAttach(getBaseContext());
}

@Override
protected void attachBaseContext(Context base) {
protected void attachBaseContext(final Context base) {
super.attachBaseContext(LocaleHelper.onAttach(base));
}

Expand Down Expand Up @@ -639,7 +652,7 @@ public void run() {
}

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
int page = 0;

switch (item.getItemId()) {
Expand All @@ -665,7 +678,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
}

@Override
public void hashDataFile(List<HashData> data) {
public void hashDataFile(final List<HashData> data) {
fileLoading = false;
pgbFile.setVisibility(View.GONE);

Expand Down Expand Up @@ -696,7 +709,7 @@ protected void onActivityResult(final int requestCode, final int resultCode, @Nu
try (final InputStream selectedFileStream = getContentResolver().openInputStream(selectedFileUri)) {
final File outputFile = new File(getApplicationContext().getCacheDir(), tmpFile);

try (final FileOutputStream outputStream = new FileOutputStream(outputFile)) {
try (final FileOutputStream outputStream = new FileOutputStream(outputFile, false)) {
if (selectedFileStream != null) {
StreamUtility.copyStream(selectedFileStream, outputStream);
edtFilePath.setText(selectedFileUri.getPath());
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
<string name="dialog_select_file">Wählen Sie eine Datei aus</string>
<string name="error_copy_file">Es kann keine Kopie der ausgewählten Datei erstellt werden!</string>
<string name="error_open_file">Die ausgewählte Datei kann nicht geöffnet werden!</string>
<string name="error_no_file">Es wurde keine Datei ausgewählt!</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
<string name="dialog_select_file">Sélectionner un fichier</string>
<string name="error_copy_file">Impossible de créer une copie du fichier sélectionné!</string>
<string name="error_open_file">Impossible d\'ouvrir le fichier sélectionné!</string>
<string name="error_no_file">Aucun fichier n\'a été sélectionné!</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
<string name="dialog_select_file">Seleziona un file</string>
<string name="error_copy_file">Impossibile creare una copia del file selezionato!</string>
<string name="error_open_file">Impossibile aprire il file selezionato!</string>
<string name="error_no_file">Nessun file è stato selezionato!</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
<string name="dialog_select_file">Selecteer een bestand</string>
<string name="error_copy_file">Kon geen kopie van het bestand maken!</string>
<string name="error_open_file">Kon het geselecteerde bestand niet openen!</string>
<string name="error_no_file">Geen bestand geselecteerd!</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
<string name="dialog_select_file">Selecione um arquivo</string>
<string name="error_copy_file">Não foi possível criar uma cópia do arquivo selecionado!</string>
<string name="error_open_file">Não foi possível abrir o arquivo selecionado!</string>
<string name="error_no_file">Nenhum arquivo foi selecionado!</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<string name="dialog_select_file">Select a file</string>
<string name="error_open_file">Unable to open the selected file!</string>
<string name="error_copy_file">Unable to create a copy of the selected file!</string>
<string name="error_no_file">No file was selected!</string>

<string-array name="array_languages" translatable="false">
<item>English</item>
Expand Down

0 comments on commit 1e5b26d

Please sign in to comment.