Fixed feed update

This commit is contained in:
daniel oeh 2012-07-01 22:21:06 +02:00
parent 5a0f1f49c9
commit 3b4bf9374a
3 changed files with 13 additions and 18 deletions

View File

@ -1,14 +0,0 @@
package de.podfetcher.feed;
import java.util.Comparator;
/** Compares the pubDate of two FeedItems */
public class FeedItemPubdateComparator implements Comparator<FeedItem> {
@Override
public int compare(FeedItem lhs, FeedItem rhs) {
long diff = lhs.getPubDate().getTime() - rhs.getPubDate().getTime();
return (int) Math.signum(diff);
}
}

View File

@ -9,6 +9,7 @@ import de.podfetcher.activity.MediaplayerActivity;
import de.podfetcher.asynctask.DownloadStatus;
import de.podfetcher.service.PlaybackService;
import de.podfetcher.storage.*;
import de.podfetcher.util.FeedItemPubdateComparator;
import de.podfetcher.util.FeedtitleComparator;
import android.content.Context;
import android.content.Intent;
@ -243,9 +244,9 @@ public class FeedManager {
* adapter.setFeedItem(item); } else { feed.getItems().add(item); item.id =
* adapter.setFeedItem(item); } }
*/
public void updateFeed(Context context, Feed newFeed) {
public void updateFeed(Context context, final Feed newFeed) {
// Look up feed in the feedslist
Feed savedFeed = searchFeedByLink(newFeed.getLink());
final Feed savedFeed = searchFeedByLink(newFeed.getLink());
if (savedFeed == null) {
Log.d(TAG,
"Found no existing Feed with title " + newFeed.getTitle()
@ -257,17 +258,20 @@ public class FeedManager {
Log.d(TAG, "Feed with title " + newFeed.getTitle()
+ " already exists. Syncing new with existing one.");
// Look for new or updated Items
for (FeedItem item : newFeed.getItems()) {
for (int idx = 0; idx < newFeed.getItems().size(); idx++) {
FeedItem item = newFeed.getItems().get(idx);
FeedItem oldItem = searchFeedItemByLink(savedFeed,
item.getLink());
if (oldItem == null) {
// item is new
savedFeed.getItems().add(item);
item.setFeed(savedFeed);
savedFeed.getItems().add(idx, item);
markItemRead(context, item, false);
}
}
savedFeed.setLastUpdate(newFeed.getLastUpdate());
setFeed(context, savedFeed);
}
}
@ -568,6 +572,7 @@ public class FeedManager {
items.add(item);
} while (itemlistCursor.moveToNext());
}
Collections.sort(items, new FeedItemPubdateComparator());
return items;
}

View File

@ -7,6 +7,10 @@ import de.podfetcher.feed.FeedItem;
/** Compares the pubDate of two FeedItems for sorting*/
public class FeedItemPubdateComparator implements Comparator<FeedItem> {
/** Returns a new instance of this comparator in reverse order.
public static FeedItemPubdateComparator newInstance() {
FeedItemPubdateComparator
}*/
@Override
public int compare(FeedItem lhs, FeedItem rhs) {
return -lhs.getPubDate().compareTo(rhs.getPubDate());