Browse Source

SetupEncryptionDialogFragment: use builtin onCancel for setting cancel result

This captures back button as well

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 years ago
parent
commit
1b945b6131

+ 11 - 5
app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java

@@ -155,11 +155,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
         MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(v.getContext());
         builder.setView(v).setPositiveButton(R.string.common_ok, null)
             .setNeutralButton(R.string.common_cancel, (dialog, which) -> {
-                final FragmentManager parentFragmentManager = getParentFragmentManager();
-                final Bundle bundle = new Bundle();
-                bundle.putString(RESULT_KEY, RESULT_CANCELED);
-                parentFragmentManager.setFragmentResult(RESULT_REQUEST_KEY, bundle);
-                dismiss();
+                dialog.cancel();
             })
             .setTitle(R.string.end_to_end_encryption_title);
 
@@ -265,6 +261,16 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
         return dialog;
     }
 
+
+    @Override
+    public void onCancel(@NonNull DialogInterface dialog) {
+        super.onCancel(dialog);
+        final FragmentManager parentFragmentManager = getParentFragmentManager();
+        final Bundle bundle = new Bundle();
+        bundle.putString(RESULT_KEY, RESULT_CANCELED);
+        parentFragmentManager.setFragmentResult(RESULT_REQUEST_KEY, bundle);
+    }
+
     public class DownloadKeysAsyncTask extends AsyncTask<Void, Void, String> {
         @Override
         protected void onPreExecute() {