summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-06-14 14:13:54 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-06-14 14:13:54 +0200
commit922b868914eaa571786256012d23ad2cb925ad74 (patch)
treef4e05b445154abe69e13989b5782ce7f114eb832
parent80c7616c7d87ebd789c085d64a4c2d7b269ebfc6 (diff)
downloadAntennaPod-922b868914eaa571786256012d23ad2cb925ad74.zip
Added 'lastUpdate' attribute to Feed
-rw-r--r--res/layout/feedlist_item.xml61
-rw-r--r--src/de/podfetcher/activity/AddFeedActivity.java4
-rw-r--r--src/de/podfetcher/adapter/FeedlistAdapter.java48
-rw-r--r--src/de/podfetcher/feed/Feed.java35
-rw-r--r--src/de/podfetcher/feed/FeedManager.java5
-rw-r--r--src/de/podfetcher/storage/PodDBAdapter.java284
6 files changed, 248 insertions, 189 deletions
diff --git a/res/layout/feedlist_item.xml b/res/layout/feedlist_item.xml
index 9fc1191c7..c69815405 100644
--- a/res/layout/feedlist_item.xml
+++ b/res/layout/feedlist_item.xml
@@ -2,33 +2,36 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
- <ImageView
- android:id="@+id/imgvFeedimage"
- 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_toRightOf="@id/imgvFeedimage">
- <TextView
- android:id="@+id/txtvFeedname"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- <TextView
- android:id="@+id/txtvNewEpisodes"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
-
- />
-
-
- </LinearLayout>
-
-
-</RelativeLayout>
+ <ImageView
+ android:id="@+id/imgvFeedimage"
+ android:layout_width="60dip"
+ android:layout_height="60dip"
+ android:layout_alignParentLeft="true"
+ android:layout_marginBottom="1dip"
+ android:cropToPadding="true" />
+
+ <LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_toRightOf="@id/imgvFeedimage" >
+
+ <TextView
+ android:id="@+id/txtvFeedname"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <TextView
+ android:id="@+id/txtvNewEpisodes"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <TextView
+ android:id="@+id/txtvLastUpdate"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+ </LinearLayout>
+
+</RelativeLayout> \ No newline at end of file
diff --git a/src/de/podfetcher/activity/AddFeedActivity.java b/src/de/podfetcher/activity/AddFeedActivity.java
index 2013d204e..b4c9ddb3f 100644
--- a/src/de/podfetcher/activity/AddFeedActivity.java
+++ b/src/de/podfetcher/activity/AddFeedActivity.java
@@ -15,6 +15,8 @@ import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
+
+import java.util.Date;
import java.util.concurrent.Callable;
/** Activity for adding/editing a Feed */
@@ -101,7 +103,7 @@ public class AddFeedActivity extends SherlockActivity {
url = URLChecker.prepareURL(url);
if(url != null) {
- Feed feed = new Feed(url);
+ Feed feed = new Feed(url, new Date());
downloadId = requester.downloadFeed(this, feed);
observeDownload(feed);
}
diff --git a/src/de/podfetcher/adapter/FeedlistAdapter.java b/src/de/podfetcher/adapter/FeedlistAdapter.java
index 7c654f010..39c935e8f 100644
--- a/src/de/podfetcher/adapter/FeedlistAdapter.java
+++ b/src/de/podfetcher/adapter/FeedlistAdapter.java
@@ -1,12 +1,14 @@
package de.podfetcher.adapter;
import java.io.File;
+import java.text.DateFormat;
import java.util.List;
import de.podfetcher.R;
import de.podfetcher.feed.Feed;
import android.content.Context;
import android.net.Uri;
+import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -16,38 +18,49 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.graphics.BitmapFactory;
-
public class FeedlistAdapter extends ArrayAdapter<Feed> {
- public FeedlistAdapter(Context context,
- int textViewResourceId, List<Feed> objects) {
+ public FeedlistAdapter(Context context, int textViewResourceId,
+ List<Feed> objects) {
super(context, textViewResourceId, objects);
}
-
-
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- Holder holder;
+ Holder holder;
Feed feed = getItem(position);
// Inflate Layout
if (convertView == null) {
holder = new Holder();
- LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ LayoutInflater inflater = (LayoutInflater) getContext()
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- convertView = inflater.inflate(R.layout.feedlist_item, null);
- holder.title = (TextView) convertView.findViewById(R.id.txtvFeedname);
- holder.image = (ImageView) convertView.findViewById(R.id.imgvFeedimage);
+ convertView = inflater.inflate(R.layout.feedlist_item, null);
+ holder.title = (TextView) convertView
+ .findViewById(R.id.txtvFeedname);
+ holder.image = (ImageView) convertView
+ .findViewById(R.id.imgvFeedimage);
+ holder.lastUpdate = (TextView) convertView
+ .findViewById(R.id.txtvLastUpdate);
+ convertView.setTag(holder);
+ } else {
+ holder = (Holder) convertView.getTag();
+ }
- convertView.setTag(holder);
- } else {
- holder = (Holder) convertView.getTag();
- }
-
holder.title.setText(feed.getTitle());
- if(feed.getImage() != null) {
- holder.image.setImageBitmap(feed.getImage().getImageBitmap()); // TODO select default picture when no image downloaded
+ holder.lastUpdate.setText(DateUtils.formatSameDayTime(feed
+ .getLastUpdate().getTime(), System.currentTimeMillis(),
+ DateFormat.SHORT, DateFormat.SHORT));
+ if (feed.getImage() != null) {
+ holder.image.setImageBitmap(feed.getImage().getImageBitmap()); // TODO
+ // select
+ // default
+ // picture
+ // when
+ // no
+ // image
+ // downloaded
}
// TODO find new Episodes txtvNewEpisodes.setText(feed)
return convertView;
@@ -55,6 +68,7 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
static class Holder {
TextView title;
+ TextView lastUpdate;
ImageView image;
}
diff --git a/src/de/podfetcher/feed/Feed.java b/src/de/podfetcher/feed/Feed.java
index d136e0056..b411b3ecb 100644
--- a/src/de/podfetcher/feed/Feed.java
+++ b/src/de/podfetcher/feed/Feed.java
@@ -1,16 +1,15 @@
package de.podfetcher.feed;
import java.util.ArrayList;
-
-
-
+import java.util.Date;
/**
* Data Object for a whole feed
+ *
* @author daniel
- *
+ *
*/
-public class Feed extends FeedFile{
+public class Feed extends FeedFile {
private String title;
/** Link to the website. */
private String link;
@@ -18,15 +17,17 @@ public class Feed extends FeedFile{
private FeedImage image;
private FeedCategory category;
private ArrayList<FeedItem> items;
-
-
- public Feed() {
+ /** Date of last refresh. */
+ private Date lastUpdate;
+
+ public Feed(Date lastUpdate) {
super();
items = new ArrayList<FeedItem>();
+ this.lastUpdate = lastUpdate;
}
-
- public Feed(String url) {
- this();
+
+ public Feed(String url, Date lastUpdate) {
+ this(lastUpdate);
this.download_url = url;
}
@@ -78,12 +79,12 @@ public class Feed extends FeedFile{
this.items = items;
}
-
+ public Date getLastUpdate() {
+ return lastUpdate;
+ }
-
-
-
-
-
+ public void setLastUpdate(Date lastUpdate) {
+ this.lastUpdate = lastUpdate;
+ }
}
diff --git a/src/de/podfetcher/feed/FeedManager.java b/src/de/podfetcher/feed/FeedManager.java
index c6913493b..4af069f83 100644
--- a/src/de/podfetcher/feed/FeedManager.java
+++ b/src/de/podfetcher/feed/FeedManager.java
@@ -204,7 +204,10 @@ public class FeedManager {
Cursor feedlistCursor = adapter.getAllFeedsCursor();
if (feedlistCursor.moveToFirst()) {
do {
- Feed feed = new Feed();
+ Date lastUpdate = new Date(
+ feedlistCursor.getLong(feedlistCursor
+ .getColumnIndex(PodDBAdapter.KEY_LASTUPDATE)));
+ Feed feed = new Feed(lastUpdate);
feed.id = feedlistCursor.getLong(feedlistCursor
.getColumnIndex(PodDBAdapter.KEY_ID));
diff --git a/src/de/podfetcher/storage/PodDBAdapter.java b/src/de/podfetcher/storage/PodDBAdapter.java
index 3548368df..17e8e8675 100644
--- a/src/de/podfetcher/storage/PodDBAdapter.java
+++ b/src/de/podfetcher/storage/PodDBAdapter.java
@@ -41,6 +41,7 @@ public class PodDBAdapter {
public static final String KEY_FEED = "feed";
public static final String KEY_MEDIA = "media";
public static final String KEY_DOWNLOADED = "downloaded";
+ public static final String KEY_LASTUPDATE = "last_update";
// Table names
public static final String TABLE_NAME_FEEDS = "Feeds";
@@ -54,17 +55,16 @@ public class PodDBAdapter {
+ " INTEGER PRIMARY KEY AUTOINCREMENT ,";
private static final String CREATE_TABLE_FEEDS = "CREATE TABLE "
+ TABLE_NAME_FEEDS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
- + " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION
- + " TEXT," + KEY_IMAGE + " INTEGER," + KEY_CATEGORY
- + " INTEGER," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL
- + " TEXT," + KEY_DOWNLOADED + " INTEGER)";
+ + " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION + " TEXT,"
+ + KEY_IMAGE + " INTEGER," + KEY_CATEGORY + " INTEGER,"
+ + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT,"
+ + KEY_DOWNLOADED + " INTEGER," + KEY_LASTUPDATE + " TEXT)";
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
- + " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION
- + " TEXT," + KEY_PUBDATE + " INTEGER," + KEY_MEDIA
- + " INTEGER," + KEY_FEED + " INTEGER," + KEY_READ
- + " INTEGER)";
+ + " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION + " TEXT,"
+ + KEY_PUBDATE + " INTEGER," + KEY_MEDIA + " INTEGER," + KEY_FEED
+ + " INTEGER," + KEY_READ + " INTEGER)";
private static final String CREATE_TABLE_FEED_CATEGORIES = "CREATE TABLE "
+ TABLE_NAME_FEED_CATEGORIES + " (" + TABLE_PRIMARY_KEY + KEY_NAME
@@ -72,14 +72,14 @@ public class PodDBAdapter {
private static final String CREATE_TABLE_FEED_IMAGES = "CREATE TABLE "
+ TABLE_NAME_FEED_IMAGES + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
- + " TEXT," + KEY_FILE_URL + " TEXT,"
- + KEY_DOWNLOAD_URL + " TEXT," + KEY_DOWNLOADED + " INTEGER)";
+ + " TEXT," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT,"
+ + KEY_DOWNLOADED + " INTEGER)";
private static final String CREATE_TABLE_FEED_MEDIA = "CREATE TABLE "
+ TABLE_NAME_FEED_MEDIA + " (" + TABLE_PRIMARY_KEY + KEY_DURATION
- + " INTEGER," + KEY_POSITION + " INTEGER,"
- + KEY_SIZE + " INTEGER," + KEY_MIME_TYPE + " TEXT,"
- + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT," + KEY_DOWNLOADED + " INTEGER)";
+ + " INTEGER," + KEY_POSITION + " INTEGER," + KEY_SIZE + " INTEGER,"
+ + KEY_MIME_TYPE + " TEXT," + KEY_FILE_URL + " TEXT,"
+ + KEY_DOWNLOAD_URL + " TEXT," + KEY_DOWNLOADED + " INTEGER)";
private SQLiteDatabase db;
private final Context context;
@@ -91,12 +91,12 @@ public class PodDBAdapter {
}
public PodDBAdapter open() {
- if(db == null || !db.isOpen() || db.isReadOnly()) {
- try {
- db = helper.getWritableDatabase();
- } catch (SQLException ex) {
- db = helper.getReadableDatabase();
- }
+ if (db == null || !db.isOpen() || db.isReadOnly()) {
+ try {
+ db = helper.getWritableDatabase();
+ } catch (SQLException ex) {
+ db = helper.getReadableDatabase();
+ }
}
return this;
}
@@ -104,11 +104,13 @@ public class PodDBAdapter {
public void close() {
db.close();
}
-
- /** Inserts or updates a feed entry
+
+ /**
+ * Inserts or updates a feed entry
+ *
* @return the id of the entry
* */
- public long setFeed(Feed feed) {
+ public long setFeed(Feed feed) {
ContentValues values = new ContentValues();
values.put(KEY_TITLE, feed.getTitle());
values.put(KEY_LINK, feed.getLink());
@@ -119,75 +121,83 @@ public class PodDBAdapter {
}
values.put(KEY_IMAGE, feed.getImage().getId());
}
- if(feed.getCategory() != null) {
- if(feed.getCategory().getId() == 0) {
+ if (feed.getCategory() != null) {
+ if (feed.getCategory().getId() == 0) {
setCategory(feed.getCategory());
}
values.put(KEY_CATEGORY, feed.getCategory().getId());
}
- if(feed.getFile_url() != null) {
+ if (feed.getFile_url() != null) {
values.put(KEY_FILE_URL, feed.getFile_url());
}
values.put(KEY_DOWNLOAD_URL, feed.getDownload_url());
values.put(KEY_DOWNLOADED, feed.isDownloaded());
+ values.put(KEY_LASTUPDATE, feed.getLastUpdate().getTime());
open();
- if(feed.getId() == 0) {
+ if (feed.getId() == 0) {
// Create new entry
Log.d(this.toString(), "Inserting new Feed into db");
feed.setId(db.insert(TABLE_NAME_FEEDS, null, values));
} else {
Log.d(this.toString(), "Updating existing Feed in db");
- db.update(TABLE_NAME_FEEDS, values, KEY_ID+"=?", new String[]{Long.toString(feed.getId())});
+ db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?",
+ new String[] { Long.toString(feed.getId()) });
}
close();
return feed.getId();
}
- /** Inserts or updates a category entry
+ /**
+ * Inserts or updates a category entry
+ *
* @return the id of the entry
* */
public long setCategory(FeedCategory category) {
- open();
+ open();
ContentValues values = new ContentValues();
values.put(KEY_NAME, category.getName());
- if(category.getId() == 0) {
+ if (category.getId() == 0) {
category.setId(db.insert(TABLE_NAME_FEED_CATEGORIES, null, values));
} else {
- db.update(TABLE_NAME_FEED_CATEGORIES, values, KEY_ID+"=?", new String[]{String.valueOf(category.getId())});
-
+ db.update(TABLE_NAME_FEED_CATEGORIES, values, KEY_ID + "=?",
+ new String[] { String.valueOf(category.getId()) });
+
}
close();
return category.getId();
}
- /**
- * Inserts or updates an image entry
+ /**
+ * Inserts or updates an image entry
+ *
* @return the id of the entry
* */
public long setImage(FeedImage image) {
- open();
+ open();
ContentValues values = new ContentValues();
values.put(KEY_TITLE, image.getTitle());
values.put(KEY_DOWNLOAD_URL, image.getDownload_url());
values.put(KEY_DOWNLOADED, image.isDownloaded());
- if(image.getFile_url() != null) {
+ if (image.getFile_url() != null) {
values.put(KEY_FILE_URL, image.getFile_url());
}
- if(image.getId() == 0) {
+ if (image.getId() == 0) {
image.setId(db.insert(TABLE_NAME_FEED_IMAGES, null, values));
} else {
- db.update(TABLE_NAME_FEED_IMAGES, values, KEY_ID + "=?", new String[]{String.valueOf(image.getId())});
+ db.update(TABLE_NAME_FEED_IMAGES, values, KEY_ID + "=?",
+ new String[] { String.valueOf(image.getId()) });
}
close();
return image.getId();
}
-
+
/**
- * Inserts or updates an image entry
+ * Inserts or updates an image entry
+ *
* @return the id of the entry
*/
public long setMedia(FeedMedia media) {
- open();
+ open();
ContentValues values = new ContentValues();
values.put(KEY_DURATION, media.getDuration());
values.put(KEY_POSITION, media.getPosition());
@@ -195,20 +205,22 @@ public class PodDBAdapter {
values.put(KEY_MIME_TYPE, media.getMime_type());
values.put(KEY_DOWNLOAD_URL, media.getDownload_url());
values.put(KEY_DOWNLOADED, media.isDownloaded());
- if(media.getFile_url() != null) {
+ if (media.getFile_url() != null) {
values.put(KEY_FILE_URL, media.getFile_url());
}
- if(media.getId() == 0) {
+ if (media.getId() == 0) {
media.setId(db.insert(TABLE_NAME_FEED_MEDIA, null, values));
} else {
- db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?", new String[]{String.valueOf(media.getId())});
+ db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?",
+ new String[] { String.valueOf(media.getId()) });
}
close();
return media.getId();
}
-
+
/**
- * Inserts or updates a feeditem entry
+ * Inserts or updates a feeditem entry
+ *
* @return the id of the entry
*/
public long setFeedItem(FeedItem item) {
@@ -218,7 +230,7 @@ public class PodDBAdapter {
values.put(KEY_DESCRIPTION, item.getDescription());
values.put(KEY_PUBDATE, item.getPubDate().getTime());
if (item.getMedia() != null) {
- if(item.getMedia().getId() == 0) {
+ if (item.getMedia().getId() == 0) {
setMedia(item.getMedia());
}
values.put(KEY_MEDIA, item.getMedia().getId());
@@ -231,111 +243,131 @@ public class PodDBAdapter {
open();
if (item.getId() == 0) {
- item.setId(db.insert(TABLE_NAME_FEED_ITEMS, null, values));
+ item.setId(db.insert(TABLE_NAME_FEED_ITEMS, null, values));
} else {
- db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?",
- new String[]{String.valueOf(item.getId())});
+ db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?",
+ new String[] { String.valueOf(item.getId()) });
}
close();
return item.getId();
}
- /** Get all Categories from the Categories Table.
- * @return The cursor of the query
- * */
+ /**
+ * Get all Categories from the Categories Table.
+ *
+ * @return The cursor of the query
+ * */
public final Cursor getAllCategoriesCursor() {
- open();
- Cursor c = 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;
}
- /** Get all Feeds from the Feed Table.
- * @return The cursor of the query
- * */
+ /**
+ * Get all Feeds from the Feed Table.
+ *
+ * @return The cursor of the query
+ * */
public final Cursor getAllFeedsCursor() {
- open();
- Cursor c = 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;
}
- /** Returns a cursor with all FeedItems of a Feed.
- * @param feed The feed you want to get the FeedItems from.
- * @return The cursor of the query
- * */
+ /**
+ * Returns a cursor with all FeedItems of a Feed.
+ *
+ * @param feed
+ * The feed you want to get the FeedItems from.
+ * @return The cursor of the query
+ * */
public final Cursor getAllItemsOfFeedCursor(final Feed feed) {
- open();
- Cursor c = 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;
}
- /** Returns a cursor for a DB query in the FeedMedia table for a given ID.
- * @param item The item you want to get the FeedMedia from
- * @return The cursor of the query
- * */
+ /**
+ * Returns a cursor for a DB query in the FeedMedia table for a given ID.
+ *
+ * @param item
+ * The item you want to get the FeedMedia from
+ * @return The cursor of the query
+ * */
public final Cursor getFeedMediaOfItemCursor(final FeedItem item) {
- open();
- Cursor c = 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;
}
- /** Returns a cursor for a DB query in the FeedImages table for a given ID.
- * @param id ID of the FeedImage
- * @return The cursor of the query
- * */
+ /**
+ * Returns a cursor for a DB query in the FeedImages table for a given ID.
+ *
+ * @param id
+ * ID of the FeedImage
+ * @return The cursor of the query
+ * */
public final Cursor getImageOfFeedCursor(final long id) {
- open();
- Cursor c = db.query(TABLE_NAME_FEED_IMAGES, null, KEY_ID + "=?",
- new String[]{String.valueOf(id)}, null, null, null);
+ open();
+ Cursor c = db.query(TABLE_NAME_FEED_IMAGES, null, KEY_ID + "=?",
+ new String[] { String.valueOf(id) }, null, null, null);
return c;
}
- /** Get a FeedMedia object from the Database.
- * @param rowIndex DB Index of Media object
- * @param owner FeedItem the Media object belongs to
- * @return A newly created FeedMedia object
- * */
- public final FeedMedia getFeedMedia(final long rowIndex, final FeedItem owner)
- throws SQLException {
- open();
+ /**
+ * Get a FeedMedia object from the Database.
+ *
+ * @param rowIndex
+ * DB Index of Media object
+ * @param owner
+ * FeedItem the Media object belongs to
+ * @return A newly created FeedMedia object
+ * */
+ public final FeedMedia getFeedMedia(final long rowIndex,
+ final FeedItem owner) throws SQLException {
+ open();
Cursor cursor = db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID + "=?",
- new String[]{String.valueOf(rowIndex)}, null, null, null);
+ new String[] { String.valueOf(rowIndex) }, null, null, null);
if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
throw new SQLException("No FeedMedia found at index: " + rowIndex);
}
- FeedMedia media = new FeedMedia(rowIndex,
- owner,
- cursor.getInt(cursor.getColumnIndex(KEY_DURATION)),
- cursor.getInt(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)),
- cursor.getInt(cursor.getColumnIndex(KEY_DOWNLOADED)) > 0);
+ FeedMedia media = new FeedMedia(rowIndex, owner, cursor.getInt(cursor
+ .getColumnIndex(KEY_DURATION)), cursor.getInt(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)), cursor.getInt(cursor
+ .getColumnIndex(KEY_DOWNLOADED)) > 0);
close();
return media;
}
- /** Searches the DB for a FeedImage of the given id.
- * @param id The id of the object
- * @return The found object
+ /**
+ * Searches the DB for a FeedImage of the given id.
+ *
+ * @param id
+ * The id of the object
+ * @return The found object
* */
public final FeedImage getFeedImage(final long id) throws SQLException {
- open();
+ open();
Cursor cursor = this.getImageOfFeedCursor(id);
if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
throw new SQLException("No FeedImage found at index: " + id);
}
- 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)),
- cursor.getInt(cursor.getColumnIndex(KEY_DOWNLOADED)) > 0);
+ 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)), cursor.getInt(cursor
+ .getColumnIndex(KEY_DOWNLOADED)) > 0);
close();
return image;
}
@@ -343,15 +375,20 @@ public class PodDBAdapter {
/** Helper class for opening the Podfetcher database. */
private static class PodDBHelper extends SQLiteOpenHelper {
- /** Constructor.
- * @param context Context to use
- * @param name Name of the database
- * @param factory to use for creating cursor objects
- * @param version number of the database
+ /**
+ * Constructor.
+ *
+ * @param context
+ * Context to use
+ * @param name
+ * Name of the database
+ * @param factory
+ * to use for creating cursor objects
+ * @param version
+ * number of the database
* */
- public PodDBHelper(final Context context,
- final String name, final CursorFactory factory,
- final int version) {
+ public PodDBHelper(final Context context, final String name,
+ final CursorFactory factory, final int version) {
super(context, name, factory, version);
}
@@ -365,10 +402,9 @@ public class PodDBAdapter {
}
@Override
- public void onUpgrade(final SQLiteDatabase db,
- final int oldVersion, final int newVersion) {
- Log.w("DBAdapter", "Upgrading from version "
- + oldVersion + " to "
+ public void onUpgrade(final SQLiteDatabase db, final int oldVersion,
+ final int newVersion) {
+ Log.w("DBAdapter", "Upgrading from version " + oldVersion + " to "
+ newVersion + ".");
// TODO delete Database
}