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

Commit a5b9440

Browse files
Sam1301timabbott
authored andcommitted
Reset zulipServices object during login.
During login, new zulipServices object should be created to prevent unnecessary caching of previously entered server url. Also, any leading or trailing whitespaces should be removed from the url before making the network request. Fixes: #227.
1 parent 1894a03 commit a5b9440

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void afterLogin() {
187187
}
188188

189189
public ZulipServices getZulipServices() {
190-
if(zulipServices == null) {
190+
if (zulipServices == null) {
191191
HttpLoggingInterceptor logging = new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY);
192192
zulipServices = new Retrofit.Builder()
193193
.client(new OkHttpClient.Builder().readTimeout(60, TimeUnit.SECONDS)
@@ -202,6 +202,10 @@ public ZulipServices getZulipServices() {
202202
return zulipServices;
203203
}
204204

205+
public void setZulipServices(ZulipServices zulipServices) {
206+
this.zulipServices = zulipServices;
207+
}
208+
205209
public Gson getGson() {
206210
if(gson == null) {
207211
gson = buildGson();

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ protected void onStop() {
151151

152152
private void checkForError() {
153153
String serverURL = serverIn.getText().toString();
154+
155+
// trim leading or trailing white spaces in Url
156+
serverURL = serverURL.trim();
157+
154158
int errorMessage = R.string.invalid_server_domain;
155159
String httpScheme = (BuildConfig.DEBUG) ? "http" : "https";
156160

@@ -184,6 +188,11 @@ public void onSaveInstanceState(Bundle savedInstanceState){
184188
}
185189

186190
private void showBackends(String httpScheme, String serverURL) {
191+
// if server url does not end with "/", then append it
192+
if (!serverURL.endsWith("/")) {
193+
serverURL = serverURL + "/";
194+
}
195+
187196
Uri serverUri = Uri.parse(serverURL);
188197

189198
serverUri = serverUri.buildUpon().scheme(httpScheme).build();
@@ -198,6 +207,9 @@ private void showBackends(String httpScheme, String serverURL) {
198207
mServerEditText.setEnabled(false);
199208
((ZulipApp) getApplication()).setServerURL(serverUri.toString());
200209

210+
// create new zulipServices object every time by setting it to null
211+
getApp().setZulipServices(null);
212+
201213
getServices()
202214
.getAuthBackends()
203215
.enqueue(new DefaultCallback<ZulipBackendResponse>() {

0 commit comments

Comments
 (0)