16
16
import android .support .v4 .app .FragmentTransaction ;
17
17
import android .support .v7 .app .AlertDialog ;
18
18
19
+ import android .text .TextUtils ;
19
20
import android .view .Menu ;
20
21
import android .view .MenuInflater ;
21
22
import android .view .MenuItem ;
22
23
import android .view .View ;
23
24
import android .widget .LinearLayout ;
24
25
import android .widget .ProgressBar ;
25
26
27
+ import android .widget .Toast ;
26
28
import com .google .gson .Gson ;
27
29
import com .google .gson .GsonBuilder ;
28
30
31
+ import io .reactivex .functions .Consumer ;
32
+ import java .io .IOException ;
33
+ import java .net .UnknownHostException ;
29
34
import java .util .List ;
30
35
31
36
import javax .inject .Inject ;
@@ -427,8 +432,17 @@ private void refreshView(LocationServiceManager.LocationChangeType locationChang
427
432
.loadAttractionsFromLocation (curLatLng ))
428
433
.subscribeOn (Schedulers .io ())
429
434
.observeOn (AndroidSchedulers .mainThread ())
430
- .subscribe (this ::populatePlaces );
431
- } else if (locationChangeType .equals (LocationServiceManager .LocationChangeType .LOCATION_SLIGHTLY_CHANGED )) {
435
+ .subscribe (this ::populatePlaces ,
436
+ throwable -> {
437
+ if (throwable instanceof UnknownHostException ) {
438
+ showErrorMessage (getString (R .string .slow_internet ));
439
+ } else {
440
+ showErrorMessage (throwable .getMessage ());
441
+ }
442
+ progressBar .setVisibility (View .GONE );
443
+ });
444
+ } else if (locationChangeType
445
+ .equals (LocationServiceManager .LocationChangeType .LOCATION_SLIGHTLY_CHANGED )) {
432
446
Gson gson = new GsonBuilder ()
433
447
.registerTypeAdapter (Uri .class , new UriSerializer ())
434
448
.create ();
@@ -451,7 +465,7 @@ private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo)
451
465
if (placeList .size () == 0 ) {
452
466
ViewUtil .showSnackbar (findViewById (R .id .container ), R .string .no_nearby );
453
467
}
454
-
468
+
455
469
bundle .putString ("PlaceList" , gsonPlaceList );
456
470
//bundle.putString("CurLatLng", gsonCurLatLng);
457
471
bundle .putString ("BoundaryCoord" , gsonBoundaryCoordinates );
@@ -580,7 +594,15 @@ private void updateMapFragment(boolean isSlightUpdate) {
580
594
.loadAttractionsFromLocation (curLatLng ))
581
595
.subscribeOn (Schedulers .io ())
582
596
.observeOn (AndroidSchedulers .mainThread ())
583
- .subscribe (this ::populatePlaces );
597
+ .subscribe (this ::populatePlaces ,
598
+ throwable -> {
599
+ if (throwable instanceof UnknownHostException ) {
600
+ showErrorMessage (getString (R .string .slow_internet ));
601
+ } else {
602
+ showErrorMessage (throwable .getMessage ());
603
+ }
604
+ progressBar .setVisibility (View .GONE );
605
+ });
584
606
nearbyMapFragment .setBundleForUpdtes (bundle );
585
607
nearbyMapFragment .updateMapSignificantly ();
586
608
updateListFragment ();
@@ -646,4 +668,11 @@ public void onLocationChangedSlightly(LatLng latLng) {
646
668
public void prepareViewsForSheetPosition (int bottomSheetState ) {
647
669
// TODO
648
670
}
671
+
672
+ private void showErrorMessage (String message ) {
673
+ if (TextUtils .isEmpty (message )) {
674
+ message = getString (R .string .something_went_wrong );
675
+ }
676
+ ViewUtil .showLongToast (NearbyActivity .this , message );
677
+ }
649
678
}
0 commit comments