summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/feed/FeedImage.java
blob: 09595f5eb3a1158d28e782ec9b341b8dcb5a487e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package de.danoeh.antennapod.feed;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import de.danoeh.antennapod.asynctask.ImageLoader;

;

public class FeedImage extends FeedFile implements
		ImageLoader.ImageWorkerTaskResource {
	public static final int FEEDFILETYPE_FEEDIMAGE = 1;

	protected String title;
	protected Feed feed;

	public FeedImage(String download_url, String title) {
		super(null, download_url, false);
		this.download_url = download_url;
		this.title = title;
	}

	public FeedImage(long id, String title, String file_url,
			String download_url, boolean downloaded) {
		super(file_url, download_url, downloaded);
		this.id = id;
		this.title = title;
	}

	@Override
	public String getHumanReadableIdentifier() {
		if (feed != null && feed.getTitle() != null) {
			return feed.getTitle();
		} else {
			return download_url;
		}
	}

	@Override
	public int getTypeAsInt() {
		return FEEDFILETYPE_FEEDIMAGE;
	}

	public FeedImage() {
		super();
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Feed getFeed() {
		return feed;
	}

	public void setFeed(Feed feed) {
		this.feed = feed;
	}

	@Override
	public InputStream openImageInputStream() {
		if (file_url != null) {
			File file = new File(file_url);
			if (file.exists()) {
				try {
					return new FileInputStream(file_url);
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	}

	@Override
	public String getImageLoaderCacheKey() {
		return file_url;
	}

	@Override
	public InputStream reopenImageInputStream(InputStream input) {
		IOUtils.closeQuietly(input);
		return openImageInputStream();
	}

}