From 25191a968f84d0cb504f0668321e52878d7ada8a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 23 Apr 2013 12:21:54 -0700 Subject: [PATCH] Categories now save :D Still to do: * limit number of entries * order by last-used * show entries on the initial screen before searching --- .../commons/CategorizationFragment.java | 16 +++++++++++++--- .../org/wikimedia/commons/category/Category.java | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/commons/src/main/java/org/wikimedia/commons/CategorizationFragment.java b/commons/src/main/java/org/wikimedia/commons/CategorizationFragment.java index 129dfa5ef..d85c28fe3 100644 --- a/commons/src/main/java/org/wikimedia/commons/CategorizationFragment.java +++ b/commons/src/main/java/org/wikimedia/commons/CategorizationFragment.java @@ -1,6 +1,7 @@ package org.wikimedia.commons; import android.app.Activity; +import android.content.ContentProviderClient; import android.content.Context; import android.database.Cursor; import android.os.AsyncTask; @@ -249,14 +250,21 @@ public class CategorizationFragment extends SherlockFragment{ cat.setName(name); cat.setLastUsed(new Date()); cat.setTimesUsed(0); - // fixme do we have to dispose of this ContentProviderClient? - cat.setContentProviderClient(getActivity().getContentResolver().acquireContentProviderClient(CategoryContentProvider.AUTHORITY)); return cat; } private void updateCategoryCount(String name) { Category cat = lookupCategory(name); cat.incTimesUsed(); + + ContentProviderClient client = getActivity().getContentResolver().acquireContentProviderClient(CategoryContentProvider.AUTHORITY); + if (client == null) { + // explode + throw new RuntimeException("wtf"); + } + cat.setContentProviderClient(client); cat.save(); + cat.setContentProviderClient(null); + client.release(); } @Override @@ -294,7 +302,9 @@ public class CategorizationFragment extends SherlockFragment{ item.selected = !item.selected; checkedView.setChecked(item.selected); // fixme do this asynchronously? - updateCategoryCount(item.name); + if (item.selected) { + updateCategoryCount(item.name); + } } }); diff --git a/commons/src/main/java/org/wikimedia/commons/category/Category.java b/commons/src/main/java/org/wikimedia/commons/category/Category.java index 33609962b..6ea7f5076 100644 --- a/commons/src/main/java/org/wikimedia/commons/category/Category.java +++ b/commons/src/main/java/org/wikimedia/commons/category/Category.java @@ -87,7 +87,7 @@ public class Category { public static Category fromCursor(Cursor cursor) { // Hardcoding column positions! Category c = new Category(); - c.contentUri = ContributionsContentProvider.uriForId(cursor.getInt(0)); + c.contentUri = CategoryContentProvider.uriForId(cursor.getInt(0)); c.name = cursor.getString(1); c.lastUsed = new Date(cursor.getLong(2)); c.timesUsed = cursor.getInt(3);