mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Use a single content provider client for all cat queries
This commit is contained in:
parent
25191a968f
commit
d974630704
1 changed files with 25 additions and 20 deletions
|
|
@ -4,10 +4,7 @@ import android.app.Activity;
|
||||||
import android.content.ContentProviderClient;
|
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.*;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
|
@ -51,6 +48,8 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
|
|
||||||
private HashMap<String, ArrayList<String>> categoriesCache;
|
private HashMap<String, ArrayList<String>> categoriesCache;
|
||||||
|
|
||||||
|
private ContentProviderClient client;
|
||||||
|
|
||||||
public static class CategoryItem implements Parcelable {
|
public static class CategoryItem implements Parcelable {
|
||||||
public String name;
|
public String name;
|
||||||
public boolean selected;
|
public boolean selected;
|
||||||
|
|
@ -132,15 +131,20 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
ArrayList<String> items = new ArrayList<String>();
|
ArrayList<String> items = new ArrayList<String>();
|
||||||
// fixme add a limit?
|
// fixme add a limit?
|
||||||
// fixme sort by last_used descending?
|
// fixme sort by last_used descending?
|
||||||
Cursor cursor = getActivity().getContentResolver().query(
|
try {
|
||||||
CategoryContentProvider.BASE_URI,
|
Cursor cursor = client.query(
|
||||||
Category.Table.ALL_FIELDS,
|
CategoryContentProvider.BASE_URI,
|
||||||
null,
|
Category.Table.ALL_FIELDS,
|
||||||
new String[]{},
|
null,
|
||||||
null);
|
new String[]{},
|
||||||
while (cursor.moveToNext()) {
|
null);
|
||||||
Category cat = Category.fromCursor(cursor);
|
while (cursor.moveToNext()) {
|
||||||
items.add(cat.getName());
|
Category cat = Category.fromCursor(cursor);
|
||||||
|
items.add(cat.getName());
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// faaaail
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
@ -256,15 +260,8 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
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.setContentProviderClient(client);
|
||||||
cat.save();
|
cat.save();
|
||||||
cat.setContentProviderClient(null);
|
|
||||||
client.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -340,6 +337,14 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
getActivity().setTitle(R.string.categories_activity_title);
|
getActivity().setTitle(R.string.categories_activity_title);
|
||||||
|
client = getActivity().getContentResolver().acquireContentProviderClient(CategoryContentProvider.AUTHORITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
client.release();
|
||||||
|
client = null;
|
||||||
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue