Commit 06c75718 authored by Andreas Schildbach's avatar Andreas Schildbach

BackupWalletDialogFragment: Put fragment into its own activity.

parent 359c0ead
......@@ -158,6 +158,10 @@
android:name="de.schildbach.wallet.ui.preference.PreferenceActivity"
android:label="@string/preferences_activity_title"
android:theme="@style/My.Theme.ChildActivity" />
<activity
android:name="de.schildbach.wallet.ui.backup.BackupWalletActivity"
android:configChanges="orientation|keyboard|keyboardHidden"
android:theme="@style/My.Theme.Dialog" />
<activity
android:name="de.schildbach.wallet.ui.backup.RestoreWalletFromExternalActivity"
android:configChanges="orientation|keyboard|keyboardHidden"
......
......@@ -30,7 +30,7 @@ import de.schildbach.wallet.data.PaymentIntent;
import de.schildbach.wallet.service.BlockchainService;
import de.schildbach.wallet.ui.InputParser.BinaryInputParser;
import de.schildbach.wallet.ui.InputParser.StringInputParser;
import de.schildbach.wallet.ui.backup.BackupWalletDialogFragment;
import de.schildbach.wallet.ui.backup.BackupWalletActivity;
import de.schildbach.wallet.ui.backup.RestoreWalletDialogFragment;
import de.schildbach.wallet.ui.monitor.NetworkMonitorActivity;
import de.schildbach.wallet.ui.preference.PreferenceActivity;
......@@ -113,7 +113,7 @@ public final class WalletActivity extends AbstractWalletActivity {
viewModel.showBackupWalletDialog.observe(this, new Event.Observer<Void>() {
@Override
public void onEvent(final Void v) {
BackupWalletDialogFragment.show(getSupportFragmentManager());
BackupWalletActivity.start(WalletActivity.this);
}
});
viewModel.showRestoreWalletDialog.observe(this, new Event.Observer<Void>() {
......
/*
* Copyright the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.schildbach.wallet.ui.backup;
import de.schildbach.wallet.ui.AbstractWalletActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.core.app.ActivityCompat;
/**
* @author Andreas Schildbach
*/
public class BackupWalletActivity extends AbstractWalletActivity {
public static void start(final Context context) {
context.startActivity(new Intent(context, BackupWalletActivity.class));
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
log.info("Referrer: {}", ActivityCompat.getReferrer(this));
BackupWalletDialogFragment.show(getSupportFragmentManager());
}
}
......@@ -155,10 +155,9 @@ public class BackupWalletDialogFragment extends DialogFragment {
// dummies, just to make buttons show
builder.setPositiveButton(R.string.button_ok, null);
builder.setNegativeButton(R.string.button_cancel, null);
builder.setCancelable(false);
final AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(final DialogInterface d) {
......@@ -177,6 +176,7 @@ public class BackupWalletDialogFragment extends DialogFragment {
@Override
public void onClick(final View v) {
dismissAllowingStateLoss();
activity.finish();
}
});
......@@ -240,6 +240,12 @@ public class BackupWalletDialogFragment extends DialogFragment {
super.onDismiss(dialog);
}
@Override
public void onCancel(final DialogInterface dialog) {
activity.finish();
super.onCancel(dialog);
}
private void handleGo() {
final String password = passwordView.getText().toString().trim();
final String passwordAgain = passwordAgainView.getText().toString().trim();
......@@ -337,6 +343,7 @@ public class BackupWalletDialogFragment extends DialogFragment {
log.info("cancelled backing up wallet");
passwordView.setEnabled(true);
passwordAgainView.setEnabled(true);
activity.finish();
}
} else {
super.onActivityResult(requestCode, resultCode, intent);
......@@ -358,6 +365,8 @@ public class BackupWalletDialogFragment extends DialogFragment {
private static final String FRAGMENT_TAG = SuccessDialogFragment.class.getName();
private static final String KEY_TARGET = "target";
private Activity activity;
public static void showDialog(final FragmentManager fm, final String target) {
final DialogFragment newFragment = new SuccessDialogFragment();
final Bundle args = new Bundle();
......@@ -366,13 +375,24 @@ public class BackupWalletDialogFragment extends DialogFragment {
newFragment.show(fm, FRAGMENT_TAG);
}
@Override
public void onAttach(final Context context) {
super.onAttach(context);
this.activity = (Activity) context;
}
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final String target = getArguments().getString(KEY_TARGET);
final DialogBuilder dialog = new DialogBuilder(getContext());
dialog.setTitle(R.string.export_keys_dialog_title);
dialog.setMessage(Html.fromHtml(getString(R.string.export_keys_dialog_success, target)));
dialog.singleDismissButton(null);
dialog.singleDismissButton(new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
activity.finish();
}
});
return dialog.create();
}
}
......@@ -381,6 +401,8 @@ public class BackupWalletDialogFragment extends DialogFragment {
private static final String FRAGMENT_TAG = ErrorDialogFragment.class.getName();
private static final String KEY_EXCEPTION_MESSAGE = "exception_message";
private Activity activity;
public static void showDialog(final FragmentManager fm, final String exceptionMessage) {
final DialogFragment newFragment = new ErrorDialogFragment();
final Bundle args = new Bundle();
......@@ -389,13 +411,24 @@ public class BackupWalletDialogFragment extends DialogFragment {
newFragment.show(fm, FRAGMENT_TAG);
}
@Override
public void onAttach(final Context context) {
super.onAttach(context);
this.activity = (Activity) context;
}
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final String exceptionMessage = getArguments().getString(KEY_EXCEPTION_MESSAGE);
final DialogBuilder dialog = DialogBuilder.warn(getContext(),
R.string.import_export_keys_dialog_failure_title);
dialog.setMessage(getString(R.string.export_keys_dialog_failure, exceptionMessage));
dialog.singleDismissButton(null);
dialog.singleDismissButton(new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
activity.finish();
}
});
return dialog.create();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment