Skip to content

Commit

Permalink
make dbadapter a single field to avoid recreating it
Browse files Browse the repository at this point in the history
  • Loading branch information
thasmin committed Aug 19, 2012
1 parent bda0668 commit 284662f
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/com/axelby/gpodder/Provider.java
Expand Up @@ -17,6 +17,7 @@ public class Provider extends ContentProvider {
+ "/vnd.axelby.gpodder.podcast";

public static final String URL = "url";
private DBAdapter _dbAdapter = new DBAdapter(this.getContext());

@Override
public boolean onCreate() {
Expand All @@ -35,8 +36,7 @@ public String getType(Uri uri) {
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
DBAdapter dbAdapter = new DBAdapter(this.getContext());
SQLiteDatabase db = dbAdapter.getReadableDatabase();
SQLiteDatabase db = _dbAdapter.getReadableDatabase();
Cursor c;
if (uri.equals(URI))
c = db.rawQuery("SELECT url FROM " +
Expand All @@ -62,8 +62,7 @@ public Uri insert(Uri uri, ContentValues values) {
return null;
String url = values.getAsString(URL);
Log.d("gpodder", "adding " + url);
DBAdapter dbAdapter = new DBAdapter(this.getContext());
SQLiteDatabase db = dbAdapter.getReadableDatabase();
SQLiteDatabase db = _dbAdapter.getReadableDatabase();
db.delete("pending_remove", "url = ?", new String[] { url });
Cursor c = db.rawQuery("SELECT COUNT(*) FROM subscriptions WHERE url = ?", new String[] { url });
c.moveToFirst();
Expand All @@ -81,8 +80,7 @@ public int delete(Uri uri, String selection, String[] selectionArgs) {
if (!uri.equals(URI))
return 0;

DBAdapter dbAdapter = new DBAdapter(this.getContext());
SQLiteDatabase db = dbAdapter.getWritableDatabase();
SQLiteDatabase db = _dbAdapter.getWritableDatabase();

if (selectionArgs != null && selectionArgs.length > 0) {
for (String url : selectionArgs) {
Expand Down Expand Up @@ -112,8 +110,7 @@ private ContentValues makeUrlValues(String url) {
}

public void fakeSync() {
DBAdapter dbAdapter = new DBAdapter(this.getContext());
SQLiteDatabase db = dbAdapter.getWritableDatabase();
SQLiteDatabase db = _dbAdapter.getWritableDatabase();

Cursor c = db.query("pending_remove", new String[] { "url" }, null, null, null, null, null);
while (c.moveToNext())
Expand Down

0 comments on commit 284662f

Please sign in to comment.