|
1 | 1 | package fr.free.nrw.commons.repository;
|
2 | 2 |
|
| 3 | +import java.io.IOException; |
3 | 4 | import java.util.Comparator;
|
4 | 5 | import java.util.List;
|
| 6 | +import java.util.Locale; |
5 | 7 |
|
6 | 8 | import javax.inject.Inject;
|
7 | 9 | import javax.inject.Singleton;
|
|
10 | 12 | import fr.free.nrw.commons.category.CategoryItem;
|
11 | 13 | import fr.free.nrw.commons.contributions.Contribution;
|
12 | 14 | import fr.free.nrw.commons.filepicker.UploadableFile;
|
| 15 | +import fr.free.nrw.commons.location.LatLng; |
| 16 | +import fr.free.nrw.commons.nearby.NearbyPlaces; |
13 | 17 | import fr.free.nrw.commons.nearby.Place;
|
14 | 18 | import fr.free.nrw.commons.upload.SimilarImageInterface;
|
15 | 19 | import fr.free.nrw.commons.upload.UploadController;
|
|
24 | 28 | @Singleton
|
25 | 29 | public class UploadRemoteDataSource {
|
26 | 30 |
|
| 31 | + private static final double NEARBY_RADIUS_IN_KILO_METERS = 0.1; //100 meters |
| 32 | + |
27 | 33 | private UploadModel uploadModel;
|
28 | 34 | private UploadController uploadController;
|
29 | 35 | private CategoriesModel categoriesModel;
|
| 36 | + private NearbyPlaces nearbyPlaces; |
30 | 37 |
|
31 | 38 | @Inject
|
32 | 39 | public UploadRemoteDataSource(UploadModel uploadModel, UploadController uploadController,
|
33 |
| - CategoriesModel categoriesModel) { |
| 40 | + CategoriesModel categoriesModel, |
| 41 | + NearbyPlaces nearbyPlaces) { |
34 | 42 | this.uploadModel = uploadModel;
|
35 | 43 | this.uploadController = uploadController;
|
36 | 44 | this.categoriesModel = categoriesModel;
|
| 45 | + this.nearbyPlaces = nearbyPlaces; |
37 | 46 | }
|
38 | 47 |
|
39 | 48 | /**
|
@@ -176,4 +185,22 @@ public Observable<UploadItem> preProcessImage(UploadableFile uploadableFile, Pla
|
176 | 185 | public Single<Integer> getImageQuality(UploadItem uploadItem, boolean shouldValidateTitle) {
|
177 | 186 | return uploadModel.getImageQuality(uploadItem, shouldValidateTitle);
|
178 | 187 | }
|
| 188 | + |
| 189 | + /** |
| 190 | + * gets nearby places matching with upload item's GPS location |
| 191 | + * |
| 192 | + * @param latitude |
| 193 | + * @param longitude |
| 194 | + * @return |
| 195 | + */ |
| 196 | + public Place getNearbyPlaces(double latitude, double longitude) { |
| 197 | + try { |
| 198 | + List<Place> fromWikidataQuery = nearbyPlaces.getFromWikidataQuery(new LatLng(latitude, longitude, 0.0f), |
| 199 | + Locale.getDefault().getLanguage(), |
| 200 | + NEARBY_RADIUS_IN_KILO_METERS); |
| 201 | + return fromWikidataQuery.size() > 0 ? fromWikidataQuery.get(0) : null; |
| 202 | + } catch (IOException e) { |
| 203 | + return null; |
| 204 | + } |
| 205 | + } |
179 | 206 | }
|
0 commit comments