mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
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:
parent
79f6185f8c
commit
25191a968f
2 changed files with 14 additions and 4 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package org.wikimedia.commons;
|
package org.wikimedia.commons;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.ContentProviderClient;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
@ -249,14 +250,21 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
cat.setName(name);
|
cat.setName(name);
|
||||||
cat.setLastUsed(new Date());
|
cat.setLastUsed(new Date());
|
||||||
cat.setTimesUsed(0);
|
cat.setTimesUsed(0);
|
||||||
// fixme do we have to dispose of this ContentProviderClient?
|
|
||||||
cat.setContentProviderClient(getActivity().getContentResolver().acquireContentProviderClient(CategoryContentProvider.AUTHORITY));
|
|
||||||
return cat;
|
return cat;
|
||||||
}
|
}
|
||||||
private void updateCategoryCount(String name) {
|
private void updateCategoryCount(String name) {
|
||||||
Category cat = lookupCategory(name);
|
Category cat = lookupCategory(name);
|
||||||
cat.incTimesUsed();
|
cat.incTimesUsed();
|
||||||
|
|
||||||
|
ContentProviderClient client = getActivity().getContentResolver().acquireContentProviderClient(CategoryContentProvider.AUTHORITY);
|
||||||
|
if (client == null) {
|
||||||
|
// explode
|
||||||
|
throw new RuntimeException("wtf");
|
||||||
|
}
|
||||||
|
cat.setContentProviderClient(client);
|
||||||
cat.save();
|
cat.save();
|
||||||
|
cat.setContentProviderClient(null);
|
||||||
|
client.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -294,7 +302,9 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
item.selected = !item.selected;
|
item.selected = !item.selected;
|
||||||
checkedView.setChecked(item.selected);
|
checkedView.setChecked(item.selected);
|
||||||
// fixme do this asynchronously?
|
// fixme do this asynchronously?
|
||||||
updateCategoryCount(item.name);
|
if (item.selected) {
|
||||||
|
updateCategoryCount(item.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ public class Category {
|
||||||
public static Category fromCursor(Cursor cursor) {
|
public static Category fromCursor(Cursor cursor) {
|
||||||
// Hardcoding column positions!
|
// Hardcoding column positions!
|
||||||
Category c = new Category();
|
Category c = new Category();
|
||||||
c.contentUri = ContributionsContentProvider.uriForId(cursor.getInt(0));
|
c.contentUri = CategoryContentProvider.uriForId(cursor.getInt(0));
|
||||||
c.name = cursor.getString(1);
|
c.name = cursor.getString(1);
|
||||||
c.lastUsed = new Date(cursor.getLong(2));
|
c.lastUsed = new Date(cursor.getLong(2));
|
||||||
c.timesUsed = cursor.getInt(3);
|
c.timesUsed = cursor.getInt(3);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue