android: Change progress dialog handling

With the previous code the dialog sometimes was hidden for a short while
before it got reopened.
This commit is contained in:
Tobias Brunner
2013-09-26 13:53:25 +02:00
parent cfed5679b8
commit 00f7b29422
@@ -57,6 +57,8 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
private TextView mStateView; private TextView mStateView;
private int stateBaseColor; private int stateBaseColor;
private Button mActionButton; private Button mActionButton;
private ProgressDialog mConnectDialog;
private ProgressDialog mDisconnectDialog;
private ProgressDialog mProgressDialog; private ProgressDialog mProgressDialog;
private AlertDialog mErrorDialog; private AlertDialog mErrorDialog;
private long mErrorConnectionID; private long mErrorConnectionID;
@@ -192,7 +194,6 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
return; return;
} }
hideProgressDialog();
enableActionButton(false); enableActionButton(false);
mProfileNameView.setText(name); mProfileNameView.setText(name);
@@ -200,6 +201,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
{ {
case DISABLED: case DISABLED:
showProfile(false); showProfile(false);
hideProgressDialog();
mStateView.setText(R.string.state_disabled); mStateView.setText(R.string.state_disabled);
mStateView.setTextColor(stateBaseColor); mStateView.setTextColor(stateBaseColor);
break; break;
@@ -211,6 +213,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
break; break;
case CONNECTED: case CONNECTED:
showProfile(true); showProfile(true);
hideProgressDialog();
enableActionButton(true); enableActionButton(true);
mStateView.setText(R.string.state_connected); mStateView.setText(R.string.state_connected);
mStateView.setTextColor(getResources().getColor(R.color.success_text)); mStateView.setTextColor(getResources().getColor(R.color.success_text));
@@ -295,6 +298,7 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
{ {
mProgressDialog.dismiss(); mProgressDialog.dismiss();
mProgressDialog = null; mProgressDialog = null;
mDisconnectDialog = mConnectDialog = null;
} }
} }
@@ -315,12 +319,18 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
private void showConnectDialog(String profile, String gateway) private void showConnectDialog(String profile, String gateway)
{ {
mProgressDialog = new ProgressDialog(getActivity()); if (mConnectDialog != null)
mProgressDialog.setTitle(String.format(getString(R.string.connecting_title), profile)); { /* already showing the dialog */
mProgressDialog.setMessage(String.format(getString(R.string.connecting_message), gateway)); return;
mProgressDialog.setIndeterminate(true); }
mProgressDialog.setCancelable(false); hideProgressDialog();
mProgressDialog.setButton(getString(android.R.string.cancel), mConnectDialog = new ProgressDialog(getActivity());
mConnectDialog.setTitle(String.format(getString(R.string.connecting_title), profile));
mConnectDialog.setMessage(String.format(getString(R.string.connecting_message), gateway));
mConnectDialog.setIndeterminate(true);
mConnectDialog.setCancelable(false);
mConnectDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
getString(android.R.string.cancel),
new DialogInterface.OnClickListener() new DialogInterface.OnClickListener()
{ {
@Override @Override
@@ -332,16 +342,23 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
} }
} }
}); });
mProgressDialog.show(); mConnectDialog.show();
mProgressDialog = mConnectDialog;
} }
private void showDisconnectDialog(String profile) private void showDisconnectDialog(String profile)
{ {
mProgressDialog = new ProgressDialog(getActivity()); if (mDisconnectDialog != null)
mProgressDialog.setMessage(getString(R.string.state_disconnecting)); { /* already showing the dialog */
mProgressDialog.setIndeterminate(true); return;
mProgressDialog.setCancelable(false); }
mProgressDialog.show(); hideProgressDialog();
mDisconnectDialog = new ProgressDialog(getActivity());
mDisconnectDialog.setMessage(getString(R.string.state_disconnecting));
mDisconnectDialog.setIndeterminate(true);
mDisconnectDialog.setCancelable(false);
mDisconnectDialog.show();
mProgressDialog = mDisconnectDialog;
} }
private void showErrorDialog(int textid) private void showErrorDialog(int textid)