mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Data client simplification / removal (#5507)
* Removed unused code from the data client module * Move remaining code out of the data-client and remove it
This commit is contained in:
parent
72a6fd2c90
commit
0c3085257d
337 changed files with 964 additions and 31321 deletions
53
app/src/main/java/fr/free/nrw/commons/utils/DateUtil.java
Normal file
53
app/src/main/java/fr/free/nrw/commons/utils/DateUtil.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import static android.text.format.DateFormat.getBestDateTimePattern;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public final class DateUtil {
|
||||
private static Map<String, SimpleDateFormat> DATE_FORMATS = new HashMap<>();
|
||||
|
||||
// TODO: Switch to DateTimeFormatter when minSdk = 26.
|
||||
|
||||
public static synchronized String iso8601DateFormat(Date date) {
|
||||
return getCachedDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT, true).format(date);
|
||||
}
|
||||
|
||||
public static synchronized Date iso8601DateParse(String date) throws ParseException {
|
||||
return getCachedDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT, true).parse(date);
|
||||
}
|
||||
|
||||
public static String getMonthOnlyDateString(@NonNull Date date) {
|
||||
return getDateStringWithSkeletonPattern(date, "MMMM d");
|
||||
}
|
||||
|
||||
public static String getExtraShortDateString(@NonNull Date date) {
|
||||
return getDateStringWithSkeletonPattern(date, "MMM d");
|
||||
}
|
||||
|
||||
public static synchronized String getDateStringWithSkeletonPattern(@NonNull Date date, @NonNull String pattern) {
|
||||
return getCachedDateFormat(getBestDateTimePattern(Locale.getDefault(), pattern), Locale.getDefault(), false).format(date);
|
||||
}
|
||||
|
||||
private static SimpleDateFormat getCachedDateFormat(String pattern, Locale locale, boolean utc) {
|
||||
if (!DATE_FORMATS.containsKey(pattern)) {
|
||||
SimpleDateFormat df = new SimpleDateFormat(pattern, locale);
|
||||
if (utc) {
|
||||
df.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
DATE_FORMATS.put(pattern, df);
|
||||
}
|
||||
return DATE_FORMATS.get(pattern);
|
||||
}
|
||||
|
||||
private DateUtil() {
|
||||
}
|
||||
}
|
||||
38
app/src/main/java/fr/free/nrw/commons/utils/StringUtil.java
Normal file
38
app/src/main/java/fr/free/nrw/commons/utils/StringUtil.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.SpannedString;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public final class StringUtil {
|
||||
|
||||
/**
|
||||
* @param source String that may contain HTML tags.
|
||||
* @return returned Spanned string that may contain spans parsed from the HTML source.
|
||||
*/
|
||||
@NonNull public static Spanned fromHtml(@Nullable String source) {
|
||||
if (source == null) {
|
||||
return new SpannedString("");
|
||||
}
|
||||
if (!source.contains("<") && !source.contains("&")) {
|
||||
// If the string doesn't contain any hints of HTML entities, then skip the expensive
|
||||
// processing that fromHtml() performs.
|
||||
return new SpannedString(source);
|
||||
}
|
||||
source = source.replaceAll("‎", "\u200E")
|
||||
.replaceAll("‏", "\u200F")
|
||||
.replaceAll("&", "&");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
return Html.fromHtml(source);
|
||||
}
|
||||
}
|
||||
|
||||
private StringUtil() {
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue