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

Commit a5cbeae

Browse files
kunall17niftynei
authored andcommitted
Fetch backends using the httpScheme
1 parent 82ac093 commit a5cbeae

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

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

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,16 @@ private void checkForError() {
147147
if (!BuildConfig.DEBUG && serverUri.getScheme().equals("http")) { //Production build and not https
148148
showHTTPDialog(serverURL);
149149
} else {
150+
showBackends(httpScheme, serverURL);
150151
}
151152
}
152153
}
153154

155+
private void showBackends(String httpScheme, String serverURL) {
154156
Uri serverUri = Uri.parse(serverURL);
157+
155158
if (serverUri.isRelative()) {
156-
serverUri = serverUri.buildUpon().scheme("http").build();
159+
serverUri = serverUri.buildUpon().scheme(httpScheme).build();
157160
}
158161

159162
// if does not begin with "api.zulip.com" and if the path is empty, use "/api" as first segment in the path
@@ -165,19 +168,56 @@ private void checkForError() {
165168
mServerEditText.setText(serverUri.toString());
166169
mServerEditText.setEnabled(false);
167170
((ZulipApp) getApplication()).setServerURL(serverUri.toString());
168-
return true;
171+
AsyncGetBackends asyncGetBackends = new AsyncGetBackends(ZulipApp.get());
172+
asyncGetBackends.setCallback(new AsyncTaskCompleteListener() {
173+
@Override
174+
public void onTaskComplete(String result, JSONObject jsonObject) {
175+
try {
176+
JSONObject object = new JSONObject(result);
177+
if (!object.getString("result").equals("success")) {
178+
onTaskFailure("");
179+
return;
180+
}
181+
182+
if (object.getString("password").equals("true")) {
183+
findViewById(R.id.passwordAuthLayout).setVisibility(View.VISIBLE);
184+
}
185+
186+
if (object.getString("google").equals("true")) {
187+
findViewById(R.id.google_sign_in_button).setVisibility(View.VISIBLE);
188+
}
189+
190+
if (object.getString("dev").equals("true")) {
191+
findViewById(R.id.local_server_button).setVisibility(View.VISIBLE);
192+
}
193+
showLoginFields();
194+
} catch (JSONException e) {
195+
e.printStackTrace();
196+
}
197+
}
198+
199+
@Override
200+
public void onTaskFailure(String result) {
201+
Toast.makeText(LoginActivity.this, "Failed to fetch Backends!", Toast.LENGTH_SHORT).show();
202+
}
203+
});
204+
asyncGetBackends.execute();
205+
}
206+
169207
private void showHTTPDialog(final String serverURL) {
170208
new AlertDialog.Builder(this)
171209
.setTitle(R.string.http_or_https)
172210
.setMessage(R.string.http_message)
173211
.setPositiveButton(R.string.use_https, new DialogInterface.OnClickListener() {
174212
public void onClick(DialogInterface dialog, int which) {
175213
dialog.dismiss();
214+
showBackends("https", serverURL);
176215
}
177216
})
178217
.setNeutralButton(R.string.use_http, new DialogInterface.OnClickListener() {
179218
public void onClick(DialogInterface dialog, int which) {
180219
dialog.dismiss();
220+
showBackends("http", serverURL);
181221
}
182222
})
183223
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

0 commit comments

Comments
 (0)