11package fr .free .nrw .commons .nearby ;
22
3+ import android .content .BroadcastReceiver ;
4+ import android .content .Context ;
35import android .content .Intent ;
6+ import android .content .IntentFilter ;
47import android .content .pm .PackageManager ;
58import android .net .Uri ;
69import android .os .Build ;
1013
1114import android .support .v4 .app .FragmentTransaction ;
1215import android .support .v7 .app .AlertDialog ;
16+ import android .util .Log ;
1317import android .view .Menu ;
1418import android .view .MenuInflater ;
1519import android .view .MenuItem ;
3337import fr .free .nrw .commons .location .LocationServiceManager ;
3438import fr .free .nrw .commons .location .LocationUpdateListener ;
3539import fr .free .nrw .commons .theme .NavigationBaseActivity ;
40+ import fr .free .nrw .commons .utils .NetworkUtils ;
3641import fr .free .nrw .commons .utils .UriSerializer ;
3742
3843import fr .free .nrw .commons .utils .ViewUtil ;
@@ -69,11 +74,14 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
6974 private boolean lockNearbyView ; //Determines if the nearby places needs to be refreshed
7075 private BottomSheetBehavior bottomSheetBehavior ; // Behavior for list bottom sheet
7176 private BottomSheetBehavior bottomSheetBehaviorForDetails ; // Behavior for details bottom sheet
72- private NearbyMapFragment nearbyMapFragment ;
77+ public NearbyMapFragment nearbyMapFragment ;
7378 private NearbyListFragment nearbyListFragment ;
7479 private static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment .class .getSimpleName ();
7580 private static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment .class .getSimpleName ();
7681
82+ private final String NETWORK_INTENT_ACTION = "android.net.conn.CONNECTIVITY_CHANGE" ;
83+ private BroadcastReceiver broadcastReceiver ;
84+
7785 @ Override
7886 protected void onCreate (Bundle savedInstanceState ) {
7987 super .onCreate (savedInstanceState );
@@ -271,6 +279,7 @@ protected void onResume() {
271279 super .onResume ();
272280 lockNearbyView = false ;
273281 checkGps ();
282+ addNetworkBroadcastReceiver ();
274283 }
275284
276285 @ Override
@@ -283,9 +292,28 @@ public void onPause() {
283292 // to the retained fragment object to perform its own cleanup.
284293 removeMapFragment ();
285294 removeListFragment ();
295+ unregisterReceiver (broadcastReceiver );
286296 }
287297 }
288298
299+ private void addNetworkBroadcastReceiver () {
300+ IntentFilter intentFilter = new IntentFilter (NETWORK_INTENT_ACTION );
301+
302+ broadcastReceiver = new BroadcastReceiver () {
303+
304+ @ Override
305+ public void onReceive (Context context , Intent intent ) {
306+ if (NetworkUtils .isInternetConnectionEstablished (NearbyActivity .this )) {
307+ refreshView (LocationServiceManager
308+ .LocationChangeType .LOCATION_SIGNIFICANTLY_CHANGED );
309+ } else {
310+ ViewUtil .showLongToast (NearbyActivity .this , getString (R .string .no_internet ));
311+ }
312+ }
313+ };
314+
315+ this .registerReceiver (broadcastReceiver , intentFilter );
316+ }
289317
290318
291319 /**
@@ -297,6 +325,12 @@ private void refreshView(LocationServiceManager.LocationChangeType locationChang
297325 if (lockNearbyView ) {
298326 return ;
299327 }
328+
329+ if (!NetworkUtils .isInternetConnectionEstablished (this )) {
330+ hideProgressBar ();
331+ return ;
332+ }
333+
300334 locationManager .registerLocationManager ();
301335 LatLng lastLocation = locationManager .getLastLocation ();
302336
0 commit comments