mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	Add boundary check to make a significant update
This commit is contained in:
		
							parent
							
								
									d2c65cfd27
								
							
						
					
					
						commit
						4ee2e1fa37
					
				
					 2 changed files with 55 additions and 17 deletions
				
			
		|  | @ -341,17 +341,21 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|                     .create(); | ||||
|             String gsonCurLatLng = gson.toJson(curLatLang); | ||||
|             bundle.putString("CurLatLng", gsonCurLatLng); | ||||
|             updateMapFragment(); | ||||
|             updateMapFragment(true); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private void populatePlaces(List<Place> placeList) { | ||||
|     //private void populatePlaces(List<Place> placeList) { | ||||
|     private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { | ||||
|         List<Place> placeList = nearbyPlacesInfo.placeList; | ||||
|         LatLng[] boundaryCoordinates = nearbyPlacesInfo.boundaryCoordinates; | ||||
|         Gson gson = new GsonBuilder() | ||||
|                 .registerTypeAdapter(Uri.class, new UriSerializer()) | ||||
|                 .create(); | ||||
|         String gsonPlaceList = gson.toJson(placeList); | ||||
|         String gsonCurLatLng = gson.toJson(curLatLang); | ||||
|         String gsonBoundaryCoordinates = gson.toJson(boundaryCoordinates); | ||||
| 
 | ||||
|         if (placeList.size() == 0) { | ||||
|             int duration = Toast.LENGTH_SHORT; | ||||
|  | @ -362,13 +366,20 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|         bundle.clear(); | ||||
|         bundle.putString("PlaceList", gsonPlaceList); | ||||
|         bundle.putString("CurLatLng", gsonCurLatLng); | ||||
|         bundle.putString("BoundaryCoord", gsonBoundaryCoordinates); | ||||
| 
 | ||||
|         lockNearbyView(true); | ||||
|         setMapFragment(); | ||||
|         setListFragment(); | ||||
|         // First time to init fragments | ||||
|         if (getMapFragment() == null){ | ||||
|             lockNearbyView(true); | ||||
|             setMapFragment(); | ||||
|             setListFragment(); | ||||
| 
 | ||||
|             hideProgressBar(); | ||||
|             lockNearbyView(false); | ||||
|         } else { // There are fragments, just update the map and list | ||||
|             updateMapFragment(false); | ||||
|         } | ||||
| 
 | ||||
|         hideProgressBar(); | ||||
|         lockNearbyView(false); | ||||
|     } | ||||
| 
 | ||||
|     private void lockNearbyView(boolean lock) { | ||||
|  | @ -393,11 +404,38 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|         return (NearbyMapFragment) getSupportFragmentManager().findFragmentByTag("NearbyMapFragment"); | ||||
|     } | ||||
| 
 | ||||
|     private void updateMapFragment() { | ||||
|     private void updateMapFragment(boolean isSlightUpdate) { | ||||
|         /* | ||||
|         * Significant update means updating nearby place markers. Slightly update means only | ||||
|         * updating current location marker and camera target. | ||||
|         * We update our map Significantly on each 1000 meter change, but we can't never know | ||||
|         * the frequency of nearby places. Thus we check if we are close to the boundaries of | ||||
|         * our nearby markers, we update our map Significantly. | ||||
|         * */ | ||||
| 
 | ||||
|         NearbyMapFragment nearbyMapFragment = getMapFragment(); | ||||
|         if (nearbyMapFragment != null) { | ||||
|             nearbyMapFragment.setArguments(bundle); | ||||
|             nearbyMapFragment.updateMapWithLocationChanges(); | ||||
|             // TODO: buradasın eger sınırlara yakınsan significant update yap ve methodların adlarını değiştir. | ||||
|             /* | ||||
|             * 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 (curLatLang.getLatitude() <= nearbyMapFragment.boundaryCoordinates[0].getLatitude() | ||||
|                     || curLatLang.getLatitude() >= nearbyMapFragment.boundaryCoordinates[1].getLatitude() | ||||
|                     || curLatLang.getLatitude() <= nearbyMapFragment.boundaryCoordinates[2].getLatitude() | ||||
|                     || curLatLang.getLatitude() >= nearbyMapFragment.boundaryCoordinates[3].getLatitude()) { | ||||
|                 nearbyMapFragment.setArguments(bundle); | ||||
|                 nearbyMapFragment.updateMapSignificantly(); | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             if (isSlightUpdate) { | ||||
|                 nearbyMapFragment.setArguments(bundle); | ||||
|                 nearbyMapFragment.updateMapSlightly(); | ||||
|             } else { | ||||
|                 nearbyMapFragment.setArguments(bundle); | ||||
|                 nearbyMapFragment.updateMapSignificantly(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -52,7 +52,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|     private MapView mapView; | ||||
|     private List<NearbyBaseMarker> baseMarkerOptions; | ||||
|     private fr.free.nrw.commons.location.LatLng curLatLng; | ||||
|     private fr.free.nrw.commons.location.LatLng[] boundaryCoordinations; | ||||
|     public fr.free.nrw.commons.location.LatLng[] boundaryCoordinates; | ||||
|     // Latest significant update means update of nearby markers | ||||
|     private fr.free.nrw.commons.location.LatLng latestSignificantUpdate; | ||||
| 
 | ||||
|  | @ -116,11 +116,11 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|                     .loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, | ||||
|                             placeList, | ||||
|                             getActivity()); | ||||
|             boundaryCoordinations = gson.fromJson(gsonBoundaryCoordinates, gsonBoundaryCoordinatesType); | ||||
|             Log.d("deneme",boundaryCoordinations[0].getLatitude()+","+boundaryCoordinations[0].getLongitude()); | ||||
|             Log.d("deneme",boundaryCoordinations[1].getLatitude()+","+boundaryCoordinations[1].getLongitude()); | ||||
|             Log.d("deneme",boundaryCoordinations[2].getLatitude()+","+boundaryCoordinations[2].getLongitude()); | ||||
|             Log.d("deneme",boundaryCoordinations[3].getLatitude()+","+boundaryCoordinations[3].getLongitude()); | ||||
|             boundaryCoordinates = gson.fromJson(gsonBoundaryCoordinates, gsonBoundaryCoordinatesType); | ||||
|             Log.d("deneme", boundaryCoordinates[0].getLatitude()+","+ boundaryCoordinates[0].getLongitude()); | ||||
|             Log.d("deneme", boundaryCoordinates[1].getLatitude()+","+ boundaryCoordinates[1].getLongitude()); | ||||
|             Log.d("deneme", boundaryCoordinates[2].getLatitude()+","+ boundaryCoordinates[2].getLongitude()); | ||||
|             Log.d("deneme", boundaryCoordinates[3].getLatitude()+","+ boundaryCoordinates[3].getLongitude()); | ||||
|         } | ||||
|         Mapbox.getInstance(getActivity(), | ||||
|                 getString(R.string.mapbox_commons_app_token)); | ||||
|  | @ -198,7 +198,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|                     .loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, | ||||
|                             placeList, | ||||
|                             getActivity()); | ||||
|             boundaryCoordinations = gson.fromJson(gsonBoundaryCoordinates, gsonBoundaryCoordinatesType); | ||||
|             boundaryCoordinates = gson.fromJson(gsonBoundaryCoordinates, gsonBoundaryCoordinatesType); | ||||
|         } | ||||
|         updateMapToTrackPosition(); | ||||
|         addNearbyMarkerstoMapBoxMap(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 neslihanturan
						neslihanturan