mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Remove CSV option for nearby places
This commit is contained in:
parent
f8695209e5
commit
7408d89abd
3 changed files with 15 additions and 87 deletions
|
|
@ -41,29 +41,28 @@ public class NearbyController {
|
||||||
* Prepares Place list to make their distance information update later.
|
* Prepares Place list to make their distance information update later.
|
||||||
*
|
*
|
||||||
* @param curLatLng current location for user
|
* @param curLatLng current location for user
|
||||||
* @param context context
|
|
||||||
* @return Place list without distance information
|
* @return Place list without distance information
|
||||||
*/
|
*/
|
||||||
public List<Place> loadAttractionsFromLocation(LatLng curLatLng, Context context) {
|
public List<Place> loadAttractionsFromLocation(LatLng curLatLng) {
|
||||||
Timber.d("Loading attractions near %s", curLatLng);
|
Timber.d("Loading attractions near %s", curLatLng);
|
||||||
if (curLatLng == null) {
|
if (curLatLng == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
List<Place> places = prefs.getBoolean("useWikidata", true)
|
List<Place> places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage());
|
||||||
? nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage())
|
if (curLatLng != null) {
|
||||||
: nearbyPlaces.getFromWikiNeedsPictures();
|
Timber.d("Sorting places by distance...");
|
||||||
Timber.d("Sorting places by distance...");
|
final Map<Place, Double> distances = new HashMap<>();
|
||||||
final Map<Place, Double> distances = new HashMap<>();
|
for (Place place: places) {
|
||||||
for (Place place : places) {
|
distances.put(place, computeDistanceBetween(place.location, curLatLng));
|
||||||
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;
|
return places;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package fr.free.nrw.commons.nearby;
|
package fr.free.nrw.commons.nearby;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.StrictMode;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
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 static final Uri WIKIDATA_QUERY_UI_URL = Uri.parse("https://query.wikidata.org/");
|
||||||
private final String wikidataQuery;
|
private final String wikidataQuery;
|
||||||
private double radius = INITIAL_RADIUS;
|
private double radius = INITIAL_RADIUS;
|
||||||
private List<Place> places;
|
|
||||||
|
|
||||||
public NearbyPlaces() {
|
public NearbyPlaces() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -141,66 +139,4 @@ public class NearbyPlaces {
|
||||||
|
|
||||||
return places;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,6 @@
|
||||||
android:key="theme"
|
android:key="theme"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:key="useWikidata"
|
|
||||||
android:title="@string/use_wikidata"
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:summary="@string/use_wikidata_summary"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="uploads"
|
android:key="uploads"
|
||||||
android:defaultValue="100"
|
android:defaultValue="100"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue