diff --git a/src/de/danoeh/antennapod/feed/Feed.java b/src/de/danoeh/antennapod/feed/Feed.java index 9e423ff8b..f9da65e03 100644 --- a/src/de/danoeh/antennapod/feed/Feed.java +++ b/src/de/danoeh/antennapod/feed/Feed.java @@ -223,6 +223,8 @@ public class Feed extends FeedFile implements FlattrThing { public String getIdentifyingValue() { if (feedIdentifier != null && !feedIdentifier.isEmpty()) { return feedIdentifier; + } else if (download_url != null && !download_url.isEmpty()) { + return download_url; } else if (title != null && !title.isEmpty()) { return title; } else { diff --git a/src/de/danoeh/antennapod/service/download/DownloadService.java b/src/de/danoeh/antennapod/service/download/DownloadService.java index 2d82d8631..d06bc6760 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadService.java +++ b/src/de/danoeh/antennapod/service/download/DownloadService.java @@ -648,6 +648,7 @@ public class DownloadService extends Service { Feed feed = new Feed(request.getSource(), new Date()); feed.setFile_url(request.getDestination()); + feed.setId(request.getFeedfileId()); feed.setDownloaded(true); feed.setPreferences(new FeedPreferences(0, true, request.getUsername(), request.getPassword())); diff --git a/src/de/danoeh/antennapod/storage/DBTasks.java b/src/de/danoeh/antennapod/storage/DBTasks.java index 92efeea62..49644af01 100644 --- a/src/de/danoeh/antennapod/storage/DBTasks.java +++ b/src/de/danoeh/antennapod/storage/DBTasks.java @@ -595,12 +595,16 @@ public final class DBTasks { return QueueAccess.IDListAccess(queue).contains(feedItemId); } - private static Feed searchFeedByIdentifyingValue(Context context, - String identifier) { - List feeds = DBReader.getFeedList(context); - for (Feed feed : feeds) { - if (feed.getIdentifyingValue().equals(identifier)) { - return feed; + private static Feed searchFeedByIdentifyingValueOrID(Context context, + Feed feed) { + if (feed.getId() != 0) { + return DBReader.getFeed(context, feed.getId()); + } else { + List feeds = DBReader.getFeedList(context); + for (Feed f : feeds) { + if (f.getIdentifyingValue().equals(feed.getIdentifyingValue())) { + return f; + } } } return null; @@ -632,8 +636,8 @@ public final class DBTasks { public static synchronized Feed updateFeed(final Context context, final Feed newFeed) { // Look up feed in the feedslist - final Feed savedFeed = searchFeedByIdentifyingValue(context, - newFeed.getIdentifyingValue()); + final Feed savedFeed = searchFeedByIdentifyingValueOrID(context, + newFeed); if (savedFeed == null) { if (BuildConfig.DEBUG) Log.d(TAG, diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java index 714ad952f..7bf21352a 100644 --- a/src/de/danoeh/antennapod/storage/DownloadRequester.java +++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java @@ -114,7 +114,7 @@ public class DownloadRequester { item.setDownload_url(URLChecker.prepareURL(item.getDownload_url())); DownloadRequest request = new DownloadRequest(dest.toString(), - item.getDownload_url(), item.getHumanReadableIdentifier(), + URLChecker.prepareURL(item.getDownload_url()), item.getHumanReadableIdentifier(), item.getId(), item.getTypeAsInt(), username, password, deleteOnFailure); download(context, request); diff --git a/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java b/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java index b03d83d25..cb854b88d 100644 --- a/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java +++ b/src/instrumentationTest/de/test/antennapod/storage/DBReaderTest.java @@ -78,7 +78,7 @@ public class DBReaderTest extends InstrumentationTestCase { List feeds = saveFeedlist(context, 10, 0, false); List savedFeeds = DBReader.getFeedList(context); assertNotNull(savedFeeds); - assertTrue(savedFeeds.size() == feeds.size()); + assertEquals(feeds.size(), savedFeeds.size()); for (int i = 0; i < feeds.size(); i++) { assertTrue(savedFeeds.get(i).getId() == feeds.get(i).getId()); } diff --git a/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java b/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java index 2372757ce..9ab1481be 100644 --- a/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java +++ b/src/instrumentationTest/de/test/antennapod/storage/DBTasksTest.java @@ -212,6 +212,22 @@ public class DBTasksTest extends InstrumentationTestCase { } } + /** Two feeds with the same title, but different download URLs should be treated as different feeds. */ + public void testUpdateFeedSameTitle() { + final Context context = getInstrumentation().getTargetContext(); + + Feed feed1 = new Feed("url1", new Date(), "title"); + Feed feed2 = new Feed("url2", new Date(), "title"); + + feed1.setItems(new ArrayList()); + feed2.setItems(new ArrayList()); + + Feed savedFeed1 = DBTasks.updateFeed(context, feed1); + Feed savedFeed2 = DBTasks.updateFeed(context, feed2); + + assertTrue(savedFeed1.getId() != savedFeed2.getId()); + } + public void testUpdateFeedUpdatedFeed() { final Context context = getInstrumentation().getTargetContext(); final int NUM_ITEMS_OLD = 10;