|
5 | 5 | import android.content.DialogInterface;
|
6 | 6 | import android.content.Intent;
|
7 | 7 | import android.content.IntentSender.SendIntentException;
|
| 8 | +import android.net.ConnectivityManager; |
| 9 | +import android.net.NetworkInfo; |
8 | 10 | import android.net.Uri;
|
9 | 11 | import android.os.Build;
|
10 | 12 | import android.os.Bundle;
|
|
15 | 17 | import android.util.Patterns;
|
16 | 18 | import android.view.View;
|
17 | 19 | import android.view.inputmethod.InputMethodManager;
|
| 20 | +import android.webkit.URLUtil; |
18 | 21 | import android.widget.Button;
|
19 | 22 | import android.widget.EditText;
|
20 | 23 | import android.widget.Toast;
|
@@ -197,6 +200,13 @@ private void showBackends(String httpScheme, String serverURL) {
|
197 | 200 | serverURL = serverURL + "/";
|
198 | 201 | }
|
199 | 202 |
|
| 203 | + boolean isValid = URLUtil.isValidUrl(String.valueOf(serverURL)); |
| 204 | + |
| 205 | + if (!isValid){ |
| 206 | + Toast.makeText(LoginActivity.this, R.string.invalid_url , Toast.LENGTH_SHORT).show(); |
| 207 | + return; |
| 208 | + } |
| 209 | + |
200 | 210 | Uri serverUri = Uri.parse(serverURL);
|
201 | 211 |
|
202 | 212 | serverUri = serverUri.buildUpon().scheme(httpScheme).build();
|
@@ -251,12 +261,28 @@ public void onError(Call<ZulipBackendResponse> call, Response<ZulipBackendRespon
|
251 | 261 | @Override
|
252 | 262 | public void onFailure(Call<ZulipBackendResponse> call, Throwable t) {
|
253 | 263 | super.onFailure(call, t);
|
254 |
| - Toast.makeText(LoginActivity.this, R.string.toast_login_failed_fetching_backends, Toast.LENGTH_SHORT).show(); |
| 264 | + if (!isNetworkAvailable()) |
| 265 | + { |
| 266 | + Toast.makeText(LoginActivity.this, R.string.toast_no_internet_connection, Toast.LENGTH_SHORT).show(); |
| 267 | + } |
| 268 | + else |
| 269 | + { |
| 270 | + Toast.makeText(LoginActivity.this, R.string.invalid_url, Toast.LENGTH_SHORT).show(); |
| 271 | + } |
255 | 272 | }
|
256 | 273 | });
|
257 | 274 |
|
258 | 275 | }
|
259 | 276 |
|
| 277 | + private boolean isNetworkAvailable() { |
| 278 | + ConnectivityManager connectivityManager |
| 279 | + = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); |
| 280 | + NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); |
| 281 | + return activeNetworkInfo != null && activeNetworkInfo.isConnected(); |
| 282 | + } |
| 283 | + |
| 284 | + |
| 285 | + |
260 | 286 | private void showHTTPDialog(final String serverURL) {
|
261 | 287 | new AlertDialog.Builder(this)
|
262 | 288 | .setTitle(R.string.http_or_https)
|
@@ -353,7 +379,15 @@ public void onConnectionFailed(ConnectionResult result) {
|
353 | 379 | }
|
354 | 380 | } else {
|
355 | 381 | connectionProgressDialog.dismiss();
|
356 |
| - Toast.makeText(LoginActivity.this, R.string.google_app_login_failed, Toast.LENGTH_SHORT).show(); |
| 382 | + if (!isNetworkAvailable()) |
| 383 | + { |
| 384 | + Toast.makeText(LoginActivity.this,R.string.toast_no_internet_connection, Toast.LENGTH_SHORT).show(); |
| 385 | + } |
| 386 | + else |
| 387 | + { |
| 388 | + Toast.makeText(LoginActivity.this, R.string.google_app_login_failed, Toast.LENGTH_SHORT).show(); |
| 389 | + } |
| 390 | + |
357 | 391 | }
|
358 | 392 | }
|
359 | 393 | }
|
@@ -422,15 +456,30 @@ public void onError(Call<LoginResponse> call, Response<LoginResponse> response)
|
422 | 456 | Toast.makeText(LoginActivity.this, R.string.login_activity_toast_login_error, Toast.LENGTH_LONG).show();
|
423 | 457 | }
|
424 | 458 | } else {
|
425 |
| - Toast.makeText(LoginActivity.this, R.string.login_activity_toast_login_error, Toast.LENGTH_LONG).show(); |
| 459 | + if (!isNetworkAvailable()) |
| 460 | + { |
| 461 | + Toast.makeText(LoginActivity.this, R.string.toast_no_internet_connection, Toast.LENGTH_LONG).show(); |
| 462 | + } |
| 463 | + else |
| 464 | + { |
| 465 | + Toast.makeText(LoginActivity.this, R.string.login_activity_toast_login_error, Toast.LENGTH_LONG).show(); |
| 466 | + } |
| 467 | + |
426 | 468 | }
|
427 | 469 | }
|
428 | 470 |
|
429 | 471 | @Override
|
430 | 472 | public void onFailure(Call<LoginResponse> call, Throwable t) {
|
431 | 473 | super.onFailure(call, t);
|
432 | 474 | connectionProgressDialog.dismiss();
|
433 |
| - Toast.makeText(LoginActivity.this, R.string.login_activity_toast_login_error, Toast.LENGTH_LONG).show(); |
| 475 | + if (!isNetworkAvailable()) |
| 476 | + { |
| 477 | + Toast.makeText(LoginActivity.this, R.string.toast_no_internet_connection, Toast.LENGTH_LONG).show(); |
| 478 | + } |
| 479 | + else |
| 480 | + { |
| 481 | + Toast.makeText(LoginActivity.this, R.string.login_activity_toast_login_error, Toast.LENGTH_LONG).show(); |
| 482 | + } |
434 | 483 | }
|
435 | 484 | });
|
436 | 485 |
|
|
0 commit comments