@@ -147,13 +147,16 @@ private void checkForError() {
147
147
if (!BuildConfig .DEBUG && serverUri .getScheme ().equals ("http" )) { //Production build and not https
148
148
showHTTPDialog (serverURL );
149
149
} else {
150
+ showBackends (httpScheme , serverURL );
150
151
}
151
152
}
152
153
}
153
154
155
+ private void showBackends (String httpScheme , String serverURL ) {
154
156
Uri serverUri = Uri .parse (serverURL );
157
+
155
158
if (serverUri .isRelative ()) {
156
- serverUri = serverUri .buildUpon ().scheme (" http " ).build();
159
+ serverUri = serverUri .buildUpon ().scheme (httpScheme ).build ();
157
160
}
158
161
159
162
// 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() {
165
168
mServerEditText .setText (serverUri .toString ());
166
169
mServerEditText .setEnabled (false );
167
170
((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
+
169
207
private void showHTTPDialog (final String serverURL ) {
170
208
new AlertDialog .Builder (this )
171
209
.setTitle (R .string .http_or_https )
172
210
.setMessage (R .string .http_message )
173
211
.setPositiveButton (R .string .use_https , new DialogInterface .OnClickListener () {
174
212
public void onClick (DialogInterface dialog , int which ) {
175
213
dialog .dismiss ();
214
+ showBackends ("https" , serverURL );
176
215
}
177
216
})
178
217
.setNeutralButton (R .string .use_http , new DialogInterface .OnClickListener () {
179
218
public void onClick (DialogInterface dialog , int which ) {
180
219
dialog .dismiss ();
220
+ showBackends ("http" , serverURL );
181
221
}
182
222
})
183
223
.setNegativeButton (android .R .string .cancel , new DialogInterface .OnClickListener () {
0 commit comments