mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Use JSON SPARQL query for fetching nearby places (#2398)
* Use JSON response for nearby places * Move okhttp calls to a different class * wip * Fetch picture of the day using JSON API * Search images using JSON APIs * tests * Fix injection based on code review comments
This commit is contained in:
parent
323527b3be
commit
f12837650a
44 changed files with 1472 additions and 418 deletions
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.utils;
|
|||
|
||||
import android.text.format.DateFormat;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
|
@ -38,11 +39,21 @@ public class DateUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static Date getDateFromString(String dateString) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
|
||||
try {
|
||||
return dateFormat.parse(dateString);
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCurrentDate() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
|
||||
Date date = new Date();
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
public static String dateInLocaleFormat(Date date){
|
||||
String formatter;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
|
||||
public class PlaceUtils {
|
||||
|
|
@ -22,4 +25,21 @@ public class PlaceUtils {
|
|||
String[] parts = latLngString.split("/");
|
||||
return new LatLng(Double.parseDouble(parts[0]), Double.parseDouble(parts[1]), 0);
|
||||
}
|
||||
|
||||
public static LatLng latLngFromPointString(String pointString) {
|
||||
double latitude;
|
||||
double longitude;
|
||||
Matcher matcher = Pattern.compile("Point\\(([^ ]+) ([^ ]+)\\)").matcher(pointString);
|
||||
if (!matcher.find()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
longitude = Double.parseDouble(matcher.group(1));
|
||||
latitude = Double.parseDouble(matcher.group(2));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new LatLng(latitude, longitude, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import android.os.Build;
|
|||
import android.text.Html;
|
||||
|
||||
public class StringUtils {
|
||||
public static final String EMPTY = "";
|
||||
|
||||
public static String getParsedStringFromHtml(String source) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
|
|
@ -16,4 +18,45 @@ public class StringUtils {
|
|||
public static boolean isNullOrWhiteSpace(String value) {
|
||||
return value == null || value.trim().isEmpty();
|
||||
}
|
||||
|
||||
// Defaults
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Returns either the passed in String,
|
||||
* or if the String is {@code null}, an empty String ("").</p>
|
||||
*
|
||||
* <pre>
|
||||
* StringUtils.defaultString(null) = ""
|
||||
* StringUtils.defaultString("") = ""
|
||||
* StringUtils.defaultString("bat") = "bat"
|
||||
* </pre>
|
||||
*
|
||||
* @see String#valueOf(Object)
|
||||
* @param str the String to check, may be null
|
||||
* @return the passed in String, or the empty String if it
|
||||
* was {@code null}
|
||||
*/
|
||||
public static String defaultString(final String str) {
|
||||
return defaultString(str, EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns either the passed in String, or if the String is
|
||||
* {@code null}, the value of {@code defaultStr}.</p>
|
||||
*
|
||||
* <pre>
|
||||
* StringUtils.defaultString(null, "NULL") = "NULL"
|
||||
* StringUtils.defaultString("", "NULL") = ""
|
||||
* StringUtils.defaultString("bat", "NULL") = "bat"
|
||||
* </pre>
|
||||
*
|
||||
* @see String#valueOf(Object)
|
||||
* @param str the String to check, may be null
|
||||
* @param defaultStr the default String to return
|
||||
* if the input is {@code null}, may be null
|
||||
* @return the passed in String, or the default if it was {@code null}
|
||||
*/
|
||||
public static String defaultString(final String str, final String defaultStr) {
|
||||
return str == null ? defaultStr : str;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue