From 7408d89abd1c8ceda1558e995f6b936223908a7e Mon Sep 17 00:00:00 2001 From: maskara Date: Sat, 25 Nov 2017 14:12:38 +0530 Subject: [PATCH] Remove CSV option for nearby places --- .../nrw/commons/nearby/NearbyController.java | 31 +++++---- .../free/nrw/commons/nearby/NearbyPlaces.java | 64 ------------------- app/src/main/res/xml/preferences.xml | 7 -- 3 files changed, 15 insertions(+), 87 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java index 035532c11..f4a8fc3f7 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java @@ -41,29 +41,28 @@ public class NearbyController { * Prepares Place list to make their distance information update later. * * @param curLatLng current location for user - * @param context context * @return Place list without distance information */ - public List loadAttractionsFromLocation(LatLng curLatLng, Context context) { + public List loadAttractionsFromLocation(LatLng curLatLng) { Timber.d("Loading attractions near %s", curLatLng); if (curLatLng == null) { return Collections.emptyList(); } - List places = prefs.getBoolean("useWikidata", true) - ? nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage()) - : nearbyPlaces.getFromWikiNeedsPictures(); - Timber.d("Sorting places by distance..."); - final Map distances = new HashMap<>(); - for (Place place : places) { - distances.put(place, computeDistanceBetween(place.location, curLatLng)); + List places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage()); + if (curLatLng != null) { + Timber.d("Sorting places by distance..."); + final Map distances = new HashMap<>(); + for (Place place: places) { + distances.put(place, computeDistanceBetween(place.location, curLatLng)); + } + Collections.sort(places, + (lhs, rhs) -> { + double lhsDistance = distances.get(lhs); + double rhsDistance = distances.get(rhs); + return (int) (lhsDistance - rhsDistance); + } + ); } - Collections.sort(places, - (lhs, rhs) -> { - double lhsDistance = distances.get(lhs); - double rhsDistance = distances.get(rhs); - return (int) (lhsDistance - rhsDistance); - } - ); return places; } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java index f13aa1ae3..0137516bb 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java @@ -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 places; public NearbyPlaces() { try { @@ -141,66 +139,4 @@ public class NearbyPlaces { return places; } - - List 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; - } } diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index b7b63d39c..bf6b55686 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -31,13 +31,6 @@ android:key="theme" /> - -