Added 'lastUpdate' attribute to Feed
This commit is contained in:
parent
80c7616c7d
commit
922b868914
|
@ -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_height="60dip"
|
||||
android:layout_alignParentLeft="true"
|
||||
/>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="fill_parent"
|
||||
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_toRightOf="@id/imgvFeedimage">
|
||||
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"
|
||||
/>
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvNewEpisodes"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
/>
|
||||
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvLastUpdate"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
</RelativeLayout>
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,16 +18,13 @@ 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;
|
||||
|
@ -34,20 +33,34 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
|
|||
// 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);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
/** Date of last refresh. */
|
||||
private Date lastUpdate;
|
||||
|
||||
|
||||
public Feed() {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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,7 +91,7 @@ public class PodDBAdapter {
|
|||
}
|
||||
|
||||
public PodDBAdapter open() {
|
||||
if(db == null || !db.isOpen() || db.isReadOnly()) {
|
||||
if (db == null || !db.isOpen() || db.isReadOnly()) {
|
||||
try {
|
||||
db = helper.getWritableDatabase();
|
||||
} catch (SQLException ex) {
|
||||
|
@ -105,7 +105,9 @@ public class PodDBAdapter {
|
|||
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) {
|
||||
|
@ -119,41 +121,46 @@ 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();
|
||||
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();
|
||||
|
@ -162,6 +169,7 @@ public class PodDBAdapter {
|
|||
|
||||
/**
|
||||
* Inserts or updates an image entry
|
||||
*
|
||||
* @return the id of the entry
|
||||
* */
|
||||
public long setImage(FeedImage image) {
|
||||
|
@ -170,13 +178,14 @@ public class PodDBAdapter {
|
|||
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();
|
||||
|
@ -184,6 +193,7 @@ public class PodDBAdapter {
|
|||
|
||||
/**
|
||||
* Inserts or updates an image entry
|
||||
*
|
||||
* @return the id of the entry
|
||||
*/
|
||||
public long setMedia(FeedMedia media) {
|
||||
|
@ -195,13 +205,14 @@ 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();
|
||||
|
@ -209,6 +220,7 @@ public class PodDBAdapter {
|
|||
|
||||
/**
|
||||
* 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());
|
||||
|
@ -234,92 +246,115 @@ public class PodDBAdapter {
|
|||
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())});
|
||||
new String[] { String.valueOf(item.getId()) });
|
||||
}
|
||||
close();
|
||||
return item.getId();
|
||||
}
|
||||
|
||||
/** Get all Categories from the Categories Table.
|
||||
/**
|
||||
* 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);
|
||||
Cursor c = db.query(TABLE_NAME_FEED_CATEGORIES, null, null, null, null,
|
||||
null, null);
|
||||
return c;
|
||||
}
|
||||
|
||||
/** Get all Feeds from the Feed Table.
|
||||
/**
|
||||
* 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);
|
||||
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.
|
||||
/**
|
||||
* 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);
|
||||
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
|
||||
/**
|
||||
* 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);
|
||||
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
|
||||
/**
|
||||
* 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);
|
||||
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
|
||||
/**
|
||||
* 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 {
|
||||
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
|
||||
/**
|
||||
* 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 {
|
||||
|
@ -328,14 +363,11 @@ public class PodDBAdapter {
|
|||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue