Local feeds, add successful download log entry (#4608)
Co-authored-by: moralesg
This commit is contained in:
parent
370df3a26c
commit
3a87982628
|
@ -14,6 +14,7 @@ import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -25,6 +26,7 @@ import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.R;
|
import de.danoeh.antennapod.core.R;
|
||||||
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
||||||
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.core.util.DateUtils;
|
import de.danoeh.antennapod.core.util.DateUtils;
|
||||||
|
@ -110,6 +112,10 @@ public class LocalFeedUpdater {
|
||||||
// deleting played state or position in case the folder is temporarily unavailable.
|
// deleting played state or position in case the folder is temporarily unavailable.
|
||||||
boolean removeUnlistedItems = (newItems.size() >= 1);
|
boolean removeUnlistedItems = (newItems.size() >= 1);
|
||||||
DBTasks.updateFeed(context, feed, removeUnlistedItems);
|
DBTasks.updateFeed(context, feed, removeUnlistedItems);
|
||||||
|
|
||||||
|
if (mustReportDownloadSuccessful(feed)) {
|
||||||
|
reportSuccess(feed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,4 +187,35 @@ public class LocalFeedUpdater {
|
||||||
DBWriter.addDownloadStatus(status);
|
DBWriter.addDownloadStatus(status);
|
||||||
DBWriter.setFeedLastUpdateFailed(feed.getId(), true);
|
DBWriter.setFeedLastUpdateFailed(feed.getId(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports a successful download status.
|
||||||
|
*/
|
||||||
|
private static void reportSuccess(Feed feed) {
|
||||||
|
DownloadStatus status = new DownloadStatus(feed, feed.getTitle(),
|
||||||
|
DownloadError.SUCCESS, true, null, true);
|
||||||
|
DBWriter.addDownloadStatus(status);
|
||||||
|
DBWriter.setFeedLastUpdateFailed(feed.getId(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Answers if reporting success is needed for the given feed.
|
||||||
|
*/
|
||||||
|
private static boolean mustReportDownloadSuccessful(Feed feed) {
|
||||||
|
List<DownloadStatus> downloadStatuses = DBReader.getFeedDownloadLog(feed.getId());
|
||||||
|
|
||||||
|
if (downloadStatuses.isEmpty()) {
|
||||||
|
// report success if never reported before
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(downloadStatuses, (downloadStatus1, downloadStatus2) ->
|
||||||
|
downloadStatus1.getCompletionDate().compareTo(downloadStatus2.getCompletionDate()));
|
||||||
|
|
||||||
|
DownloadStatus lastDownloadStatus = downloadStatuses.get(downloadStatuses.size() - 1);
|
||||||
|
|
||||||
|
// report success if the last update was not successful
|
||||||
|
// (avoid logging success again if the last update was ok)
|
||||||
|
return !lastDownloadStatus.isSuccessful();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue