mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Work in progress: hook up content provider for recent cats
This commit is contained in:
parent
8d67c5c2d5
commit
8b7095042d
1 changed files with 34 additions and 2 deletions
|
|
@ -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;
|
||||||
|
|
@ -134,7 +135,7 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
CategoryContentProvider.BASE_URI,
|
CategoryContentProvider.BASE_URI,
|
||||||
Category.Table.ALL_FIELDS,
|
Category.Table.ALL_FIELDS,
|
||||||
null,
|
null,
|
||||||
new String[] {},
|
new String[]{},
|
||||||
null);
|
null);
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
Category cat = Category.fromCursor(cursor);
|
Category cat = Category.fromCursor(cursor);
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue