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"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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>
|
|
@ -15,6 +15,8 @@ import com.actionbarsherlock.app.SherlockActivity;
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
/** Activity for adding/editing a Feed */
|
/** Activity for adding/editing a Feed */
|
||||||
|
@ -101,7 +103,7 @@ public class AddFeedActivity extends SherlockActivity {
|
||||||
url = URLChecker.prepareURL(url);
|
url = URLChecker.prepareURL(url);
|
||||||
|
|
||||||
if(url != null) {
|
if(url != null) {
|
||||||
Feed feed = new Feed(url);
|
Feed feed = new Feed(url, new Date());
|
||||||
downloadId = requester.downloadFeed(this, feed);
|
downloadId = requester.downloadFeed(this, feed);
|
||||||
observeDownload(feed);
|
observeDownload(feed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package de.podfetcher.adapter;
|
package de.podfetcher.adapter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.text.DateFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.podfetcher.R;
|
import de.podfetcher.R;
|
||||||
import de.podfetcher.feed.Feed;
|
import de.podfetcher.feed.Feed;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -16,38 +18,49 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
|
||||||
|
|
||||||
public class FeedlistAdapter extends ArrayAdapter<Feed> {
|
public class FeedlistAdapter extends ArrayAdapter<Feed> {
|
||||||
|
|
||||||
public FeedlistAdapter(Context context,
|
public FeedlistAdapter(Context context, int textViewResourceId,
|
||||||
int textViewResourceId, List<Feed> objects) {
|
List<Feed> objects) {
|
||||||
super(context, textViewResourceId, objects);
|
super(context, textViewResourceId, objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
Holder holder;
|
Holder holder;
|
||||||
Feed feed = getItem(position);
|
Feed feed = getItem(position);
|
||||||
|
|
||||||
// Inflate Layout
|
// Inflate Layout
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
holder = new Holder();
|
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);
|
convertView = inflater.inflate(R.layout.feedlist_item, null);
|
||||||
holder.title = (TextView) convertView.findViewById(R.id.txtvFeedname);
|
holder.title = (TextView) convertView
|
||||||
holder.image = (ImageView) convertView.findViewById(R.id.imgvFeedimage);
|
.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());
|
holder.title.setText(feed.getTitle());
|
||||||
if(feed.getImage() != null) {
|
holder.lastUpdate.setText(DateUtils.formatSameDayTime(feed
|
||||||
holder.image.setImageBitmap(feed.getImage().getImageBitmap()); // TODO select default picture when no image downloaded
|
.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)
|
// TODO find new Episodes txtvNewEpisodes.setText(feed)
|
||||||
return convertView;
|
return convertView;
|
||||||
|
@ -55,6 +68,7 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
|
||||||
|
|
||||||
static class Holder {
|
static class Holder {
|
||||||
TextView title;
|
TextView title;
|
||||||
|
TextView lastUpdate;
|
||||||
ImageView image;
|
ImageView image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
package de.podfetcher.feed;
|
package de.podfetcher.feed;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data Object for a whole feed
|
* Data Object for a whole feed
|
||||||
|
*
|
||||||
* @author daniel
|
* @author daniel
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Feed extends FeedFile{
|
public class Feed extends FeedFile {
|
||||||
private String title;
|
private String title;
|
||||||
/** Link to the website. */
|
/** Link to the website. */
|
||||||
private String link;
|
private String link;
|
||||||
|
@ -18,15 +17,17 @@ public class Feed extends FeedFile{
|
||||||
private FeedImage image;
|
private FeedImage image;
|
||||||
private FeedCategory category;
|
private FeedCategory category;
|
||||||
private ArrayList<FeedItem> items;
|
private ArrayList<FeedItem> items;
|
||||||
|
/** Date of last refresh. */
|
||||||
|
private Date lastUpdate;
|
||||||
public Feed() {
|
|
||||||
|
public Feed(Date lastUpdate) {
|
||||||
super();
|
super();
|
||||||
items = new ArrayList<FeedItem>();
|
items = new ArrayList<FeedItem>();
|
||||||
|
this.lastUpdate = lastUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Feed(String url) {
|
public Feed(String url, Date lastUpdate) {
|
||||||
this();
|
this(lastUpdate);
|
||||||
this.download_url = url;
|
this.download_url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,12 +79,12 @@ public class Feed extends FeedFile{
|
||||||
this.items = items;
|
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();
|
Cursor feedlistCursor = adapter.getAllFeedsCursor();
|
||||||
if (feedlistCursor.moveToFirst()) {
|
if (feedlistCursor.moveToFirst()) {
|
||||||
do {
|
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
|
feed.id = feedlistCursor.getLong(feedlistCursor
|
||||||
.getColumnIndex(PodDBAdapter.KEY_ID));
|
.getColumnIndex(PodDBAdapter.KEY_ID));
|
||||||
|
|
|
@ -41,6 +41,7 @@ public class PodDBAdapter {
|
||||||
public static final String KEY_FEED = "feed";
|
public static final String KEY_FEED = "feed";
|
||||||
public static final String KEY_MEDIA = "media";
|
public static final String KEY_MEDIA = "media";
|
||||||
public static final String KEY_DOWNLOADED = "downloaded";
|
public static final String KEY_DOWNLOADED = "downloaded";
|
||||||
|
public static final String KEY_LASTUPDATE = "last_update";
|
||||||
|
|
||||||
// Table names
|
// Table names
|
||||||
public static final String TABLE_NAME_FEEDS = "Feeds";
|
public static final String TABLE_NAME_FEEDS = "Feeds";
|
||||||
|
@ -54,17 +55,16 @@ public class PodDBAdapter {
|
||||||
+ " INTEGER PRIMARY KEY AUTOINCREMENT ,";
|
+ " INTEGER PRIMARY KEY AUTOINCREMENT ,";
|
||||||
private static final String CREATE_TABLE_FEEDS = "CREATE TABLE "
|
private static final String CREATE_TABLE_FEEDS = "CREATE TABLE "
|
||||||
+ TABLE_NAME_FEEDS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
|
+ TABLE_NAME_FEEDS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
|
||||||
+ " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION
|
+ " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION + " TEXT,"
|
||||||
+ " TEXT," + KEY_IMAGE + " INTEGER," + KEY_CATEGORY
|
+ KEY_IMAGE + " INTEGER," + KEY_CATEGORY + " INTEGER,"
|
||||||
+ " INTEGER," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL
|
+ KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT,"
|
||||||
+ " TEXT," + KEY_DOWNLOADED + " INTEGER)";
|
+ KEY_DOWNLOADED + " INTEGER," + KEY_LASTUPDATE + " TEXT)";
|
||||||
|
|
||||||
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
|
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
|
||||||
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
|
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
|
||||||
+ " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION
|
+ " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION + " TEXT,"
|
||||||
+ " TEXT," + KEY_PUBDATE + " INTEGER," + KEY_MEDIA
|
+ KEY_PUBDATE + " INTEGER," + KEY_MEDIA + " INTEGER," + KEY_FEED
|
||||||
+ " INTEGER," + KEY_FEED + " INTEGER," + KEY_READ
|
+ " INTEGER," + KEY_READ + " INTEGER)";
|
||||||
+ " INTEGER)";
|
|
||||||
|
|
||||||
private static final String CREATE_TABLE_FEED_CATEGORIES = "CREATE TABLE "
|
private static final String CREATE_TABLE_FEED_CATEGORIES = "CREATE TABLE "
|
||||||
+ TABLE_NAME_FEED_CATEGORIES + " (" + TABLE_PRIMARY_KEY + KEY_NAME
|
+ 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 "
|
private static final String CREATE_TABLE_FEED_IMAGES = "CREATE TABLE "
|
||||||
+ TABLE_NAME_FEED_IMAGES + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
|
+ TABLE_NAME_FEED_IMAGES + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
|
||||||
+ " TEXT," + KEY_FILE_URL + " TEXT,"
|
+ " TEXT," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT,"
|
||||||
+ KEY_DOWNLOAD_URL + " TEXT," + KEY_DOWNLOADED + " INTEGER)";
|
+ KEY_DOWNLOADED + " INTEGER)";
|
||||||
|
|
||||||
private static final String CREATE_TABLE_FEED_MEDIA = "CREATE TABLE "
|
private static final String CREATE_TABLE_FEED_MEDIA = "CREATE TABLE "
|
||||||
+ TABLE_NAME_FEED_MEDIA + " (" + TABLE_PRIMARY_KEY + KEY_DURATION
|
+ TABLE_NAME_FEED_MEDIA + " (" + TABLE_PRIMARY_KEY + KEY_DURATION
|
||||||
+ " INTEGER," + KEY_POSITION + " INTEGER,"
|
+ " INTEGER," + KEY_POSITION + " INTEGER," + KEY_SIZE + " INTEGER,"
|
||||||
+ KEY_SIZE + " INTEGER," + KEY_MIME_TYPE + " TEXT,"
|
+ KEY_MIME_TYPE + " TEXT," + KEY_FILE_URL + " TEXT,"
|
||||||
+ KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT," + KEY_DOWNLOADED + " INTEGER)";
|
+ KEY_DOWNLOAD_URL + " TEXT," + KEY_DOWNLOADED + " INTEGER)";
|
||||||
|
|
||||||
private SQLiteDatabase db;
|
private SQLiteDatabase db;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
@ -91,12 +91,12 @@ public class PodDBAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PodDBAdapter open() {
|
public PodDBAdapter open() {
|
||||||
if(db == null || !db.isOpen() || db.isReadOnly()) {
|
if (db == null || !db.isOpen() || db.isReadOnly()) {
|
||||||
try {
|
try {
|
||||||
db = helper.getWritableDatabase();
|
db = helper.getWritableDatabase();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
db = helper.getReadableDatabase();
|
db = helper.getReadableDatabase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -104,11 +104,13 @@ public class PodDBAdapter {
|
||||||
public void close() {
|
public void close() {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts or updates a feed entry
|
/**
|
||||||
|
* Inserts or updates a feed entry
|
||||||
|
*
|
||||||
* @return the id of the entry
|
* @return the id of the entry
|
||||||
* */
|
* */
|
||||||
public long setFeed(Feed feed) {
|
public long setFeed(Feed feed) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(KEY_TITLE, feed.getTitle());
|
values.put(KEY_TITLE, feed.getTitle());
|
||||||
values.put(KEY_LINK, feed.getLink());
|
values.put(KEY_LINK, feed.getLink());
|
||||||
|
@ -119,75 +121,83 @@ public class PodDBAdapter {
|
||||||
}
|
}
|
||||||
values.put(KEY_IMAGE, feed.getImage().getId());
|
values.put(KEY_IMAGE, feed.getImage().getId());
|
||||||
}
|
}
|
||||||
if(feed.getCategory() != null) {
|
if (feed.getCategory() != null) {
|
||||||
if(feed.getCategory().getId() == 0) {
|
if (feed.getCategory().getId() == 0) {
|
||||||
setCategory(feed.getCategory());
|
setCategory(feed.getCategory());
|
||||||
}
|
}
|
||||||
values.put(KEY_CATEGORY, feed.getCategory().getId());
|
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_FILE_URL, feed.getFile_url());
|
||||||
}
|
}
|
||||||
values.put(KEY_DOWNLOAD_URL, feed.getDownload_url());
|
values.put(KEY_DOWNLOAD_URL, feed.getDownload_url());
|
||||||
values.put(KEY_DOWNLOADED, feed.isDownloaded());
|
values.put(KEY_DOWNLOADED, feed.isDownloaded());
|
||||||
|
values.put(KEY_LASTUPDATE, feed.getLastUpdate().getTime());
|
||||||
open();
|
open();
|
||||||
if(feed.getId() == 0) {
|
if (feed.getId() == 0) {
|
||||||
// Create new entry
|
// Create new entry
|
||||||
Log.d(this.toString(), "Inserting new Feed into db");
|
Log.d(this.toString(), "Inserting new Feed into db");
|
||||||
feed.setId(db.insert(TABLE_NAME_FEEDS, null, values));
|
feed.setId(db.insert(TABLE_NAME_FEEDS, null, values));
|
||||||
} else {
|
} else {
|
||||||
Log.d(this.toString(), "Updating existing Feed in db");
|
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();
|
close();
|
||||||
return feed.getId();
|
return feed.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts or updates a category entry
|
/**
|
||||||
|
* Inserts or updates a category entry
|
||||||
|
*
|
||||||
* @return the id of the entry
|
* @return the id of the entry
|
||||||
* */
|
* */
|
||||||
public long setCategory(FeedCategory category) {
|
public long setCategory(FeedCategory category) {
|
||||||
open();
|
open();
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(KEY_NAME, category.getName());
|
values.put(KEY_NAME, category.getName());
|
||||||
if(category.getId() == 0) {
|
if (category.getId() == 0) {
|
||||||
category.setId(db.insert(TABLE_NAME_FEED_CATEGORIES, null, values));
|
category.setId(db.insert(TABLE_NAME_FEED_CATEGORIES, null, values));
|
||||||
} else {
|
} 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();
|
close();
|
||||||
return category.getId();
|
return category.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts or updates an image entry
|
* Inserts or updates an image entry
|
||||||
|
*
|
||||||
* @return the id of the entry
|
* @return the id of the entry
|
||||||
* */
|
* */
|
||||||
public long setImage(FeedImage image) {
|
public long setImage(FeedImage image) {
|
||||||
open();
|
open();
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(KEY_TITLE, image.getTitle());
|
values.put(KEY_TITLE, image.getTitle());
|
||||||
values.put(KEY_DOWNLOAD_URL, image.getDownload_url());
|
values.put(KEY_DOWNLOAD_URL, image.getDownload_url());
|
||||||
values.put(KEY_DOWNLOADED, image.isDownloaded());
|
values.put(KEY_DOWNLOADED, image.isDownloaded());
|
||||||
if(image.getFile_url() != null) {
|
if (image.getFile_url() != null) {
|
||||||
values.put(KEY_FILE_URL, image.getFile_url());
|
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));
|
image.setId(db.insert(TABLE_NAME_FEED_IMAGES, null, values));
|
||||||
} else {
|
} 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();
|
close();
|
||||||
return image.getId();
|
return image.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts or updates an image entry
|
* Inserts or updates an image entry
|
||||||
|
*
|
||||||
* @return the id of the entry
|
* @return the id of the entry
|
||||||
*/
|
*/
|
||||||
public long setMedia(FeedMedia media) {
|
public long setMedia(FeedMedia media) {
|
||||||
open();
|
open();
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(KEY_DURATION, media.getDuration());
|
values.put(KEY_DURATION, media.getDuration());
|
||||||
values.put(KEY_POSITION, media.getPosition());
|
values.put(KEY_POSITION, media.getPosition());
|
||||||
|
@ -195,20 +205,22 @@ public class PodDBAdapter {
|
||||||
values.put(KEY_MIME_TYPE, media.getMime_type());
|
values.put(KEY_MIME_TYPE, media.getMime_type());
|
||||||
values.put(KEY_DOWNLOAD_URL, media.getDownload_url());
|
values.put(KEY_DOWNLOAD_URL, media.getDownload_url());
|
||||||
values.put(KEY_DOWNLOADED, media.isDownloaded());
|
values.put(KEY_DOWNLOADED, media.isDownloaded());
|
||||||
if(media.getFile_url() != null) {
|
if (media.getFile_url() != null) {
|
||||||
values.put(KEY_FILE_URL, media.getFile_url());
|
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));
|
media.setId(db.insert(TABLE_NAME_FEED_MEDIA, null, values));
|
||||||
} else {
|
} 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();
|
close();
|
||||||
return media.getId();
|
return media.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts or updates a feeditem entry
|
* Inserts or updates a feeditem entry
|
||||||
|
*
|
||||||
* @return the id of the entry
|
* @return the id of the entry
|
||||||
*/
|
*/
|
||||||
public long setFeedItem(FeedItem item) {
|
public long setFeedItem(FeedItem item) {
|
||||||
|
@ -218,7 +230,7 @@ public class PodDBAdapter {
|
||||||
values.put(KEY_DESCRIPTION, item.getDescription());
|
values.put(KEY_DESCRIPTION, item.getDescription());
|
||||||
values.put(KEY_PUBDATE, item.getPubDate().getTime());
|
values.put(KEY_PUBDATE, item.getPubDate().getTime());
|
||||||
if (item.getMedia() != null) {
|
if (item.getMedia() != null) {
|
||||||
if(item.getMedia().getId() == 0) {
|
if (item.getMedia().getId() == 0) {
|
||||||
setMedia(item.getMedia());
|
setMedia(item.getMedia());
|
||||||
}
|
}
|
||||||
values.put(KEY_MEDIA, item.getMedia().getId());
|
values.put(KEY_MEDIA, item.getMedia().getId());
|
||||||
|
@ -231,111 +243,131 @@ public class PodDBAdapter {
|
||||||
|
|
||||||
open();
|
open();
|
||||||
if (item.getId() == 0) {
|
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 {
|
} else {
|
||||||
db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?",
|
db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?",
|
||||||
new String[]{String.valueOf(item.getId())});
|
new String[] { String.valueOf(item.getId()) });
|
||||||
}
|
}
|
||||||
close();
|
close();
|
||||||
return item.getId();
|
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() {
|
public final Cursor getAllCategoriesCursor() {
|
||||||
open();
|
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;
|
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() {
|
public final Cursor getAllFeedsCursor() {
|
||||||
open();
|
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;
|
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.
|
||||||
* @return The cursor of the query
|
*
|
||||||
* */
|
* @param feed
|
||||||
|
* The feed you want to get the FeedItems from.
|
||||||
|
* @return The cursor of the query
|
||||||
|
* */
|
||||||
public final Cursor getAllItemsOfFeedCursor(final Feed feed) {
|
public final Cursor getAllItemsOfFeedCursor(final Feed feed) {
|
||||||
open();
|
open();
|
||||||
Cursor c = db.query(TABLE_NAME_FEED_ITEMS, null, KEY_FEED + "=?",
|
Cursor c = db
|
||||||
new String[]{String.valueOf(feed.getId())}, null, null, null);
|
.query(TABLE_NAME_FEED_ITEMS, null, KEY_FEED + "=?",
|
||||||
|
new String[] { String.valueOf(feed.getId()) }, null,
|
||||||
|
null, null);
|
||||||
return c;
|
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.
|
||||||
* @return The cursor of the query
|
*
|
||||||
* */
|
* @param item
|
||||||
|
* The item you want to get the FeedMedia from
|
||||||
|
* @return The cursor of the query
|
||||||
|
* */
|
||||||
public final Cursor getFeedMediaOfItemCursor(final FeedItem item) {
|
public final Cursor getFeedMediaOfItemCursor(final FeedItem item) {
|
||||||
open();
|
open();
|
||||||
Cursor c = db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID + "=?",
|
Cursor c = db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID + "=?",
|
||||||
new String[]{String.valueOf(item.getMedia().getId())},
|
new String[] { String.valueOf(item.getMedia().getId()) }, null,
|
||||||
null, null, null);
|
null, null);
|
||||||
return c;
|
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.
|
||||||
* @return The cursor of the query
|
*
|
||||||
* */
|
* @param id
|
||||||
|
* ID of the FeedImage
|
||||||
|
* @return The cursor of the query
|
||||||
|
* */
|
||||||
public final Cursor getImageOfFeedCursor(final long id) {
|
public final Cursor getImageOfFeedCursor(final long id) {
|
||||||
open();
|
open();
|
||||||
Cursor c = db.query(TABLE_NAME_FEED_IMAGES, null, KEY_ID + "=?",
|
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;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get a FeedMedia object from the Database.
|
/**
|
||||||
* @param rowIndex DB Index of Media object
|
* Get a FeedMedia object from the Database.
|
||||||
* @param owner FeedItem the Media object belongs to
|
*
|
||||||
* @return A newly created FeedMedia object
|
* @param rowIndex
|
||||||
* */
|
* DB Index of Media object
|
||||||
public final FeedMedia getFeedMedia(final long rowIndex, final FeedItem owner)
|
* @param owner
|
||||||
throws SQLException {
|
* FeedItem the Media object belongs to
|
||||||
open();
|
* @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 + "=?",
|
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()) {
|
if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
|
||||||
throw new SQLException("No FeedMedia found at index: " + rowIndex);
|
throw new SQLException("No FeedMedia found at index: " + rowIndex);
|
||||||
}
|
}
|
||||||
FeedMedia media = new FeedMedia(rowIndex,
|
FeedMedia media = new FeedMedia(rowIndex, owner, cursor.getInt(cursor
|
||||||
owner,
|
.getColumnIndex(KEY_DURATION)), cursor.getInt(cursor
|
||||||
cursor.getInt(cursor.getColumnIndex(KEY_DURATION)),
|
.getColumnIndex(KEY_POSITION)), cursor.getLong(cursor
|
||||||
cursor.getInt(cursor.getColumnIndex(KEY_POSITION)),
|
.getColumnIndex(KEY_SIZE)), cursor.getString(cursor
|
||||||
cursor.getLong(cursor.getColumnIndex(KEY_SIZE)),
|
.getColumnIndex(KEY_MIME_TYPE)), cursor.getString(cursor
|
||||||
cursor.getString(cursor.getColumnIndex(KEY_MIME_TYPE)),
|
.getColumnIndex(KEY_FILE_URL)), cursor.getString(cursor
|
||||||
cursor.getString(cursor.getColumnIndex(KEY_FILE_URL)),
|
.getColumnIndex(KEY_DOWNLOAD_URL)), cursor.getInt(cursor
|
||||||
cursor.getString(cursor.getColumnIndex(KEY_DOWNLOAD_URL)),
|
.getColumnIndex(KEY_DOWNLOADED)) > 0);
|
||||||
cursor.getInt(cursor.getColumnIndex(KEY_DOWNLOADED)) > 0);
|
|
||||||
close();
|
close();
|
||||||
return media;
|
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.
|
||||||
* @return The found object
|
*
|
||||||
|
* @param id
|
||||||
|
* The id of the object
|
||||||
|
* @return The found object
|
||||||
* */
|
* */
|
||||||
public final FeedImage getFeedImage(final long id) throws SQLException {
|
public final FeedImage getFeedImage(final long id) throws SQLException {
|
||||||
open();
|
open();
|
||||||
Cursor cursor = this.getImageOfFeedCursor(id);
|
Cursor cursor = this.getImageOfFeedCursor(id);
|
||||||
if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
|
if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
|
||||||
throw new SQLException("No FeedImage found at index: " + id);
|
throw new SQLException("No FeedImage found at index: " + id);
|
||||||
}
|
}
|
||||||
FeedImage image = new FeedImage(id,
|
FeedImage image = new FeedImage(id, cursor.getString(cursor
|
||||||
cursor.getString(
|
.getColumnIndex(KEY_TITLE)), cursor.getString(cursor
|
||||||
cursor.getColumnIndex(KEY_TITLE)),
|
.getColumnIndex(KEY_FILE_URL)), cursor.getString(cursor
|
||||||
cursor.getString(
|
.getColumnIndex(KEY_DOWNLOAD_URL)), cursor.getInt(cursor
|
||||||
cursor.getColumnIndex(KEY_FILE_URL)),
|
.getColumnIndex(KEY_DOWNLOADED)) > 0);
|
||||||
cursor.getString(
|
|
||||||
cursor.getColumnIndex(KEY_DOWNLOAD_URL)),
|
|
||||||
cursor.getInt(cursor.getColumnIndex(KEY_DOWNLOADED)) > 0);
|
|
||||||
close();
|
close();
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
@ -343,15 +375,20 @@ public class PodDBAdapter {
|
||||||
/** Helper class for opening the Podfetcher database. */
|
/** Helper class for opening the Podfetcher database. */
|
||||||
private static class PodDBHelper extends SQLiteOpenHelper {
|
private static class PodDBHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
/** Constructor.
|
/**
|
||||||
* @param context Context to use
|
* Constructor.
|
||||||
* @param name Name of the database
|
*
|
||||||
* @param factory to use for creating cursor objects
|
* @param context
|
||||||
* @param version number of the database
|
* 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,
|
public PodDBHelper(final Context context, final String name,
|
||||||
final String name, final CursorFactory factory,
|
final CursorFactory factory, final int version) {
|
||||||
final int version) {
|
|
||||||
super(context, name, factory, version);
|
super(context, name, factory, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,10 +402,9 @@ public class PodDBAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(final SQLiteDatabase db,
|
public void onUpgrade(final SQLiteDatabase db, final int oldVersion,
|
||||||
final int oldVersion, final int newVersion) {
|
final int newVersion) {
|
||||||
Log.w("DBAdapter", "Upgrading from version "
|
Log.w("DBAdapter", "Upgrading from version " + oldVersion + " to "
|
||||||
+ oldVersion + " to "
|
|
||||||
+ newVersion + ".");
|
+ newVersion + ".");
|
||||||
// TODO delete Database
|
// TODO delete Database
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue