use of de.danoeh.antennapod.core.service.download.DownloadStatus in project AntennaPod by AntennaPod.
the class LocalFeedUpdater method reportSuccess.
/**
* 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);
}
use of de.danoeh.antennapod.core.service.download.DownloadStatus in project AntennaPod by AntennaPod.
the class LocalFeedUpdater method reportError.
private static void reportError(Feed feed, String reasonDetailed) {
DownloadStatus status = new DownloadStatus(feed, feed.getTitle(), DownloadError.ERROR_IO_ERROR, false, reasonDetailed, true);
DBWriter.addDownloadStatus(status);
DBWriter.setFeedLastUpdateFailed(feed.getId(), true);
}
use of de.danoeh.antennapod.core.service.download.DownloadStatus in project AntennaPod by AntennaPod.
the class LocalFeedUpdater method mustReportDownloadSuccessful.
/**
* 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);
// (avoid logging success again if the last update was ok)
return !lastDownloadStatus.isSuccessful();
}
use of de.danoeh.antennapod.core.service.download.DownloadStatus in project AntennaPod by AntennaPod.
the class DownloadLogAdapter method bind.
private void bind(DownloadLogItemViewHolder holder, DownloadStatus status, int position) {
String statusText = "";
if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
statusText += context.getString(R.string.download_type_feed);
} else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
statusText += context.getString(R.string.download_type_media);
}
statusText += " ยท ";
statusText += DateUtils.getRelativeTimeSpanString(status.getCompletionDate().getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0);
holder.status.setText(statusText);
if (status.getTitle() != null) {
holder.title.setText(status.getTitle());
} else {
holder.title.setText(R.string.download_log_title_unknown);
}
if (status.isSuccessful()) {
holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_success_green));
holder.icon.setText("{fa-check-circle}");
holder.icon.setContentDescription(context.getString(R.string.download_successful));
holder.secondaryActionButton.setVisibility(View.INVISIBLE);
holder.reason.setVisibility(View.GONE);
holder.tapForDetails.setVisibility(View.GONE);
} else {
if (status.getReason() == DownloadError.ERROR_PARSER_EXCEPTION_DUPLICATE) {
holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_warning_yellow));
holder.icon.setText("{fa-exclamation-circle}");
} else {
holder.icon.setTextColor(ContextCompat.getColor(context, R.color.download_failed_red));
holder.icon.setText("{fa-times-circle}");
}
holder.icon.setContentDescription(context.getString(R.string.error_label));
holder.reason.setText(status.getReason().getErrorString(context));
holder.reason.setVisibility(View.VISIBLE);
holder.tapForDetails.setVisibility(View.VISIBLE);
if (newerWasSuccessful(position - runningDownloads.size(), status.getFeedfileType(), status.getFeedfileId())) {
holder.secondaryActionButton.setVisibility(View.INVISIBLE);
holder.secondaryActionButton.setOnClickListener(null);
holder.secondaryActionButton.setTag(null);
} else {
holder.secondaryActionIcon.setImageResource(R.drawable.ic_refresh);
holder.secondaryActionButton.setVisibility(View.VISIBLE);
if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
holder.secondaryActionButton.setOnClickListener(v -> {
holder.secondaryActionButton.setVisibility(View.INVISIBLE);
Feed feed = DBReader.getFeed(status.getFeedfileId());
if (feed == null) {
Log.e(TAG, "Could not find feed for feed id: " + status.getFeedfileId());
return;
}
DBTasks.forceRefreshFeed(context, feed, true);
});
} else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
holder.secondaryActionButton.setOnClickListener(v -> {
holder.secondaryActionButton.setVisibility(View.INVISIBLE);
FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId());
if (media == null) {
Log.e(TAG, "Could not find feed media for feed id: " + status.getFeedfileId());
return;
}
DownloadService.download(context, true, DownloadRequestCreator.create(media).build());
((MainActivity) context).showSnackbarAbovePlayer(R.string.status_downloading_label, Toast.LENGTH_SHORT);
});
}
}
}
}
Aggregations