Merge pull request #1172 from TomHennen/fix_new_episodes

Fix new episodes
This commit is contained in:
Tom Hennen 2015-09-07 14:27:36 -04:00
commit 6780980b1c
3 changed files with 29 additions and 26 deletions

View File

@ -29,12 +29,10 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
* This method is executed on an internal single thread executor.
*
* @param context Used for accessing the DB.
* @param mediaIds If this list is not empty, the method will only download a candidate for automatic downloading if
* its media ID is in the mediaIds list.
* @return A Runnable that will be submitted to an ExecutorService.
*/
@Override
public Runnable autoDownloadUndownloadedItems(final Context context, final long... mediaIds) {
public Runnable autoDownloadUndownloadedItems(final Context context) {
return new Runnable() {
@Override
public void run() {
@ -53,9 +51,6 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
Log.d(TAG, "Performing auto-dl of undownloaded episodes");
List<FeedItem> candidates;
if(mediaIds.length > 0) {
candidates = DBReader.getFeedItems(context, mediaIds);
} else {
final List<FeedItem> queue = DBReader.getQueue(context);
final List<FeedItem> newItems = DBReader.getNewItemsList(context);
candidates = new ArrayList<FeedItem>(queue.size() + newItems.size());
@ -65,7 +60,6 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
candidates.add(newItem);
}
}
}
// filter items that are not auto downloadable
Iterator<FeedItem> it = candidates.iterator();

View File

@ -12,9 +12,7 @@ public interface AutomaticDownloadAlgorithm {
* This method is executed on an internal single thread executor.
*
* @param context Used for accessing the DB.
* @param mediaIds If this list is not empty, the method will only download a candidate for automatic downloading if
* its media ID is in the mediaIds list.
* @return A Runnable that will be submitted to an ExecutorService.
*/
public Runnable autoDownloadUndownloadedItems(Context context, long... mediaIds);
public Runnable autoDownloadUndownloadedItems(Context context);
}

View File

@ -374,14 +374,12 @@ public final class DBTasks {
* This method is executed on an internal single thread executor.
*
* @param context Used for accessing the DB.
* @param mediaIds If this list is not empty, the method will only download a candidate for automatic downloading if
* its media ID is in the mediaIds list.
* @return A Future that can be used for waiting for the methods completion.
*/
public static Future<?> autodownloadUndownloadedItems(final Context context, final long... mediaIds) {
public static Future<?> autodownloadUndownloadedItems(final Context context) {
Log.d(TAG, "autodownloadUndownloadedItems");
return autodownloadExec.submit(ClientConfig.dbTasksCallbacks.getAutomaticDownloadAlgorithm()
.autoDownloadUndownloadedItems(context, mediaIds));
.autoDownloadUndownloadedItems(context));
}
@ -516,22 +514,27 @@ public final class DBTasks {
Collections.sort(newFeed.getItems(), new FeedItemPubdateComparator());
final boolean markNewItems;
if (newFeed.getPageNr() == savedFeed.getPageNr()) {
if (savedFeed.compareWithOther(newFeed)) {
Log.d(TAG, "Feed has updated attribute values. Updating old feed's attributes");
savedFeed.updateFromOther(newFeed);
}
markNewItems = true;
} else {
Log.d(TAG, "New feed has a higher page number. Merging without marking as unread");
markNewItems = false;
Log.d(TAG, "New feed has a higher page number.");
savedFeed.setNextPageLink(newFeed.getNextPageLink());
}
if (savedFeed.getPreferences().compareWithOther(newFeed.getPreferences())) {
Log.d(TAG, "Feed has updated preferences. Updating old feed's preferences");
savedFeed.getPreferences().updateFromOther(newFeed.getPreferences());
}
// get the most recent date now, before we start changing the list
FeedItem priorMostRecent = savedFeed.getMostRecentItem();
Date priorMostRecentDate = null;
if (priorMostRecent != null) {
priorMostRecentDate = priorMostRecent.getPubDate();
}
// Look for new or updated Items
for (int idx = 0; idx < newFeed.getItems().size(); idx++) {
final FeedItem item = newFeed.getItems().get(idx);
@ -542,7 +545,15 @@ public final class DBTasks {
item.setFeed(savedFeed);
item.setAutoDownload(savedFeed.getPreferences().getAutoDownload());
savedFeed.getItems().add(idx, item);
if (markNewItems) {
// only mark the item new if it actually occurs
// before the most recent item (before we started adding things)
// (if the most recent date is null then we can assume there are no items
// and this is the first, hence 'new')
if (priorMostRecentDate == null ||
priorMostRecentDate.before(item.getPubDate())) {
Log.d(TAG, "Marking item published on " + item.getPubDate() +
" new, prior most recent date = " + priorMostRecentDate);
item.setNew();
}
} else {