diff --git a/commons/commons.iml b/commons/commons.iml
index 0fec16f50..55cc5b2fb 100644
--- a/commons/commons.iml
+++ b/commons/commons.iml
@@ -5,28 +5,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
- /res-overlay
-
- true
true
-
diff --git a/commons/src/main/java/org/wikimedia/commons/CategorizationFragment.java b/commons/src/main/java/org/wikimedia/commons/CategorizationFragment.java
index b294dd1af..3ffa89498 100644
--- a/commons/src/main/java/org/wikimedia/commons/CategorizationFragment.java
+++ b/commons/src/main/java/org/wikimedia/commons/CategorizationFragment.java
@@ -239,15 +239,20 @@ public class CategorizationFragment extends SherlockFragment{
}
private Category lookupCategory(String name) {
- Cursor cursor = getActivity().getContentResolver().query(
- CategoryContentProvider.BASE_URI,
- Category.Table.ALL_FIELDS,
- Category.Table.COLUMN_NAME + "=?",
- new String[] {name},
- null);
- if (cursor.moveToNext()) {
- Category cat = Category.fromCursor(cursor);
- return cat;
+ try {
+ Cursor cursor = client.query(
+ CategoryContentProvider.BASE_URI,
+ Category.Table.ALL_FIELDS,
+ Category.Table.COLUMN_NAME + "=?",
+ new String[] {name},
+ null);
+ if (cursor.moveToFirst()) {
+ Category cat = Category.fromCursor(cursor);
+ return cat;
+ }
+ } catch (RemoteException e) {
+ // This feels lazy, but to hell with checked exceptions. :)
+ throw new RuntimeException(e);
}
// Newly used category...
@@ -257,12 +262,27 @@ public class CategorizationFragment extends SherlockFragment{
cat.setTimesUsed(0);
return cat;
}
- private void updateCategoryCount(String name) {
- Category cat = lookupCategory(name);
- cat.incTimesUsed();
- cat.setContentProviderClient(client);
- cat.save();
+ private class CategoryCountUpdater extends AsyncTask {
+
+ private String name;
+
+ public CategoryCountUpdater(String name) {
+ this.name = name;
+ }
+
+ @Override
+ protected void doInBackground(Void... voids) {
+ Category cat = lookupCategory(name);
+ cat.incTimesUsed();
+
+ cat.setContentProviderClient(client);
+ cat.save();
+ }
+ }
+
+ private void updateCategoryCount(String name) {
+ Utils.executeAsyncTask(new CategoryCountUpdater(name), executor);
}
@Override
@@ -299,7 +319,6 @@ public class CategorizationFragment extends SherlockFragment{
CategoryItem item = (CategoryItem) adapterView.getAdapter().getItem(index);
item.selected = !item.selected;
checkedView.setChecked(item.selected);
- // fixme do this asynchronously?
if (item.selected) {
updateCategoryCount(item.name);
}
@@ -348,9 +367,8 @@ public class CategorizationFragment extends SherlockFragment{
@Override
public void onDestroy() {
- client.release();
- client = null;
super.onDestroy();
+ client.release();
}
@Override
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 920afbf98..ae2045867 100644
--- a/commons/src/main/java/org/wikimedia/commons/category/Category.java
+++ b/commons/src/main/java/org/wikimedia/commons/category/Category.java
@@ -13,13 +13,6 @@ import org.wikimedia.commons.contributions.ContributionsContentProvider;
import java.util.Date;
-/**
- * Created with IntelliJ IDEA.
- * User: brion
- * Date: 4/22/13
- * Time: 3:37 PM
- * To change this template use File | Settings | File Templates.
- */
public class Category {
private ContentProviderClient client;
private Uri contentUri;
@@ -33,8 +26,8 @@ public class Category {
return name;
}
- public void setName(String name_) {
- name = name_;
+ public void setName(String name) {
+ this.name = name;
}
public Date getLastUsed() {
@@ -42,9 +35,9 @@ public class Category {
return (Date)lastUsed.clone();
}
- public void setLastUsed(Date lastUsed_) {
+ public void setLastUsed(Date lastUsed) {
// warning: Date objects are mutable.
- lastUsed = (Date)lastUsed_.clone();
+ this.lastUsed = (Date)lastUsed.clone();
}
public void touch() {
@@ -55,8 +48,8 @@ public class Category {
return timesUsed;
}
- public void setTimesUsed(int timesUsed_) {
- timesUsed = timesUsed_;
+ public void setTimesUsed(int timesUsed) {
+ this.timesUsed = timesUsed;
}
public void incTimesUsed() {
@@ -119,7 +112,7 @@ public class Category {
private static final String CREATE_TABLE_STATEMENT = "CREATE TABLE " + TABLE_NAME + " ("
+ COLUMN_ID + " INTEGER PRIMARY KEY,"
+ COLUMN_NAME + " STRING,"
- + COLUMN_LAST_USED + " INTEGER," // Will this roll over in 2038? :)
+ + COLUMN_LAST_USED + " INTEGER,"
+ COLUMN_TIMES_USED + " INTEGER"
+ ");";
diff --git a/commons/src/main/java/org/wikimedia/commons/category/CategoryContentProvider.java b/commons/src/main/java/org/wikimedia/commons/category/CategoryContentProvider.java
index 0276b29ca..c8dccd062 100644
--- a/commons/src/main/java/org/wikimedia/commons/category/CategoryContentProvider.java
+++ b/commons/src/main/java/org/wikimedia/commons/category/CategoryContentProvider.java
@@ -12,16 +12,9 @@ import android.util.Log;
import org.wikimedia.commons.CommonsApplication;
import org.wikimedia.commons.data.DBOpenHelper;
-/**
- * Created with IntelliJ IDEA.
- * User: brion
- * Date: 4/22/13
- * Time: 4:09 PM
- * To change this template use File | Settings | File Templates.
- */
public class CategoryContentProvider extends ContentProvider {
- // ????
+ // For URI matcher
private static final int CATEGORIES = 1;
private static final int CATEGORIES_ID = 2;