diff --git a/app/src/main/java/de/joel/zoomhelper/BackupController.java b/app/src/main/java/de/joel/zoomhelper/BackupController.java index a5ecf0f..2793fb7 100644 --- a/app/src/main/java/de/joel/zoomhelper/BackupController.java +++ b/app/src/main/java/de/joel/zoomhelper/BackupController.java @@ -3,13 +3,18 @@ package de.joel.zoomhelper; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.os.Environment; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AlertDialog; import java.io.File; import java.io.FileOutputStream; @@ -31,26 +36,53 @@ public class BackupController { Encrypter encrypter = new Encrypter(); SharedPreferences mPrefs = activity.getPreferences(Context.MODE_PRIVATE); String value = mPrefs.getString("Meetings", ""); - File destination = new File(activity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(), "backup.tmp"); + final File tempDestination = new File(activity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(), "backup.tmp"); + final File destination = new File(activity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(), "backup.zoomhelper"); + String password; try { - writeStringToFile(value, destination.getAbsolutePath()); + writeStringToFile(value, tempDestination.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } - //TODO: Eingabefeld für Passwort - try { - encrypter.encrypt(destination.getAbsolutePath(), "test"); - } catch (BadPaddingException | IllegalBlockSizeException | IOException | NoSuchAlgorithmException | InvalidKeySpecException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchPaddingException e) { - e.printStackTrace(); - } - //noinspection ResultOfMethodCallIgnored - destination.delete(); - destination = new File(activity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(), "backup.zoomhelper"); - shareFile(destination, activity); + // get prompts.xml view + LayoutInflater li = LayoutInflater.from(activity); + View promptsView = li.inflate(R.layout.prompts, null); + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity); + + // set prompts.xml to alertdialog builder + alertDialogBuilder.setView(promptsView); + + final EditText userInput = (EditText) promptsView + .findViewById(R.id.editTextDialogUserInput); + + // set dialog message + alertDialogBuilder + .setCancelable(false) + .setPositiveButton("OK", + (dialog, id) -> { + try { + encrypter.encrypt(tempDestination.getAbsolutePath(), userInput.getText().toString()); + } catch (BadPaddingException | IllegalBlockSizeException | IOException | NoSuchAlgorithmException | InvalidKeySpecException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchPaddingException e) { + e.printStackTrace(); + } + //noinspection ResultOfMethodCallIgnored + tempDestination.delete(); + shareFile(destination, activity); + + }) + .setNegativeButton("Cancel", + (dialog, id) -> dialog.cancel()); + + // create alert dialog + AlertDialog alertDialog = alertDialogBuilder.create(); + + // show it + alertDialog.show(); } + //TODO:Methode erneut aufrufen dann mit Passwort, mit vorheriger Quelle public void restore(Activity activity) { new FileChooser(activity).openFile(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5dcd10a..b2a1a00 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -45,5 +45,6 @@ Daten wiederherstellen Einstellungen Info + "Passworteingabe: " \ No newline at end of file