Completely removed CommaSeparatedList
class, replaced with two helper methods in Utils
.
The two helper methods alleviate the need for copious null checks. They also provide consistent behaviour when there are zero elements (i.e. they return null, rather than an empty string or empty array, as was the case before).
This commit is contained in:
parent
d99b357a1f
commit
a192389318
@ -27,7 +27,7 @@ public class AppFilter {
|
|||||||
public boolean filter(App app) {
|
public boolean filter(App app) {
|
||||||
if (app.requirements != null && !Preferences.get().filterAppsRequiringRoot()) {
|
if (app.requirements != null && !Preferences.get().filterAppsRequiringRoot()) {
|
||||||
for (String requirement : app.requirements) {
|
for (String requirement : app.requirements) {
|
||||||
if (requirement.equals("root")) {
|
if ("root".equals(requirement)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import android.content.pm.PackageManager;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.fdroid.fdroid.compat.SupportedArchitectures;
|
import org.fdroid.fdroid.compat.SupportedArchitectures;
|
||||||
import org.fdroid.fdroid.data.Apk;
|
import org.fdroid.fdroid.data.Apk;
|
||||||
@ -114,7 +115,7 @@ public class CompatibilityChecker {
|
|||||||
if (!compatibleApi(apk.nativecode)) {
|
if (!compatibleApi(apk.nativecode)) {
|
||||||
Collections.addAll(incompatibleReasons, apk.nativecode);
|
Collections.addAll(incompatibleReasons, apk.nativecode);
|
||||||
Utils.debugLog(TAG, apk.packageName + " vercode " + apk.versionCode
|
Utils.debugLog(TAG, apk.packageName + " vercode " + apk.versionCode
|
||||||
+ " only supports " + Utils.CommaSeparatedList.str(apk.nativecode)
|
+ " only supports " + TextUtils.join(", ", apk.nativecode)
|
||||||
+ " while your architectures are " + cpuAbisDesc);
|
+ " while your architectures are " + cpuAbisDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,13 +142,13 @@ public class RepoXMLHandler extends DefaultHandler {
|
|||||||
curapk.added = Utils.parseDate(str, null);
|
curapk.added = Utils.parseDate(str, null);
|
||||||
break;
|
break;
|
||||||
case "permissions":
|
case "permissions":
|
||||||
curapk.permissions = Utils.CommaSeparatedList.make(str);
|
curapk.permissions = Utils.parseCommaSeparatedString(str);
|
||||||
break;
|
break;
|
||||||
case "features":
|
case "features":
|
||||||
curapk.features = Utils.CommaSeparatedList.make(str);
|
curapk.features = Utils.parseCommaSeparatedString(str);
|
||||||
break;
|
break;
|
||||||
case "nativecode":
|
case "nativecode":
|
||||||
curapk.nativecode = Utils.CommaSeparatedList.make(str);
|
curapk.nativecode = Utils.parseCommaSeparatedString(str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (curapp != null) {
|
} else if (curapp != null) {
|
||||||
@ -218,13 +218,13 @@ public class RepoXMLHandler extends DefaultHandler {
|
|||||||
curapp.upstreamVersionCode = Utils.parseInt(str, -1);
|
curapp.upstreamVersionCode = Utils.parseInt(str, -1);
|
||||||
break;
|
break;
|
||||||
case "categories":
|
case "categories":
|
||||||
curapp.categories = Utils.CommaSeparatedList.make(str);
|
curapp.categories = Utils.parseCommaSeparatedString(str);
|
||||||
break;
|
break;
|
||||||
case "antifeatures":
|
case "antifeatures":
|
||||||
curapp.antiFeatures = Utils.CommaSeparatedList.make(str);
|
curapp.antiFeatures = Utils.parseCommaSeparatedString(str);
|
||||||
break;
|
break;
|
||||||
case "requirements":
|
case "requirements":
|
||||||
curapp.requirements = Utils.CommaSeparatedList.make(str);
|
curapp.requirements = Utils.parseCommaSeparatedString(str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if ("description".equals(localName)) {
|
} else if ("description".equals(localName)) {
|
||||||
|
@ -57,12 +57,8 @@ import java.security.cert.CertificateEncodingException;
|
|||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Formatter;
|
import java.util.Formatter;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public final class Utils {
|
public final class Utils {
|
||||||
@ -403,36 +399,6 @@ public final class Utils {
|
|||||||
return new Locale(languageTag);
|
return new Locale(languageTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class CommaSeparatedList {
|
|
||||||
@Nullable
|
|
||||||
public static String[] make(List<String> list) {
|
|
||||||
if (list == null || list.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return list.toArray(new String[list.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static String[] make(String[] list) {
|
|
||||||
if (list == null || list.length == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static String[] make(@Nullable String list) {
|
|
||||||
if (TextUtils.isEmpty(list)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return list.split(",");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String str(@Nullable String[] values) {
|
|
||||||
return values == null ? null : TextUtils.join(",", values);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DisplayImageOptions.Builder getImageLoadingOptions() {
|
public static DisplayImageOptions.Builder getImageLoadingOptions() {
|
||||||
return new DisplayImageOptions.Builder()
|
return new DisplayImageOptions.Builder()
|
||||||
.cacheInMemory(true)
|
.cacheInMemory(true)
|
||||||
@ -510,6 +476,16 @@ public final class Utils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static String[] parseCommaSeparatedString(String values) {
|
||||||
|
return values == null || values.length() == 0 ? null : values.split(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static String serializeCommaSeparatedString(@Nullable String[] values) {
|
||||||
|
return values == null || values.length == 0 ? null : TextUtils.join(",", values);
|
||||||
|
}
|
||||||
|
|
||||||
private static Date parseDateFormat(DateFormat format, String str, Date fallback) {
|
private static Date parseDateFormat(DateFormat format, String str, Date fallback) {
|
||||||
if (str == null || str.length() == 0) {
|
if (str == null || str.length() == 0) {
|
||||||
return fallback;
|
return fallback;
|
||||||
|
@ -83,7 +83,7 @@ public class Apk extends ValueObject implements Comparable<Apk> {
|
|||||||
added = Utils.parseDate(cursor.getString(i), null);
|
added = Utils.parseDate(cursor.getString(i), null);
|
||||||
break;
|
break;
|
||||||
case ApkProvider.DataColumns.FEATURES:
|
case ApkProvider.DataColumns.FEATURES:
|
||||||
features = Utils.CommaSeparatedList.make(cursor.getString(i));
|
features = Utils.parseCommaSeparatedString(cursor.getString(i));
|
||||||
break;
|
break;
|
||||||
case ApkProvider.DataColumns.PACKAGE_NAME:
|
case ApkProvider.DataColumns.PACKAGE_NAME:
|
||||||
packageName = cursor.getString(i);
|
packageName = cursor.getString(i);
|
||||||
@ -104,13 +104,13 @@ public class Apk extends ValueObject implements Comparable<Apk> {
|
|||||||
apkName = cursor.getString(i);
|
apkName = cursor.getString(i);
|
||||||
break;
|
break;
|
||||||
case ApkProvider.DataColumns.PERMISSIONS:
|
case ApkProvider.DataColumns.PERMISSIONS:
|
||||||
permissions = Utils.CommaSeparatedList.make(cursor.getString(i));
|
permissions = Utils.parseCommaSeparatedString(cursor.getString(i));
|
||||||
break;
|
break;
|
||||||
case ApkProvider.DataColumns.NATIVE_CODE:
|
case ApkProvider.DataColumns.NATIVE_CODE:
|
||||||
nativecode = Utils.CommaSeparatedList.make(cursor.getString(i));
|
nativecode = Utils.parseCommaSeparatedString(cursor.getString(i));
|
||||||
break;
|
break;
|
||||||
case ApkProvider.DataColumns.INCOMPATIBLE_REASONS:
|
case ApkProvider.DataColumns.INCOMPATIBLE_REASONS:
|
||||||
incompatibleReasons = Utils.CommaSeparatedList.make(cursor.getString(i));
|
incompatibleReasons = Utils.parseCommaSeparatedString(cursor.getString(i));
|
||||||
break;
|
break;
|
||||||
case ApkProvider.DataColumns.REPO_ID:
|
case ApkProvider.DataColumns.REPO_ID:
|
||||||
repo = cursor.getInt(i);
|
repo = cursor.getInt(i);
|
||||||
@ -205,10 +205,10 @@ public class Apk extends ValueObject implements Comparable<Apk> {
|
|||||||
values.put(ApkProvider.DataColumns.TARGET_SDK_VERSION, targetSdkVersion);
|
values.put(ApkProvider.DataColumns.TARGET_SDK_VERSION, targetSdkVersion);
|
||||||
values.put(ApkProvider.DataColumns.MAX_SDK_VERSION, maxSdkVersion);
|
values.put(ApkProvider.DataColumns.MAX_SDK_VERSION, maxSdkVersion);
|
||||||
values.put(ApkProvider.DataColumns.ADDED_DATE, Utils.formatDate(added, ""));
|
values.put(ApkProvider.DataColumns.ADDED_DATE, Utils.formatDate(added, ""));
|
||||||
values.put(ApkProvider.DataColumns.PERMISSIONS, Utils.CommaSeparatedList.str(permissions));
|
values.put(ApkProvider.DataColumns.PERMISSIONS, Utils.serializeCommaSeparatedString(permissions));
|
||||||
values.put(ApkProvider.DataColumns.FEATURES, Utils.CommaSeparatedList.str(features));
|
values.put(ApkProvider.DataColumns.FEATURES, Utils.serializeCommaSeparatedString(features));
|
||||||
values.put(ApkProvider.DataColumns.NATIVE_CODE, Utils.CommaSeparatedList.str(nativecode));
|
values.put(ApkProvider.DataColumns.NATIVE_CODE, Utils.serializeCommaSeparatedString(nativecode));
|
||||||
values.put(ApkProvider.DataColumns.INCOMPATIBLE_REASONS, Utils.CommaSeparatedList.str(incompatibleReasons));
|
values.put(ApkProvider.DataColumns.INCOMPATIBLE_REASONS, Utils.serializeCommaSeparatedString(incompatibleReasons));
|
||||||
values.put(ApkProvider.DataColumns.IS_COMPATIBLE, compatible ? 1 : 0);
|
values.put(ApkProvider.DataColumns.IS_COMPATIBLE, compatible ? 1 : 0);
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
@ -221,13 +221,13 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
lastUpdated = Utils.parseDate(cursor.getString(i), null);
|
lastUpdated = Utils.parseDate(cursor.getString(i), null);
|
||||||
break;
|
break;
|
||||||
case AppProvider.DataColumns.CATEGORIES:
|
case AppProvider.DataColumns.CATEGORIES:
|
||||||
categories = Utils.CommaSeparatedList.make(cursor.getString(i));
|
categories = Utils.parseCommaSeparatedString(cursor.getString(i));
|
||||||
break;
|
break;
|
||||||
case AppProvider.DataColumns.ANTI_FEATURES:
|
case AppProvider.DataColumns.ANTI_FEATURES:
|
||||||
antiFeatures = Utils.CommaSeparatedList.make(cursor.getString(i));
|
antiFeatures = Utils.parseCommaSeparatedString(cursor.getString(i));
|
||||||
break;
|
break;
|
||||||
case AppProvider.DataColumns.REQUIREMENTS:
|
case AppProvider.DataColumns.REQUIREMENTS:
|
||||||
requirements = Utils.CommaSeparatedList.make(cursor.getString(i));
|
requirements = Utils.parseCommaSeparatedString(cursor.getString(i));
|
||||||
break;
|
break;
|
||||||
case AppProvider.DataColumns.IGNORE_ALLUPDATES:
|
case AppProvider.DataColumns.IGNORE_ALLUPDATES:
|
||||||
ignoreAllUpdates = cursor.getInt(i) == 1;
|
ignoreAllUpdates = cursor.getInt(i) == 1;
|
||||||
@ -334,7 +334,7 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
apk.targetSdkVersion = minTargetMax[1];
|
apk.targetSdkVersion = minTargetMax[1];
|
||||||
apk.maxSdkVersion = minTargetMax[2];
|
apk.maxSdkVersion = minTargetMax[2];
|
||||||
apk.packageName = this.packageName;
|
apk.packageName = this.packageName;
|
||||||
apk.permissions = Utils.CommaSeparatedList.make(packageInfo.requestedPermissions);
|
apk.permissions = packageInfo.requestedPermissions;
|
||||||
apk.apkName = apk.packageName + "_" + apk.versionCode + ".apk";
|
apk.apkName = apk.packageName + "_" + apk.versionCode + ".apk";
|
||||||
apk.installedFile = apkFile;
|
apk.installedFile = apkFile;
|
||||||
|
|
||||||
@ -348,15 +348,14 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
abis.add(matcher.group(1));
|
abis.add(matcher.group(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apk.nativecode = Utils.CommaSeparatedList.make(abis.toArray(new String[abis.size()]));
|
apk.nativecode = abis.toArray(new String[abis.size()]);
|
||||||
|
|
||||||
final FeatureInfo[] features = packageInfo.reqFeatures;
|
final FeatureInfo[] features = packageInfo.reqFeatures;
|
||||||
if (features != null && features.length > 0) {
|
if (features != null && features.length > 0) {
|
||||||
final String[] featureNames = new String[features.length];
|
apk.features = new String[features.length];
|
||||||
for (int i = 0; i < features.length; i++) {
|
for (int i = 0; i < features.length; i++) {
|
||||||
featureNames[i] = features[i].name;
|
apk.features[i] = features[i].name;
|
||||||
}
|
}
|
||||||
apk.features = Utils.CommaSeparatedList.make(featureNames);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final JarEntry aSignedEntry = (JarEntry) apkJar.getEntry("AndroidManifest.xml");
|
final JarEntry aSignedEntry = (JarEntry) apkJar.getEntry("AndroidManifest.xml");
|
||||||
@ -462,9 +461,9 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
values.put(AppProvider.DataColumns.SUGGESTED_VERSION_CODE, suggestedVersionCode);
|
values.put(AppProvider.DataColumns.SUGGESTED_VERSION_CODE, suggestedVersionCode);
|
||||||
values.put(AppProvider.DataColumns.UPSTREAM_VERSION_NAME, upstreamVersionName);
|
values.put(AppProvider.DataColumns.UPSTREAM_VERSION_NAME, upstreamVersionName);
|
||||||
values.put(AppProvider.DataColumns.UPSTREAM_VERSION_CODE, upstreamVersionCode);
|
values.put(AppProvider.DataColumns.UPSTREAM_VERSION_CODE, upstreamVersionCode);
|
||||||
values.put(AppProvider.DataColumns.CATEGORIES, Utils.CommaSeparatedList.str(categories));
|
values.put(AppProvider.DataColumns.CATEGORIES, Utils.serializeCommaSeparatedString(categories));
|
||||||
values.put(AppProvider.DataColumns.ANTI_FEATURES, Utils.CommaSeparatedList.str(antiFeatures));
|
values.put(AppProvider.DataColumns.ANTI_FEATURES, Utils.serializeCommaSeparatedString(antiFeatures));
|
||||||
values.put(AppProvider.DataColumns.REQUIREMENTS, Utils.CommaSeparatedList.str(requirements));
|
values.put(AppProvider.DataColumns.REQUIREMENTS, Utils.serializeCommaSeparatedString(requirements));
|
||||||
values.put(AppProvider.DataColumns.IS_COMPATIBLE, compatible ? 1 : 0);
|
values.put(AppProvider.DataColumns.IS_COMPATIBLE, compatible ? 1 : 0);
|
||||||
values.put(AppProvider.DataColumns.IGNORE_ALLUPDATES, ignoreAllUpdates ? 1 : 0);
|
values.put(AppProvider.DataColumns.IGNORE_ALLUPDATES, ignoreAllUpdates ? 1 : 0);
|
||||||
values.put(AppProvider.DataColumns.IGNORE_THISUPDATE, ignoreThisUpdate);
|
values.put(AppProvider.DataColumns.IGNORE_THISUPDATE, ignoreThisUpdate);
|
||||||
|
@ -98,7 +98,7 @@ public class AppProvider extends FDroidProvider {
|
|||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
while (!cursor.isAfterLast()) {
|
while (!cursor.isAfterLast()) {
|
||||||
final String categoriesString = cursor.getString(0);
|
final String categoriesString = cursor.getString(0);
|
||||||
String[] categoriesList = Utils.CommaSeparatedList.make(categoriesString);
|
String[] categoriesList = Utils.parseCommaSeparatedString(categoriesString);
|
||||||
if (categoriesList != null) {
|
if (categoriesList != null) {
|
||||||
Collections.addAll(categorySet, categoriesList);
|
Collections.addAll(categorySet, categoriesList);
|
||||||
}
|
}
|
||||||
|
@ -284,7 +284,7 @@ public class RepoPersister {
|
|||||||
final List<String> reasons = checker.getIncompatibleReasons(apk);
|
final List<String> reasons = checker.getIncompatibleReasons(apk);
|
||||||
if (reasons.size() > 0) {
|
if (reasons.size() > 0) {
|
||||||
apk.compatible = false;
|
apk.compatible = false;
|
||||||
apk.incompatibleReasons = Utils.CommaSeparatedList.make(reasons);
|
apk.incompatibleReasons = reasons.toArray(new String[reasons.size()]);
|
||||||
} else {
|
} else {
|
||||||
apk.compatible = true;
|
apk.compatible = true;
|
||||||
apk.incompatibleReasons = null;
|
apk.incompatibleReasons = null;
|
||||||
|
@ -454,7 +454,7 @@ public final class LocalRepoManager {
|
|||||||
private void tagFeatures(App app) throws IOException {
|
private void tagFeatures(App app) throws IOException {
|
||||||
serializer.startTag("", "features");
|
serializer.startTag("", "features");
|
||||||
if (app.installedApk.features != null) {
|
if (app.installedApk.features != null) {
|
||||||
serializer.text(Utils.CommaSeparatedList.str(app.installedApk.features));
|
serializer.text(TextUtils.join(",", app.installedApk.features));
|
||||||
}
|
}
|
||||||
serializer.endTag("", "features");
|
serializer.endTag("", "features");
|
||||||
}
|
}
|
||||||
@ -462,7 +462,7 @@ public final class LocalRepoManager {
|
|||||||
private void tagNativecode(App app) throws IOException {
|
private void tagNativecode(App app) throws IOException {
|
||||||
if (app.installedApk.nativecode != null) {
|
if (app.installedApk.nativecode != null) {
|
||||||
serializer.startTag("", "nativecode");
|
serializer.startTag("", "nativecode");
|
||||||
serializer.text(Utils.CommaSeparatedList.str(app.installedApk.nativecode));
|
serializer.text(TextUtils.join(",", app.installedApk.nativecode));
|
||||||
serializer.endTag("", "nativecode");
|
serializer.endTag("", "nativecode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import android.net.Uri;
|
|||||||
|
|
||||||
import org.fdroid.fdroid.Assert;
|
import org.fdroid.fdroid.Assert;
|
||||||
import org.fdroid.fdroid.BuildConfig;
|
import org.fdroid.fdroid.BuildConfig;
|
||||||
import org.fdroid.fdroid.Utils;
|
|
||||||
import org.fdroid.fdroid.mock.MockApk;
|
import org.fdroid.fdroid.mock.MockApk;
|
||||||
import org.fdroid.fdroid.mock.MockApp;
|
import org.fdroid.fdroid.mock.MockApp;
|
||||||
import org.fdroid.fdroid.mock.MockRepo;
|
import org.fdroid.fdroid.mock.MockRepo;
|
||||||
@ -410,7 +409,7 @@ public class ApkProviderTest extends FDroidProviderTest {
|
|||||||
assertNull(apk.added);
|
assertNull(apk.added);
|
||||||
assertNull(apk.hashType);
|
assertNull(apk.hashType);
|
||||||
|
|
||||||
apk.features = Utils.CommaSeparatedList.make("one,two,three");
|
apk.features = new String[] {"one", "two", "three" };
|
||||||
long dateTimestamp = System.currentTimeMillis();
|
long dateTimestamp = System.currentTimeMillis();
|
||||||
apk.added = new Date(dateTimestamp);
|
apk.added = new Date(dateTimestamp);
|
||||||
apk.hashType = "i'm a hash type";
|
apk.hashType = "i'm a hash type";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user