- Added password input when importing file backups

master
Javier Varona 2018-04-04 21:09:58 -04:00
parent eb36492879
commit 998332c2e5
2 changed files with 79 additions and 24 deletions

View File

@ -1,6 +1,7 @@
package cy.agorise.crystalwallet.fragments;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@ -12,6 +13,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.net.URISyntaxException;
@ -93,37 +95,62 @@ public class ImportAccountOptionsFragment extends DialogFragment {
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_CONTENT_REQUEST_CODE){
Uri fileUri = data.getData();
LayoutInflater inflater = getActivity().getLayoutInflater();
View passwordDialogView = inflater.inflate(R.layout.dialog_password_input, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getContext());
alertDialogBuilder.setView(passwordDialogView);
String filePath = null;
try {
filePath = UriTranslator.getFilePath(getContext(), fileUri);
} catch (URISyntaxException e) {
e.printStackTrace();
}
final EditText passwordInput = (EditText) passwordDialogView.findViewById(R.id.etPasswordInput);
final ImportBackupRequest importBackupRequest = new ImportBackupRequest(getContext(), "", filePath);
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
String passwordString = (passwordInput.getText()).toString();
importBackupRequest.setListener(new FileServiceRequestListener() {
@Override
public void onCarryOut() {
if (importBackupRequest.getStatus() == ImportBackupRequest.StatusCode.SUCCEEDED){
Toast toast = Toast.makeText(
getContext(), "Backup restored!", Toast.LENGTH_LONG);
toast.show();
} else if (importBackupRequest.getStatus() == ImportBackupRequest.StatusCode.FAILED){
Toast toast = Toast.makeText(
getContext(), "An error ocurred while restoring the backup!", Toast.LENGTH_LONG);
toast.show();
}
}
});
Uri fileUri = data.getData();
FileServiceRequests.getInstance().addRequest(importBackupRequest);
String filePath = null;
try {
filePath = UriTranslator.getFilePath(getContext(), fileUri);
} catch (URISyntaxException e) {
e.printStackTrace();
}
final ImportBackupRequest importBackupRequest = new ImportBackupRequest(getContext(), passwordString, filePath);
importBackupRequest.setListener(new FileServiceRequestListener() {
@Override
public void onCarryOut() {
if (importBackupRequest.getStatus() == ImportBackupRequest.StatusCode.SUCCEEDED){
Toast toast = Toast.makeText(
getContext(), "Backup restored!", Toast.LENGTH_LONG);
toast.show();
} else if (importBackupRequest.getStatus() == ImportBackupRequest.StatusCode.FAILED){
Toast toast = Toast.makeText(
getContext(), "An error ocurred while restoring the backup!", Toast.LENGTH_LONG);
toast.show();
}
}
});
FileServiceRequests.getInstance().addRequest(importBackupRequest);
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog passwordDialog = alertDialogBuilder.create();
passwordDialog.show();
}
}

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvPasswordInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Enter password to restore backup:" />
<EditText
android:id="@+id/etPasswordInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvPasswordInput"
android:layout_centerHorizontal="true"
android:ems="10"
android:inputType="numberPassword" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>