]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Add disconnect button to dialog if already connected to profile
authorTobias Brunner <tobias@strongswan.org>
Tue, 22 Aug 2017 16:28:39 +0000 (18:28 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 4 Sep 2017 08:41:30 +0000 (10:41 +0200)
src/frontends/android/app/src/main/java/org/strongswan/android/ui/MainActivity.java

index f2a9eaaf8d7c01e322658858e2ea92c12839cca8..c0e375da45a5fd866fd3b4c21f6b13230b180b95 100644 (file)
@@ -474,42 +474,65 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
                                button = R.string.disconnect;
                        }
 
-                       return new AlertDialog.Builder(getActivity())
-                               .setIcon(icon)
-                               .setTitle(String.format(getString(title), profileInfo.getString(PROFILE_NAME)))
-                               .setMessage(message)
-                               .setPositiveButton(button, new DialogInterface.OnClickListener()
+                       DialogInterface.OnClickListener connectListener = new DialogInterface.OnClickListener()
+                       {
+                               @Override
+                               public void onClick(DialogInterface dialog, int which)
                                {
-                                       @Override
-                                       public void onClick(DialogInterface dialog, int whichButton)
+                                       MainActivity activity = (MainActivity)getActivity();
+                                       activity.startVpnProfile(profileInfo);
+                               }
+                       };
+                       DialogInterface.OnClickListener disconnectListener = new DialogInterface.OnClickListener()
+                       {
+                               @Override
+                               public void onClick(DialogInterface dialog, int which)
+                               {
+                                       MainActivity activity = (MainActivity)getActivity();
+                                       if (activity.mService != null)
                                        {
-                                               MainActivity activity = (MainActivity)getActivity();
-                                               if (profileInfo.getBoolean(PROFILE_DISCONNECT))
-                                               {
-                                                       if (activity.mService != null)
-                                                       {
-                                                               activity.mService.disconnect();
-                                                       }
-                                               }
-                                               else
-                                               {
-                                                       activity.startVpnProfile(profileInfo);
-                                               }
+                                               activity.mService.disconnect();
                                        }
-                               })
-                               .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener()
+                               }
+                       };
+                       DialogInterface.OnClickListener cancelListener = new DialogInterface.OnClickListener()
+                       {
+                               @Override
+                               public void onClick(DialogInterface dialog, int which)
                                {
-                                       @Override
-                                       public void onClick(DialogInterface dialog, int which)
-                                       {
-                                               dismiss();
-                                               if (!profileInfo.getBoolean(PROFILE_FOREGROUND))
-                                               {       /* if the app was not in the foreground before this action was triggered
-                                                        * externally, we just close the activity if canceled */
-                                                       getActivity().finish();
-                                               }
+                                       dismiss();
+                                       if (!profileInfo.getBoolean(PROFILE_FOREGROUND))
+                                       {       /* if the app was not in the foreground before this action was triggered
+                                                * externally, we just close the activity if canceled */
+                                               getActivity().finish();
                                        }
-                               }).create();
+                               }
+                       };
+
+                       AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
+                               .setIcon(icon)
+                               .setTitle(String.format(getString(title), profileInfo.getString(PROFILE_NAME)))
+                               .setMessage(message);
+
+                       if (profileInfo.getBoolean(PROFILE_DISCONNECT))
+                       {
+                               builder.setPositiveButton(button, disconnectListener);
+                       }
+                       else
+                       {
+                               builder.setPositiveButton(button, connectListener);
+                       }
+
+                       if (profileInfo.getBoolean(PROFILE_RECONNECT))
+                       {
+                               builder.setNegativeButton(R.string.disconnect, disconnectListener);
+                               builder.setNeutralButton(android.R.string.cancel, cancelListener);
+                       }
+                       else
+                       {
+                               builder.setNegativeButton(android.R.string.cancel, cancelListener);
+                       }
+                       return builder.create();
                }
        }