- Added password input when importing file backups

This commit is contained in:
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; package cy.agorise.crystalwallet.fragments;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -12,6 +13,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -93,10 +95,24 @@ public class ImportAccountOptionsFragment extends DialogFragment {
} }
@Override @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); super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_CONTENT_REQUEST_CODE){ if (requestCode == FILE_CONTENT_REQUEST_CODE){
LayoutInflater inflater = getActivity().getLayoutInflater();
View passwordDialogView = inflater.inflate(R.layout.dialog_password_input, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getContext());
alertDialogBuilder.setView(passwordDialogView);
final EditText passwordInput = (EditText) passwordDialogView.findViewById(R.id.etPasswordInput);
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
String passwordString = (passwordInput.getText()).toString();
Uri fileUri = data.getData(); Uri fileUri = data.getData();
String filePath = null; String filePath = null;
@ -106,7 +122,7 @@ public class ImportAccountOptionsFragment extends DialogFragment {
e.printStackTrace(); e.printStackTrace();
} }
final ImportBackupRequest importBackupRequest = new ImportBackupRequest(getContext(), "", filePath); final ImportBackupRequest importBackupRequest = new ImportBackupRequest(getContext(), passwordString, filePath);
importBackupRequest.setListener(new FileServiceRequestListener() { importBackupRequest.setListener(new FileServiceRequestListener() {
@Override @Override
@ -124,6 +140,17 @@ public class ImportAccountOptionsFragment extends DialogFragment {
}); });
FileServiceRequests.getInstance().addRequest(importBackupRequest); 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>