summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Oeh <daniel@danielpc.(none)>2012-04-11 18:14:43 +0200
committerDaniel Oeh <daniel@danielpc.(none)>2012-04-11 18:14:43 +0200
commit7fbd960310a460a0094f202cfb359143b449a353 (patch)
treeab54447060334d03b397e28b5cbbd332055b0d46
parentba7759607d5ad7d53d76b04b9d1f577e660e7927 (diff)
downloadAntennaPod-7fbd960310a460a0094f202cfb359143b449a353.zip
Fixed layout and bugs in DBAdapter
-rw-r--r--res/layout/feedlist_item.xml10
-rw-r--r--src/de/podfetcher/PodcastApp.java5
-rw-r--r--src/de/podfetcher/feed/FeedManager.java12
-rw-r--r--src/de/podfetcher/gui/FeedlistAdapter.java2
-rw-r--r--src/de/podfetcher/storage/PodDBAdapter.java40
5 files changed, 42 insertions, 27 deletions
diff --git a/res/layout/feedlist_item.xml b/res/layout/feedlist_item.xml
index f204d1807..9fc1191c7 100644
--- a/res/layout/feedlist_item.xml
+++ b/res/layout/feedlist_item.xml
@@ -4,16 +4,16 @@
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imgvFeedimage"
- android:layout_height="fill_parent"
- android:layout_width="50dip"
- android:padding="10dip"
+ android:layout_height="60dip"
+ android:layout_width="60dip"
+ android:layout_marginBottom="1dip"
android:cropToPadding="true"
android:layout_alignParentLeft="true"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
- android:layout_alignParentRight="true">
+ android:layout_toRightOf="@id/imgvFeedimage">
<TextView
android:id="@+id/txtvFeedname"
android:layout_width="fill_parent"
@@ -31,4 +31,4 @@
-</RelativeLayout> \ No newline at end of file
+</RelativeLayout>
diff --git a/src/de/podfetcher/PodcastApp.java b/src/de/podfetcher/PodcastApp.java
index ebaef0e43..ba9e07884 100644
--- a/src/de/podfetcher/PodcastApp.java
+++ b/src/de/podfetcher/PodcastApp.java
@@ -1,6 +1,7 @@
package de.podfetcher;
import de.podfetcher.activity.PodfetcherActivity;
+import de.podfetcher.feed.FeedManager;
import android.app.Application;
public class PodcastApp extends Application {
@@ -17,8 +18,8 @@ public class PodcastApp extends Application {
super.onCreate();
singleton = this;
- //FeedManager manager = FeedManager.getInstance();
- //manager.loadDBData(getApplicationContext());
+ FeedManager manager = FeedManager.getInstance();
+ manager.loadDBData(getApplicationContext());
}
diff --git a/src/de/podfetcher/feed/FeedManager.java b/src/de/podfetcher/feed/FeedManager.java
index ce644dde8..031cdaca5 100644
--- a/src/de/podfetcher/feed/FeedManager.java
+++ b/src/de/podfetcher/feed/FeedManager.java
@@ -22,7 +22,6 @@ public class FeedManager {
private ArrayList<Feed> feeds;
private ArrayList<FeedCategory> categories;
- Cursor feedlistCursor;
private FeedManager() {
@@ -150,14 +149,11 @@ public class FeedManager {
/** Reads the database */
public void loadDBData(Context context) {
PodDBAdapter adapter = new PodDBAdapter(context);
- feedlistCursor = adapter.getAllFeedsCursor();
updateArrays(context);
}
public void updateArrays(Context context) {
- feedlistCursor.requery();
- PodDBAdapter adapter = new PodDBAdapter(context);
feeds.clear();
categories.clear();
extractFeedlistFromCursor(context);
@@ -165,6 +161,8 @@ public class FeedManager {
private void extractFeedlistFromCursor(Context context) {
PodDBAdapter adapter = new PodDBAdapter(context);
+ adapter.open();
+ Cursor feedlistCursor = adapter.getAllFeedsCursor();
if(feedlistCursor.moveToFirst()) {
do {
Feed feed = new Feed();
@@ -173,7 +171,7 @@ public class FeedManager {
feed.setTitle(feedlistCursor.getString(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_TITLE)));
feed.setLink(feedlistCursor.getString(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_LINK)));
feed.setDescription(feedlistCursor.getString(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_DESCRIPTION)));
- feed.setImage(adapter.getFeedImage(feed));
+ feed.setImage(adapter.getFeedImage(feedlistCursor.getLong(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_IMAGE))));
feed.file_url = feedlistCursor.getString(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_FILE_URL));
feed.download_url = feedlistCursor.getString(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_DOWNLOAD_URL));
@@ -184,12 +182,13 @@ public class FeedManager {
feeds.add(feed);
}while(feedlistCursor.moveToNext());
}
+ adapter.close();
}
private ArrayList<FeedItem> extractFeedItemsFromCursor(Context context, Cursor itemlistCursor) {
ArrayList<FeedItem> items = new ArrayList<FeedItem>();
PodDBAdapter adapter = new PodDBAdapter(context);
-
+ adapter.open();
if(itemlistCursor.moveToFirst()) {
do {
FeedItem item = new FeedItem();
@@ -205,6 +204,7 @@ public class FeedManager {
items.add(item);
} while(itemlistCursor.moveToNext());
}
+ adapter.close();
return items;
}
diff --git a/src/de/podfetcher/gui/FeedlistAdapter.java b/src/de/podfetcher/gui/FeedlistAdapter.java
index 6c4aec069..b8e6b5e4b 100644
--- a/src/de/podfetcher/gui/FeedlistAdapter.java
+++ b/src/de/podfetcher/gui/FeedlistAdapter.java
@@ -48,7 +48,7 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
TextView txtvFeedname = (TextView)feedlistView.findViewById(R.id.txtvFeedname);
TextView txtvNewEpisodes = (TextView)feedlistView.findViewById(R.id.txtvNewEpisodes);
if(feed.getImage() != null) {
- imageView.setImageURI(Uri.fromFile(new File(feed.getFile_url()))); // TODO select default picture when no image downloaded
+ imageView.setImageURI(Uri.fromFile(new File(feed.getImage().getFile_url()))); // TODO select default picture when no image downloaded
}
txtvFeedname.setText(feed.getTitle());
// TODO find new Episodes txtvNewEpisodes.setText(feed)
diff --git a/src/de/podfetcher/storage/PodDBAdapter.java b/src/de/podfetcher/storage/PodDBAdapter.java
index 76af8e07f..01bc44092 100644
--- a/src/de/podfetcher/storage/PodDBAdapter.java
+++ b/src/de/podfetcher/storage/PodDBAdapter.java
@@ -237,51 +237,65 @@ public class PodDBAdapter {
}
public Cursor getAllCategoriesCursor() {
- return db.query(TABLE_NAME_FEED_CATEGORIES, null, null, null, null, null, null);
+ open();
+ Cursor c = db.query(TABLE_NAME_FEED_CATEGORIES, null, null, null, null, null, null);
+ return c;
}
public Cursor getAllFeedsCursor() {
- return db.query(TABLE_NAME_FEEDS, null, null, null, null, null, null);
+ open();
+ Cursor c = db.query(TABLE_NAME_FEEDS, null, null, null, null, null, null);
+ return c;
}
public Cursor getAllItemsOfFeedCursor(Feed feed) {
- return db.query(TABLE_NAME_FEED_ITEMS, null, KEY_FEED+"=?", new String[]{String.valueOf(feed.getId())}, null, null, null);
+ open();
+ Cursor c = db.query(TABLE_NAME_FEED_ITEMS, null, KEY_FEED+"=?", new String[]{String.valueOf(feed.getId())}, null, null, null);
+ return c;
}
public Cursor getFeedMediaOfItemCursor(FeedItem item) {
- return db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID+"=?", new String[]{String.valueOf(item.getMedia().getId())}, null, null, null);
+ open();
+ Cursor c = db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID+"=?", new String[]{String.valueOf(item.getMedia().getId())}, null, null, null);
+ return c;
}
- public Cursor getImageOfFeedCursor(Feed feed) {
- return db.query(TABLE_NAME_FEED_IMAGES, null, KEY_ID+"=?", new String[]{String.valueOf(feed.getImage().getId())}, null, null, null);
+ public Cursor getImageOfFeedCursor(long id) {
+ open();
+ Cursor c = db.query(TABLE_NAME_FEED_IMAGES, null, KEY_ID+"=?", new String[]{String.valueOf(id)}, null, null, null);
+ return c;
}
public FeedMedia getFeedMedia(long row_index) throws SQLException{
+ open();
Cursor cursor = db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID+"=?", new String[]{String.valueOf(row_index)}, null, null, null);
if((cursor.getCount() == 0) || !cursor.moveToFirst()) {
throw new SQLException("No FeedMedia found at index: "+ row_index);
}
-
- return new FeedMedia(row_index,
+ FeedMedia media = new FeedMedia(row_index,
cursor.getLong(cursor.getColumnIndex(KEY_LENGTH)),
cursor.getLong(cursor.getColumnIndex(KEY_POSITION)),
cursor.getLong(cursor.getColumnIndex(KEY_SIZE)),
cursor.getString(cursor.getColumnIndex(KEY_MIME_TYPE)),
cursor.getString(cursor.getColumnIndex(KEY_FILE_URL)),
cursor.getString(cursor.getColumnIndex(KEY_DOWNLOAD_URL)));
+ close();
+ return media;
}
- public FeedImage getFeedImage(Feed feed) throws SQLException {
- Cursor cursor = this.getImageOfFeedCursor(feed);
+ public FeedImage getFeedImage(long id) throws SQLException {
+ open();
+ Cursor cursor = this.getImageOfFeedCursor(id);
if((cursor.getCount() == 0) || !cursor.moveToFirst()) {
- throw new SQLException("No FeedImage found at index: "+ feed.getImage().getId());
+ throw new SQLException("No FeedImage found at index: "+ id);
}
-
- return new FeedImage(feed.getImage().getId(), cursor.getString(cursor.getColumnIndex(KEY_TITLE)),
+ FeedImage image = new FeedImage(id, cursor.getString(cursor.getColumnIndex(KEY_TITLE)),
cursor.getString(cursor.getColumnIndex(KEY_FILE_URL)),
cursor.getString(cursor.getColumnIndex(KEY_DOWNLOAD_URL)));
+ close();
+ return image;
}
private static class PodDBHelper extends SQLiteOpenHelper {