Added some more getters and setters for feed classes

This commit is contained in:
Daniel Oeh 2011-12-25 15:01:23 +01:00
parent 1a9c6053df
commit d63097d696
8 changed files with 168 additions and 50 deletions

4
.gitignore vendored
View File

@ -17,3 +17,7 @@ local.properties
# Backup files
*~
# Eclipse project files
.classpath
.project

View File

@ -1,12 +1,20 @@
package de.podfetcher.feed;
public class FeedCategory extends FeedComponent{
public String name;
protected String name;
public FeedCategory(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
}

View File

@ -1,7 +1,7 @@
package de.podfetcher.feed;
public class FeedImage extends FeedFile {
public String title;
protected String title;
public FeedImage(String download_url, String title) {
super();
@ -19,6 +19,12 @@ public class FeedImage extends FeedFile {
public FeedImage() {
}
public String getTitle() {
return title;
}

View File

@ -7,13 +7,13 @@ package de.podfetcher.feed;
*
*/
public class FeedItem extends FeedComponent{
public String title;
public String description;
public String link;
public String pubDate;
public FeedMedia media;
public Feed feed;
public boolean read;
private String title;
private String description;
private String link;
private String pubDate;
private FeedMedia media;
private Feed feed;
private boolean read;
public FeedItem() {
this.read = false;
@ -30,4 +30,62 @@ public class FeedItem extends FeedComponent{
this.feed = feed;
this.read = false;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getPubDate() {
return pubDate;
}
public void setPubDate(String pubDate) {
this.pubDate = pubDate;
}
public FeedMedia getMedia() {
return media;
}
public void setMedia(FeedMedia media) {
this.media = media;
}
public Feed getFeed() {
return feed;
}
public void setFeed(Feed feed) {
this.feed = feed;
}
public boolean isRead() {
return read;
}
public void setRead(boolean read) {
this.read = read;
}
}

View File

@ -60,13 +60,13 @@ public class FeedManager {
public void addFeedItem(Context context, FeedItem item) {
PodDBAdapter adapter = new PodDBAdapter(context);
// Search list for feeditem
Feed foundFeed = searchFeedByLink(item.link);
FeedItem foundItem = searchFeedItemByLink(foundFeed, item.link);
Feed foundFeed = searchFeedByLink(item.getLink());
FeedItem foundItem = searchFeedItemByLink(foundFeed, item.getLink());
if(foundItem != null) {
// Update Information
item.id = foundItem.id;
foundItem = item;
item.read = foundItem.read;
item.setRead(foundItem.isRead());
adapter.setFeedItem(item);
} else {
foundFeed.getItems().add(item);
@ -87,7 +87,7 @@ public class FeedManager {
/** Get a FeedItem by its link */
private FeedItem searchFeedItemByLink(Feed feed, String link) {
for(FeedItem item : feed.getItems()) {
if(item.link.equals(link)) {
if(item.getLink().equals(link)) {
return item;
}
}
@ -158,12 +158,12 @@ public class FeedManager {
FeedItem item = new FeedItem();
item.id = itemlistCursor.getLong(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_ID));
item.title = itemlistCursor.getString(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_TITLE));
item.link = itemlistCursor.getString(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_LINK));
item.description = itemlistCursor.getString(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_DESCRIPTION));
item.pubDate = itemlistCursor.getString(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_PUBDATE));
item.media = adapter.getFeedMedia(itemlistCursor.getLong(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_MEDIA)));
item.read = (itemlistCursor.getInt(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_READ)) > 0) ? true : false;
item.setTitle(itemlistCursor.getString(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_TITLE)));
item.setLink(itemlistCursor.getString(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_LINK)));
item.setDescription(itemlistCursor.getString(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_DESCRIPTION)));
item.setPubDate(itemlistCursor.getString(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_PUBDATE)));
item.setMedia(adapter.getFeedMedia(itemlistCursor.getLong(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_MEDIA))));
item.setRead((itemlistCursor.getInt(itemlistCursor.getColumnIndex(PodDBAdapter.KEY_READ)) > 0) ? true : false);
items.add(item);
} while(itemlistCursor.moveToNext());

View File

@ -1,12 +1,12 @@
package de.podfetcher.feed;
public class FeedMedia extends FeedFile{
public long length;
public long position;
public long size; // File size in Byte
public String mime_type;
private long length;
private long position;
private long size; // File size in Byte
private String mime_type;
public FeedItem item; // TODO remove
private FeedItem item; // TODO remove
public FeedMedia(FeedItem i, String download_url, long size, String mime_type) {
this.item = i;
@ -26,6 +26,48 @@ public class FeedMedia extends FeedFile{
this.file_url = file_url;
this.download_url = download_url;
}
public long getLength() {
return length;
}
public void setLength(long length) {
this.length = length;
}
public long getPosition() {
return position;
}
public void setPosition(long position) {
this.position = position;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public String getMime_type() {
return mime_type;
}
public void setMime_type(String mime_type) {
this.mime_type = mime_type;
}
public FeedItem getItem() {
return item;
}
public void setItem(FeedItem item) {
this.item = item;
}

View File

@ -43,13 +43,13 @@ public class RSSHandler extends DefaultHandler {
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (qName.equalsIgnoreCase(FeedHandler.ITEM)) {
currentItem.feed = feed;
currentItem.setFeed(feed);
items.add(currentItem);
} else if (qName.equalsIgnoreCase(FeedHandler.TITLE)) {
if (active_root_element.equalsIgnoreCase(FeedHandler.CHANNEL)) {
feed.setTitle(strBuilder.toString());
} else if(active_root_element.equalsIgnoreCase(FeedHandler.TITLE)) {
currentItem.title = strBuilder.toString();
currentItem.setTitle(strBuilder.toString());
} else if(active_root_element.equalsIgnoreCase(FeedHandler.IMAGE)) {
feed.getImage().title = strBuilder.toString();
}
@ -57,17 +57,17 @@ public class RSSHandler extends DefaultHandler {
if (active_root_element.equalsIgnoreCase(FeedHandler.CHANNEL)) {
feed.setDescription(strBuilder.toString());
} else {
currentItem.description = strBuilder.toString();
currentItem.setDescription(strBuilder.toString());
}
} else if (qName.equalsIgnoreCase(FeedHandler.LINK)) {
if (active_root_element.equalsIgnoreCase(FeedHandler.CHANNEL)) {
feed.setLink(strBuilder.toString());
} else if(active_root_element.equalsIgnoreCase(FeedHandler.TITLE)){
currentItem.link = strBuilder.toString();
currentItem.setLink(strBuilder.toString());
}
} else if (qName.equalsIgnoreCase(FeedHandler.PUBDATE)) {
if (active_root_element.equalsIgnoreCase(FeedHandler.ITEM)) {
currentItem.pubDate = strBuilder.toString();
currentItem.setPubDate(strBuilder.toString());
}
} else if (qName.equalsIgnoreCase(FeedHandler.URL)) {
if(active_root_element.equalsIgnoreCase(FeedHandler.IMAGE)) {
@ -107,10 +107,10 @@ public class RSSHandler extends DefaultHandler {
} else if (qName.equalsIgnoreCase(FeedHandler.PUBDATE)) {
active_sub_element = qName;
} else if (qName.equalsIgnoreCase(FeedHandler.ENCLOSURE)) {
currentItem.media = new FeedMedia(currentItem,
currentItem.setMedia(new FeedMedia(currentItem,
attributes.getValue(FeedHandler.ENC_URL),
Long.parseLong(attributes.getValue(FeedHandler.ENC_LEN)),
attributes.getValue(FeedHandler.ENC_TYPE));
attributes.getValue(FeedHandler.ENC_TYPE)));
} else if(qName.equalsIgnoreCase(FeedHandler.IMAGE)) {
feed.setImage(new FeedImage());
active_root_element = qName;

View File

@ -143,7 +143,7 @@ public class PodDBAdapter {
* */
public long setCategory(FeedCategory category) {
ContentValues values = new ContentValues();
values.put(KEY_NAME, category.name);
values.put(KEY_NAME, category.getName());
if(category.getId() == 0) {
category.setId(db.insert(TABLE_NAME_FEED_CATEGORIES, null, values));
} else {
@ -159,7 +159,7 @@ public class PodDBAdapter {
* */
public long setImage(FeedImage image) {
ContentValues values = new ContentValues();
values.put(KEY_TITLE, image.title);
values.put(KEY_TITLE, image.getTitle());
values.put(KEY_DOWNLOAD_URL, image.getDownload_url());
if(image.getFile_url() != null) {
values.put(KEY_FILE_URL, image.getFile_url());
@ -178,10 +178,10 @@ public class PodDBAdapter {
*/
public long setMedia(FeedMedia media) {
ContentValues values = new ContentValues();
values.put(KEY_LENGTH, media.length);
values.put(KEY_POSITION, media.position);
values.put(KEY_SIZE, media.size);
values.put(KEY_MIME_TYPE, media.mime_type);
values.put(KEY_LENGTH, media.getLength());
values.put(KEY_POSITION, media.getPosition());
values.put(KEY_SIZE, media.getSize());
values.put(KEY_MIME_TYPE, media.getMime_type());
values.put(KEY_DOWNLOAD_URL, media.getDownload_url());
if(media.getFile_url() != null) {
values.put(KEY_FILE_URL, media.getFile_url());
@ -200,21 +200,21 @@ public class PodDBAdapter {
*/
public long setFeedItem(FeedItem item) {
ContentValues values = new ContentValues();
values.put(KEY_TITLE, item.title);
values.put(KEY_LINK, item.link);
values.put(KEY_DESCRIPTION, item.description);
values.put(KEY_PUBDATE, item.pubDate);
if(item.media != null) {
if(item.media.getId() == 0) {
setMedia(item.media);
values.put(KEY_TITLE, item.getTitle());
values.put(KEY_LINK, item.getLink());
values.put(KEY_DESCRIPTION, item.getDescription());
values.put(KEY_PUBDATE, item.getPubDate());
if(item.getMedia() != null) {
if(item.getMedia().getId() == 0) {
setMedia(item.getMedia());
}
values.put(KEY_MEDIA, item.media.getId());
values.put(KEY_MEDIA, item.getMedia().getId());
}
if(item.feed.getId() == 0) {
setFeed(item.feed);
if(item.getFeed().getId() == 0) {
setFeed(item.getFeed());
}
values.put(KEY_FEED, item.feed.getId());
values.put(KEY_READ, (item.read) ? 1 : 0);
values.put(KEY_FEED, item.getFeed().getId());
values.put(KEY_READ, (item.isRead()) ? 1 : 0);
return item.getId();
}
@ -231,7 +231,7 @@ public class PodDBAdapter {
}
public Cursor getFeedMediaOfItemCursor(FeedItem item) {
return db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID+"=?", new String[]{String.valueOf(item.media.getId())}, null, null, null);
return db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID+"=?", new String[]{String.valueOf(item.getMedia().getId())}, null, null, null);
}
public Cursor getImageOfFeedCursor(Feed feed) {