Fixed feed update
This commit is contained in:
parent
5a0f1f49c9
commit
3b4bf9374a
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -9,6 +9,7 @@ import de.podfetcher.activity.MediaplayerActivity;
|
||||||
import de.podfetcher.asynctask.DownloadStatus;
|
import de.podfetcher.asynctask.DownloadStatus;
|
||||||
import de.podfetcher.service.PlaybackService;
|
import de.podfetcher.service.PlaybackService;
|
||||||
import de.podfetcher.storage.*;
|
import de.podfetcher.storage.*;
|
||||||
|
import de.podfetcher.util.FeedItemPubdateComparator;
|
||||||
import de.podfetcher.util.FeedtitleComparator;
|
import de.podfetcher.util.FeedtitleComparator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -243,9 +244,9 @@ public class FeedManager {
|
||||||
* adapter.setFeedItem(item); } else { feed.getItems().add(item); item.id =
|
* adapter.setFeedItem(item); } else { feed.getItems().add(item); item.id =
|
||||||
* adapter.setFeedItem(item); } }
|
* adapter.setFeedItem(item); } }
|
||||||
*/
|
*/
|
||||||
public void updateFeed(Context context, Feed newFeed) {
|
public void updateFeed(Context context, final Feed newFeed) {
|
||||||
// Look up feed in the feedslist
|
// Look up feed in the feedslist
|
||||||
Feed savedFeed = searchFeedByLink(newFeed.getLink());
|
final Feed savedFeed = searchFeedByLink(newFeed.getLink());
|
||||||
if (savedFeed == null) {
|
if (savedFeed == null) {
|
||||||
Log.d(TAG,
|
Log.d(TAG,
|
||||||
"Found no existing Feed with title " + newFeed.getTitle()
|
"Found no existing Feed with title " + newFeed.getTitle()
|
||||||
|
@ -257,17 +258,20 @@ public class FeedManager {
|
||||||
Log.d(TAG, "Feed with title " + newFeed.getTitle()
|
Log.d(TAG, "Feed with title " + newFeed.getTitle()
|
||||||
+ " already exists. Syncing new with existing one.");
|
+ " already exists. Syncing new with existing one.");
|
||||||
// Look for new or updated Items
|
// 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,
|
FeedItem oldItem = searchFeedItemByLink(savedFeed,
|
||||||
item.getLink());
|
item.getLink());
|
||||||
if (oldItem == null) {
|
if (oldItem == null) {
|
||||||
// item is new
|
// item is new
|
||||||
savedFeed.getItems().add(item);
|
item.setFeed(savedFeed);
|
||||||
|
savedFeed.getItems().add(idx, item);
|
||||||
markItemRead(context, item, false);
|
markItemRead(context, item, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
savedFeed.setLastUpdate(newFeed.getLastUpdate());
|
savedFeed.setLastUpdate(newFeed.getLastUpdate());
|
||||||
setFeed(context, savedFeed);
|
setFeed(context, savedFeed);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -568,6 +572,7 @@ public class FeedManager {
|
||||||
items.add(item);
|
items.add(item);
|
||||||
} while (itemlistCursor.moveToNext());
|
} while (itemlistCursor.moveToNext());
|
||||||
}
|
}
|
||||||
|
Collections.sort(items, new FeedItemPubdateComparator());
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,10 @@ import de.podfetcher.feed.FeedItem;
|
||||||
/** Compares the pubDate of two FeedItems for sorting*/
|
/** Compares the pubDate of two FeedItems for sorting*/
|
||||||
public class FeedItemPubdateComparator implements Comparator<FeedItem> {
|
public class FeedItemPubdateComparator implements Comparator<FeedItem> {
|
||||||
|
|
||||||
|
/** Returns a new instance of this comparator in reverse order.
|
||||||
|
public static FeedItemPubdateComparator newInstance() {
|
||||||
|
FeedItemPubdateComparator
|
||||||
|
}*/
|
||||||
@Override
|
@Override
|
||||||
public int compare(FeedItem lhs, FeedItem rhs) {
|
public int compare(FeedItem lhs, FeedItem rhs) {
|
||||||
return -lhs.getPubDate().compareTo(rhs.getPubDate());
|
return -lhs.getPubDate().compareTo(rhs.getPubDate());
|
||||||
|
|
Loading…
Reference in New Issue