diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-04-27 16:35:25 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-04-27 16:35:25 +0200 |
commit | 8769d29ceffe3d0157278a62aaefd6c21d46fd01 (patch) | |
tree | 81ba06da5cdb044826b048f92bc23ee5fe3bb72b /src/de/danoeh/antennapod | |
parent | c881b7982c41a3d668ad1e651352029d9e378126 (diff) | |
download | AntennaPod-8769d29ceffe3d0157278a62aaefd6c21d46fd01.zip |
Made sure that the downloaded-attribute of FeedFile does not reach an inconsistent state
(downloaded=false and file_url != null)
Diffstat (limited to 'src/de/danoeh/antennapod')
-rw-r--r-- | src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java | 2 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/adapter/FeedlistAdapter.java | 2 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/feed/FeedFile.java | 150 |
3 files changed, 87 insertions, 67 deletions
diff --git a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index 6bd5e4eb9..674fc9476 100644 --- a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -181,7 +181,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity { } private void parseFeed() { - if (feed == null || feed.getFile_url() == null) { + if (feed == null || feed.getFile_url() == null && feed.isDownloaded()) { throw new IllegalStateException( "feed must be non-null and downloaded when parseFeed is called"); } diff --git a/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java b/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java index 37600838e..30c1ff880 100644 --- a/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java +++ b/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java @@ -118,7 +118,7 @@ public class FeedlistAdapter extends BaseAdapter { holder.inProgressEpisodesLabel.setVisibility(View.INVISIBLE); } } - final String imageUrl = (feed.getImage() != null) ? feed.getImage() + final String imageUrl = (feed.getImage() != null && feed.getImage().isDownloaded()) ? feed.getImage() .getFile_url() : null; imageLoader.loadThumbnailBitmap( feed.getImage(), diff --git a/src/de/danoeh/antennapod/feed/FeedFile.java b/src/de/danoeh/antennapod/feed/FeedFile.java index 28a9b1e10..a05533ebc 100644 --- a/src/de/danoeh/antennapod/feed/FeedFile.java +++ b/src/de/danoeh/antennapod/feed/FeedFile.java @@ -2,84 +2,104 @@ package de.danoeh.antennapod.feed; import java.io.File; -/** Represents a component of a Feed that has to be downloaded */ +/** + * Represents a component of a Feed that has to be downloaded + */ public abstract class FeedFile extends FeedComponent { - protected String file_url; - protected String download_url; - protected boolean downloaded; + protected String file_url; + protected String download_url; + protected boolean downloaded; - public FeedFile(String file_url, String download_url, boolean downloaded) { - super(); - this.file_url = file_url; - this.download_url = download_url; - this.downloaded = downloaded; - } + /** + * Creates a new FeedFile object. + * + * @param file_url The location of the FeedFile. If this is null, the downloaded-attribute + * will automatically be set to false. + * @param download_url The location where the FeedFile can be downloaded. + * @param downloaded true if the FeedFile has been downloaded, false otherwise. This parameter + * will automatically be interpreted as false if the file_url is null. + */ + public FeedFile(String file_url, String download_url, boolean downloaded) { + super(); + this.file_url = file_url; + this.download_url = download_url; + this.downloaded = (file_url != null) && downloaded; + } - public FeedFile() { + public FeedFile() { this(null, null, false); } - public abstract int getTypeAsInt(); + 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; - } + /** + * 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; - } - - /** Returns true if the file exists at file_url. */ - public boolean fileExists() { - if (file_url == null) { - return false; - } else { - File f = new File(file_url); - return f.exists(); - } - } + /** + * 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; - } + /** + * Returns true if the file exists at file_url. + */ + public boolean fileExists() { + if (file_url == null) { + return false; + } else { + File f = new File(file_url); + return f.exists(); + } + } - public void setFile_url(String file_url) { - this.file_url = file_url; - } + public String getFile_url() { + return file_url; + } - public String getDownload_url() { - return download_url; - } + /** + * Changes the file_url of this FeedFile. Setting this value to + * null will also set the downloaded-attribute to false. + */ + public void setFile_url(String file_url) { + this.file_url = file_url; + if (file_url == null) { + downloaded = false; + } + } - public void setDownload_url(String download_url) { - this.download_url = download_url; - } + public String getDownload_url() { + return download_url; + } - public boolean isDownloaded() { - return downloaded; - } + public void setDownload_url(String download_url) { + this.download_url = download_url; + } - public void setDownloaded(boolean downloaded) { - this.downloaded = downloaded; - } + public boolean isDownloaded() { + return downloaded; + } + + public void setDownloaded(boolean downloaded) { + this.downloaded = downloaded; + } } |