mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Merge changes from 3.1-release (#4629)
* Cherry-Picked NPE fix from master (#4569) * Fix notification bug #4547 (#4570) * Make Single Query for Nearby and WLM pins (#4573) * Merge nearby and monument queries * Bug Fix- query resource path change on shouldQueryForMonuments * Bug Fixes 1. Propagate exceptions for nearby API calls to caller 2. Fix too much work on main thread exception in NearbyParentFragment * Modify parameters for Nearby query * Bug fix- current location marker (#4580) * Move WLM template below geolocation template (#4582) * Modify string for WLM upload notice * Fix bug #4583 (#4591) * Fix bug #4585 by updating kotlin and acra version (#4592) * Fixes #4554 - only use WLM2021 template for countries that are included in it (#4574) * Fixes #4554 1. For WLM uploads reverse geo code and see if the country code is supported -only then is the WLM upload flow triggered, otherwise usual nearby uploads happen 2. Bug Fix - Current Location marker and area * Fixed compile error added after rebasing * Bug fix for country code in reverse geo code * Update WLM camaign dates [Do not merge now, merge only after alpha release] (#4584) * Updates dates for WML campaign * Bug fix- campaign dates * Fixed logic for WLM enablement - stick to the month of September * Add countries supported by WLM2021 template, except Italy * Versioning for v3.1.0 * Update changelog.md * Fix empty default lang bug (#4608) * Fix bug #4583 * Fix empty default lang bug * Fixes #4595 - Updated nearby query (#4622) * Fixes #4595 - Updated nearby query * Removed logic to replace local language in nearby query - that might acccidentally replace other strings * Fetch property location in usual nearby query * Remove duplicate line (#4626) * Change "learn more" link to new wiki * Add Sweden's P3426 to property filter * Fixes #4601 - 1. Handle possible exceptions in upload file from stash 2. Modify MWException, as error is nullable, update getTitle and getMessage to rever that (#4627) * Versioning for v3.1.1 * Update changelog.md * Updated DB version to rever integrity Co-authored-by: Madhur Gupta <30932899+madhurgupta10@users.noreply.github.com> Co-authored-by: Josephine Lim <josephinelim86@gmail.com>
This commit is contained in:
		
							parent
							
								
									b91222329e
								
							
						
					
					
						commit
						7476b0a24d
					
				
					 38 changed files with 383 additions and 409 deletions
				
			
		|  | @ -57,7 +57,9 @@ public class NearbyController { | |||
|      * @return NearbyPlacesInfo a variable holds Place list without distance information | ||||
|      * and boundary coordinates of current Place List | ||||
|      */ | ||||
|     public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng searchLatLng, boolean returnClosestResult, boolean checkingAroundCurrentLocation) throws IOException { | ||||
|     public NearbyPlacesInfo loadAttractionsFromLocation(final LatLng curLatLng, final LatLng searchLatLng, | ||||
|         final boolean returnClosestResult, final boolean checkingAroundCurrentLocation, | ||||
|         final boolean shouldQueryForMonuments) throws Exception { | ||||
| 
 | ||||
|         Timber.d("Loading attractions near %s", searchLatLng); | ||||
|         NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo(); | ||||
|  | @ -66,7 +68,9 @@ public class NearbyController { | |||
|             Timber.d("Loading attractions nearby, but curLatLng is null"); | ||||
|             return null; | ||||
|         } | ||||
|         List<Place> places = nearbyPlaces.radiusExpander(searchLatLng, Locale.getDefault().getLanguage(), returnClosestResult); | ||||
|         List<Place> places = nearbyPlaces | ||||
|             .radiusExpander(searchLatLng, Locale.getDefault().getLanguage(), returnClosestResult, | ||||
|                 shouldQueryForMonuments); | ||||
| 
 | ||||
|         if (null != places && places.size() > 0) { | ||||
|             LatLng[] boundaryCoordinates = {places.get(0).location,   // south | ||||
|  | @ -128,11 +132,6 @@ public class NearbyController { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public Observable<List<Place>> queryWikiDataForMonuments( | ||||
|         final LatLng latLng, final String language) { | ||||
|         return nearbyPlaces.queryWikiDataForMonuments(latLng, language); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Loads attractions from location for list view, we need to return Place data type. | ||||
|      * | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| package fr.free.nrw.commons.nearby; | ||||
| 
 | ||||
| import io.reactivex.Observable; | ||||
| import java.io.IOException; | ||||
| import java.io.InterruptedIOException; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| 
 | ||||
|  | @ -19,8 +17,8 @@ import timber.log.Timber; | |||
| @Singleton | ||||
| public class NearbyPlaces { | ||||
| 
 | ||||
|     private static final double INITIAL_RADIUS = 1.0; // in kilometers | ||||
|     private static final double RADIUS_MULTIPLIER = 1.618; | ||||
|     private static final double INITIAL_RADIUS = 0.3; // in kilometers | ||||
|     private static final double RADIUS_MULTIPLIER = 2.0; | ||||
|     public double radius = INITIAL_RADIUS; | ||||
| 
 | ||||
|     private final OkHttpJsonApiClient okHttpJsonApiClient; | ||||
|  | @ -41,12 +39,12 @@ public class NearbyPlaces { | |||
|      * @param lang user's language | ||||
|      * @param returnClosestResult true if only the nearest point is desired | ||||
|      * @return list of places obtained | ||||
|      * @throws IOException if query fails | ||||
|      */ | ||||
|     List<Place> radiusExpander(LatLng curLatLng, String lang, boolean returnClosestResult) throws IOException { | ||||
|     List<Place> radiusExpander(final LatLng curLatLng, final String lang, final boolean returnClosestResult | ||||
|         , final boolean shouldQueryForMonuments) throws Exception { | ||||
| 
 | ||||
|         int minResults; | ||||
|         double maxRadius; | ||||
|         final int minResults; | ||||
|         final double maxRadius; | ||||
| 
 | ||||
|         List<Place> places = Collections.emptyList(); | ||||
| 
 | ||||
|  | @ -57,19 +55,14 @@ public class NearbyPlaces { | |||
|             maxRadius = 5;  // Return places only in 5 km area | ||||
|             radius = INITIAL_RADIUS; // refresh radius again, otherwise increased radius is grater than MAX_RADIUS, thus returns null | ||||
|         } else { | ||||
|             minResults = 40; | ||||
|             minResults = 20; | ||||
|             maxRadius = 300.0; // in kilometers | ||||
|             radius = INITIAL_RADIUS; | ||||
|         } | ||||
| 
 | ||||
|             // Increase the radius gradually to find a satisfactory number of nearby places | ||||
|             while (radius <= maxRadius) { | ||||
|                 try { | ||||
|                     places = getFromWikidataQuery(curLatLng, lang, radius); | ||||
|                 } catch (final Exception e) { | ||||
|                     Timber.e(e, "Exception in fetching nearby places"); | ||||
|                     break; | ||||
|                 } | ||||
|                 places = getFromWikidataQuery(curLatLng, lang, radius, shouldQueryForMonuments); | ||||
|                 Timber.d("%d results at radius: %f", places.size(), radius); | ||||
|                 if (places.size() >= minResults) { | ||||
|                     break; | ||||
|  | @ -89,16 +82,12 @@ public class NearbyPlaces { | |||
|      * @param cur coordinates of search location | ||||
|      * @param lang user's language | ||||
|      * @param radius radius for search, as determined by radiusExpander() | ||||
|      * @param shouldQueryForMonuments should the query include properites for monuments | ||||
|      * @return list of places obtained | ||||
|      * @throws IOException if query fails | ||||
|      */ | ||||
|     public List<Place> getFromWikidataQuery(LatLng cur, String lang, double radius) throws Exception { | ||||
|         return okHttpJsonApiClient.getNearbyPlaces(cur, lang, radius).blockingSingle(); | ||||
|     } | ||||
| 
 | ||||
|     public Observable<List<Place>> queryWikiDataForMonuments( | ||||
|         LatLng latLng, String language) { | ||||
|         return okHttpJsonApiClient | ||||
|             .getNearbyMonuments(latLng, language, radius); | ||||
|     public List<Place> getFromWikidataQuery(final LatLng cur, final String lang, | ||||
|         final double radius, final boolean shouldQueryForMonuments) throws Exception { | ||||
|         return okHttpJsonApiClient.getNearbyPlaces(cur, lang, radius, shouldQueryForMonuments); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -245,7 +245,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|     /** | ||||
|      * WLM URL | ||||
|      */ | ||||
|     public static final String WLM_URL = "https://www.wikilovesmonuments.org/"; | ||||
|     public static final String WLM_URL = "https://commons.wikimedia.org/wiki/Commons:Mobile_app/Contributing_to_WLM_using_the_app"; | ||||
| 
 | ||||
|     @NonNull | ||||
|     public static NearbyParentFragment newInstance() { | ||||
|  | @ -284,7 +284,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|     public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { | ||||
|         super.onViewCreated(view, savedInstanceState); | ||||
|         isDarkTheme = systemThemeUtils.isDeviceInNightMode(); | ||||
|         if (Utils.isMonumentsEnabled(new Date(), applicationKvStore)) { | ||||
|         if (Utils.isMonumentsEnabled(new Date())) { | ||||
|             rlContainerWLMMonthMessage.setVisibility(View.VISIBLE); | ||||
|         } else { | ||||
|             rlContainerWLMMonthMessage.setVisibility(View.GONE); | ||||
|  | @ -513,7 +513,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|         setBottomSheetCallbacks(); | ||||
|         decideButtonVisibilities(); | ||||
|         addActionToTitle(); | ||||
|         if(!Utils.isMonumentsEnabled(new Date(), applicationKvStore)){ | ||||
|         if (!Utils.isMonumentsEnabled(new Date())) { | ||||
|             chipWlm.setVisibility(View.GONE); | ||||
|         } | ||||
|     } | ||||
|  | @ -883,29 +883,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
| 
 | ||||
|         final Observable<NearbyPlacesInfo> nearbyPlacesInfoObservable = Observable | ||||
|             .fromCallable(() -> nearbyController | ||||
|                 .loadAttractionsFromLocation(curlatLng, searchLatLng, false, true)); | ||||
|                 .loadAttractionsFromLocation(curlatLng, searchLatLng, | ||||
|                     false, true, Utils.isMonumentsEnabled(new Date()))); | ||||
| 
 | ||||
|         Observable<List<Place>> observableWikidataMonuments = Observable.empty(); | ||||
|         if(Utils.isMonumentsEnabled(new Date(), applicationKvStore)){ | ||||
|                 observableWikidataMonuments = | ||||
|                     nearbyController | ||||
|                         .queryWikiDataForMonuments(searchLatLng, Locale.getDefault().getLanguage()); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         compositeDisposable.add(Observable.zip(nearbyPlacesInfoObservable | ||||
|             , observableWikidataMonuments.onErrorReturn(throwable -> { | ||||
|                 showErrorMessage(getString(R.string.error_fetching_nearby_monuments) + throwable | ||||
|                     .getLocalizedMessage()); | ||||
|                 return new ArrayList<>(); | ||||
|             }), | ||||
|             (nearbyPlacesInfo, monuments) -> { | ||||
|                 final List<Place> places = mergeNearbyPlacesAndMonuments(nearbyPlacesInfo.placeList, | ||||
|                     monuments); | ||||
|                 nearbyPlacesInfo.placeList.clear(); | ||||
|                 nearbyPlacesInfo.placeList.addAll(places); | ||||
|                 return nearbyPlacesInfo; | ||||
|             }).subscribeOn(Schedulers.io()) | ||||
|         compositeDisposable.add(nearbyPlacesInfoObservable | ||||
|             .subscribeOn(Schedulers.io()) | ||||
|             .observeOn(AndroidSchedulers.mainThread()) | ||||
|             .subscribe(nearbyPlacesInfo -> { | ||||
|                     updateMapMarkers(nearbyPlacesInfo, true); | ||||
|  | @ -925,28 +907,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
| 
 | ||||
|         final Observable<NearbyPlacesInfo> nearbyPlacesInfoObservable = Observable | ||||
|             .fromCallable(() -> nearbyController | ||||
|                 .loadAttractionsFromLocation(curlatLng, searchLatLng, false, false)); | ||||
|                 .loadAttractionsFromLocation(curlatLng, searchLatLng, | ||||
|                     false, true, Utils.isMonumentsEnabled(new Date()))); | ||||
| 
 | ||||
|         Observable<List<Place>> observableWikidataMonuments = Observable.empty(); | ||||
|         if (Utils.isMonumentsEnabled(new Date(), applicationKvStore)) { | ||||
|             observableWikidataMonuments = nearbyController | ||||
|                 .queryWikiDataForMonuments(searchLatLng, Locale.getDefault().getLanguage()); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         compositeDisposable.add(Observable.zip(nearbyPlacesInfoObservable | ||||
|             , observableWikidataMonuments.onErrorReturn(throwable -> { | ||||
|                 showErrorMessage(getString(R.string.error_fetching_nearby_monuments) + throwable | ||||
|                     .getLocalizedMessage()); | ||||
|                 return new ArrayList<>(); | ||||
|             }), | ||||
|             (nearbyPlacesInfo, monuments) -> { | ||||
|                 final List<Place> places = mergeNearbyPlacesAndMonuments(nearbyPlacesInfo.placeList, | ||||
|                     monuments); | ||||
|                 nearbyPlacesInfo.placeList.clear(); | ||||
|                 nearbyPlacesInfo.placeList.addAll(places); | ||||
|                 return nearbyPlacesInfo; | ||||
|             }).subscribeOn(Schedulers.io()) | ||||
|         compositeDisposable.add(nearbyPlacesInfoObservable | ||||
|             .subscribeOn(Schedulers.io()) | ||||
|             .observeOn(AndroidSchedulers.mainThread()) | ||||
|             .subscribe(nearbyPlacesInfo -> { | ||||
|                     updateMapMarkers(nearbyPlacesInfo, false); | ||||
|  | @ -961,25 +926,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|                 })); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * If a nearby place happens to be a monument as well, don't make the Pin's overlap, instead | ||||
|      * show it as a monument | ||||
|      * | ||||
|      * @param nearbyPlaces | ||||
|      * @param monuments | ||||
|      * @return | ||||
|      */ | ||||
|     private List<Place> mergeNearbyPlacesAndMonuments(List<Place> nearbyPlaces, List<Place> monuments){ | ||||
|         List<Place> allPlaces= new ArrayList<>(); | ||||
|         allPlaces.addAll(monuments); | ||||
|         for (Place place : nearbyPlaces){ | ||||
|             if(!allPlaces.contains(place)){ | ||||
|                 allPlaces.add(place); | ||||
|             } | ||||
|         } | ||||
|         return allPlaces; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Populates places for your location, should be used for finding nearby places around a | ||||
|      * location where you are. | ||||
|  | @ -1248,8 +1194,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|                         .position(new LatLng(curLatLng.getLatitude(), | ||||
|                                 curLatLng.getLongitude())); | ||||
|                 currentLocationMarkerOptions.setIcon(icon); // Set custom icon | ||||
|                 mapView.post(() -> currentLocationMarker = mapBox.addMarker(currentLocationMarkerOptions)); | ||||
| 
 | ||||
|                 mapView.post( | ||||
|                     () -> currentLocationMarker = mapBox.addMarker(currentLocationMarkerOptions)); | ||||
| 
 | ||||
|                 final List<LatLng> circle = UiUtils | ||||
|                         .createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(), | ||||
|  | @ -1259,8 +1205,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|                         .addAll(circle) | ||||
|                         .strokeColor(getResources().getColor(R.color.current_marker_stroke)) | ||||
|                         .fillColor(getResources().getColor(R.color.current_marker_fill)); | ||||
|                 mapView.post(() -> currentLocationPolygon = mapBox.addPolygon(currentLocationPolygonOptions)); | ||||
| 
 | ||||
|                 mapView.post( | ||||
|                     () -> currentLocationPolygon = mapBox | ||||
|                         .addPolygon(currentLocationPolygonOptions)); | ||||
|             }); | ||||
|         } else { | ||||
|             Timber.d("not adding current location marker..current location is null"); | ||||
|  |  | |||
|  | @ -14,7 +14,8 @@ class NearbyResultItem(private val item: ResultTuple?, | |||
|                        @field:SerializedName("pic") private val pic: ResultTuple?, | ||||
|                        @field:SerializedName("destroyed") private val destroyed: ResultTuple?, | ||||
|                        @field:SerializedName("description") private val description: ResultTuple?, | ||||
|                        @field:SerializedName("endTime") private val endTime: ResultTuple?) { | ||||
|                        @field:SerializedName("endTime") private val endTime: ResultTuple?, | ||||
|                        @field:SerializedName("monument") private val monument: ResultTuple?) { | ||||
| 
 | ||||
|     fun getItem(): ResultTuple { | ||||
|         return item ?: ResultTuple() | ||||
|  | @ -71,4 +72,8 @@ class NearbyResultItem(private val item: ResultTuple?, | |||
|     fun getAddress(): String { | ||||
|         return address?.value?:"" | ||||
|     } | ||||
| 
 | ||||
|     fun getMonument():ResultTuple?{ | ||||
|         return monument | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ashish
						Ashish