Removed FeedImage
This commit is contained in:
parent
fe92c98661
commit
ba2233430e
|
@ -17,7 +17,6 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.Chapter;
|
import de.danoeh.antennapod.core.feed.Chapter;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.syndication.handler.FeedHandler;
|
import de.danoeh.antennapod.core.syndication.handler.FeedHandler;
|
||||||
|
@ -82,15 +81,7 @@ public class FeedHandlerTest extends InstrumentationTestCase {
|
||||||
assertEquals(feed.getLink(), parsedFeed.getLink());
|
assertEquals(feed.getLink(), parsedFeed.getLink());
|
||||||
assertEquals(feed.getDescription(), parsedFeed.getDescription());
|
assertEquals(feed.getDescription(), parsedFeed.getDescription());
|
||||||
assertEquals(feed.getPaymentLink(), parsedFeed.getPaymentLink());
|
assertEquals(feed.getPaymentLink(), parsedFeed.getPaymentLink());
|
||||||
|
assertEquals(feed.getImageUrl(), parsedFeed.getImageUrl());
|
||||||
if (feed.getImage() != null) {
|
|
||||||
FeedImage image = feed.getImage();
|
|
||||||
FeedImage parsedImage = parsedFeed.getImage();
|
|
||||||
assertNotNull(parsedImage);
|
|
||||||
|
|
||||||
assertEquals(image.getTitle(), parsedImage.getTitle());
|
|
||||||
assertEquals(image.getDownload_url(), parsedImage.getDownload_url());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (feed.getItems() != null) {
|
if (feed.getItems() != null) {
|
||||||
assertNotNull(parsedFeed.getItems());
|
assertNotNull(parsedFeed.getItems());
|
||||||
|
@ -119,14 +110,7 @@ public class FeedHandlerTest extends InstrumentationTestCase {
|
||||||
assertEquals(media.getMime_type(), parsedMedia.getMime_type());
|
assertEquals(media.getMime_type(), parsedMedia.getMime_type());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.hasItemImage()) {
|
assertEquals(item.getImageUrl(), parsedFeed.getImageUrl());
|
||||||
assertTrue(parsedItem.hasItemImage());
|
|
||||||
FeedImage image = item.getImage();
|
|
||||||
FeedImage parsedImage = parsedItem.getImage();
|
|
||||||
|
|
||||||
assertEquals(image.getTitle(), parsedImage.getTitle());
|
|
||||||
assertEquals(image.getDownload_url(), parsedImage.getDownload_url());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.getChapters() != null) {
|
if (item.getChapters() != null) {
|
||||||
assertNotNull(parsedItem.getChapters());
|
assertNotNull(parsedItem.getChapters());
|
||||||
|
@ -158,12 +142,8 @@ public class FeedHandlerTest extends InstrumentationTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Feed createTestFeed(int numItems, boolean withImage, boolean withFeedMedia, boolean withChapters) {
|
private Feed createTestFeed(int numItems, boolean withImage, boolean withFeedMedia, boolean withChapters) {
|
||||||
FeedImage image = null;
|
|
||||||
if (withImage) {
|
|
||||||
image = new FeedImage(0, "image", null, "http://example.com/picture", false);
|
|
||||||
}
|
|
||||||
Feed feed = new Feed(0, null, "title", "http://example.com", "This is the description",
|
Feed feed = new Feed(0, null, "title", "http://example.com", "This is the description",
|
||||||
"http://example.com/payment", "Daniel", "en", null, "http://example.com/feed", image, file.getAbsolutePath(),
|
"http://example.com/payment", "Daniel", "en", null, "http://example.com/feed", "http://example.com/picture", file.getAbsolutePath(),
|
||||||
"http://example.com/feed", true);
|
"http://example.com/feed", true);
|
||||||
feed.setItems(new ArrayList<>());
|
feed.setItems(new ArrayList<>());
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,7 @@ import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.Chapter;
|
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.feed.SimpleChapter;
|
import de.danoeh.antennapod.core.feed.SimpleChapter;
|
||||||
|
@ -124,89 +122,13 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
assertNull(media.getFile_url());
|
assertNull(media.getFile_url());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteFeed() throws IOException, ExecutionException, InterruptedException, TimeoutException {
|
public void testDeleteFeed() throws ExecutionException, InterruptedException, IOException, TimeoutException {
|
||||||
File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
|
File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
|
||||||
assertNotNull(destFolder);
|
assertNotNull(destFolder);
|
||||||
|
|
||||||
Feed feed = new Feed("url", null, "title");
|
Feed feed = new Feed("url", null, "title");
|
||||||
feed.setItems(new ArrayList<>());
|
feed.setItems(new ArrayList<>());
|
||||||
|
|
||||||
// create Feed image
|
|
||||||
File imgFile = new File(destFolder, "image");
|
|
||||||
assertTrue(imgFile.createNewFile());
|
|
||||||
FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
|
|
||||||
image.setOwner(feed);
|
|
||||||
feed.setImage(image);
|
|
||||||
|
|
||||||
List<File> itemFiles = new ArrayList<>();
|
|
||||||
// create items with downloaded media files
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed, true);
|
|
||||||
feed.getItems().add(item);
|
|
||||||
|
|
||||||
File enc = new File(destFolder, "file " + i);
|
|
||||||
assertTrue(enc.createNewFile());
|
|
||||||
itemFiles.add(enc);
|
|
||||||
|
|
||||||
FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", enc.getAbsolutePath(), "download_url", true, null, 0, 0);
|
|
||||||
item.setMedia(media);
|
|
||||||
|
|
||||||
item.setChapters(new ArrayList<>());
|
|
||||||
item.getChapters().add(new SimpleChapter(0, "item " + i, item, "example.com"));
|
|
||||||
}
|
|
||||||
|
|
||||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
|
||||||
adapter.open();
|
|
||||||
adapter.setCompleteFeed(feed);
|
|
||||||
adapter.close();
|
|
||||||
|
|
||||||
assertTrue(feed.getId() != 0);
|
|
||||||
assertTrue(feed.getImage().getId() != 0);
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
|
||||||
assertTrue(item.getId() != 0);
|
|
||||||
assertTrue(item.getMedia().getId() != 0);
|
|
||||||
assertTrue(item.getChapters().get(0).getId() != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
// check if files still exist
|
|
||||||
assertFalse(imgFile.exists());
|
|
||||||
for (File f : itemFiles) {
|
|
||||||
assertFalse(f.exists());
|
|
||||||
}
|
|
||||||
|
|
||||||
adapter = PodDBAdapter.getInstance();
|
|
||||||
adapter.open();
|
|
||||||
Cursor c = adapter.getFeedCursor(feed.getId());
|
|
||||||
assertEquals(0, c.getCount());
|
|
||||||
c.close();
|
|
||||||
c = adapter.getImageCursor(String.valueOf(image.getId()));
|
|
||||||
assertEquals(0, c.getCount());
|
|
||||||
c.close();
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
|
||||||
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
|
|
||||||
assertEquals(0, c.getCount());
|
|
||||||
c.close();
|
|
||||||
c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
|
|
||||||
assertEquals(0, c.getCount());
|
|
||||||
c.close();
|
|
||||||
c = adapter.getSimpleChaptersOfFeedItemCursor(item);
|
|
||||||
assertEquals(0, c.getCount());
|
|
||||||
c.close();
|
|
||||||
}
|
|
||||||
adapter.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteFeedNoImage() throws ExecutionException, InterruptedException, IOException, TimeoutException {
|
|
||||||
File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
|
|
||||||
assertNotNull(destFolder);
|
|
||||||
|
|
||||||
Feed feed = new Feed("url", null, "title");
|
|
||||||
feed.setItems(new ArrayList<>());
|
|
||||||
|
|
||||||
feed.setImage(null);
|
|
||||||
|
|
||||||
List<File> itemFiles = new ArrayList<>();
|
List<File> itemFiles = new ArrayList<>();
|
||||||
// create items with downloaded media files
|
// create items with downloaded media files
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
@ -261,13 +183,7 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
Feed feed = new Feed("url", null, "title");
|
Feed feed = new Feed("url", null, "title");
|
||||||
feed.setItems(null);
|
feed.setItems(null);
|
||||||
|
feed.setImageUrl("url");
|
||||||
// create Feed image
|
|
||||||
File imgFile = new File(destFolder, "image");
|
|
||||||
assertTrue(imgFile.createNewFile());
|
|
||||||
FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
|
|
||||||
image.setOwner(feed);
|
|
||||||
feed.setImage(image);
|
|
||||||
|
|
||||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||||
adapter.open();
|
adapter.open();
|
||||||
|
@ -275,21 +191,14 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
adapter.close();
|
adapter.close();
|
||||||
|
|
||||||
assertTrue(feed.getId() != 0);
|
assertTrue(feed.getId() != 0);
|
||||||
assertTrue(feed.getImage().getId() != 0);
|
|
||||||
|
|
||||||
DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
|
DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
|
||||||
|
|
||||||
// check if files still exist
|
|
||||||
assertFalse(imgFile.exists());
|
|
||||||
|
|
||||||
adapter = PodDBAdapter.getInstance();
|
adapter = PodDBAdapter.getInstance();
|
||||||
adapter.open();
|
adapter.open();
|
||||||
Cursor c = adapter.getFeedCursor(feed.getId());
|
Cursor c = adapter.getFeedCursor(feed.getId());
|
||||||
assertTrue(c.getCount() == 0);
|
assertTrue(c.getCount() == 0);
|
||||||
c.close();
|
c.close();
|
||||||
c = adapter.getImageCursor(String.valueOf(image.getId()));
|
|
||||||
assertTrue(c.getCount() == 0);
|
|
||||||
c.close();
|
|
||||||
adapter.close();
|
adapter.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,12 +209,7 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
Feed feed = new Feed("url", null, "title");
|
Feed feed = new Feed("url", null, "title");
|
||||||
feed.setItems(new ArrayList<>());
|
feed.setItems(new ArrayList<>());
|
||||||
|
|
||||||
// create Feed image
|
feed.setImageUrl("url");
|
||||||
File imgFile = new File(destFolder, "image");
|
|
||||||
assertTrue(imgFile.createNewFile());
|
|
||||||
FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
|
|
||||||
image.setOwner(feed);
|
|
||||||
feed.setImage(image);
|
|
||||||
|
|
||||||
// create items
|
// create items
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
@ -320,24 +224,18 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
adapter.close();
|
adapter.close();
|
||||||
|
|
||||||
assertTrue(feed.getId() != 0);
|
assertTrue(feed.getId() != 0);
|
||||||
assertTrue(feed.getImage().getId() != 0);
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
assertTrue(item.getId() != 0);
|
assertTrue(item.getId() != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
|
DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
|
||||||
|
|
||||||
// check if files still exist
|
|
||||||
assertFalse(imgFile.exists());
|
|
||||||
|
|
||||||
adapter = PodDBAdapter.getInstance();
|
adapter = PodDBAdapter.getInstance();
|
||||||
adapter.open();
|
adapter.open();
|
||||||
Cursor c = adapter.getFeedCursor(feed.getId());
|
Cursor c = adapter.getFeedCursor(feed.getId());
|
||||||
assertTrue(c.getCount() == 0);
|
assertTrue(c.getCount() == 0);
|
||||||
c.close();
|
c.close();
|
||||||
c = adapter.getImageCursor(String.valueOf(image.getId()));
|
|
||||||
assertTrue(c.getCount() == 0);
|
|
||||||
c.close();
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
|
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
|
||||||
assertTrue(c.getCount() == 0);
|
assertTrue(c.getCount() == 0);
|
||||||
|
@ -346,65 +244,6 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
adapter.close();
|
adapter.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteFeedWithItemImages() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
|
||||||
File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
|
|
||||||
assertNotNull(destFolder);
|
|
||||||
|
|
||||||
Feed feed = new Feed("url", null, "title");
|
|
||||||
feed.setItems(new ArrayList<>());
|
|
||||||
|
|
||||||
// create Feed image
|
|
||||||
File imgFile = new File(destFolder, "image");
|
|
||||||
assertTrue(imgFile.createNewFile());
|
|
||||||
FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
|
|
||||||
image.setOwner(feed);
|
|
||||||
feed.setImage(image);
|
|
||||||
|
|
||||||
// create items with images
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed);
|
|
||||||
feed.getItems().add(item);
|
|
||||||
File itemImageFile = new File(destFolder, "item-image-" + i);
|
|
||||||
FeedImage itemImage = new FeedImage(0, "item-image" + i, itemImageFile.getAbsolutePath(), "url", true);
|
|
||||||
item.setImage(itemImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
|
||||||
adapter.open();
|
|
||||||
adapter.setCompleteFeed(feed);
|
|
||||||
adapter.close();
|
|
||||||
|
|
||||||
assertTrue(feed.getId() != 0);
|
|
||||||
assertTrue(feed.getImage().getId() != 0);
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
|
||||||
assertTrue(item.getId() != 0);
|
|
||||||
assertTrue(item.getImage().getId() != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
// check if files still exist
|
|
||||||
assertFalse(imgFile.exists());
|
|
||||||
|
|
||||||
adapter = PodDBAdapter.getInstance();
|
|
||||||
adapter.open();
|
|
||||||
Cursor c = adapter.getFeedCursor(feed.getId());
|
|
||||||
assertTrue(c.getCount() == 0);
|
|
||||||
c.close();
|
|
||||||
c = adapter.getImageCursor(String.valueOf(image.getId()));
|
|
||||||
assertTrue(c.getCount() == 0);
|
|
||||||
c.close();
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
|
||||||
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
|
|
||||||
assertTrue(c.getCount() == 0);
|
|
||||||
c.close();
|
|
||||||
c = adapter.getImageCursor(String.valueOf(item.getImage().getId()));
|
|
||||||
assertEquals(0, c.getCount());
|
|
||||||
c.close();
|
|
||||||
}
|
|
||||||
adapter.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteFeedWithQueueItems() throws ExecutionException, InterruptedException, TimeoutException {
|
public void testDeleteFeedWithQueueItems() throws ExecutionException, InterruptedException, TimeoutException {
|
||||||
File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
|
File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
|
||||||
assertNotNull(destFolder);
|
assertNotNull(destFolder);
|
||||||
|
@ -412,11 +251,7 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
Feed feed = new Feed("url", null, "title");
|
Feed feed = new Feed("url", null, "title");
|
||||||
feed.setItems(new ArrayList<>());
|
feed.setItems(new ArrayList<>());
|
||||||
|
|
||||||
// create Feed image
|
feed.setImageUrl("url");
|
||||||
File imgFile = new File(destFolder, "image");
|
|
||||||
FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
|
|
||||||
image.setOwner(feed);
|
|
||||||
feed.setImage(image);
|
|
||||||
|
|
||||||
List<File> itemFiles = new ArrayList<>();
|
List<File> itemFiles = new ArrayList<>();
|
||||||
// create items with downloaded media files
|
// create items with downloaded media files
|
||||||
|
@ -437,7 +272,6 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
adapter.close();
|
adapter.close();
|
||||||
|
|
||||||
assertTrue(feed.getId() != 0);
|
assertTrue(feed.getId() != 0);
|
||||||
assertTrue(feed.getImage().getId() != 0);
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
assertTrue(item.getId() != 0);
|
assertTrue(item.getId() != 0);
|
||||||
assertTrue(item.getMedia().getId() != 0);
|
assertTrue(item.getMedia().getId() != 0);
|
||||||
|
@ -460,9 +294,6 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
Cursor c = adapter.getFeedCursor(feed.getId());
|
Cursor c = adapter.getFeedCursor(feed.getId());
|
||||||
assertTrue(c.getCount() == 0);
|
assertTrue(c.getCount() == 0);
|
||||||
c.close();
|
c.close();
|
||||||
c = adapter.getImageCursor(String.valueOf(image.getId()));
|
|
||||||
assertTrue(c.getCount() == 0);
|
|
||||||
c.close();
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
|
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
|
||||||
assertTrue(c.getCount() == 0);
|
assertTrue(c.getCount() == 0);
|
||||||
|
@ -484,11 +315,7 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
Feed feed = new Feed("url", null, "title");
|
Feed feed = new Feed("url", null, "title");
|
||||||
feed.setItems(new ArrayList<>());
|
feed.setItems(new ArrayList<>());
|
||||||
|
|
||||||
// create Feed image
|
feed.setImageUrl("url");
|
||||||
File imgFile = new File(destFolder, "image");
|
|
||||||
FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
|
|
||||||
image.setOwner(feed);
|
|
||||||
feed.setImage(image);
|
|
||||||
|
|
||||||
List<File> itemFiles = new ArrayList<>();
|
List<File> itemFiles = new ArrayList<>();
|
||||||
// create items with downloaded media files
|
// create items with downloaded media files
|
||||||
|
@ -509,7 +336,6 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
adapter.close();
|
adapter.close();
|
||||||
|
|
||||||
assertTrue(feed.getId() != 0);
|
assertTrue(feed.getId() != 0);
|
||||||
assertTrue(feed.getImage().getId() != 0);
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
assertTrue(item.getId() != 0);
|
assertTrue(item.getId() != 0);
|
||||||
assertTrue(item.getMedia().getId() != 0);
|
assertTrue(item.getMedia().getId() != 0);
|
||||||
|
@ -522,9 +348,6 @@ public class DBWriterTest extends InstrumentationTestCase {
|
||||||
Cursor c = adapter.getFeedCursor(feed.getId());
|
Cursor c = adapter.getFeedCursor(feed.getId());
|
||||||
assertTrue(c.getCount() == 0);
|
assertTrue(c.getCount() == 0);
|
||||||
c.close();
|
c.close();
|
||||||
c = adapter.getImageCursor(String.valueOf(image.getId()));
|
|
||||||
assertTrue(c.getCount() == 0);
|
|
||||||
c.close();
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
|
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
|
||||||
assertTrue(c.getCount() == 0);
|
assertTrue(c.getCount() == 0);
|
||||||
|
|
|
@ -22,7 +22,6 @@ import de.danoeh.antennapod.activity.MainActivity;
|
||||||
import de.danoeh.antennapod.core.event.QueueEvent;
|
import de.danoeh.antennapod.core.event.QueueEvent;
|
||||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||||
|
@ -136,12 +135,9 @@ class UITestUtils {
|
||||||
public void addHostedFeedData() throws IOException {
|
public void addHostedFeedData() throws IOException {
|
||||||
if (feedDataHosted) throw new IllegalStateException("addHostedFeedData was called twice on the same instance");
|
if (feedDataHosted) throw new IllegalStateException("addHostedFeedData was called twice on the same instance");
|
||||||
for (int i = 0; i < NUM_FEEDS; i++) {
|
for (int i = 0; i < NUM_FEEDS; i++) {
|
||||||
File bitmapFile = newBitmapFile("image" + i);
|
|
||||||
FeedImage image = new FeedImage(0, "image " + i, null, hostFile(bitmapFile), false);
|
|
||||||
Feed feed = new Feed(0, null, "Title " + i, "http://example.com/" + i, "Description of feed " + i,
|
Feed feed = new Feed(0, null, "Title " + i, "http://example.com/" + i, "Description of feed " + i,
|
||||||
"http://example.com/pay/feed" + i, "author " + i, "en", Feed.TYPE_RSS2, "feed" + i, image, null,
|
"http://example.com/pay/feed" + i, "author " + i, "en", Feed.TYPE_RSS2, "feed" + i, null, null,
|
||||||
"http://example.com/feed/src/" + i, false);
|
"http://example.com/feed/src/" + i, false);
|
||||||
image.setOwner(feed);
|
|
||||||
|
|
||||||
// create items
|
// create items
|
||||||
List<FeedItem> items = new ArrayList<>();
|
List<FeedItem> items = new ArrayList<>();
|
||||||
|
@ -187,12 +183,6 @@ class UITestUtils {
|
||||||
List<FeedItem> queue = new ArrayList<>();
|
List<FeedItem> queue = new ArrayList<>();
|
||||||
for (Feed feed : hostedFeeds) {
|
for (Feed feed : hostedFeeds) {
|
||||||
feed.setDownloaded(true);
|
feed.setDownloaded(true);
|
||||||
if (feed.getImage() != null) {
|
|
||||||
FeedImage image = feed.getImage();
|
|
||||||
int fileId = Integer.parseInt(StringUtils.substringAfter(image.getDownload_url(), "files/"));
|
|
||||||
image.setFile_url(server.accessFile(fileId).getAbsolutePath());
|
|
||||||
image.setDownloaded(true);
|
|
||||||
}
|
|
||||||
if (downloadEpisodes) {
|
if (downloadEpisodes) {
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
if (item.hasMedia()) {
|
if (item.hasMedia()) {
|
||||||
|
|
|
@ -38,9 +38,6 @@ public class UITestUtilsTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
for (Feed feed : feeds) {
|
for (Feed feed : feeds) {
|
||||||
testUrlReachable(feed.getDownload_url());
|
testUrlReachable(feed.getDownload_url());
|
||||||
if (feed.getImage() != null) {
|
|
||||||
testUrlReachable(feed.getImage().getDownload_url());
|
|
||||||
}
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
if (item.hasMedia()) {
|
if (item.hasMedia()) {
|
||||||
testUrlReachable(item.getMedia().getDownload_url());
|
testUrlReachable(item.getMedia().getDownload_url());
|
||||||
|
@ -66,9 +63,6 @@ public class UITestUtilsTest extends InstrumentationTestCase {
|
||||||
|
|
||||||
for (Feed feed : uiTestUtils.hostedFeeds) {
|
for (Feed feed : uiTestUtils.hostedFeeds) {
|
||||||
assertTrue(feed.getId() != 0);
|
assertTrue(feed.getId() != 0);
|
||||||
if (feed.getImage() != null) {
|
|
||||||
assertTrue(feed.getImage().getId() != 0);
|
|
||||||
}
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
assertTrue(item.getId() != 0);
|
assertTrue(item.getId() != 0);
|
||||||
if (item.hasMedia()) {
|
if (item.hasMedia()) {
|
||||||
|
|
|
@ -393,9 +393,9 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||||
|
|
||||||
subscribeButton = (Button) header.findViewById(R.id.butSubscribe);
|
subscribeButton = (Button) header.findViewById(R.id.butSubscribe);
|
||||||
|
|
||||||
if (feed.getImage() != null && StringUtils.isNotBlank(feed.getImage().getDownload_url())) {
|
if (StringUtils.isNotBlank(feed.getImageUrl())) {
|
||||||
Glide.with(this)
|
Glide.with(this)
|
||||||
.load(feed.getImage().getDownload_url())
|
.load(feed.getImageUrl())
|
||||||
.placeholder(R.color.light_gray)
|
.placeholder(R.color.light_gray)
|
||||||
.error(R.color.light_gray)
|
.error(R.color.light_gray)
|
||||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||||
|
|
|
@ -19,7 +19,6 @@ import com.joanzapata.iconify.widget.IconTextView;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
|
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
|
@ -67,8 +66,6 @@ public class DownloadLogAdapter extends BaseAdapter {
|
||||||
holder.type.setText(R.string.download_type_feed);
|
holder.type.setText(R.string.download_type_feed);
|
||||||
} else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
} else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
||||||
holder.type.setText(R.string.download_type_media);
|
holder.type.setText(R.string.download_type_media);
|
||||||
} else if (status.getFeedfileType() == FeedImage.FEEDFILETYPE_FEEDIMAGE) {
|
|
||||||
holder.type.setText(R.string.download_type_image);
|
|
||||||
}
|
}
|
||||||
if (status.getTitle() != null) {
|
if (status.getTitle() != null) {
|
||||||
holder.title.setText(status.getTitle());
|
holder.title.setText(status.getTitle());
|
||||||
|
@ -94,8 +91,7 @@ public class DownloadLogAdapter extends BaseAdapter {
|
||||||
}
|
}
|
||||||
holder.reason.setText(reasonText);
|
holder.reason.setText(reasonText);
|
||||||
holder.reason.setVisibility(View.VISIBLE);
|
holder.reason.setVisibility(View.VISIBLE);
|
||||||
if(status.getFeedfileType() != FeedImage.FEEDFILETYPE_FEEDIMAGE &&
|
if(!newerWasSuccessful(position, status.getFeedfileType(), status.getFeedfileId())) {
|
||||||
!newerWasSuccessful(position, status.getFeedfileType(), status.getFeedfileId())) {
|
|
||||||
holder.retry.setVisibility(View.VISIBLE);
|
holder.retry.setVisibility(View.VISIBLE);
|
||||||
holder.retry.setOnClickListener(clickListener);
|
holder.retry.setOnClickListener(clickListener);
|
||||||
ButtonHolder btnHolder;
|
ButtonHolder btnHolder;
|
||||||
|
|
|
@ -14,7 +14,6 @@ import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
|
@ -64,29 +63,6 @@ class UpdateManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onUpgrade(final int oldVersionCode, final int newVersionCode) {
|
private static void onUpgrade(final int oldVersionCode, final int newVersionCode) {
|
||||||
if(oldVersionCode < 1030099) {
|
|
||||||
// delete the now obsolete image cache
|
|
||||||
// from now on, Glide will handle caching images
|
|
||||||
new Thread() {
|
|
||||||
public void run() {
|
|
||||||
List<Feed> feeds = DBReader.getFeedList();
|
|
||||||
for (Feed podcast : feeds) {
|
|
||||||
List<FeedItem> episodes = DBReader.getFeedItemList(podcast);
|
|
||||||
for (FeedItem episode : episodes) {
|
|
||||||
FeedImage image = episode.getImage();
|
|
||||||
if (image != null && image.isDownloaded() && image.getFile_url() != null) {
|
|
||||||
File imageFile = new File(image.getFile_url());
|
|
||||||
if (imageFile.exists()) {
|
|
||||||
imageFile.delete();
|
|
||||||
}
|
|
||||||
image.setFile_url(null); // calls setDownloaded(false)
|
|
||||||
DBWriter.setFeedImage(image);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
}
|
|
||||||
if(oldVersionCode < 1050004) {
|
if(oldVersionCode < 1050004) {
|
||||||
if(MediaPlayer.isPrestoLibraryInstalled(context) && Build.VERSION.SDK_INT >= 16) {
|
if(MediaPlayer.isPrestoLibraryInstalled(context) && Build.VERSION.SDK_INT >= 16) {
|
||||||
UserPreferences.enableSonic(true);
|
UserPreferences.enableSonic(true);
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
|
||||||
* Name of the author
|
* Name of the author
|
||||||
*/
|
*/
|
||||||
private String author;
|
private String author;
|
||||||
private FeedImage image;
|
private String imageUrl;
|
||||||
private List<FeedItem> items;
|
private List<FeedItem> items;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,7 +96,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
|
||||||
* This constructor is used for restoring a feed from the database.
|
* This constructor is used for restoring a feed from the database.
|
||||||
*/
|
*/
|
||||||
public Feed(long id, String lastUpdate, String title, String customTitle, String link, String description, String paymentLink,
|
public Feed(long id, String lastUpdate, String title, String customTitle, String link, String description, String paymentLink,
|
||||||
String author, String language, String type, String feedIdentifier, FeedImage image, String fileUrl,
|
String author, String language, String type, String feedIdentifier, String imageUrl, String fileUrl,
|
||||||
String downloadUrl, boolean downloaded, FlattrStatus status, boolean paged, String nextPageLink,
|
String downloadUrl, boolean downloaded, FlattrStatus status, boolean paged, String nextPageLink,
|
||||||
String filter, boolean lastUpdateFailed) {
|
String filter, boolean lastUpdateFailed) {
|
||||||
super(fileUrl, downloadUrl, downloaded);
|
super(fileUrl, downloadUrl, downloaded);
|
||||||
|
@ -111,7 +111,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
|
||||||
this.language = language;
|
this.language = language;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.feedIdentifier = feedIdentifier;
|
this.feedIdentifier = feedIdentifier;
|
||||||
this.image = image;
|
this.imageUrl = imageUrl;
|
||||||
this.flattrStatus = status;
|
this.flattrStatus = status;
|
||||||
this.paged = paged;
|
this.paged = paged;
|
||||||
this.nextPageLink = nextPageLink;
|
this.nextPageLink = nextPageLink;
|
||||||
|
@ -128,9 +128,9 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
|
||||||
* This constructor is used for test purposes and uses a default flattr status object.
|
* This constructor is used for test purposes and uses a default flattr status object.
|
||||||
*/
|
*/
|
||||||
public Feed(long id, String lastUpdate, String title, String link, String description, String paymentLink,
|
public Feed(long id, String lastUpdate, String title, String link, String description, String paymentLink,
|
||||||
String author, String language, String type, String feedIdentifier, FeedImage image, String fileUrl,
|
String author, String language, String type, String feedIdentifier, String imageUrl, String fileUrl,
|
||||||
String downloadUrl, boolean downloaded) {
|
String downloadUrl, boolean downloaded) {
|
||||||
this(id, lastUpdate, title, null, link, description, paymentLink, author, language, type, feedIdentifier, image,
|
this(id, lastUpdate, title, null, link, description, paymentLink, author, language, type, feedIdentifier, imageUrl,
|
||||||
fileUrl, downloadUrl, downloaded, new FlattrStatus(), false, null, null, false);
|
fileUrl, downloadUrl, downloaded, new FlattrStatus(), false, null, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,8 +266,8 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
|
||||||
public void updateFromOther(Feed other) {
|
public void updateFromOther(Feed other) {
|
||||||
// don't update feed's download_url, we do that manually if redirected
|
// don't update feed's download_url, we do that manually if redirected
|
||||||
// see AntennapodHttpClient
|
// see AntennapodHttpClient
|
||||||
if (other.image != null) {
|
if (other.imageUrl != null) {
|
||||||
this.image = other.image;
|
this.imageUrl = other.imageUrl;
|
||||||
}
|
}
|
||||||
if (other.feedTitle != null) {
|
if (other.feedTitle != null) {
|
||||||
feedTitle = other.feedTitle;
|
feedTitle = other.feedTitle;
|
||||||
|
@ -305,8 +305,8 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
|
||||||
if (super.compareWithOther(other)) {
|
if (super.compareWithOther(other)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (other.image != null) {
|
if (other.imageUrl != null) {
|
||||||
if (image == null || !TextUtils.equals(image.download_url, other.image.download_url)) {
|
if (imageUrl == null || !TextUtils.equals(imageUrl, other.imageUrl)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,12 +411,12 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FeedImage getImage() {
|
public String getImageUrl() {
|
||||||
return image;
|
return imageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImage(FeedImage image) {
|
public void setImageUrl(String imageUrl) {
|
||||||
this.image = image;
|
this.imageUrl = imageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedItem> getItems() {
|
public List<FeedItem> getItems() {
|
||||||
|
@ -505,11 +505,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getImageLocation() {
|
public String getImageLocation() {
|
||||||
if (image != null) {
|
return imageUrl;
|
||||||
return image.getImageLocation();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPageNr() {
|
public int getPageNr() {
|
||||||
|
|
|
@ -1,92 +0,0 @@
|
||||||
package de.danoeh.antennapod.core.feed;
|
|
||||||
|
|
||||||
import android.database.Cursor;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.asynctask.ImageResource;
|
|
||||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
|
||||||
|
|
||||||
|
|
||||||
public class FeedImage extends FeedFile implements ImageResource {
|
|
||||||
public static final int FEEDFILETYPE_FEEDIMAGE = 1;
|
|
||||||
|
|
||||||
private String title;
|
|
||||||
private FeedComponent owner;
|
|
||||||
|
|
||||||
public FeedImage(FeedComponent owner, String download_url, String title) {
|
|
||||||
super(null, download_url, false);
|
|
||||||
this.download_url = download_url;
|
|
||||||
this.title = title;
|
|
||||||
this.owner = owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FeedImage() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FeedImage fromCursor(Cursor cursor) {
|
|
||||||
int indexId = cursor.getColumnIndex(PodDBAdapter.KEY_ID);
|
|
||||||
int indexTitle = cursor.getColumnIndex(PodDBAdapter.KEY_TITLE);
|
|
||||||
int indexFileUrl = cursor.getColumnIndex(PodDBAdapter.KEY_FILE_URL);
|
|
||||||
int indexDownloadUrl = cursor.getColumnIndex(PodDBAdapter.KEY_DOWNLOAD_URL);
|
|
||||||
int indexDownloaded = cursor.getColumnIndex(PodDBAdapter.KEY_DOWNLOADED);
|
|
||||||
|
|
||||||
return new FeedImage(
|
|
||||||
cursor.getLong(indexId),
|
|
||||||
cursor.getString(indexTitle),
|
|
||||||
cursor.getString(indexFileUrl),
|
|
||||||
cursor.getString(indexDownloadUrl),
|
|
||||||
cursor.getInt(indexDownloaded) > 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getHumanReadableIdentifier() {
|
|
||||||
if (owner != null && owner.getHumanReadableIdentifier() != null) {
|
|
||||||
return owner.getHumanReadableIdentifier();
|
|
||||||
} else {
|
|
||||||
return download_url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTypeAsInt() {
|
|
||||||
return FEEDFILETYPE_FEEDIMAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FeedComponent getOwner() {
|
|
||||||
return owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOwner(FeedComponent owner) {
|
|
||||||
this.owner = owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getImageLocation() {
|
|
||||||
if (file_url != null && downloaded) {
|
|
||||||
return new File(file_url).getAbsolutePath();
|
|
||||||
} else if(download_url != null) {
|
|
||||||
return download_url;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,6 +4,7 @@ import android.database.Cursor;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import de.danoeh.antennapod.core.asynctask.ImageResource;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
@ -14,7 +15,6 @@ import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.asynctask.ImageResource;
|
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||||
import de.danoeh.antennapod.core.util.ShownotesProvider;
|
import de.danoeh.antennapod.core.util.ShownotesProvider;
|
||||||
|
@ -75,7 +75,7 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
|
||||||
* in the database. The 'hasChapters' attribute should be used to check if this item has any chapters.
|
* in the database. The 'hasChapters' attribute should be used to check if this item has any chapters.
|
||||||
* */
|
* */
|
||||||
private List<Chapter> chapters;
|
private List<Chapter> chapters;
|
||||||
private FeedImage image;
|
private String imageUrl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 0: auto download disabled
|
* 0: auto download disabled
|
||||||
|
@ -100,7 +100,7 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
|
||||||
* This constructor is used by DBReader.
|
* This constructor is used by DBReader.
|
||||||
* */
|
* */
|
||||||
public FeedItem(long id, String title, String link, Date pubDate, String paymentLink, long feedId,
|
public FeedItem(long id, String title, String link, Date pubDate, String paymentLink, long feedId,
|
||||||
FlattrStatus flattrStatus, boolean hasChapters, FeedImage image, int state,
|
FlattrStatus flattrStatus, boolean hasChapters, String imageUrl, int state,
|
||||||
String itemIdentifier, long autoDownload) {
|
String itemIdentifier, long autoDownload) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
@ -110,7 +110,7 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
|
||||||
this.feedId = feedId;
|
this.feedId = feedId;
|
||||||
this.flattrStatus = flattrStatus;
|
this.flattrStatus = flattrStatus;
|
||||||
this.hasChapters = hasChapters;
|
this.hasChapters = hasChapters;
|
||||||
this.image = image;
|
this.imageUrl = imageUrl;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.itemIdentifier = itemIdentifier;
|
this.itemIdentifier = itemIdentifier;
|
||||||
this.autoDownload = autoDownload;
|
this.autoDownload = autoDownload;
|
||||||
|
@ -177,8 +177,8 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
|
||||||
|
|
||||||
public void updateFromOther(FeedItem other) {
|
public void updateFromOther(FeedItem other) {
|
||||||
super.updateFromOther(other);
|
super.updateFromOther(other);
|
||||||
if (other.image != null) {
|
if (other.imageUrl != null) {
|
||||||
this.image = other.image;
|
this.imageUrl = other.imageUrl;
|
||||||
}
|
}
|
||||||
if (other.title != null) {
|
if (other.title != null) {
|
||||||
title = other.title;
|
title = other.title;
|
||||||
|
@ -212,9 +212,6 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
|
||||||
chapters = other.chapters;
|
chapters = other.chapters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (image == null) {
|
|
||||||
image = other.image;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -389,8 +386,8 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
|
||||||
public String getImageLocation() {
|
public String getImageLocation() {
|
||||||
if(media != null && media.hasEmbeddedPicture()) {
|
if(media != null && media.hasEmbeddedPicture()) {
|
||||||
return media.getImageLocation();
|
return media.getImageLocation();
|
||||||
} else if (image != null) {
|
} else if (imageUrl != null) {
|
||||||
return image.getImageLocation();
|
return imageUrl;
|
||||||
} else if (feed != null) {
|
} else if (feed != null) {
|
||||||
return feed.getImageLocation();
|
return feed.getImageLocation();
|
||||||
} else {
|
} else {
|
||||||
|
@ -426,29 +423,12 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr
|
||||||
* Returns the image of this item or the image of the feed if this item does
|
* Returns the image of this item or the image of the feed if this item does
|
||||||
* not have its own image.
|
* not have its own image.
|
||||||
*/
|
*/
|
||||||
public FeedImage getImage() {
|
public String getImageUrl() {
|
||||||
return (hasItemImage()) ? image : feed.getImage();
|
return (imageUrl != null) ? imageUrl : feed.getImageUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImage(FeedImage image) {
|
public void setImageUrl(String imageUrl) {
|
||||||
this.image = image;
|
this.imageUrl = imageUrl;
|
||||||
if (image != null) {
|
|
||||||
image.setOwner(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this FeedItem has its own image, false otherwise.
|
|
||||||
*/
|
|
||||||
public boolean hasItemImage() {
|
|
||||||
return image != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this FeedItem has its own image and the image has been downloaded.
|
|
||||||
*/
|
|
||||||
public boolean hasItemImageDownloaded() {
|
|
||||||
return image != null && image.isDownloaded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -55,7 +55,6 @@ import de.danoeh.antennapod.core.R;
|
||||||
import de.danoeh.antennapod.core.event.DownloadEvent;
|
import de.danoeh.antennapod.core.event.DownloadEvent;
|
||||||
import de.danoeh.antennapod.core.event.FeedItemEvent;
|
import de.danoeh.antennapod.core.event.FeedItemEvent;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||||
|
@ -489,9 +488,7 @@ public class DownloadService extends Service {
|
||||||
if (status.isSuccessful()) {
|
if (status.isSuccessful()) {
|
||||||
successfulDownloads++;
|
successfulDownloads++;
|
||||||
} else if (!status.isCancelled()) {
|
} else if (!status.isCancelled()) {
|
||||||
if (status.getFeedfileType() != FeedImage.FEEDFILETYPE_FEEDIMAGE) {
|
createReport = true;
|
||||||
createReport = true;
|
|
||||||
}
|
|
||||||
failedDownloads++;
|
failedDownloads++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -688,10 +685,6 @@ public class DownloadService extends Service {
|
||||||
|
|
||||||
Log.d(TAG, "Bundling " + results.size() + " feeds");
|
Log.d(TAG, "Bundling " + results.size() + " feeds");
|
||||||
|
|
||||||
for (Pair<DownloadRequest, FeedHandlerResult> result : results) {
|
|
||||||
removeDuplicateImages(result.second.feed); // duplicate images have to removed because the DownloadRequester does not accept two downloads with the same download URL yet.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save information of feed in DB
|
// Save information of feed in DB
|
||||||
if (dbUpdateFuture != null) {
|
if (dbUpdateFuture != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -1101,26 +1094,6 @@ public class DownloadService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the FeedItems of this feed have images that point to the same URL. If two FeedItems
|
|
||||||
* have an image that points to the same URL, the reference of the second item is removed, so
|
|
||||||
* that every image reference is unique.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
static void removeDuplicateImages(Feed feed) {
|
|
||||||
Set<String> known = new HashSet<>();
|
|
||||||
for (FeedItem item : feed.getItems()) {
|
|
||||||
String url = item.hasItemImage() ? item.getImage().getDownload_url() : null;
|
|
||||||
if (url != null) {
|
|
||||||
if (known.contains(url)) {
|
|
||||||
item.setImage(null);
|
|
||||||
} else {
|
|
||||||
known.add(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String compileNotificationString(List<Downloader> downloads) {
|
private static String compileNotificationString(List<Downloader> downloads) {
|
||||||
List<String> lines = new ArrayList<>(downloads.size());
|
List<String> lines = new ArrayList<>(downloads.size());
|
||||||
for (Downloader downloader : downloads) {
|
for (Downloader downloader : downloads) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.util.Date;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.ClientConfig;
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
import de.danoeh.antennapod.core.R;
|
import de.danoeh.antennapod.core.R;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.util.DateUtils;
|
import de.danoeh.antennapod.core.util.DateUtils;
|
||||||
import de.danoeh.antennapod.core.util.DownloadError;
|
import de.danoeh.antennapod.core.util.DownloadError;
|
||||||
|
@ -50,13 +49,8 @@ public class HttpDownloader extends Downloader {
|
||||||
|
|
||||||
if (request.isDeleteOnFailure() && fileExists) {
|
if (request.isDeleteOnFailure() && fileExists) {
|
||||||
Log.w(TAG, "File already exists");
|
Log.w(TAG, "File already exists");
|
||||||
if (request.getFeedfileType() != FeedImage.FEEDFILETYPE_FEEDIMAGE) {
|
onSuccess();
|
||||||
onFail(DownloadError.ERROR_FILE_EXISTS, null);
|
return;
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
onSuccess();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OkHttpClient.Builder httpClientBuilder = AntennapodHttpClient.newBuilder();
|
OkHttpClient.Builder httpClientBuilder = AntennapodHttpClient.newBuilder();
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.Chapter;
|
import de.danoeh.antennapod.core.feed.Chapter;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||||
|
@ -213,13 +212,8 @@ public final class DBReader {
|
||||||
result.add(item);
|
result.add(item);
|
||||||
itemIds.add(item.getId());
|
itemIds.add(item.getId());
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
Map<Long, FeedImage> images = getFeedImages(adapter, imageIds.toArray());
|
|
||||||
Map<Long, FeedMedia> medias = getFeedMedia(adapter, itemIds);
|
Map<Long, FeedMedia> medias = getFeedMedia(adapter, itemIds);
|
||||||
for (int i = 0; i < result.size(); i++) {
|
for (FeedItem item : result) {
|
||||||
FeedItem item = result.get(i);
|
|
||||||
long imageId = imageIds.get(i);
|
|
||||||
FeedImage image = images.get(imageId);
|
|
||||||
item.setImage(image);
|
|
||||||
FeedMedia media = medias.get(item.getId());
|
FeedMedia media = medias.get(item.getId());
|
||||||
item.setMedia(media);
|
item.setMedia(media);
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
|
@ -254,24 +248,9 @@ public final class DBReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Feed extractFeedFromCursorRow(PodDBAdapter adapter, Cursor cursor) {
|
private static Feed extractFeedFromCursorRow(PodDBAdapter adapter, Cursor cursor) {
|
||||||
final FeedImage image;
|
|
||||||
int indexImage = cursor.getColumnIndex(PodDBAdapter.KEY_IMAGE);
|
|
||||||
long imageId = cursor.getLong(indexImage);
|
|
||||||
if (imageId != 0) {
|
|
||||||
image = getFeedImage(adapter, imageId);
|
|
||||||
} else {
|
|
||||||
image = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Feed feed = Feed.fromCursor(cursor);
|
Feed feed = Feed.fromCursor(cursor);
|
||||||
if (image != null) {
|
|
||||||
feed.setImage(image);
|
|
||||||
image.setOwner(feed);
|
|
||||||
}
|
|
||||||
|
|
||||||
FeedPreferences preferences = FeedPreferences.fromCursor(cursor);
|
FeedPreferences preferences = FeedPreferences.fromCursor(cursor);
|
||||||
feed.setPreferences(preferences);
|
feed.setPreferences(preferences);
|
||||||
|
|
||||||
return feed;
|
return feed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -838,62 +817,6 @@ public final class DBReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches the DB for a FeedImage of the given id.
|
|
||||||
*
|
|
||||||
* @param imageId The id of the object
|
|
||||||
* @return The found object
|
|
||||||
*/
|
|
||||||
public static FeedImage getFeedImage(final long imageId) {
|
|
||||||
Log.d(TAG, "getFeedImage() called with: " + "imageId = [" + imageId + "]");
|
|
||||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
|
||||||
adapter.open();
|
|
||||||
try {
|
|
||||||
return getFeedImage(adapter, imageId);
|
|
||||||
} finally {
|
|
||||||
adapter.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches the DB for a FeedImage of the given id.
|
|
||||||
*
|
|
||||||
* @param imageId The id of the object
|
|
||||||
* @return The found object
|
|
||||||
*/
|
|
||||||
private static FeedImage getFeedImage(PodDBAdapter adapter, final long imageId) {
|
|
||||||
return getFeedImages(adapter, imageId).get(imageId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches the DB for a FeedImage of the given id.
|
|
||||||
*
|
|
||||||
* @param imageIds The ids of the images
|
|
||||||
* @return Map that associates the id of an image with the image itself
|
|
||||||
*/
|
|
||||||
private static Map<Long, FeedImage> getFeedImages(PodDBAdapter adapter, final long... imageIds) {
|
|
||||||
String[] ids = new String[imageIds.length];
|
|
||||||
for (int i = 0, len = imageIds.length; i < len; i++) {
|
|
||||||
ids[i] = String.valueOf(imageIds[i]);
|
|
||||||
}
|
|
||||||
Cursor cursor = adapter.getImageCursor(ids);
|
|
||||||
int imageCount = cursor.getCount();
|
|
||||||
if (imageCount == 0) {
|
|
||||||
cursor.close();
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
Map<Long, FeedImage> result = new ArrayMap<>(imageCount);
|
|
||||||
try {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
FeedImage image = FeedImage.fromCursor(cursor);
|
|
||||||
result.put(image.getId(), image);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches the DB for a FeedMedia of the given id.
|
* Searches the DB for a FeedMedia of the given id.
|
||||||
*
|
*
|
||||||
|
|
|
@ -32,7 +32,6 @@ import de.danoeh.antennapod.core.event.QueueEvent;
|
||||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedEvent;
|
import de.danoeh.antennapod.core.feed.FeedEvent;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||||
|
@ -166,17 +165,6 @@ public class DBWriter {
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete image file
|
|
||||||
if (feed.getImage() != null) {
|
|
||||||
if (feed.getImage().isDownloaded()
|
|
||||||
&& feed.getImage().getFile_url() != null) {
|
|
||||||
File imageFile = new File(feed.getImage()
|
|
||||||
.getFile_url());
|
|
||||||
imageFile.delete();
|
|
||||||
} else if (requester.isDownloadingFile(feed.getImage())) {
|
|
||||||
requester.cancelDownload(context, feed.getImage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// delete stored media files and mark them as read
|
// delete stored media files and mark them as read
|
||||||
List<FeedItem> queue = DBReader.getQueue();
|
List<FeedItem> queue = DBReader.getQueue();
|
||||||
List<FeedItem> removed = new ArrayList<>();
|
List<FeedItem> removed = new ArrayList<>();
|
||||||
|
@ -200,16 +188,6 @@ public class DBWriter {
|
||||||
&& requester.isDownloadingFile(item.getMedia())) {
|
&& requester.isDownloadingFile(item.getMedia())) {
|
||||||
requester.cancelDownload(context, item.getMedia());
|
requester.cancelDownload(context, item.getMedia());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.hasItemImage()) {
|
|
||||||
FeedImage image = item.getImage();
|
|
||||||
if (image.isDownloaded() && image.getFile_url() != null) {
|
|
||||||
File imgFile = new File(image.getFile_url());
|
|
||||||
imgFile.delete();
|
|
||||||
} else if (requester.isDownloadingFile(image)) {
|
|
||||||
requester.cancelDownload(context, item.getImage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||||
adapter.open();
|
adapter.open();
|
||||||
|
@ -785,21 +763,6 @@ public class DBWriter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves a FeedImage object in the database. This method will save all attributes of the FeedImage object. The
|
|
||||||
* contents of FeedComponent-attributes (e.g. the FeedImages's 'feed'-attribute) will not be saved.
|
|
||||||
*
|
|
||||||
* @param image The FeedImage object.
|
|
||||||
*/
|
|
||||||
public static Future<?> setFeedImage(final FeedImage image) {
|
|
||||||
return dbExec.submit(() -> {
|
|
||||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
|
||||||
adapter.open();
|
|
||||||
adapter.setImage(image);
|
|
||||||
adapter.close();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates download URL of a feed
|
* Updates download URL of a feed
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,7 +27,6 @@ import de.danoeh.antennapod.core.event.ProgressEvent;
|
||||||
import de.danoeh.antennapod.core.feed.Chapter;
|
import de.danoeh.antennapod.core.feed.Chapter;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedComponent;
|
import de.danoeh.antennapod.core.feed.FeedComponent;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||||
|
@ -74,6 +73,7 @@ public class PodDBAdapter {
|
||||||
public static final String KEY_SIZE = "filesize";
|
public static final String KEY_SIZE = "filesize";
|
||||||
public static final String KEY_MIME_TYPE = "mime_type";
|
public static final String KEY_MIME_TYPE = "mime_type";
|
||||||
public static final String KEY_IMAGE = "image";
|
public static final String KEY_IMAGE = "image";
|
||||||
|
public static final String KEY_IMAGE_URL = "image_url";
|
||||||
public static final String KEY_FEED = "feed";
|
public static final String KEY_FEED = "feed";
|
||||||
private static final String KEY_MEDIA = "media";
|
private static final String KEY_MEDIA = "media";
|
||||||
public static final String KEY_DOWNLOADED = "downloaded";
|
public static final String KEY_DOWNLOADED = "downloaded";
|
||||||
|
@ -388,12 +388,7 @@ public class PodDBAdapter {
|
||||||
values.put(KEY_PAYMENT_LINK, feed.getPaymentLink());
|
values.put(KEY_PAYMENT_LINK, feed.getPaymentLink());
|
||||||
values.put(KEY_AUTHOR, feed.getAuthor());
|
values.put(KEY_AUTHOR, feed.getAuthor());
|
||||||
values.put(KEY_LANGUAGE, feed.getLanguage());
|
values.put(KEY_LANGUAGE, feed.getLanguage());
|
||||||
if (feed.getImage() != null) {
|
//TODO values.put(KEY_IMAGE_URL, feed.getImageUrl());
|
||||||
if (feed.getImage().getId() == 0) {
|
|
||||||
setImage(feed.getImage());
|
|
||||||
}
|
|
||||||
values.put(KEY_IMAGE, feed.getImage().getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
values.put(KEY_FILE_URL, feed.getFile_url());
|
values.put(KEY_FILE_URL, feed.getFile_url());
|
||||||
values.put(KEY_DOWNLOAD_URL, feed.getDownload_url());
|
values.put(KEY_DOWNLOAD_URL, feed.getDownload_url());
|
||||||
|
@ -450,54 +445,7 @@ public class PodDBAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts or updates an image entry
|
* Inserts or updates a media entry
|
||||||
*
|
|
||||||
* @return the id of the entry
|
|
||||||
*/
|
|
||||||
public long setImage(FeedImage image) {
|
|
||||||
boolean startedTransaction = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!db.inTransaction()) {
|
|
||||||
db.beginTransactionNonExclusive();
|
|
||||||
startedTransaction = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(KEY_TITLE, image.getTitle());
|
|
||||||
values.put(KEY_DOWNLOAD_URL, image.getDownload_url());
|
|
||||||
values.put(KEY_DOWNLOADED, image.isDownloaded());
|
|
||||||
values.put(KEY_FILE_URL, image.getFile_url());
|
|
||||||
if (image.getId() == 0) {
|
|
||||||
image.setId(db.insert(TABLE_NAME_FEED_IMAGES, null, values));
|
|
||||||
} else {
|
|
||||||
db.update(TABLE_NAME_FEED_IMAGES, values, KEY_ID + "=?",
|
|
||||||
new String[]{String.valueOf(image.getId())});
|
|
||||||
}
|
|
||||||
|
|
||||||
final FeedComponent owner = image.getOwner();
|
|
||||||
if (owner != null && owner.getId() != 0) {
|
|
||||||
values.clear();
|
|
||||||
values.put(KEY_IMAGE, image.getId());
|
|
||||||
if (owner instanceof Feed) {
|
|
||||||
db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[]{String.valueOf(image.getOwner().getId())});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (startedTransaction) {
|
|
||||||
db.setTransactionSuccessful();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Log.e(TAG, Log.getStackTraceString(e));
|
|
||||||
} finally {
|
|
||||||
if (startedTransaction) {
|
|
||||||
db.endTransaction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return image.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inserts or updates an image entry
|
|
||||||
*
|
*
|
||||||
* @return the id of the entry
|
* @return the id of the entry
|
||||||
*/
|
*/
|
||||||
|
@ -759,12 +707,7 @@ public class PodDBAdapter {
|
||||||
values.put(KEY_ITEM_IDENTIFIER, item.getItemIdentifier());
|
values.put(KEY_ITEM_IDENTIFIER, item.getItemIdentifier());
|
||||||
values.put(KEY_FLATTR_STATUS, item.getFlattrStatus().toLong());
|
values.put(KEY_FLATTR_STATUS, item.getFlattrStatus().toLong());
|
||||||
values.put(KEY_AUTO_DOWNLOAD, item.getAutoDownload());
|
values.put(KEY_AUTO_DOWNLOAD, item.getAutoDownload());
|
||||||
if (item.hasItemImage()) {
|
values.put(KEY_IMAGE_URL, item.getImageUrl());
|
||||||
if (item.getImage().getId() == 0) {
|
|
||||||
setImage(item.getImage());
|
|
||||||
}
|
|
||||||
values.put(KEY_IMAGE, item.getImage().getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.getId() == 0) {
|
if (item.getId() == 0) {
|
||||||
item.setId(db.insert(TABLE_NAME_FEED_ITEMS, null, values));
|
item.setId(db.insert(TABLE_NAME_FEED_ITEMS, null, values));
|
||||||
|
@ -993,11 +936,6 @@ public class PodDBAdapter {
|
||||||
new String[]{String.valueOf(item.getId())});
|
new String[]{String.valueOf(item.getId())});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeFeedImage(FeedImage image) {
|
|
||||||
db.delete(TABLE_NAME_FEED_IMAGES, KEY_ID + "=?",
|
|
||||||
new String[]{String.valueOf(image.getId())});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a FeedItem and its FeedMedia entry.
|
* Remove a FeedItem and its FeedMedia entry.
|
||||||
*/
|
*/
|
||||||
|
@ -1008,9 +946,6 @@ public class PodDBAdapter {
|
||||||
if (item.hasChapters() || item.getChapters() != null) {
|
if (item.hasChapters() || item.getChapters() != null) {
|
||||||
removeChaptersOfItem(item);
|
removeChaptersOfItem(item);
|
||||||
}
|
}
|
||||||
if (item.hasItemImage()) {
|
|
||||||
removeFeedImage(item.getImage());
|
|
||||||
}
|
|
||||||
db.delete(TABLE_NAME_FEED_ITEMS, KEY_ID + "=?",
|
db.delete(TABLE_NAME_FEED_ITEMS, KEY_ID + "=?",
|
||||||
new String[]{String.valueOf(item.getId())});
|
new String[]{String.valueOf(item.getId())});
|
||||||
}
|
}
|
||||||
|
@ -1021,9 +956,6 @@ public class PodDBAdapter {
|
||||||
public void removeFeed(Feed feed) {
|
public void removeFeed(Feed feed) {
|
||||||
try {
|
try {
|
||||||
db.beginTransactionNonExclusive();
|
db.beginTransactionNonExclusive();
|
||||||
if (feed.getImage() != null) {
|
|
||||||
removeFeedImage(feed.getImage());
|
|
||||||
}
|
|
||||||
if (feed.getItems() != null) {
|
if (feed.getItems() != null) {
|
||||||
for (FeedItem item : feed.getItems()) {
|
for (FeedItem item : feed.getItems()) {
|
||||||
removeFeedItem(item);
|
removeFeedItem(item);
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.xml.sax.Attributes;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
|
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
|
||||||
|
|
||||||
public class NSITunes extends Namespace {
|
public class NSITunes extends Namespace {
|
||||||
|
@ -16,7 +15,6 @@ public class NSITunes extends Namespace {
|
||||||
public static final String NSURI = "http://www.itunes.com/dtds/podcast-1.0.dtd";
|
public static final String NSURI = "http://www.itunes.com/dtds/podcast-1.0.dtd";
|
||||||
|
|
||||||
private static final String IMAGE = "image";
|
private static final String IMAGE = "image";
|
||||||
private static final String IMAGE_TITLE = "image";
|
|
||||||
private static final String IMAGE_HREF = "href";
|
private static final String IMAGE_HREF = "href";
|
||||||
|
|
||||||
private static final String AUTHOR = "author";
|
private static final String AUTHOR = "author";
|
||||||
|
@ -29,21 +27,15 @@ public class NSITunes extends Namespace {
|
||||||
public SyndElement handleElementStart(String localName, HandlerState state,
|
public SyndElement handleElementStart(String localName, HandlerState state,
|
||||||
Attributes attributes) {
|
Attributes attributes) {
|
||||||
if (IMAGE.equals(localName)) {
|
if (IMAGE.equals(localName)) {
|
||||||
FeedImage image = new FeedImage();
|
String url = attributes.getValue(IMAGE_HREF);
|
||||||
image.setTitle(IMAGE_TITLE);
|
|
||||||
image.setDownload_url(attributes.getValue(IMAGE_HREF));
|
|
||||||
|
|
||||||
if (state.getCurrentItem() != null) {
|
if (state.getCurrentItem() != null) {
|
||||||
// this is an items image
|
state.getCurrentItem().setImageUrl(url);
|
||||||
image.setTitle(state.getCurrentItem().getTitle() + IMAGE_TITLE);
|
|
||||||
image.setOwner(state.getCurrentItem());
|
|
||||||
state.getCurrentItem().setImage(image);
|
|
||||||
} else {
|
} else {
|
||||||
// this is the feed image
|
// this is the feed image
|
||||||
// prefer to all other images
|
// prefer to all other images
|
||||||
if (!TextUtils.isEmpty(image.getDownload_url())) {
|
if (!TextUtils.isEmpty(url)) {
|
||||||
image.setOwner(state.getFeed());
|
state.getFeed().setImageUrl(url);
|
||||||
state.getFeed().setImage(image);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.xml.sax.Attributes;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
|
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
|
||||||
import de.danoeh.antennapod.core.syndication.namespace.atom.AtomText;
|
import de.danoeh.antennapod.core.syndication.namespace.atom.AtomText;
|
||||||
|
@ -94,25 +93,16 @@ public class NSMedia extends Namespace {
|
||||||
}
|
}
|
||||||
state.getCurrentItem().setMedia(media);
|
state.getCurrentItem().setMedia(media);
|
||||||
} else if (state.getCurrentItem() != null && url != null && validTypeImage) {
|
} else if (state.getCurrentItem() != null && url != null && validTypeImage) {
|
||||||
FeedImage image = new FeedImage();
|
state.getCurrentItem().setImageUrl(url);
|
||||||
image.setDownload_url(url);
|
|
||||||
image.setOwner(state.getCurrentItem());
|
|
||||||
|
|
||||||
state.getCurrentItem().setImage(image);
|
|
||||||
}
|
}
|
||||||
} else if (IMAGE.equals(localName)) {
|
} else if (IMAGE.equals(localName)) {
|
||||||
String url = attributes.getValue(IMAGE_URL);
|
String url = attributes.getValue(IMAGE_URL);
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
FeedImage image = new FeedImage();
|
|
||||||
image.setDownload_url(url);
|
|
||||||
|
|
||||||
if (state.getCurrentItem() != null) {
|
if (state.getCurrentItem() != null) {
|
||||||
image.setOwner(state.getCurrentItem());
|
state.getCurrentItem().setImageUrl(url);
|
||||||
state.getCurrentItem().setImage(image);
|
|
||||||
} else {
|
} else {
|
||||||
if (state.getFeed().getImage() == null) {
|
if (state.getFeed().getImageUrl() == null) {
|
||||||
image.setOwner(state.getFeed());
|
state.getFeed().setImageUrl(url);
|
||||||
state.getFeed().setImage(image);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import android.util.Log;
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
|
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
|
||||||
|
@ -77,17 +76,6 @@ public class NSRSS20 extends Namespace {
|
||||||
state.getCurrentItem().setMedia(media);
|
state.getCurrentItem().setMedia(media);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (IMAGE.equals(localName)) {
|
|
||||||
if (state.getTagstack().size() >= 1) {
|
|
||||||
String parent = state.getTagstack().peek().getName();
|
|
||||||
if (CHANNEL.equals(parent)) {
|
|
||||||
Feed feed = state.getFeed();
|
|
||||||
if(feed != null && feed.getImage() == null) {
|
|
||||||
feed.setImage(new FeedImage());
|
|
||||||
feed.getImage().setOwner(state.getFeed());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new SyndElement(localName, this);
|
return new SyndElement(localName, this);
|
||||||
}
|
}
|
||||||
|
@ -134,11 +122,6 @@ public class NSRSS20 extends Namespace {
|
||||||
state.getCurrentItem().setTitle(title);
|
state.getCurrentItem().setTitle(title);
|
||||||
} else if (CHANNEL.equals(second) && state.getFeed() != null) {
|
} else if (CHANNEL.equals(second) && state.getFeed() != null) {
|
||||||
state.getFeed().setTitle(title);
|
state.getFeed().setTitle(title);
|
||||||
} else if (IMAGE.equals(second) && CHANNEL.equals(third)) {
|
|
||||||
if(state.getFeed() != null && state.getFeed().getImage() != null &&
|
|
||||||
state.getFeed().getImage().getTitle() == null) {
|
|
||||||
state.getFeed().getImage().setTitle(title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (LINK.equals(top)) {
|
} else if (LINK.equals(top)) {
|
||||||
if (CHANNEL.equals(second) && state.getFeed() != null) {
|
if (CHANNEL.equals(second) && state.getFeed() != null) {
|
||||||
|
@ -150,9 +133,8 @@ public class NSRSS20 extends Namespace {
|
||||||
state.getCurrentItem().setPubDate(DateUtils.parse(content));
|
state.getCurrentItem().setPubDate(DateUtils.parse(content));
|
||||||
} else if (URL.equals(top) && IMAGE.equals(second) && CHANNEL.equals(third)) {
|
} else if (URL.equals(top) && IMAGE.equals(second) && CHANNEL.equals(third)) {
|
||||||
// prefer itunes:image
|
// prefer itunes:image
|
||||||
if(state.getFeed() != null && state.getFeed().getImage() != null &&
|
if (state.getFeed() != null) {
|
||||||
state.getFeed().getImage().getDownload_url() == null) {
|
state.getFeed().setImageUrl(content);
|
||||||
state.getFeed().getImage().setDownload_url(content);
|
|
||||||
}
|
}
|
||||||
} else if (DESCR.equals(localName)) {
|
} else if (DESCR.equals(localName)) {
|
||||||
if (CHANNEL.equals(second) && state.getFeed() != null) {
|
if (CHANNEL.equals(second) && state.getFeed() != null) {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.util.Log;
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
|
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
|
||||||
|
@ -210,10 +209,10 @@ public class NSAtom extends Namespace {
|
||||||
state.getCurrentItem().setPubDate(DateUtils.parse(content));
|
state.getCurrentItem().setPubDate(DateUtils.parse(content));
|
||||||
} else if (PUBLISHED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null) {
|
} else if (PUBLISHED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null) {
|
||||||
state.getCurrentItem().setPubDate(DateUtils.parse(content));
|
state.getCurrentItem().setPubDate(DateUtils.parse(content));
|
||||||
} else if (IMAGE_LOGO.equals(top) && state.getFeed() != null && state.getFeed().getImage() == null) {
|
} else if (IMAGE_LOGO.equals(top) && state.getFeed() != null && state.getFeed().getImageUrl() == null) {
|
||||||
state.getFeed().setImage(new FeedImage(state.getFeed(), content, null));
|
state.getFeed().setImageUrl(content);
|
||||||
} else if (IMAGE_ICON.equals(top) && state.getFeed() != null) {
|
} else if (IMAGE_ICON.equals(top) && state.getFeed() != null) {
|
||||||
state.getFeed().setImage(new FeedImage(state.getFeed(), content, null));
|
state.getFeed().setImageUrl(content);
|
||||||
} else if (AUTHOR_NAME.equals(top) && AUTHOR.equals(second) &&
|
} else if (AUTHOR_NAME.equals(top) && AUTHOR.equals(second) &&
|
||||||
state.getFeed() != null && state.getCurrentItem() == null) {
|
state.getFeed() != null && state.getCurrentItem() == null) {
|
||||||
String currentName = state.getFeed().getAuthor();
|
String currentName = state.getFeed().getAuthor();
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
|
@ -97,9 +96,9 @@ public class CastUtils {
|
||||||
if (subtitle != null) {
|
if (subtitle != null) {
|
||||||
metadata.putString(MediaMetadata.KEY_SUBTITLE, subtitle);
|
metadata.putString(MediaMetadata.KEY_SUBTITLE, subtitle);
|
||||||
}
|
}
|
||||||
FeedImage image = feedItem.getImage();
|
|
||||||
if (image != null && !TextUtils.isEmpty(image.getDownload_url())) {
|
if (!TextUtils.isEmpty(feedItem.getImageUrl())) {
|
||||||
metadata.addImage(new WebImage(Uri.parse(image.getDownload_url())));
|
metadata.addImage(new WebImage(Uri.parse(feedItem.getImageUrl())));
|
||||||
}
|
}
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(media.getItem().getPubDate());
|
calendar.setTime(media.getItem().getPubDate());
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package de.danoeh.antennapod.core.feed;
|
|
||||||
|
|
||||||
class FeedImageMother {
|
|
||||||
|
|
||||||
public static FeedImage anyFeedImage() {
|
|
||||||
return new FeedImage(0, "image", null, "http://example.com/picture", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package de.danoeh.antennapod.core.feed;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import static de.danoeh.antennapod.core.feed.FeedImageMother.anyFeedImage;
|
|
||||||
import static de.danoeh.antennapod.core.feed.FeedMother.anyFeed;
|
|
||||||
|
|
||||||
class FeedItemMother {
|
|
||||||
|
|
||||||
static FeedItem anyFeedItemWithImage() {
|
|
||||||
FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), FeedItem.PLAYED, anyFeed());
|
|
||||||
item.setImage(anyFeedImage());
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
package de.danoeh.antennapod.core.feed;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static de.danoeh.antennapod.core.feed.FeedItemMother.anyFeedItemWithImage;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class FeedItemTest {
|
|
||||||
|
|
||||||
private FeedItem original;
|
|
||||||
private FeedImage originalImage;
|
|
||||||
private FeedItem changedFeedItem;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
original = anyFeedItemWithImage();
|
|
||||||
originalImage = original.getImage();
|
|
||||||
changedFeedItem = anyFeedItemWithImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateFromOther_feedItemImageDownloadUrlChanged() throws Exception {
|
|
||||||
setNewFeedItemImageDownloadUrl();
|
|
||||||
|
|
||||||
original.updateFromOther(changedFeedItem);
|
|
||||||
|
|
||||||
feedItemImageWasUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateFromOther_feedItemImageRemoved() throws Exception {
|
|
||||||
feedItemImageRemoved();
|
|
||||||
|
|
||||||
original.updateFromOther(changedFeedItem);
|
|
||||||
|
|
||||||
feedItemImageWasNotUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateFromOther_feedItemImageAdded() throws Exception {
|
|
||||||
feedItemHadNoImage();
|
|
||||||
setNewFeedItemImageDownloadUrl();
|
|
||||||
|
|
||||||
original.updateFromOther(changedFeedItem);
|
|
||||||
|
|
||||||
feedItemImageWasUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedItemHadNoImage() {
|
|
||||||
original.setImage(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setNewFeedItemImageDownloadUrl() {
|
|
||||||
changedFeedItem.getImage().setDownload_url("http://example.com/new_picture");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedItemImageRemoved() {
|
|
||||||
changedFeedItem.setImage(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedItemImageWasUpdated() {
|
|
||||||
assertEquals(original.getImage().getDownload_url(), changedFeedItem.getImage().getDownload_url());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedItemImageWasNotUpdated() {
|
|
||||||
assertTrue(originalImage == original.getImage());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package de.danoeh.antennapod.core.feed;
|
|
||||||
|
|
||||||
import static de.danoeh.antennapod.core.feed.FeedImageMother.anyFeedImage;
|
|
||||||
|
|
||||||
class FeedMother {
|
|
||||||
|
|
||||||
public static Feed anyFeed() {
|
|
||||||
FeedImage image = anyFeedImage();
|
|
||||||
return new Feed(0, null, "title", "http://example.com", "This is the description",
|
|
||||||
"http://example.com/payment", "Daniel", "en", null, "http://example.com/feed", image,
|
|
||||||
null, "http://example.com/feed", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,102 +0,0 @@
|
||||||
package de.danoeh.antennapod.core.feed;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static de.danoeh.antennapod.core.feed.FeedImageMother.anyFeedImage;
|
|
||||||
import static de.danoeh.antennapod.core.feed.FeedMother.anyFeed;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class FeedTest {
|
|
||||||
|
|
||||||
private Feed original;
|
|
||||||
private FeedImage originalImage;
|
|
||||||
private Feed changedFeed;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
original = anyFeed();
|
|
||||||
originalImage = original.getImage();
|
|
||||||
changedFeed = anyFeed();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCompareWithOther_feedImageDownloadUrlChanged() throws Exception {
|
|
||||||
setNewFeedImageDownloadUrl();
|
|
||||||
|
|
||||||
feedHasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCompareWithOther_sameFeedImage() throws Exception {
|
|
||||||
changedFeed.setImage(anyFeedImage());
|
|
||||||
|
|
||||||
feedHasNotChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCompareWithOther_feedImageRemoved() throws Exception {
|
|
||||||
feedImageRemoved();
|
|
||||||
|
|
||||||
feedHasNotChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateFromOther_feedImageDownloadUrlChanged() throws Exception {
|
|
||||||
setNewFeedImageDownloadUrl();
|
|
||||||
|
|
||||||
original.updateFromOther(changedFeed);
|
|
||||||
|
|
||||||
feedImageWasUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateFromOther_feedImageRemoved() throws Exception {
|
|
||||||
feedImageRemoved();
|
|
||||||
|
|
||||||
original.updateFromOther(changedFeed);
|
|
||||||
|
|
||||||
feedImageWasNotUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateFromOther_feedImageAdded() throws Exception {
|
|
||||||
feedHadNoImage();
|
|
||||||
setNewFeedImageDownloadUrl();
|
|
||||||
|
|
||||||
original.updateFromOther(changedFeed);
|
|
||||||
|
|
||||||
feedImageWasUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedHasNotChanged() {
|
|
||||||
assertFalse(original.compareWithOther(changedFeed));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedHadNoImage() {
|
|
||||||
original.setImage(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setNewFeedImageDownloadUrl() {
|
|
||||||
changedFeed.getImage().setDownload_url("http://example.com/new_picture");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedHasChanged() {
|
|
||||||
assertTrue(original.compareWithOther(changedFeed));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedImageRemoved() {
|
|
||||||
changedFeed.setImage(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedImageWasUpdated() {
|
|
||||||
assertEquals(original.getImage().getDownload_url(), changedFeed.getImage().getDownload_url());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feedImageWasNotUpdated() {
|
|
||||||
assertTrue(originalImage == original.getImage());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
package de.danoeh.antennapod.core.service.download;
|
|
||||||
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedImage;
|
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class DownloadServiceTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRemoveDuplicateImages() {
|
|
||||||
List<FeedItem> items = new ArrayList<>();
|
|
||||||
for (int i = 0; i < 50; i++) {
|
|
||||||
FeedItem item = new FeedItem();
|
|
||||||
String url = (i % 5 == 0) ? "dupe_url" : String.format("url_%d", i);
|
|
||||||
item.setImage(new FeedImage(null, url, ""));
|
|
||||||
items.add(item);
|
|
||||||
}
|
|
||||||
Feed feed = new Feed();
|
|
||||||
feed.setItems(items);
|
|
||||||
|
|
||||||
DownloadService.removeDuplicateImages(feed);
|
|
||||||
|
|
||||||
assertEquals(50, items.size());
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
|
||||||
FeedItem item = items.get(i);
|
|
||||||
String want = (i == 0) ? "dupe_url" : (i % 5 == 0) ? null : String.format("url_%d", i);
|
|
||||||
assertEquals(want, item.getImageLocation());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue