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 .ConnectException ;
34
+ import java .net .UnknownHostException ;
29
35
import java .util .List ;
30
36
31
37
import javax .inject .Inject ;
@@ -427,8 +433,14 @@ private void refreshView(LocationServiceManager.LocationChangeType locationChang
427
433
.loadAttractionsFromLocation (curLatLng ))
428
434
.subscribeOn (Schedulers .io ())
429
435
.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 )) {
432
444
Gson gson = new GsonBuilder ()
433
445
.registerTypeAdapter (Uri .class , new UriSerializer ())
434
446
.create ();
@@ -451,7 +463,7 @@ private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo)
451
463
if (placeList .size () == 0 ) {
452
464
ViewUtil .showSnackbar (findViewById (R .id .container ), R .string .no_nearby );
453
465
}
454
-
466
+
455
467
bundle .putString ("PlaceList" , gsonPlaceList );
456
468
//bundle.putString("CurLatLng", gsonCurLatLng);
457
469
bundle .putString ("BoundaryCoord" , gsonBoundaryCoordinates );
@@ -580,7 +592,12 @@ private void updateMapFragment(boolean isSlightUpdate) {
580
592
.loadAttractionsFromLocation (curLatLng ))
581
593
.subscribeOn (Schedulers .io ())
582
594
.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
+ });
584
601
nearbyMapFragment .setBundleForUpdtes (bundle );
585
602
nearbyMapFragment .updateMapSignificantly ();
586
603
updateListFragment ();
@@ -646,4 +663,8 @@ public void onLocationChangedSlightly(LatLng latLng) {
646
663
public void prepareViewsForSheetPosition (int bottomSheetState ) {
647
664
// TODO
648
665
}
666
+
667
+ private void showErrorMessage (String message ) {
668
+ ViewUtil .showLongToast (NearbyActivity .this , message );
669
+ }
649
670
}
0 commit comments