From ee4a5927ab1cb28402a7daaf0911375919f4863f Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Wed, 8 Aug 2012 23:32:42 +0200 Subject: [PATCH] Show collection, not wishlist * src/ryuslash/org/dvdroid/DVDDataSource.java (getListFromCursor): (getWatchList): (getCollection): New functions. (getWishList): Use `getListFromCursor' to retrieve data. * src/ryuslash/org/dvdroid/DVDroidActivity.java (getData): New function. (onActivityResult): (onCreate): Use `getData' instead of `datasource.getWishlist'. --- src/ryuslash/org/dvdroid/DVDDataSource.java | 32 ++++++++++++++++--- src/ryuslash/org/dvdroid/DVDroidActivity.java | 9 ++++-- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/ryuslash/org/dvdroid/DVDDataSource.java b/src/ryuslash/org/dvdroid/DVDDataSource.java index 6658c8d..b9fe166 100644 --- a/src/ryuslash/org/dvdroid/DVDDataSource.java +++ b/src/ryuslash/org/dvdroid/DVDDataSource.java @@ -65,24 +65,48 @@ public class DVDDataSource SQLiteHelper.COLUMN_ID + " = " + id, null); } - public List getWishlist() + public List getListFromCursor(Cursor cursor) { List dvds = new ArrayList(); - Cursor cursor = database.query(SQLiteHelper.TABLE_DVD, - allColumns, "wishlist = 1", null, - null, null, "title"); cursor.moveToFirst(); + while(!cursor.isAfterLast()) { DVD dvd = cursorToDVD(cursor); + dvds.add(dvd); cursor.moveToNext(); } cursor.close(); + return dvds; } + public List getWishList() + { + Cursor cursor = database.query(SQLiteHelper.TABLE_DVD, + allColumns, "wishlist = 1", null, + null, null, "title"); + return getListFromCursor(cursor); + } + + public List getWatchList() + { + Cursor cursor = database.query(SQLiteHelper.TABLE_DVD, + allColumns, "watched = 0", null, + null, null, "title"); + return getListFromCursor(cursor); + } + + public List getCollection() + { + Cursor cursor = database.query(SQLiteHelper.TABLE_DVD, + allColumns, "wishlist = 0", null, + null, null, "title"); + return getListFromCursor(cursor); + } + private DVD cursorToDVD(Cursor cursor) { DVD dvd = new DVD(); diff --git a/src/ryuslash/org/dvdroid/DVDroidActivity.java b/src/ryuslash/org/dvdroid/DVDroidActivity.java index e510a7b..533bc62 100644 --- a/src/ryuslash/org/dvdroid/DVDroidActivity.java +++ b/src/ryuslash/org/dvdroid/DVDroidActivity.java @@ -18,6 +18,11 @@ public class DVDroidActivity extends ListActivity { private DVDDataSource datasource; + private List getData() + { + return datasource.getCollection(); + } + @Override protected void onActivityResult(int requestCode, int resultCode, @@ -27,7 +32,7 @@ public class DVDroidActivity extends ListActivity datasource.open(); ArrayAdapter adapter = (ArrayAdapter)getListAdapter(); - List dvds = datasource.getWishlist(); + List dvds = getData(); adapter.clear(); adapter.addAll(dvds); @@ -44,7 +49,7 @@ public class DVDroidActivity extends ListActivity datasource = new DVDDataSource(this); datasource.open(); - List values = datasource.getWishlist(); + List values = getData(); ArrayAdapter adapter = new ArrayAdapter(this,