android: Add disconnect button to dialog if already connected to profile
This commit is contained in:
+38
-15
@@ -474,30 +474,28 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
|
|||||||
button = R.string.disconnect;
|
button = R.string.disconnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AlertDialog.Builder(getActivity())
|
DialogInterface.OnClickListener connectListener = new DialogInterface.OnClickListener()
|
||||||
.setIcon(icon)
|
|
||||||
.setTitle(String.format(getString(title), profileInfo.getString(PROFILE_NAME)))
|
|
||||||
.setMessage(message)
|
|
||||||
.setPositiveButton(button, new DialogInterface.OnClickListener()
|
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int whichButton)
|
public void onClick(DialogInterface dialog, int which)
|
||||||
{
|
{
|
||||||
MainActivity activity = (MainActivity)getActivity();
|
MainActivity activity = (MainActivity)getActivity();
|
||||||
if (profileInfo.getBoolean(PROFILE_DISCONNECT))
|
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)
|
if (activity.mService != null)
|
||||||
{
|
{
|
||||||
activity.mService.disconnect();
|
activity.mService.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
};
|
||||||
{
|
DialogInterface.OnClickListener cancelListener = new DialogInterface.OnClickListener()
|
||||||
activity.startVpnProfile(profileInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener()
|
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which)
|
public void onClick(DialogInterface dialog, int which)
|
||||||
@@ -509,7 +507,32 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
|
|||||||
getActivity().finish();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user