mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Update master with backend overhaul branch (#2829)
* Beginnings of integration with Wikipedia client library. (#2642) * Remove remaining unnecessary API version check. * Roll up sleeves. * Add and integrate the beginnings of app adapter. * Remove vestigial event logging logic. Event logging is no longer used in this app. * Beginnings: remove StringUtils and associated redundancies. * Remove redundant capitalize() method. * Remove redundant urlEncode() method. * Remove redundant (and incomplete) language lists. * Remove redundant usages of SimpleDateFormat. * Remove redundant json type adapter. * Remove redundant MW error model classes. * Rip out redundant MW model classes. * Pass SessionManager into AppAdapter instead of injecting. * Wire up more of the AppAdapter. * Remove redundant Gson initialization and type adapters. * Rip out PageTitle. This was being used in some slightly incorrect/unexpected ways. * Don't need static WikiSite. * Bump data client library version * Bump library version and fix build * Fix tests * Fix build * Fix media of the day * With fixes in recently modified APIs
This commit is contained in:
parent
76e5a30fb5
commit
dcbf076965
76 changed files with 424 additions and 2122 deletions
|
|
@ -1,67 +0,0 @@
|
|||
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;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DateUtils {
|
||||
private static final SimpleDateFormat isoFormat =
|
||||
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
|
||||
|
||||
public static String getTimeAgo(Date currDate, Date itemDate) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(currDate);
|
||||
int yearNow = c.get(Calendar.YEAR);
|
||||
int monthNow = c.get(Calendar.MONTH);
|
||||
int dayNow = c.get(Calendar.DAY_OF_MONTH);
|
||||
int hourNow = c.get(Calendar.HOUR_OF_DAY);
|
||||
int minuteNow = c.get(Calendar.MINUTE);
|
||||
c.setTime(itemDate);
|
||||
int videoYear = c.get(Calendar.YEAR);
|
||||
int videoMonth = c.get(Calendar.MONTH);
|
||||
int videoDays = c.get(Calendar.DAY_OF_MONTH);
|
||||
int videoHour = c.get(Calendar.HOUR_OF_DAY);
|
||||
int videoMinute = c.get(Calendar.MINUTE);
|
||||
|
||||
if (yearNow != videoYear) {
|
||||
return (String.valueOf(yearNow - videoYear) + "-" + "years");
|
||||
} else if (monthNow != videoMonth) {
|
||||
return (String.valueOf(monthNow - videoMonth) + "-" + "months");
|
||||
} else if (dayNow != videoDays) {
|
||||
return (String.valueOf(dayNow - videoDays) + "-" + "days");
|
||||
} else if (hourNow != videoHour) {
|
||||
return (String.valueOf(hourNow - videoHour) + "-" + "hours");
|
||||
} else if (minuteNow != videoMinute) {
|
||||
return (String.valueOf(minuteNow - videoMinute) + "-" + "minutes");
|
||||
} else {
|
||||
return "0-seconds";
|
||||
}
|
||||
}
|
||||
|
||||
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){
|
||||
return new SimpleDateFormat(DateFormat.getBestDateTimePattern(Locale.getDefault(), "dd MMM yyyy"), Locale.getDefault()).format(date);
|
||||
}
|
||||
|
||||
public static String formatMWDate(Date date) {
|
||||
return isoFormat.format(date);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,8 @@ import android.app.Dialog;
|
|||
import android.content.DialogInterface;
|
||||
import android.view.View;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -59,7 +61,7 @@ public class DialogUtil {
|
|||
builder.setTitle(title);
|
||||
builder.setMessage(message);
|
||||
|
||||
if (!StringUtils.isNullOrWhiteSpace(positiveButtonText)) {
|
||||
if (!StringUtils.isBlank(positiveButtonText)) {
|
||||
builder.setPositiveButton(positiveButtonText, (dialogInterface, i) -> {
|
||||
dialogInterface.dismiss();
|
||||
if (onPositiveBtnClick != null) {
|
||||
|
|
@ -68,7 +70,7 @@ public class DialogUtil {
|
|||
});
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrWhiteSpace(negativeButtonText)) {
|
||||
if (!StringUtils.isBlank(negativeButtonText)) {
|
||||
builder.setNegativeButton(negativeButtonText, (DialogInterface dialogInterface, int i) -> {
|
||||
dialogInterface.dismiss();
|
||||
if (onNegativeBtnClick != null) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
|
@ -33,13 +35,13 @@ public class MediaDataExtractorUtil {
|
|||
* @return
|
||||
*/
|
||||
public static List<String> extractCategoriesFromList(String source) {
|
||||
if (StringUtils.isNullOrWhiteSpace(source)) {
|
||||
if (StringUtils.isBlank(source)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
String[] cats = source.split("\\|");
|
||||
List<String> categories = new ArrayList<>();
|
||||
for (String category : cats) {
|
||||
if (!StringUtils.isNullOrWhiteSpace(category.trim())) {
|
||||
if (!StringUtils.isBlank(category.trim())) {
|
||||
categories.add(category);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
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();
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
return Html.fromHtml(source).toString();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class UriDeserializer implements JsonDeserializer<Uri> {
|
||||
@Override
|
||||
public Uri deserialize(final JsonElement src, final Type srcType,
|
||||
final JsonDeserializationContext context) throws JsonParseException {
|
||||
return Uri.parse(src.getAsString());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
|
||||
public class UriSerializer implements JsonSerializer<Uri> {
|
||||
public JsonElement serialize(Uri src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.toString());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue