1
1
package fr .free .nrw .commons .nearby ;
2
2
3
+ import android .content .BroadcastReceiver ;
4
+ import android .content .Context ;
3
5
import android .content .Intent ;
6
+ import android .content .IntentFilter ;
4
7
import android .content .pm .PackageManager ;
5
8
import android .net .Uri ;
6
9
import android .os .Build ;
10
13
11
14
import android .support .v4 .app .FragmentTransaction ;
12
15
import android .support .v7 .app .AlertDialog ;
16
+ import android .util .Log ;
13
17
import android .view .Menu ;
14
18
import android .view .MenuInflater ;
15
19
import android .view .MenuItem ;
33
37
import fr .free .nrw .commons .location .LocationServiceManager ;
34
38
import fr .free .nrw .commons .location .LocationUpdateListener ;
35
39
import fr .free .nrw .commons .theme .NavigationBaseActivity ;
40
+ import fr .free .nrw .commons .utils .NetworkUtils ;
36
41
import fr .free .nrw .commons .utils .UriSerializer ;
37
42
38
43
import fr .free .nrw .commons .utils .ViewUtil ;
@@ -69,11 +74,14 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
69
74
private boolean lockNearbyView ; //Determines if the nearby places needs to be refreshed
70
75
private BottomSheetBehavior bottomSheetBehavior ; // Behavior for list bottom sheet
71
76
private BottomSheetBehavior bottomSheetBehaviorForDetails ; // Behavior for details bottom sheet
72
- private NearbyMapFragment nearbyMapFragment ;
77
+ public NearbyMapFragment nearbyMapFragment ;
73
78
private NearbyListFragment nearbyListFragment ;
74
79
private static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment .class .getSimpleName ();
75
80
private static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment .class .getSimpleName ();
76
81
82
+ private final String NETWORK_INTENT_ACTION = "android.net.conn.CONNECTIVITY_CHANGE" ;
83
+ private BroadcastReceiver broadcastReceiver ;
84
+
77
85
@ Override
78
86
protected void onCreate (Bundle savedInstanceState ) {
79
87
super .onCreate (savedInstanceState );
@@ -271,6 +279,7 @@ protected void onResume() {
271
279
super .onResume ();
272
280
lockNearbyView = false ;
273
281
checkGps ();
282
+ addNetworkBroadcastReceiver ();
274
283
}
275
284
276
285
@ Override
@@ -283,9 +292,28 @@ public void onPause() {
283
292
// to the retained fragment object to perform its own cleanup.
284
293
removeMapFragment ();
285
294
removeListFragment ();
295
+ unregisterReceiver (broadcastReceiver );
286
296
}
287
297
}
288
298
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
+ }
289
317
290
318
291
319
/**
@@ -297,6 +325,12 @@ private void refreshView(LocationServiceManager.LocationChangeType locationChang
297
325
if (lockNearbyView ) {
298
326
return ;
299
327
}
328
+
329
+ if (!NetworkUtils .isInternetConnectionEstablished (this )) {
330
+ hideProgressBar ();
331
+ return ;
332
+ }
333
+
300
334
locationManager .registerLocationManager ();
301
335
LatLng lastLocation = locationManager .getLastLocation ();
302
336
0 commit comments