From aa7e58dc42f05f94954a0a4ca6f03420d4c97a74 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Tue, 18 Dec 2012 17:27:22 +0100 Subject: [PATCH] Added "updateFromOther" and "compareWithOther" methods --- src/de/danoeh/antennapod/feed/Feed.java | 66 +++++++++++++++++++ .../danoeh/antennapod/feed/FeedComponent.java | 19 ++++++ src/de/danoeh/antennapod/feed/FeedFile.java | 27 ++++++++ src/de/danoeh/antennapod/feed/FeedItem.java | 40 ++++++++++- src/de/danoeh/antennapod/feed/FeedMedia.java | 25 +++++++ .../danoeh/antennapod/feed/SimpleChapter.java | 10 +++ 6 files changed, 184 insertions(+), 3 deletions(-) diff --git a/src/de/danoeh/antennapod/feed/Feed.java b/src/de/danoeh/antennapod/feed/Feed.java index 7640ef7d1..8e93d54ee 100644 --- a/src/de/danoeh/antennapod/feed/Feed.java +++ b/src/de/danoeh/antennapod/feed/Feed.java @@ -171,6 +171,72 @@ public class Feed extends FeedFile { } } + public void updateFromOther(Feed other) { + super.updateFromOther(other); + if (other.title != null) { + title = other.title; + } + if (other.feedIdentifier != null) { + feedIdentifier = other.feedIdentifier; + } + if (other.link != null) { + link = other.link; + } + if (other.description != null) { + description = other.description; + } + if (other.language != null) { + language = other.language; + } + if (other.author != null) { + author = other.author; + } + if (other.paymentLink != null) { + paymentLink = other.paymentLink; + } + } + + public boolean compareWithOther(Feed other) { + if (super.compareWithOther(other)) { + return true; + } + if (!title.equals(other.title)) { + return true; + } + if (other.feedIdentifier != null) { + if (feedIdentifier == null + || !feedIdentifier.equals(other.feedIdentifier)) { + return true; + } + } + if (other.link != null) { + if (link == null || !link.equals(other.link)) { + return true; + } + } + if (other.description != null) { + if (description == null || !description.equals(other.description)) { + return true; + } + } + if (other.language != null) { + if (language == null || !language.equals(other.language)) { + return true; + } + } + if (other.author != null) { + if (author == null || !author.equals(other.author)) { + return true; + } + } + if (other.paymentLink != null) { + if (paymentLink == null || !paymentLink.equals(other.paymentLink)) { + return true; + } + } + return false; + } + @Override public int getTypeAsInt() { return FEEDFILETYPE_FEED; diff --git a/src/de/danoeh/antennapod/feed/FeedComponent.java b/src/de/danoeh/antennapod/feed/FeedComponent.java index a192f4bc8..d23c8d7c8 100644 --- a/src/de/danoeh/antennapod/feed/FeedComponent.java +++ b/src/de/danoeh/antennapod/feed/FeedComponent.java @@ -21,6 +21,25 @@ public class FeedComponent { this.id = id; } + /** + * Update this FeedComponent's attributes with the attributes from another + * FeedComponent. This method should only update attributes which where read from + * the feed. + */ + public void updateFromOther(FeedComponent other) { + } + + /** + * Compare's this FeedComponent's attribute values with another FeedComponent's + * attribute values. This method will only compare attributes which were + * read from the feed. + * + * @return true if attribute values are different, false otherwise + */ + public boolean compareWithOther(FeedComponent other) { + return false; + } + } \ No newline at end of file diff --git a/src/de/danoeh/antennapod/feed/FeedFile.java b/src/de/danoeh/antennapod/feed/FeedFile.java index 63ce956f1..305d58c1b 100644 --- a/src/de/danoeh/antennapod/feed/FeedFile.java +++ b/src/de/danoeh/antennapod/feed/FeedFile.java @@ -26,6 +26,33 @@ public abstract class FeedFile extends FeedComponent { public abstract int getTypeAsInt(); + /** + * Update this FeedFile's attributes with the attributes from another + * FeedFile. This method should only update attributes which where read from + * the feed. + */ + public void updateFromOther(FeedFile other) { + super.updateFromOther(other); + this.download_url = other.download_url; + } + + /** + * Compare's this FeedFile's attribute values with another FeedFile's + * attribute values. This method will only compare attributes which were + * read from the feed. + * + * @return true if attribute values are different, false otherwise + */ + public boolean compareWithOther(FeedFile other) { + if (super.compareWithOther(other)) { + return true; + } + if (!download_url.equals(other.download_url)) { + return true; + } + return false; + } + public String getFile_url() { return file_url; } diff --git a/src/de/danoeh/antennapod/feed/FeedItem.java b/src/de/danoeh/antennapod/feed/FeedItem.java index e886c73b3..94c90295c 100644 --- a/src/de/danoeh/antennapod/feed/FeedItem.java +++ b/src/de/danoeh/antennapod/feed/FeedItem.java @@ -43,6 +43,38 @@ public class FeedItem extends FeedComponent { this.read = true; } + public void updateFromOther(FeedItem other) { + super.updateFromOther(other); + if (other.title != null) { + title = other.title; + } + if (other.getDescription() != null) { + description = other.getDescription(); + } + if (other.getContentEncoded() != null) { + contentEncoded = other.contentEncoded; + } + if (other.link != null) { + link = other.link; + } + if (other.pubDate != null && other.pubDate != pubDate) { + pubDate = other.pubDate; + } + if (other.media != null) { + if (media == null || media.compareWithOther(media)) { + media.updateFromOther(other.media); + } + } + if (other.paymentLink != null) { + paymentLink = other.paymentLink; + } + if (other.chapters != null) { + if (chapters == null) { + chapters = other.chapters; + } + } + } + /** * Moves the 'description' and 'contentEncoded' field of feeditem to their * SoftReference fields. @@ -214,9 +246,11 @@ public class FeedItem extends FeedComponent { public void setCachedContentEncoded(String c) { cachedContentEncoded = new SoftReference(c); } - - public enum State {NEW, IN_PROGRESS, READ, PLAYING} - + + public enum State { + NEW, IN_PROGRESS, READ, PLAYING + } + public State getState() { if (hasMedia()) { if (isPlaying()) { diff --git a/src/de/danoeh/antennapod/feed/FeedMedia.java b/src/de/danoeh/antennapod/feed/FeedMedia.java index 357a642a6..b0a6fe5d4 100644 --- a/src/de/danoeh/antennapod/feed/FeedMedia.java +++ b/src/de/danoeh/antennapod/feed/FeedMedia.java @@ -65,6 +65,31 @@ public class FeedMedia extends FeedFile { return MediaType.UNKNOWN; } + public void updateFromOther(FeedMedia other) { + super.updateFromOther(other); + if (other.size > 0) { + size = other.size; + } + if (other.mime_type != null) { + mime_type = other.mime_type; + } + } + + public boolean compareWithOther(FeedMedia other) { + if (super.compareWithOther(other)) { + return true; + } + if (other.mime_type != null) { + if (mime_type == null || !mime_type.equals(other.mime_type)) { + return true; + } + } + if (other.size > 0 && other.size != size) { + return true; + } + return false; + } + @Override public int getTypeAsInt() { return FEEDFILETYPE_FEEDMEDIA; diff --git a/src/de/danoeh/antennapod/feed/SimpleChapter.java b/src/de/danoeh/antennapod/feed/SimpleChapter.java index 7b74f28f6..3dab1b74d 100644 --- a/src/de/danoeh/antennapod/feed/SimpleChapter.java +++ b/src/de/danoeh/antennapod/feed/SimpleChapter.java @@ -12,4 +12,14 @@ public class SimpleChapter extends Chapter { return CHAPTERTYPE_SIMPLECHAPTER; } + public void updateFromOther(SimpleChapter other) { + super.updateFromOther(other); + start = other.start; + if (other.title != null) { + title = other.title; + } + if (other.link != null) { + link = other.link; + } + } }