mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Add network connectivity listener and inform user acordingly
This commit is contained in:
		
							parent
							
								
									fc91fb8d39
								
							
						
					
					
						commit
						fccc7e66d4
					
				
					 4 changed files with 63 additions and 1 deletions
				
			
		|  | @ -1,6 +1,9 @@ | |||
| package fr.free.nrw.commons.nearby; | ||||
| 
 | ||||
| import android.content.BroadcastReceiver; | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.content.IntentFilter; | ||||
| import android.content.pm.PackageManager; | ||||
| import android.net.Uri; | ||||
| import android.os.Build; | ||||
|  | @ -10,6 +13,7 @@ import android.support.design.widget.BottomSheetBehavior; | |||
| 
 | ||||
| import android.support.v4.app.FragmentTransaction; | ||||
| import android.support.v7.app.AlertDialog; | ||||
| import android.util.Log; | ||||
| import android.view.Menu; | ||||
| import android.view.MenuInflater; | ||||
| import android.view.MenuItem; | ||||
|  | @ -33,6 +37,7 @@ import fr.free.nrw.commons.location.LatLng; | |||
| import fr.free.nrw.commons.location.LocationServiceManager; | ||||
| import fr.free.nrw.commons.location.LocationUpdateListener; | ||||
| import fr.free.nrw.commons.theme.NavigationBaseActivity; | ||||
| import fr.free.nrw.commons.utils.NetworkUtils; | ||||
| import fr.free.nrw.commons.utils.UriSerializer; | ||||
| 
 | ||||
| import fr.free.nrw.commons.utils.ViewUtil; | ||||
|  | @ -69,11 +74,14 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|     private boolean lockNearbyView; //Determines if the nearby places needs to be refreshed | ||||
|     private BottomSheetBehavior bottomSheetBehavior; // Behavior for list bottom sheet | ||||
|     private BottomSheetBehavior bottomSheetBehaviorForDetails; // Behavior for details bottom sheet | ||||
|     private NearbyMapFragment nearbyMapFragment; | ||||
|     public NearbyMapFragment nearbyMapFragment; | ||||
|     private NearbyListFragment nearbyListFragment; | ||||
|     private static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment.class.getSimpleName(); | ||||
|     private static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment.class.getSimpleName(); | ||||
| 
 | ||||
|     private final String NETWORK_INTENT_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; | ||||
|     private BroadcastReceiver broadcastReceiver; | ||||
| 
 | ||||
|     @Override | ||||
|     protected void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|  | @ -271,6 +279,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|         super.onResume(); | ||||
|         lockNearbyView = false; | ||||
|         checkGps(); | ||||
|         addNetworkBroadcastReceiver(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  | @ -283,9 +292,28 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|             // to the retained fragment object to perform its own cleanup. | ||||
|             removeMapFragment(); | ||||
|             removeListFragment(); | ||||
|             unregisterReceiver(broadcastReceiver); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private void addNetworkBroadcastReceiver() { | ||||
|         IntentFilter intentFilter = new IntentFilter(NETWORK_INTENT_ACTION); | ||||
| 
 | ||||
|         broadcastReceiver = new BroadcastReceiver() { | ||||
| 
 | ||||
|             @Override | ||||
|             public void onReceive(Context context, Intent intent) { | ||||
|                 if (NetworkUtils.isInternetConnectionEstablished(NearbyActivity.this)) { | ||||
|                     refreshView(LocationServiceManager | ||||
|                             .LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED); | ||||
|                 } else { | ||||
|                     ViewUtil.showLongToast(NearbyActivity.this, getString(R.string.no_internet)); | ||||
|                 } | ||||
|             } | ||||
|         }; | ||||
| 
 | ||||
|         this.registerReceiver(broadcastReceiver, intentFilter); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|  | @ -297,6 +325,12 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|         if (lockNearbyView) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         if (!NetworkUtils.isInternetConnectionEstablished(this)) { | ||||
|             hideProgressBar(); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         locationManager.registerLocationManager(); | ||||
|         LatLng lastLocation = locationManager.getLastLocation(); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 neslihanturan
						neslihanturan