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:
Paul Hawke 2024-02-02 19:26:06 -06:00 committed by GitHub
parent 72a6fd2c90
commit 0c3085257d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
337 changed files with 964 additions and 31321 deletions

View 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() {
}
}

View 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("&#8206;", "\u200E")
.replaceAll("&#8207;", "\u200F")
.replaceAll("&amp;", "&");
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() {
}
}