mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Prevent unnecessary refreshview calls
This commit is contained in:
		
							parent
							
								
									c7b7522edd
								
							
						
					
					
						commit
						b180824382
					
				
					 2 changed files with 39 additions and 9 deletions
				
			
		|  | @ -99,6 +99,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
| 
 | ||||
|     private boolean onOrientationChanged = false; | ||||
|     private boolean populateForCurrentLocation = false; | ||||
|     private boolean isNetworkErrorOccured = false; | ||||
| 
 | ||||
|     @Override | ||||
|     public void onCreate(@Nullable Bundle savedInstanceState) { | ||||
|  | @ -126,7 +127,8 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|         super.onViewCreated(view, savedInstanceState); | ||||
|         if (savedInstanceState != null) { | ||||
|             onOrientationChanged = true; | ||||
|             refreshView(LOCATION_SIGNIFICANTLY_CHANGED); | ||||
|             Log.d("deneme","onViewCreated"); | ||||
|             //refreshView(LOCATION_SIGNIFICANTLY_CHANGED); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -218,17 +220,22 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
| 
 | ||||
|     @Override | ||||
|     public void onLocationChangedSignificantly(LatLng latLng) { | ||||
|         Log.d("deneme","onLocationChangedSignificantly"); | ||||
|             refreshView(LOCATION_SIGNIFICANTLY_CHANGED); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void onLocationChangedSlightly(LatLng latLng) { | ||||
|             refreshView(LOCATION_SLIGHTLY_CHANGED); | ||||
|         Log.d("deneme","onLocationChangedSlightly"); | ||||
| 
 | ||||
|         refreshView(LOCATION_SLIGHTLY_CHANGED); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     @Override | ||||
|     public void onLocationChangedMedium(LatLng latLng) { | ||||
|         Log.d("deneme","onLocationChangedMedium"); | ||||
| 
 | ||||
|         // For nearby map actions, there are no differences between 500 meter location change (aka medium change) and slight change | ||||
|             refreshView(LOCATION_SLIGHTLY_CHANGED); | ||||
|     } | ||||
|  | @ -237,6 +244,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|     public void onWikidataEditSuccessful() { | ||||
|         // Do not refresh nearby map if we are checking other areas with search this area button | ||||
|         if (!nearbyMapFragment.searchThisAreaModeOn) { | ||||
|             Log.d("deneme","onWikidateEditSuccesful"); | ||||
|             refreshView(MAP_UPDATED); | ||||
|         } | ||||
|     } | ||||
|  | @ -247,6 +255,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|      * @param locationChangeType defines if location shanged significantly or slightly | ||||
|      */ | ||||
|     public void refreshView(LocationServiceManager.LocationChangeType locationChangeType) { | ||||
|         Log.d("deneme","refreshView"); | ||||
|         Timber.d("Refreshing nearby places"); | ||||
|         if (lockNearbyView) { | ||||
|             return; | ||||
|  | @ -298,6 +307,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|             bundle.clear(); | ||||
|             bundle.putString("CurLatLng", gsonCurLatLng); | ||||
| 
 | ||||
|             Log.d("deneme","popuate places is called from here"); | ||||
|             placesDisposable = Observable.fromCallable(() -> nearbyController | ||||
|                     .loadAttractionsFromLocation(curLatLng, curLatLng, false, true)) | ||||
|                     .subscribeOn(Schedulers.io()) | ||||
|  | @ -331,7 +341,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|      * @param customLatLng Custom area which we will search around | ||||
|      */ | ||||
|     public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) { | ||||
| 
 | ||||
|         Log.d("deneme","refreshViewForCutomLocatiom"); | ||||
|         if (customLatLng == null) { | ||||
|             // If null, return | ||||
|             return; | ||||
|  | @ -360,6 +370,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|      * @param nearbyPlacesInfo This variable has place list information and distances. | ||||
|      */ | ||||
|     private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { | ||||
|         Log.d("deneme","populatePlacesFromCustomLocation"); | ||||
|         //NearbyMapFragment nearbyMapFragment = getMapFragment(); | ||||
|         if (nearbyMapFragment != null) { | ||||
|             nearbyMapFragment.searchThisAreaButtonProgressBar.setVisibility(View.GONE); | ||||
|  | @ -376,6 +387,8 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|     } | ||||
| 
 | ||||
|     private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { | ||||
|         Log.d("deneme","populatePlaces"); | ||||
| 
 | ||||
|         Timber.d("Populating nearby places"); | ||||
|         List<Place> placeList = nearbyPlacesInfo.placeList; | ||||
|         LatLng[] boundaryCoordinates = nearbyPlacesInfo.boundaryCoordinates; | ||||
|  | @ -428,6 +441,9 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|     } | ||||
| 
 | ||||
|     private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { | ||||
|         Log.d("deneme","update Map fragment"+" updateViaButton:"+updateViaButton+", isSlightUpdate:"+isSlightUpdate); | ||||
|         Log.d("deneme","update Map fragment status"+" checking around:"+nearbyMapFragment.checkingAround+", searchThisAreaModeOn:"+nearbyMapFragment.searchThisAreaModeOn+", onOrientationChanged:"+onOrientationChanged); | ||||
| 
 | ||||
|         if (nearbyMapFragment.checkingAround) { | ||||
|             return; | ||||
|         } | ||||
|  | @ -446,11 +462,15 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|              * If we are close to nearby places boundaries, we need a significant update to | ||||
|              * get new nearby places. Check order is south, north, west, east | ||||
|              * */ | ||||
|             if (nearbyMapFragment.boundaryCoordinates != null && !nearbyMapFragment.searchThisAreaModeOn | ||||
|                     && (curLatLng.getLatitude() <= nearbyMapFragment.boundaryCoordinates[0].getLatitude() | ||||
|                     || curLatLng.getLatitude() >= nearbyMapFragment.boundaryCoordinates[1].getLatitude() | ||||
|                     || curLatLng.getLongitude() <= nearbyMapFragment.boundaryCoordinates[2].getLongitude() | ||||
|                     || curLatLng.getLongitude() >= nearbyMapFragment.boundaryCoordinates[3].getLongitude())) { | ||||
|             if (nearbyMapFragment.boundaryCoordinates != null | ||||
|                     && !nearbyMapFragment.checkingAround | ||||
|                     && !nearbyMapFragment.searchThisAreaModeOn | ||||
|                     && !onOrientationChanged | ||||
|                     && (curLatLng.getLatitude() < nearbyMapFragment.boundaryCoordinates[0].getLatitude() | ||||
|                     || curLatLng.getLatitude() > nearbyMapFragment.boundaryCoordinates[1].getLatitude() | ||||
|                     || curLatLng.getLongitude() < nearbyMapFragment.boundaryCoordinates[2].getLongitude() | ||||
|                     || curLatLng.getLongitude() > nearbyMapFragment.boundaryCoordinates[3].getLongitude())) { | ||||
|                 Log.d("deneme","boundary is working"); | ||||
|                 // populate places | ||||
|                 placesDisposable = Observable.fromCallable(() -> nearbyController | ||||
|                         .loadAttractionsFromLocation(curLatLng, curLatLng, false, updateViaButton)) | ||||
|  | @ -637,6 +657,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|         Timber.d("Checking location permission"); | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||||
|             if (locationManager.isLocationPermissionGranted()) { | ||||
|                 Log.d("deneme","Check location permission if"); | ||||
|                 refreshView(LOCATION_SIGNIFICANTLY_CHANGED); | ||||
|             } else { | ||||
|                 // Should we show an explanation? | ||||
|  | @ -663,6 +684,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|                 } | ||||
|             } | ||||
|         } else { | ||||
|             Log.d("deneme","Check location permission else"); | ||||
|             refreshView(LOCATION_SIGNIFICANTLY_CHANGED); | ||||
|         } | ||||
|     } | ||||
|  | @ -681,9 +703,16 @@ public class NearbyFragment extends CommonsDaggerSupportFragment | |||
|             public void onReceive(Context context, Intent intent) { | ||||
|                 if (snackbar != null) { | ||||
|                     if (NetworkUtils.isInternetConnectionEstablished(getActivity())) { | ||||
|                         refreshView(LOCATION_SIGNIFICANTLY_CHANGED); | ||||
|                         Log.d("deneme","NetworkUtils.isInternetConnectionEstablished(getActivity())"); | ||||
|                         if (isNetworkErrorOccured) { | ||||
|                             Log.d("deneme","NetworkUtils.isInternetConnectionEstablished(getActivity())"); | ||||
|                             Log.d("deneme","isNetworkErrorOccured refreshed"); | ||||
|                             refreshView(LOCATION_SIGNIFICANTLY_CHANGED); | ||||
|                             isNetworkErrorOccured = false; | ||||
|                         } | ||||
|                         snackbar.dismiss(); | ||||
|                     } else { | ||||
|                         isNetworkErrorOccured = true; | ||||
|                         snackbar.show(); | ||||
|                     } | ||||
|                 } | ||||
|  |  | |||
|  | @ -1011,6 +1011,7 @@ public class NearbyMapFragment extends DaggerFragment { | |||
|         searchThisAreaModeOn = false; | ||||
|         checkingAround = false; | ||||
|         searchedAroundCurrentLocation = true; | ||||
|         boundaryCoordinates = null; | ||||
|         initViews(); | ||||
|         setListeners(); | ||||
|         transparentView.setClickable(false); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 neslihanturan
						neslihanturan