Categories now save :D

Still to do:
* limit number of entries
* order by last-used
* show entries on the initial screen before searching
This commit is contained in:
Brion Vibber 2013-04-23 12:21:54 -07:00
parent 79f6185f8c
commit 25191a968f
2 changed files with 14 additions and 4 deletions

View file

@ -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,8 +302,10 @@ public class CategorizationFragment extends SherlockFragment{
item.selected = !item.selected;
checkedView.setChecked(item.selected);
// fixme do this asynchronously?
if (item.selected) {
updateCategoryCount(item.name);
}
}
});
categoriesFilter.addTextChangedListener(new TextWatcher() {

View file

@ -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);