mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Merge remote-tracking branch 'refs/remotes/commons-app/directNearbyUploads' into nearby-uploads
# Conflicts: # app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java
This commit is contained in:
		
						commit
						8db3d55fa0
					
				
					 4 changed files with 2 additions and 75 deletions
				
			
		|  | @ -47,9 +47,7 @@ public class NearbyController { | |||
|         if (curLatLng == null) { | ||||
|             return Collections.emptyList(); | ||||
|         } | ||||
|         List<Place> places = prefs.getBoolean("useWikidata", true) | ||||
|                 ? nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage()) | ||||
|                 : nearbyPlaces.getFromWikiNeedsPictures(); | ||||
|         List<Place> places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage()); | ||||
|         if (curLatLng != null) { | ||||
|             Timber.d("Sorting places by distance..."); | ||||
|             final Map<Place, Double> distances = new HashMap<>(); | ||||
|  |  | |||
|  | @ -399,7 +399,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|             directUpload.storeSharedPrefs(); | ||||
|             directUpload.initiateGalleryUpload(); | ||||
| 
 | ||||
| //TODO: App crashes after image upload completes | ||||
| //TODO: App crashes after image upload completes - but didn't happen 2nd time I tried? | ||||
| //TODO: Handle onRequestPermissionsResult | ||||
|         }); | ||||
|     } | ||||
|  |  | |||
|  | @ -1,7 +1,6 @@ | |||
| package fr.free.nrw.commons.nearby; | ||||
| 
 | ||||
| import android.net.Uri; | ||||
| import android.os.StrictMode; | ||||
| 
 | ||||
| import java.io.BufferedReader; | ||||
| import java.io.IOException; | ||||
|  | @ -30,7 +29,6 @@ public class NearbyPlaces { | |||
|     private static final Uri WIKIDATA_QUERY_UI_URL = Uri.parse("https://query.wikidata.org/"); | ||||
|     private final String wikidataQuery; | ||||
|     private double radius = INITIAL_RADIUS; | ||||
|     private List<Place> places; | ||||
| 
 | ||||
|     public NearbyPlaces() { | ||||
|         try { | ||||
|  | @ -141,66 +139,4 @@ public class NearbyPlaces { | |||
| 
 | ||||
|         return places; | ||||
|     } | ||||
| 
 | ||||
|     List<Place> getFromWikiNeedsPictures() { | ||||
|         if (places != null) { | ||||
|             return places; | ||||
|         } else { | ||||
|             try { | ||||
|                 places = new ArrayList<>(); | ||||
|                 StrictMode.ThreadPolicy policy | ||||
|                         = new StrictMode.ThreadPolicy.Builder().permitAll().build(); | ||||
|                 StrictMode.setThreadPolicy(policy); | ||||
| 
 | ||||
|                 URL file = new URL("https://tools.wmflabs.org/wiki-needs-pictures/data/data.csv"); | ||||
| 
 | ||||
|                 BufferedReader in = new BufferedReader(new InputStreamReader(file.openStream())); | ||||
| 
 | ||||
|                 boolean firstLine = true; | ||||
|                 String line; | ||||
|                 Timber.d("Reading from CSV file..."); | ||||
| 
 | ||||
|                 while ((line = in.readLine()) != null) { | ||||
| 
 | ||||
|                     // Skip CSV header. | ||||
|                     if (firstLine) { | ||||
|                         firstLine = false; | ||||
|                         continue; | ||||
|                     } | ||||
| 
 | ||||
|                     String[] fields = line.split(","); | ||||
|                     String name = Utils.stripLocalizedString(fields[0]); | ||||
| 
 | ||||
|                     double latitude; | ||||
|                     double longitude; | ||||
|                     try { | ||||
|                         latitude = Double.parseDouble(fields[1]); | ||||
|                     } catch (NumberFormatException e) { | ||||
|                         latitude = 0; | ||||
|                     } | ||||
|                     try { | ||||
|                         longitude = Double.parseDouble(fields[2]); | ||||
|                     } catch (NumberFormatException e) { | ||||
|                         longitude = 0; | ||||
|                     } | ||||
| 
 | ||||
|                     String type = fields[3]; | ||||
| 
 | ||||
|                     places.add(new Place( | ||||
|                             name, | ||||
|                             Place.Label.fromText(type), // list | ||||
|                             type, // details | ||||
|                             null, | ||||
|                             new LatLng(latitude, longitude, 0), | ||||
|                             new Sitelinks.Builder().build() | ||||
|                     )); | ||||
|                 } | ||||
|                 in.close(); | ||||
| 
 | ||||
|             } catch (IOException e) { | ||||
|                 Timber.d(e.toString()); | ||||
|             } | ||||
|         } | ||||
|         return places; | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 misaochan
						misaochan