Browse Source

Close SetupEncryptionActivity when dialog is dismissed

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

+ 12 - 1
app/src/main/java/com/owncloud/android/ui/activity/SetupEncryptionActivity.kt

@@ -41,6 +41,17 @@ class SetupEncryptionActivity : AppCompatActivity() {
         }
 
         val setupEncryptionDialogFragment = SetupEncryptionDialogFragment.newInstance(user, -1)
-        setupEncryptionDialogFragment.show(supportFragmentManager, null)
+        supportFragmentManager.setFragmentResultListener(
+            SetupEncryptionDialogFragment.RESULT_REQUEST_KEY,
+            this
+        ) { requestKey, result ->
+            if (requestKey == SetupEncryptionDialogFragment.RESULT_REQUEST_KEY && result.getString(
+                    SetupEncryptionDialogFragment.RESULT_KEY
+                ) == SetupEncryptionDialogFragment.RESULT_CANCELED
+            ) {
+                finish()
+            }
+        }
+        setupEncryptionDialogFragment.show(supportFragmentManager, "setup_encryption")
     }
 }

+ 12 - 1
app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java

@@ -62,6 +62,7 @@ import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
 import androidx.appcompat.app.AlertDialog;
 import androidx.fragment.app.DialogFragment;
+import androidx.fragment.app.FragmentManager;
 
 import static com.owncloud.android.utils.EncryptionUtils.decodeStringToBase64Bytes;
 import static com.owncloud.android.utils.EncryptionUtils.decryptStringAsymmetric;
@@ -79,6 +80,10 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
     public static final String SETUP_ENCRYPTION_DIALOG_TAG = "SETUP_ENCRYPTION_DIALOG_TAG";
     public static final String ARG_POSITION = "ARG_POSITION";
 
+    public static final String RESULT_REQUEST_KEY = "RESULT_REQUEST";
+    public static final String RESULT_KEY = "RESULT_KEY";
+    public static final String RESULT_CANCELED = "RESULT_CANCELED";
+
     private static final String ARG_USER = "ARG_USER";
     private static final String TAG = SetupEncryptionDialogFragment.class.getSimpleName();
 
@@ -149,7 +154,13 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
     private Dialog createDialog(View v) {
         MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(v.getContext());
         builder.setView(v).setPositiveButton(R.string.common_ok, null)
-            .setNeutralButton(R.string.common_cancel, 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();
+            })
             .setTitle(R.string.end_to_end_encryption_title);
 
         viewThemeUtils.dialog.colorMaterialAlertDialogBackground(v.getContext(), builder);