- Added password input when importing file backups
This commit is contained in:
parent
eb36492879
commit
998332c2e5
2 changed files with 79 additions and 24 deletions
|
@ -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,37 +95,62 @@ 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){
|
||||||
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;
|
final EditText passwordInput = (EditText) passwordDialogView.findViewById(R.id.etPasswordInput);
|
||||||
try {
|
|
||||||
filePath = UriTranslator.getFilePath(getContext(), fileUri);
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
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() {
|
Uri fileUri = data.getData();
|
||||||
@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);
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
app/src/main/res/layout/dialog_password_input.xml
Normal file
28
app/src/main/res/layout/dialog_password_input.xml
Normal 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>
|
Loading…
Reference in a new issue