mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-02-02 11:46:55 +01:00
Treat feeds with same title and different download URLs as different feeds. fixes #101
This commit is contained in:
parent
4ef7fccf75
commit
c1c3dc593e
@ -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 {
|
||||
|
@ -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()));
|
||||
|
||||
|
@ -595,12 +595,16 @@ public final class DBTasks {
|
||||
return QueueAccess.IDListAccess(queue).contains(feedItemId);
|
||||
}
|
||||
|
||||
private static Feed searchFeedByIdentifyingValue(Context context,
|
||||
String identifier) {
|
||||
List<Feed> 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<Feed> 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,
|
||||
|
@ -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);
|
||||
|
@ -78,7 +78,7 @@ public class DBReaderTest extends InstrumentationTestCase {
|
||||
List<Feed> feeds = saveFeedlist(context, 10, 0, false);
|
||||
List<Feed> 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());
|
||||
}
|
||||
|
@ -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<FeedItem>());
|
||||
feed2.setItems(new ArrayList<FeedItem>());
|
||||
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user