Work in progress: hook up content provider for recent cats

This commit is contained in:
Brion Vibber 2013-04-23 08:31:01 -07:00
parent 8d67c5c2d5
commit 8b7095042d

View file

@ -26,6 +26,7 @@ import org.wikimedia.commons.contributions.Contribution;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
@ -228,6 +229,36 @@ public class CategorizationFragment extends SherlockFragment{
return count; return count;
} }
private Category lookupCategory(String name) {
Cursor cursor = getActivity().getContentResolver().query(
CategoryContentProvider.BASE_URI,
Category.Table.ALL_FIELDS,
null,
new String[] {},
null);
// fixme move to conditions
while (cursor.moveToNext()) {
Category cat = Category.fromCursor(cursor);
if (cat.getName().equals(name)) {
return cat;
}
}
// Newly used category...
Category cat = new Category();
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();
cat.save();
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_categorization, null); View rootView = inflater.inflate(R.layout.fragment_categorization, null);
@ -262,7 +293,8 @@ public class CategorizationFragment extends SherlockFragment{
CategoryItem item = (CategoryItem) adapterView.getAdapter().getItem(index); CategoryItem item = (CategoryItem) adapterView.getAdapter().getItem(index);
item.selected = !item.selected; item.selected = !item.selected;
checkedView.setChecked(item.selected); checkedView.setChecked(item.selected);
// fixme save/update the item in the most recently used list // fixme do this asynchronously?
updateCategoryCount(item.name);
} }
}); });