Support multiple categories as CommaSeparatedList

This commit is contained in:
Daniel Martí 2013-11-02 00:57:38 +01:00
parent be5dbbfc55
commit 327de12f1a
3 changed files with 44 additions and 27 deletions

View File

@ -88,17 +88,17 @@ public class AppListManager {
// Populate the category list with the real categories, and the // Populate the category list with the real categories, and the
// locally generated meta-categories for "All", "What's New" and // locally generated meta-categories for "All", "What's New" and
// "Recently Updated"... // "Recently Updated"...
categoryAll = fdroidActivity.getString(R.string.category_all); categoryAll = fdroidActivity
categoryWhatsNew = fdroidActivity.getString(R.string.category_whatsnew); .getString(R.string.category_all);
categoryRecentlyUpdated = fdroidActivity.getString(R.string.category_recentlyupdated); categoryWhatsNew = fdroidActivity
.getString(R.string.category_whatsnew);
categoryRecentlyUpdated = fdroidActivity
.getString(R.string.category_recentlyupdated);
categories.add(categoryWhatsNew); categories.add(categoryWhatsNew);
categories.add(categoryRecentlyUpdated); categories.add(categoryRecentlyUpdated);
categories.add(categoryAll); categories.add(categoryAll);
categories.addAll(db.getCategories());
for (String s : db.getCategories()) {
categories.add(s);
}
if (currentCategory == null) if (currentCategory == null)
currentCategory = categoryWhatsNew; currentCategory = categoryWhatsNew;

View File

@ -97,7 +97,7 @@ public class DB {
+ "antiFeatures string," + "donateURL string," + "antiFeatures string," + "donateURL string,"
+ "bitcoinAddr string," + "litecoinAddr string," + "bitcoinAddr string," + "litecoinAddr string,"
+ "flattrID string," + "requirements string," + "flattrID string," + "requirements string,"
+ "category string," + "added string," + "categories string," + "added string,"
+ "lastUpdated string," + "compatible int not null," + "lastUpdated string," + "compatible int not null,"
+ "ignoreAllUpdates int not null," + "ignoreAllUpdates int not null,"
+ "ignoreThisUpdate int not null," + "ignoreThisUpdate int not null,"
@ -111,13 +111,13 @@ public class DB {
icon = null; icon = null;
id = "unknown"; id = "unknown";
license = "Unknown"; license = "Unknown";
category = "Uncategorized";
detail_trackerURL = null; detail_trackerURL = null;
detail_sourceURL = null; detail_sourceURL = null;
detail_donateURL = null; detail_donateURL = null;
detail_bitcoinAddr = null; detail_bitcoinAddr = null;
detail_litecoinAddr = null; detail_litecoinAddr = null;
detail_webURL = null; detail_webURL = null;
categories = null;
antiFeatures = null; antiFeatures = null;
requirements = null; requirements = null;
hasUpdates = false; hasUpdates = false;
@ -149,7 +149,6 @@ public class DB {
public String detail_description; public String detail_description;
public String license; public String license;
public String category;
// Null when !detail_Populated // Null when !detail_Populated
public String detail_webURL; public String detail_webURL;
@ -189,6 +188,10 @@ public class DB {
public int installedVerCode; public int installedVerCode;
public boolean userInstalled; public boolean userInstalled;
// List of categories (as defined in the metadata
// documentation) or null if there aren't any.
public CommaSeparatedList categories;
// List of anti-features (as defined in the metadata // List of anti-features (as defined in the metadata
// documentation) or null if there aren't any. // documentation) or null if there aren't any.
public CommaSeparatedList antiFeatures; public CommaSeparatedList antiFeatures;
@ -440,12 +443,11 @@ public class DB {
public String lastetag; // last etag we updated from, null forces update public String lastetag; // last etag we updated from, null forces update
} }
private final int DBVersion = 27; private final int DBVersion = 28;
private static void createAppApk(SQLiteDatabase db) { private static void createAppApk(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_APP); db.execSQL(CREATE_TABLE_APP);
db.execSQL("create index app_id on " + TABLE_APP + " (id);"); db.execSQL("create index app_id on " + TABLE_APP + " (id);");
db.execSQL("create index app_category on " + TABLE_APP + " (category);");
db.execSQL(CREATE_TABLE_APK); db.execSQL(CREATE_TABLE_APK);
db.execSQL("create index apk_vercode on " + TABLE_APK + " (vercode);"); db.execSQL("create index apk_vercode on " + TABLE_APK + " (vercode);");
db.execSQL("create index apk_id on " + TABLE_APK + " (id);"); db.execSQL("create index apk_id on " + TABLE_APK + " (id);");
@ -628,13 +630,19 @@ public class DB {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<String>();
Cursor c = null; Cursor c = null;
try { try {
c = db.query(true, TABLE_APP, new String[] { "category" }, c = db.query(true, TABLE_APP, new String[] { "categories" },
null, null, null, null, "category", null); null, null, null, null, "categories", null);
c.moveToFirst(); c.moveToFirst();
while (!c.isAfterLast()) { while (!c.isAfterLast()) {
String s = c.getString(0); Log.d("FDroid", "== CATEGS "+c.getString(0));
if (s != null) { CommaSeparatedList categories = CommaSeparatedList
result.add(s); .make(c.getString(0));
for (String category : categories) {
Log.d("FDroid", "== CATEG "+category);
if (!result.contains(category)) {
Log.d("FDroid", "== CATEG ADDED "+category);
result.add(category);
}
} }
c.moveToNext(); c.moveToNext();
} }
@ -760,7 +768,7 @@ public class DB {
try { try {
String cols[] = new String[] { "antiFeatures", "requirements", String cols[] = new String[] { "antiFeatures", "requirements",
"id", "name", "summary", "icon", "license", "category", "categories", "id", "name", "summary", "icon", "license",
"curVersion", "curVercode", "added", "lastUpdated", "curVersion", "curVercode", "added", "lastUpdated",
"compatible", "ignoreAllUpdates", "ignoreThisUpdate" }; "compatible", "ignoreAllUpdates", "ignoreThisUpdate" };
c = db.query(TABLE_APP, cols, null, null, null, null, null); c = db.query(TABLE_APP, cols, null, null, null, null, null);
@ -770,12 +778,12 @@ public class DB {
App app = new App(); App app = new App();
app.antiFeatures = DB.CommaSeparatedList.make(c.getString(0)); app.antiFeatures = DB.CommaSeparatedList.make(c.getString(0));
app.requirements = DB.CommaSeparatedList.make(c.getString(1)); app.requirements = DB.CommaSeparatedList.make(c.getString(1));
app.id = c.getString(2); app.categories = DB.CommaSeparatedList.make(c.getString(2));
app.name = c.getString(3); app.id = c.getString(3);
app.summary = c.getString(4); app.name = c.getString(4);
app.icon = c.getString(5); app.summary = c.getString(5);
app.license = c.getString(6); app.icon = c.getString(6);
app.category = c.getString(7); app.license = c.getString(7);
app.curVersion = c.getString(8); app.curVersion = c.getString(8);
app.curVercode = c.getInt(9); app.curVercode = c.getInt(9);
String sAdded = c.getString(10); String sAdded = c.getString(10);
@ -983,6 +991,15 @@ public class DB {
splitter.setString(value); splitter.setString(value);
return splitter.iterator(); return splitter.iterator();
} }
public boolean contains(String v) {
Iterator<String> it = iterator();
while (it.hasNext()) {
if (it.next().equals(v))
return true;
}
return false;
}
} }
private List<App> updateApps = null; private List<App> updateApps = null;
@ -1128,7 +1145,6 @@ public class DB {
values.put("icon", upapp.icon); values.put("icon", upapp.icon);
values.put("description", upapp.detail_description); values.put("description", upapp.detail_description);
values.put("license", upapp.license); values.put("license", upapp.license);
values.put("category", upapp.category);
values.put("webURL", upapp.detail_webURL); values.put("webURL", upapp.detail_webURL);
values.put("trackerURL", upapp.detail_trackerURL); values.put("trackerURL", upapp.detail_trackerURL);
values.put("sourceURL", upapp.detail_sourceURL); values.put("sourceURL", upapp.detail_sourceURL);
@ -1144,6 +1160,7 @@ public class DB {
.format(upapp.lastUpdated)); .format(upapp.lastUpdated));
values.put("curVersion", upapp.curVersion); values.put("curVersion", upapp.curVersion);
values.put("curVercode", upapp.curVercode); values.put("curVercode", upapp.curVercode);
values.put("categories", CommaSeparatedList.str(upapp.categories));
values.put("antiFeatures", CommaSeparatedList.str(upapp.antiFeatures)); values.put("antiFeatures", CommaSeparatedList.str(upapp.antiFeatures));
values.put("requirements", CommaSeparatedList.str(upapp.requirements)); values.put("requirements", CommaSeparatedList.str(upapp.requirements));
values.put("compatible", upapp.compatible ? 1 : 0); values.put("compatible", upapp.compatible ? 1 : 0);

View File

@ -195,8 +195,6 @@ public class RepoXMLHandler extends DefaultHandler {
curapp.summary = str; curapp.summary = str;
} else if (curel.equals("license")) { } else if (curel.equals("license")) {
curapp.license = str; curapp.license = str;
} else if (curel.equals("category")) {
curapp.category = str;
} else if (curel.equals("source")) { } else if (curel.equals("source")) {
curapp.detail_sourceURL = str; curapp.detail_sourceURL = str;
} else if (curel.equals("donate")) { } else if (curel.equals("donate")) {
@ -233,6 +231,8 @@ public class RepoXMLHandler extends DefaultHandler {
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
curapp.curVercode = -1; curapp.curVercode = -1;
} }
} else if (curel.equals("category")) {
curapp.categories = DB.CommaSeparatedList.make(str);
} else if (curel.equals("antifeatures")) { } else if (curel.equals("antifeatures")) {
curapp.antiFeatures = DB.CommaSeparatedList.make(str); curapp.antiFeatures = DB.CommaSeparatedList.make(str);
} else if (curel.equals("requirements")) { } else if (curel.equals("requirements")) {