Merge pull request #1172 from TomHennen/fix_new_episodes
Fix new episodes
This commit is contained in:
commit
6780980b1c
@ -29,12 +29,10 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
|
|||||||
* This method is executed on an internal single thread executor.
|
* This method is executed on an internal single thread executor.
|
||||||
*
|
*
|
||||||
* @param context Used for accessing the DB.
|
* @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.
|
* @return A Runnable that will be submitted to an ExecutorService.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Runnable autoDownloadUndownloadedItems(final Context context, final long... mediaIds) {
|
public Runnable autoDownloadUndownloadedItems(final Context context) {
|
||||||
return new Runnable() {
|
return new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -53,9 +51,6 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
|
|||||||
Log.d(TAG, "Performing auto-dl of undownloaded episodes");
|
Log.d(TAG, "Performing auto-dl of undownloaded episodes");
|
||||||
|
|
||||||
List<FeedItem> candidates;
|
List<FeedItem> candidates;
|
||||||
if(mediaIds.length > 0) {
|
|
||||||
candidates = DBReader.getFeedItems(context, mediaIds);
|
|
||||||
} else {
|
|
||||||
final List<FeedItem> queue = DBReader.getQueue(context);
|
final List<FeedItem> queue = DBReader.getQueue(context);
|
||||||
final List<FeedItem> newItems = DBReader.getNewItemsList(context);
|
final List<FeedItem> newItems = DBReader.getNewItemsList(context);
|
||||||
candidates = new ArrayList<FeedItem>(queue.size() + newItems.size());
|
candidates = new ArrayList<FeedItem>(queue.size() + newItems.size());
|
||||||
@ -65,7 +60,6 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
|
|||||||
candidates.add(newItem);
|
candidates.add(newItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// filter items that are not auto downloadable
|
// filter items that are not auto downloadable
|
||||||
Iterator<FeedItem> it = candidates.iterator();
|
Iterator<FeedItem> it = candidates.iterator();
|
||||||
|
@ -12,9 +12,7 @@ public interface AutomaticDownloadAlgorithm {
|
|||||||
* This method is executed on an internal single thread executor.
|
* This method is executed on an internal single thread executor.
|
||||||
*
|
*
|
||||||
* @param context Used for accessing the DB.
|
* @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.
|
* @return A Runnable that will be submitted to an ExecutorService.
|
||||||
*/
|
*/
|
||||||
public Runnable autoDownloadUndownloadedItems(Context context, long... mediaIds);
|
public Runnable autoDownloadUndownloadedItems(Context context);
|
||||||
}
|
}
|
||||||
|
@ -374,14 +374,12 @@ public final class DBTasks {
|
|||||||
* This method is executed on an internal single thread executor.
|
* This method is executed on an internal single thread executor.
|
||||||
*
|
*
|
||||||
* @param context Used for accessing the DB.
|
* @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.
|
* @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");
|
Log.d(TAG, "autodownloadUndownloadedItems");
|
||||||
return autodownloadExec.submit(ClientConfig.dbTasksCallbacks.getAutomaticDownloadAlgorithm()
|
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());
|
Collections.sort(newFeed.getItems(), new FeedItemPubdateComparator());
|
||||||
|
|
||||||
final boolean markNewItems;
|
|
||||||
if (newFeed.getPageNr() == savedFeed.getPageNr()) {
|
if (newFeed.getPageNr() == savedFeed.getPageNr()) {
|
||||||
if (savedFeed.compareWithOther(newFeed)) {
|
if (savedFeed.compareWithOther(newFeed)) {
|
||||||
Log.d(TAG, "Feed has updated attribute values. Updating old feed's attributes");
|
Log.d(TAG, "Feed has updated attribute values. Updating old feed's attributes");
|
||||||
savedFeed.updateFromOther(newFeed);
|
savedFeed.updateFromOther(newFeed);
|
||||||
}
|
}
|
||||||
markNewItems = true;
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "New feed has a higher page number. Merging without marking as unread");
|
Log.d(TAG, "New feed has a higher page number.");
|
||||||
markNewItems = false;
|
|
||||||
savedFeed.setNextPageLink(newFeed.getNextPageLink());
|
savedFeed.setNextPageLink(newFeed.getNextPageLink());
|
||||||
}
|
}
|
||||||
if (savedFeed.getPreferences().compareWithOther(newFeed.getPreferences())) {
|
if (savedFeed.getPreferences().compareWithOther(newFeed.getPreferences())) {
|
||||||
Log.d(TAG, "Feed has updated preferences. Updating old feed's preferences");
|
Log.d(TAG, "Feed has updated preferences. Updating old feed's preferences");
|
||||||
savedFeed.getPreferences().updateFromOther(newFeed.getPreferences());
|
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
|
// Look for new or updated Items
|
||||||
for (int idx = 0; idx < newFeed.getItems().size(); idx++) {
|
for (int idx = 0; idx < newFeed.getItems().size(); idx++) {
|
||||||
final FeedItem item = newFeed.getItems().get(idx);
|
final FeedItem item = newFeed.getItems().get(idx);
|
||||||
@ -542,7 +545,15 @@ public final class DBTasks {
|
|||||||
item.setFeed(savedFeed);
|
item.setFeed(savedFeed);
|
||||||
item.setAutoDownload(savedFeed.getPreferences().getAutoDownload());
|
item.setAutoDownload(savedFeed.getPreferences().getAutoDownload());
|
||||||
savedFeed.getItems().add(idx, item);
|
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();
|
item.setNew();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user