Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9171ebf63e | |||
| 76bdb4b107 |
@@ -3,13 +3,18 @@ package de.joel.zoomhelper;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -31,26 +36,53 @@ public class BackupController {
|
|||||||
Encrypter encrypter = new Encrypter();
|
Encrypter encrypter = new Encrypter();
|
||||||
SharedPreferences mPrefs = activity.getPreferences(Context.MODE_PRIVATE);
|
SharedPreferences mPrefs = activity.getPreferences(Context.MODE_PRIVATE);
|
||||||
String value = mPrefs.getString("Meetings", "");
|
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 {
|
try {
|
||||||
writeStringToFile(value, destination.getAbsolutePath());
|
writeStringToFile(value, tempDestination.getAbsolutePath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
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) {
|
public void restore(Activity activity) {
|
||||||
new FileChooser(activity).openFile();
|
new FileChooser(activity).openFile();
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/layout_root"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/password_input"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editTextDialogUserInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<requestFocus />
|
||||||
|
|
||||||
|
</EditText>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -45,5 +45,6 @@
|
|||||||
<string name="restore">Daten wiederherstellen</string>
|
<string name="restore">Daten wiederherstellen</string>
|
||||||
<string name="settings">Einstellungen</string>
|
<string name="settings">Einstellungen</string>
|
||||||
<string name="info">Info</string>
|
<string name="info">Info</string>
|
||||||
|
<string name="password_input">"Passworteingabe: "</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user