1616import android .support .v4 .app .FragmentTransaction ;
1717import android .support .v7 .app .AlertDialog ;
1818
19+ import android .text .TextUtils ;
1920import android .view .Menu ;
2021import android .view .MenuInflater ;
2122import android .view .MenuItem ;
2223import android .view .View ;
2324import android .widget .LinearLayout ;
2425import android .widget .ProgressBar ;
2526
27+ import android .widget .Toast ;
2628import com .google .gson .Gson ;
2729import com .google .gson .GsonBuilder ;
2830
31+ import io .reactivex .functions .Consumer ;
32+ import java .io .IOException ;
33+ import java .net .ConnectException ;
34+ import java .net .UnknownHostException ;
2935import java .util .List ;
3036
3137import javax .inject .Inject ;
@@ -427,8 +433,14 @@ private void refreshView(LocationServiceManager.LocationChangeType locationChang
427433 .loadAttractionsFromLocation (curLatLng ))
428434 .subscribeOn (Schedulers .io ())
429435 .observeOn (AndroidSchedulers .mainThread ())
430- .subscribe (this ::populatePlaces );
431- } else if (locationChangeType .equals (LocationServiceManager .LocationChangeType .LOCATION_SLIGHTLY_CHANGED )) {
436+ .subscribe (this ::populatePlaces ,
437+ throwable -> {
438+ Timber .d (throwable );
439+ showErrorMessage (getString (R .string .error_fetching_nearby_places ));
440+ progressBar .setVisibility (View .GONE );
441+ });
442+ } else if (locationChangeType
443+ .equals (LocationServiceManager .LocationChangeType .LOCATION_SLIGHTLY_CHANGED )) {
432444 Gson gson = new GsonBuilder ()
433445 .registerTypeAdapter (Uri .class , new UriSerializer ())
434446 .create ();
@@ -451,7 +463,7 @@ private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo)
451463 if (placeList .size () == 0 ) {
452464 ViewUtil .showSnackbar (findViewById (R .id .container ), R .string .no_nearby );
453465 }
454-
466+
455467 bundle .putString ("PlaceList" , gsonPlaceList );
456468 //bundle.putString("CurLatLng", gsonCurLatLng);
457469 bundle .putString ("BoundaryCoord" , gsonBoundaryCoordinates );
@@ -580,7 +592,12 @@ private void updateMapFragment(boolean isSlightUpdate) {
580592 .loadAttractionsFromLocation (curLatLng ))
581593 .subscribeOn (Schedulers .io ())
582594 .observeOn (AndroidSchedulers .mainThread ())
583- .subscribe (this ::populatePlaces );
595+ .subscribe (this ::populatePlaces ,
596+ throwable -> {
597+ Timber .d (throwable );
598+ showErrorMessage (getString (R .string .error_fetching_nearby_places ));
599+ progressBar .setVisibility (View .GONE );
600+ });
584601 nearbyMapFragment .setBundleForUpdtes (bundle );
585602 nearbyMapFragment .updateMapSignificantly ();
586603 updateListFragment ();
@@ -646,4 +663,8 @@ public void onLocationChangedSlightly(LatLng latLng) {
646663 public void prepareViewsForSheetPosition (int bottomSheetState ) {
647664 // TODO
648665 }
666+
667+ private void showErrorMessage (String message ) {
668+ ViewUtil .showLongToast (NearbyActivity .this , message );
669+ }
649670}
0 commit comments