Made sure that the downloaded-attribute of FeedFile does not reach an inconsistent state

(downloaded=false and file_url != null)
This commit is contained in:
daniel oeh 2014-04-27 16:35:25 +02:00
parent c881b7982c
commit 8769d29cef
3 changed files with 87 additions and 67 deletions

View File

@ -181,7 +181,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
} }
private void parseFeed() { private void parseFeed() {
if (feed == null || feed.getFile_url() == null) { if (feed == null || feed.getFile_url() == null && feed.isDownloaded()) {
throw new IllegalStateException( throw new IllegalStateException(
"feed must be non-null and downloaded when parseFeed is called"); "feed must be non-null and downloaded when parseFeed is called");
} }

View File

@ -118,7 +118,7 @@ public class FeedlistAdapter extends BaseAdapter {
holder.inProgressEpisodesLabel.setVisibility(View.INVISIBLE); 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; .getFile_url() : null;
imageLoader.loadThumbnailBitmap( imageLoader.loadThumbnailBitmap(
feed.getImage(), feed.getImage(),

View File

@ -2,18 +2,29 @@ package de.danoeh.antennapod.feed;
import java.io.File; 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 { public abstract class FeedFile extends FeedComponent {
protected String file_url; protected String file_url;
protected String download_url; protected String download_url;
protected boolean downloaded; protected boolean 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) { public FeedFile(String file_url, String download_url, boolean downloaded) {
super(); super();
this.file_url = file_url; this.file_url = file_url;
this.download_url = download_url; this.download_url = download_url;
this.downloaded = downloaded; this.downloaded = (file_url != null) && downloaded;
} }
public FeedFile() { public FeedFile() {
@ -49,7 +60,9 @@ public abstract class FeedFile extends FeedComponent {
return false; return false;
} }
/** Returns true if the file exists at file_url. */ /**
* Returns true if the file exists at file_url.
*/
public boolean fileExists() { public boolean fileExists() {
if (file_url == null) { if (file_url == null) {
return false; return false;
@ -63,8 +76,15 @@ public abstract class FeedFile extends FeedComponent {
return file_url; return file_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) { public void setFile_url(String file_url) {
this.file_url = file_url; this.file_url = file_url;
if (file_url == null) {
downloaded = false;
}
} }
public String getDownload_url() { public String getDownload_url() {