Treat feeds with same title and different download URLs as different feeds. fixes #101

This commit is contained in:
daniel oeh 2014-05-17 17:24:52 +02:00
parent 4ef7fccf75
commit c1c3dc593e
6 changed files with 33 additions and 10 deletions

View File

@ -223,6 +223,8 @@ public class Feed extends FeedFile implements FlattrThing {
public String getIdentifyingValue() { public String getIdentifyingValue() {
if (feedIdentifier != null && !feedIdentifier.isEmpty()) { if (feedIdentifier != null && !feedIdentifier.isEmpty()) {
return feedIdentifier; return feedIdentifier;
} else if (download_url != null && !download_url.isEmpty()) {
return download_url;
} else if (title != null && !title.isEmpty()) { } else if (title != null && !title.isEmpty()) {
return title; return title;
} else { } else {

View File

@ -648,6 +648,7 @@ public class DownloadService extends Service {
Feed feed = new Feed(request.getSource(), new Date()); Feed feed = new Feed(request.getSource(), new Date());
feed.setFile_url(request.getDestination()); feed.setFile_url(request.getDestination());
feed.setId(request.getFeedfileId());
feed.setDownloaded(true); feed.setDownloaded(true);
feed.setPreferences(new FeedPreferences(0, true, request.getUsername(), request.getPassword())); feed.setPreferences(new FeedPreferences(0, true, request.getUsername(), request.getPassword()));

View File

@ -595,12 +595,16 @@ public final class DBTasks {
return QueueAccess.IDListAccess(queue).contains(feedItemId); return QueueAccess.IDListAccess(queue).contains(feedItemId);
} }
private static Feed searchFeedByIdentifyingValue(Context context, private static Feed searchFeedByIdentifyingValueOrID(Context context,
String identifier) { Feed feed) {
if (feed.getId() != 0) {
return DBReader.getFeed(context, feed.getId());
} else {
List<Feed> feeds = DBReader.getFeedList(context); List<Feed> feeds = DBReader.getFeedList(context);
for (Feed feed : feeds) { for (Feed f : feeds) {
if (feed.getIdentifyingValue().equals(identifier)) { if (f.getIdentifyingValue().equals(feed.getIdentifyingValue())) {
return feed; return f;
}
} }
} }
return null; return null;
@ -632,8 +636,8 @@ public final class DBTasks {
public static synchronized Feed updateFeed(final Context context, public static synchronized Feed updateFeed(final Context context,
final Feed newFeed) { final Feed newFeed) {
// Look up feed in the feedslist // Look up feed in the feedslist
final Feed savedFeed = searchFeedByIdentifyingValue(context, final Feed savedFeed = searchFeedByIdentifyingValueOrID(context,
newFeed.getIdentifyingValue()); newFeed);
if (savedFeed == null) { if (savedFeed == null) {
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
Log.d(TAG, Log.d(TAG,

View File

@ -114,7 +114,7 @@ public class DownloadRequester {
item.setDownload_url(URLChecker.prepareURL(item.getDownload_url())); item.setDownload_url(URLChecker.prepareURL(item.getDownload_url()));
DownloadRequest request = new DownloadRequest(dest.toString(), 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); item.getId(), item.getTypeAsInt(), username, password, deleteOnFailure);
download(context, request); download(context, request);

View File

@ -78,7 +78,7 @@ public class DBReaderTest extends InstrumentationTestCase {
List<Feed> feeds = saveFeedlist(context, 10, 0, false); List<Feed> feeds = saveFeedlist(context, 10, 0, false);
List<Feed> savedFeeds = DBReader.getFeedList(context); List<Feed> savedFeeds = DBReader.getFeedList(context);
assertNotNull(savedFeeds); assertNotNull(savedFeeds);
assertTrue(savedFeeds.size() == feeds.size()); assertEquals(feeds.size(), savedFeeds.size());
for (int i = 0; i < feeds.size(); i++) { for (int i = 0; i < feeds.size(); i++) {
assertTrue(savedFeeds.get(i).getId() == feeds.get(i).getId()); assertTrue(savedFeeds.get(i).getId() == feeds.get(i).getId());
} }

View File

@ -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() { public void testUpdateFeedUpdatedFeed() {
final Context context = getInstrumentation().getTargetContext(); final Context context = getInstrumentation().getTargetContext();
final int NUM_ITEMS_OLD = 10; final int NUM_ITEMS_OLD = 10;