android: Clear error only when the user explicitly dismisses the dialog
authorTobias Brunner <tobias@strongswan.org>
Wed, 15 May 2013 16:35:00 +0000 (18:35 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 8 Jul 2013 16:49:28 +0000 (18:49 +0200)
The previous code worked fine on rotation changes as the fragment is
destroyed and recreated causing onCreate to be called, which restores the
saved error state.  But if the user switches to a different application
and then back this is not the case.  The dialog still gets dismissed (as
we have to do so to avoid nasty exceptions on rotation changes) but since
that implicitly cleared the error state the UI was never fully restored.

src/frontends/android/src/org/strongswan/android/ui/VpnStateFragment.java

index 738ed11..6aec7e7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012-2013 Tobias Brunner
  * Copyright (C) 2012 Giuliano Grassi
  * Copyright (C) 2012 Ralf Sager
  * Hochschule fuer Technik Rapperswil
@@ -305,6 +305,12 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                }
        }
 
+       private void clearError()
+       {
+               mError = ErrorState.NO_ERROR;
+               updateView();
+       }
+
        private void showConnectDialog(String profile, String gateway)
        {
                mProgressDialog = new ProgressDialog(getActivity());
@@ -345,6 +351,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                                @Override
                                public void onClick(DialogInterface dialog, int which)
                                {
+                                       clearError();
                                        dialog.dismiss();
                                        Intent logIntent = new Intent(getActivity(), LogActivity.class);
                                        startActivity(logIntent);
@@ -354,16 +361,15 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                                @Override
                                public void onClick(DialogInterface dialog, int id)
                                {
+                                       clearError();
                                        dialog.dismiss();
                                }
                        }).create();
                mErrorDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialog)
-                       {       /* clear the error */
-                               mError = ErrorState.NO_ERROR;
+                       {
                                mErrorDialog = null;
-                               updateView();
                        }
                });
                mErrorDialog.show();