Added getters and setters for feed classes

This commit is contained in:
Daniel Oeh 2011-12-25 14:51:06 +01:00
parent 48144440cf
commit 1a9c6053df
10 changed files with 165 additions and 89 deletions

View File

@ -11,12 +11,12 @@ import java.util.ArrayList;
*
*/
public class Feed extends FeedFile{
public String title;
public String link;
public String description;
public FeedImage image;
public FeedCategory category;
public ArrayList<FeedItem> items;
private String title;
private String link;
private String description;
private FeedImage image;
private FeedCategory category;
private ArrayList<FeedItem> items;
public Feed() {
@ -37,6 +37,58 @@ public class Feed extends FeedFile{
this.category = category;
items = new ArrayList<FeedItem>();
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public FeedImage getImage() {
return image;
}
public void setImage(FeedImage image) {
this.image = image;
}
public FeedCategory getCategory() {
return category;
}
public void setCategory(FeedCategory category) {
this.category = category;
}
public ArrayList<FeedItem> getItems() {
return items;
}
public void setItems(ArrayList<FeedItem> items) {
this.items = items;
}

View File

@ -7,10 +7,20 @@ package de.podfetcher.feed;
*/
public class FeedComponent {
public long id;
protected long id;
public FeedComponent() {
super();
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}

View File

@ -1,7 +1,22 @@
package de.podfetcher.feed;
public abstract class FeedFile extends FeedComponent {
public String file_url;
public String download_url;
protected String file_url;
protected String download_url;
public String getFile_url() {
return file_url;
}
public void setFile_url(String file_url) {
this.file_url = file_url;
}
public String getDownload_url() {
return download_url;
}
public void setDownload_url(String download_url) {
this.download_url = download_url;
}
}

View File

@ -18,8 +18,8 @@ public class FeedManager {
private static FeedManager singleton;
public ArrayList<Feed> feeds;
public ArrayList<FeedCategory> categories;
private ArrayList<Feed> feeds;
private ArrayList<FeedCategory> categories;
Cursor feedlistCursor;
@ -69,7 +69,7 @@ public class FeedManager {
item.read = foundItem.read;
adapter.setFeedItem(item);
} else {
foundFeed.items.add(item);
foundFeed.getItems().add(item);
item.id = adapter.setFeedItem(item);
}
}
@ -77,7 +77,7 @@ public class FeedManager {
/** Get a Feed by its link */
private Feed searchFeedByLink(String link) {
for(Feed feed : feeds) {
if(feed.link.equals(link)) {
if(feed.getLink().equals(link)) {
return feed;
}
}
@ -86,7 +86,7 @@ public class FeedManager {
/** Get a FeedItem by its link */
private FeedItem searchFeedItemByLink(Feed feed, String link) {
for(FeedItem item : feed.items) {
for(FeedItem item : feed.getItems()) {
if(item.link.equals(link)) {
return item;
}
@ -133,16 +133,16 @@ public class FeedManager {
Feed feed = new Feed();
feed.id = feedlistCursor.getLong(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_ID));
feed.title = feedlistCursor.getString(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_TITLE));
feed.link = feedlistCursor.getString(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_LINK));
feed.description = feedlistCursor.getString(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_DESCRIPTION));
feed.image = adapter.getFeedImage(feed);
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.file_url = feedlistCursor.getString(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_FILE_URL));
feed.download_url = feedlistCursor.getString(feedlistCursor.getColumnIndex(PodDBAdapter.KEY_DOWNLOAD_URL));
// Get FeedItem-Object
Cursor itemlistCursor = adapter.getAllItemsOfFeedCursor(feed);
feed.items = extractFeedItemsFromCursor(context, itemlistCursor);
feed.setItems(extractFeedItemsFromCursor(context, itemlistCursor));
feeds.add(feed);
}while(feedlistCursor.moveToNext());

View File

@ -36,7 +36,7 @@ public class RSSHandler extends DefaultHandler {
@Override
public void endDocument() throws SAXException {
feed.items = items;
feed.setItems(items);
}
@Override
@ -47,21 +47,21 @@ public class RSSHandler extends DefaultHandler {
items.add(currentItem);
} else if (qName.equalsIgnoreCase(FeedHandler.TITLE)) {
if (active_root_element.equalsIgnoreCase(FeedHandler.CHANNEL)) {
feed.title = strBuilder.toString();
feed.setTitle(strBuilder.toString());
} else if(active_root_element.equalsIgnoreCase(FeedHandler.TITLE)) {
currentItem.title = strBuilder.toString();
} else if(active_root_element.equalsIgnoreCase(FeedHandler.IMAGE)) {
feed.image.title = strBuilder.toString();
feed.getImage().title = strBuilder.toString();
}
} else if (qName.equalsIgnoreCase(FeedHandler.DESCR)) {
if (active_root_element.equalsIgnoreCase(FeedHandler.CHANNEL)) {
feed.description = strBuilder.toString();
feed.setDescription(strBuilder.toString());
} else {
currentItem.description = strBuilder.toString();
}
} else if (qName.equalsIgnoreCase(FeedHandler.LINK)) {
if (active_root_element.equalsIgnoreCase(FeedHandler.CHANNEL)) {
feed.link = strBuilder.toString();
feed.setLink(strBuilder.toString());
} else if(active_root_element.equalsIgnoreCase(FeedHandler.TITLE)){
currentItem.link = strBuilder.toString();
}
@ -71,7 +71,7 @@ public class RSSHandler extends DefaultHandler {
}
} else if (qName.equalsIgnoreCase(FeedHandler.URL)) {
if(active_root_element.equalsIgnoreCase(FeedHandler.IMAGE)) {
feed.image.download_url = strBuilder.toString();
feed.getImage().download_url = strBuilder.toString();
}
} else if(qName.equalsIgnoreCase(FeedHandler.IMAGE)) {
active_root_element = FeedHandler.CHANNEL;
@ -112,7 +112,7 @@ public class RSSHandler extends DefaultHandler {
Long.parseLong(attributes.getValue(FeedHandler.ENC_LEN)),
attributes.getValue(FeedHandler.ENC_TYPE));
} else if(qName.equalsIgnoreCase(FeedHandler.IMAGE)) {
feed.image = new FeedImage();
feed.setImage(new FeedImage());
active_root_element = qName;
} else if(qName.equalsIgnoreCase(FeedHandler.URL)) {
active_sub_element = qName;

View File

@ -46,8 +46,8 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
TextView txtvFeedname = (TextView)feedlistView.findViewById(R.id.txtvFeedname);
TextView txtvNewEpisodes = (TextView)feedlistView.findViewById(R.id.txtvNewEpisodes);
imageView.setImageURI(Uri.fromFile(new File(feed.file_url))); // TODO select default picture when no image downloaded
txtvFeedname.setText(feed.title);
imageView.setImageURI(Uri.fromFile(new File(feed.getFile_url()))); // TODO select default picture when no image downloaded
txtvFeedname.setText(feed.getTitle());
// TODO find new Episodes txtvNewEpisodes.setText(feed)
return feedlistView;
}

View File

@ -14,7 +14,6 @@ import de.podfetcher.feed.*;
import de.podfetcher.storage.DownloadRequester;
import de.podfetcher.storage.DownloadService;
import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
@ -56,7 +55,7 @@ public class FeedSyncService extends Service {
/** Extracts a Feed object from the given Intent */
private Feed handleIntent(Intent intent) {
Feed feed = manager.getFeed(intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
feed.file_url = requester.getFeedfilePath(this) + requester.getFeedfileName(feed.id);
feed.setFile_url(requester.getFeedfilePath(this) + requester.getFeedfileName(feed.getId()));
return feed;
}
@ -101,7 +100,7 @@ public class FeedSyncService extends Service {
feed = handler.parseFeed(feed);
// Add Feeditems to the database
for(FeedItem item : feed.items) {
for(FeedItem item : feed.getItems()) {
manager.addFeedItem(service, item);
}
}

View File

@ -62,21 +62,21 @@ public class DownloadRequester {
}
public void downloadFeed(Context context, Feed feed) {
download(context, feeds, feed.download_url,
new File(getFeedfilePath(context), getFeedfileName(feed.id)),
true, ACTION_FEED_DOWNLOAD_COMPLETED, feed.id);
download(context, feeds, feed.getDownload_url(),
new File(getFeedfilePath(context), getFeedfileName(feed.getId())),
true, ACTION_FEED_DOWNLOAD_COMPLETED, feed.getId());
}
public void downloadImage(Context context, FeedImage image) {
download(context, images, image.download_url,
new File(getImagefilePath(context), getImagefileName(image.id)),
true, ACTION_IMAGE_DOWNLOAD_COMPLETED, image.id);
download(context, images, image.getDownload_url(),
new File(getImagefilePath(context), getImagefileName(image.getId())),
true, ACTION_IMAGE_DOWNLOAD_COMPLETED, image.getId());
}
public void downloadMedia(Context context, FeedMedia feedmedia) {
download(context, media, feedmedia.download_url,
new File(context.getExternalFilesDir(MEDIA_DOWNLOADPATH), "media-" + feedmedia.id),
true, ACTION_MEDIA_DOWNLOAD_COMPLETED, feedmedia.id);
download(context, media, feedmedia.getDownload_url(),
new File(context.getExternalFilesDir(MEDIA_DOWNLOADPATH), "media-" + feedmedia.getId()),
true, ACTION_MEDIA_DOWNLOAD_COMPLETED, feedmedia.getId());
}
public void removeFeedByID(long id) {

View File

@ -81,11 +81,11 @@ public class DownloadService extends Service {
requester.removeFeedByID(intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
// Get Feed Information
Feed feed = manager.getFeed(intent.getLongExtra(DownloadRequester.EXTRA_ITEM_ID, -1));
feed.file_url = requester.getFeedfilePath(context) + requester.getFeedfileName(feed.id);
feed.setFile_url(requester.getFeedfilePath(context) + requester.getFeedfileName(feed.getId()));
feed = handler.parseFeed(feed);
// Download Feed Image if provided
if(feed.image != null) {
requester.downloadImage(context, feed.image);
if(feed.getImage() != null) {
requester.downloadImage(context, feed.getImage());
}
// Update Information in Database
manager.setFeed(context, feed);

View File

@ -108,34 +108,34 @@ public class PodDBAdapter {
public long setFeed(Feed feed) {
open();
ContentValues values = new ContentValues();
values.put(KEY_TITLE, feed.title);
values.put(KEY_LINK, feed.link);
values.put(KEY_DESCRIPTION, feed.description);
if (feed.image != null) {
if (feed.image.id == 0) {
setImage(feed.image);
values.put(KEY_TITLE, feed.getTitle());
values.put(KEY_LINK, feed.getLink());
values.put(KEY_DESCRIPTION, feed.getDescription());
if (feed.getImage() != null) {
if (feed.getImage().getId() == 0) {
setImage(feed.getImage());
}
values.put(KEY_IMAGE, feed.image.id);
values.put(KEY_IMAGE, feed.getImage().getId());
}
if(feed.category != null) {
if(feed.category.id == 0) {
setCategory(feed.category);
if(feed.getCategory() != null) {
if(feed.getCategory().getId() == 0) {
setCategory(feed.getCategory());
}
values.put(KEY_CATEGORY, feed.category.id);
values.put(KEY_CATEGORY, feed.getCategory().getId());
}
if(feed.file_url != null) {
values.put(KEY_FILE_URL, feed.file_url);
if(feed.getFile_url() != null) {
values.put(KEY_FILE_URL, feed.getFile_url());
}
values.put(KEY_DOWNLOAD_URL, feed.download_url);
values.put(KEY_DOWNLOAD_URL, feed.getDownload_url());
if(feed.id == 0) {
if(feed.getId() == 0) {
// Create new entry
feed.id = db.insert(TABLE_NAME_FEEDS, null, values);
feed.setId(db.insert(TABLE_NAME_FEEDS, null, values));
} else {
db.update(TABLE_NAME_FEEDS, values, KEY_ID+"=?", new String[]{String.valueOf(feed.id)});
db.update(TABLE_NAME_FEEDS, values, KEY_ID+"=?", new String[]{String.valueOf(feed.getId())});
}
close();
return feed.id;
return feed.getId();
}
/** Inserts or updates a category entry
@ -144,13 +144,13 @@ public class PodDBAdapter {
public long setCategory(FeedCategory category) {
ContentValues values = new ContentValues();
values.put(KEY_NAME, category.name);
if(category.id == 0) {
category.id = db.insert(TABLE_NAME_FEED_CATEGORIES, null, values);
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.id)});
db.update(TABLE_NAME_FEED_CATEGORIES, values, KEY_ID+"=?", new String[]{String.valueOf(category.getId())});
}
return category.id;
return category.getId();
}
/**
@ -160,16 +160,16 @@ public class PodDBAdapter {
public long setImage(FeedImage image) {
ContentValues values = new ContentValues();
values.put(KEY_TITLE, image.title);
values.put(KEY_DOWNLOAD_URL, image.download_url);
if(image.file_url != null) {
values.put(KEY_FILE_URL, image.file_url);
values.put(KEY_DOWNLOAD_URL, image.getDownload_url());
if(image.getFile_url() != null) {
values.put(KEY_FILE_URL, image.getFile_url());
}
if(image.id == 0) {
image.id = db.insert(TABLE_NAME_FEED_IMAGES, null, values);
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.id)});
db.update(TABLE_NAME_FEED_IMAGES, values, KEY_ID+"=?", new String[]{String.valueOf(image.getId())});
}
return image.id;
return image.getId();
}
/**
@ -182,16 +182,16 @@ public class PodDBAdapter {
values.put(KEY_POSITION, media.position);
values.put(KEY_SIZE, media.size);
values.put(KEY_MIME_TYPE, media.mime_type);
values.put(KEY_DOWNLOAD_URL, media.download_url);
if(media.file_url != null) {
values.put(KEY_FILE_URL, media.file_url);
values.put(KEY_DOWNLOAD_URL, media.getDownload_url());
if(media.getFile_url() != null) {
values.put(KEY_FILE_URL, media.getFile_url());
}
if(media.id == 0) {
media.id = db.insert(TABLE_NAME_FEED_MEDIA, null, values);
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.id)});
db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID+"=?", new String[]{String.valueOf(media.getId())});
}
return media.id;
return media.getId();
}
/**
@ -205,17 +205,17 @@ public class PodDBAdapter {
values.put(KEY_DESCRIPTION, item.description);
values.put(KEY_PUBDATE, item.pubDate);
if(item.media != null) {
if(item.media.id == 0) {
if(item.media.getId() == 0) {
setMedia(item.media);
}
values.put(KEY_MEDIA, item.media.id);
values.put(KEY_MEDIA, item.media.getId());
}
if(item.feed.id == 0) {
if(item.feed.getId() == 0) {
setFeed(item.feed);
}
values.put(KEY_FEED, item.feed.id);
values.put(KEY_FEED, item.feed.getId());
values.put(KEY_READ, (item.read) ? 1 : 0);
return item.id;
return item.getId();
}
public Cursor getAllCategoriesCursor() {
@ -227,15 +227,15 @@ public class PodDBAdapter {
}
public Cursor getAllItemsOfFeedCursor(Feed feed) {
return db.query(TABLE_NAME_FEED_ITEMS, null, KEY_FEED+"=?", new String[]{String.valueOf(feed.id)}, null, null, null);
return db.query(TABLE_NAME_FEED_ITEMS, null, KEY_FEED+"=?", new String[]{String.valueOf(feed.getId())}, null, null, null);
}
public Cursor getFeedMediaOfItemCursor(FeedItem item) {
return db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID+"=?", new String[]{String.valueOf(item.media.id)}, null, null, null);
return db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID+"=?", new String[]{String.valueOf(item.media.getId())}, null, null, null);
}
public Cursor getImageOfFeedCursor(Feed feed) {
return db.query(TABLE_NAME_FEED_IMAGES, null, KEY_ID+"=?", new String[]{String.valueOf(feed.image.id)}, null, null, null);
return db.query(TABLE_NAME_FEED_IMAGES, null, KEY_ID+"=?", new String[]{String.valueOf(feed.getImage().getId())}, null, null, null);
}
public FeedMedia getFeedMedia(long row_index) throws SQLException{
@ -258,10 +258,10 @@ public class PodDBAdapter {
public FeedImage getFeedImage(Feed feed) throws SQLException {
Cursor cursor = this.getImageOfFeedCursor(feed);
if((cursor.getCount() == 0) || !cursor.moveToFirst()) {
throw new SQLException("No FeedImage found at index: "+ feed.image.id);
throw new SQLException("No FeedImage found at index: "+ feed.getImage().getId());
}
return new FeedImage(feed.image.id, cursor.getString(cursor.getColumnIndex(KEY_TITLE)),
return new FeedImage(feed.getImage().getId(), cursor.getString(cursor.getColumnIndex(KEY_TITLE)),
cursor.getString(cursor.getColumnIndex(KEY_FILE_URL)),
cursor.getString(cursor.getColumnIndex(KEY_DOWNLOAD_URL)));
}