Fixed items without pubdate getting assigned the current date on every single refresh

This commit is contained in:
ByteHamster 2020-09-20 12:24:11 +02:00
parent 410ebfe98c
commit ff116ccd8c
4 changed files with 20 additions and 18 deletions

View File

@ -352,7 +352,7 @@ public class Feed extends FeedFile implements ImageResource {
Date mostRecentDate = new Date(0);
FeedItem mostRecentItem = null;
for (FeedItem item : items) {
if (item.getPubDate().after(mostRecentDate)) {
if (item.getPubDate() != null && item.getPubDate().after(mostRecentDate)) {
mostRecentDate = item.getPubDate();
mostRecentItem = item;
}

View File

@ -18,7 +18,6 @@ import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.concurrent.Callable;
public class FeedParserTask implements Callable<FeedHandlerResult> {
@ -104,13 +103,6 @@ public class FeedParserTask implements Callable<FeedHandlerResult> {
if (item.getTitle() == null) {
throw new InvalidFeedException("Item has no title: " + item);
}
if (item.getPubDate() == null) {
Log.e(TAG, "Item has no pubDate. Using current time as pubDate");
if (item.getTitle() != null) {
Log.e(TAG, "Title of invalid item: " + item.getTitle());
}
item.setPubDate(new Date());
}
}
}

View File

@ -21,6 +21,7 @@ import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Set;
@ -593,6 +594,11 @@ public class PodDBAdapter {
* @return the id of the entry
*/
private long setFeedItem(FeedItem item, boolean saveFeed) {
if (item.getId() == 0 && item.getPubDate() == null) {
Log.e(TAG, "Newly saved item has no pubDate. Using current date as pubDate");
item.setPubDate(new Date());
}
ContentValues values = new ContentValues();
values.put(KEY_TITLE, item.getTitle());
values.put(KEY_LINK, item.getLink());

View File

@ -4,16 +4,20 @@ import java.util.Comparator;
import de.danoeh.antennapod.core.feed.FeedItem;
/** Compares the pubDate of two FeedItems for sorting*/
/**
* 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 rhs.getPubDate().compareTo(lhs.getPubDate());
}
/**
* Returns a new instance of this comparator in reverse order.
*/
@Override
public int compare(FeedItem lhs, FeedItem rhs) {
if (rhs.getPubDate() == null || lhs.getPubDate() == null) {
return 0;
}
return rhs.getPubDate().compareTo(lhs.getPubDate());
}
}