Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit edbbb14

Browse files
committed
Save the default server URL or the input server URL
1 parent 4309fd1 commit edbbb14

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

app/src/main/java/com/zulip/android/ZulipApp.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ZulipApp extends Application {
3737
public static final String EMAIL = "email";
3838
private static ZulipApp instance;
3939
private static final String USER_AGENT = "ZulipMobile";
40+
private static final String DEFAULT_SERVER_URL = "https://api.zulip.com/";
4041
private Person you;
4142
private SharedPreferences settings;
4243
private String api_key;
@@ -152,7 +153,7 @@ public String getServerURI() {
152153
if (getEmail().equals("[email protected]")) {
153154
return "http://10.0.2.2:9991/api/";
154155
}
155-
return settings.getString("server_url", "https://api.zulip.com/");
156+
return settings.getString("server_url", DEFAULT_SERVER_URL);
156157
}
157158
public String getApiKey() {
158159
return api_key;
@@ -198,6 +199,10 @@ public void setServerURL(String serverURL) {
198199
ed.apply();
199200
}
200201

202+
public void useDefaultServerURL() {
203+
setServerURL(DEFAULT_SERVER_URL);
204+
}
205+
201206
public void setLoggedInApiKey(String apiKey) {
202207
this.api_key = apiKey;
203208
Editor ed = this.settings.edit();

app/src/main/java/com/zulip/android/activities/LoginActivity.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class LoginActivity extends FragmentActivity implements View.OnClickListe
4040
private GoogleApiClient mGoogleApiClient;
4141
private EditText mServerEditText;
4242
private View mGoogleSignInButton;
43+
private CheckBox mUseZulipCheckbox;
4344

4445
@Override
4546
protected void onCreate(Bundle savedInstanceState) {
@@ -50,11 +51,13 @@ protected void onCreate(Bundle savedInstanceState) {
5051
// Progress bar to be displayed if the connection failure is not resolved.
5152
connectionProgressDialog = new ProgressDialog(this);
5253
connectionProgressDialog.setMessage(getString(R.string.signing_in));
53-
findViewById(R.id.google_sign_in_button).setOnClickListener(this);
54-
findViewById(R.id.zulip_login).setOnClickListener(this);
55-
((CheckBox) findViewById(R.id.checkbox_usezulip)).setOnCheckedChangeListener(this);
54+
55+
mUseZulipCheckbox = ((CheckBox) findViewById(R.id.checkbox_usezulip));
5656
mServerEditText = (EditText) findViewById(R.id.server_url);
5757
mGoogleSignInButton = findViewById(R.id.google_sign_in_button);
58+
findViewById(R.id.google_sign_in_button).setOnClickListener(this);
59+
findViewById(R.id.zulip_login).setOnClickListener(this);
60+
mUseZulipCheckbox.setOnCheckedChangeListener(this);
5861
}
5962

6063
@Override
@@ -85,6 +88,11 @@ protected void onStop() {
8588
}
8689

8790
private void saveServerURL() {
91+
if (mUseZulipCheckbox.isChecked()) {
92+
((ZulipApp) getApplication()).useDefaultServerURL();
93+
return;
94+
}
95+
8896
String serverURL = mServerEditText.getText().toString();
8997
int errorMessage = R.string.invalid_server_domain;
9098

@@ -217,8 +225,9 @@ public void onClick(View v) {
217225
setupGoogleSignIn();
218226
break;
219227
case R.id.zulip_login:
220-
connectionProgressDialog.show();
221228
saveServerURL();
229+
connectionProgressDialog.show();
230+
if (!mUseZulipCheckbox.isChecked()) saveServerURL();
222231
AsyncLogin alog = new AsyncLogin(LoginActivity.this, ((EditText) findViewById(R.id.username)).getText().toString(),
223232
((EditText) findViewById(R.id.password)).getText().toString());
224233
// Remove the CPD when done

0 commit comments

Comments
 (0)