add some strings

This commit is contained in:
2021-07-05 19:57:50 +02:00
parent c488052501
commit 76bdb4b107
2 changed files with 45 additions and 12 deletions
@@ -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();
+1
View File
@@ -45,5 +45,6 @@
<string name="restore">Daten wiederherstellen</string>
<string name="settings">Einstellungen</string>
<string name="info">Info</string>
<string name="password_input">"Passworteingabe: "</string>
</resources>