Search in sources :

Example 11 with DownloadStatus

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);
}
Also used : DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus)

Example 12 with DownloadStatus

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);
}
Also used : DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus)

Example 13 with DownloadStatus

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();
}
Also used : DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus)

Example 14 with DownloadStatus

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);
                });
            }
        }
    }
}
Also used : DateUtils(android.text.format.DateUtils) DownloadRequestCreator(de.danoeh.antennapod.core.service.download.DownloadRequestCreator) ArrayList(java.util.ArrayList) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) Toast(android.widget.Toast) View(android.view.View) DownloadLogItemViewHolder(de.danoeh.antennapod.view.viewholder.DownloadLogItemViewHolder) ContextCompat(androidx.core.content.ContextCompat) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Log(android.util.Log) Feed(de.danoeh.antennapod.model.feed.Feed) Formatter(android.text.format.Formatter) Downloader(de.danoeh.antennapod.core.service.download.Downloader) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ThemeUtils(de.danoeh.antennapod.ui.common.ThemeUtils) R(de.danoeh.antennapod.R) DownloadError(de.danoeh.antennapod.core.util.DownloadError) ViewGroup(android.view.ViewGroup) MainActivity(de.danoeh.antennapod.activity.MainActivity) List(java.util.List) BaseAdapter(android.widget.BaseAdapter) DBReader(de.danoeh.antennapod.core.storage.DBReader) ListFragment(androidx.fragment.app.ListFragment) Activity(android.app.Activity) DownloadService(de.danoeh.antennapod.core.service.download.DownloadService) DBTasks(de.danoeh.antennapod.core.storage.DBTasks) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Feed(de.danoeh.antennapod.model.feed.Feed)

Aggregations

DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)14 ArrayList (java.util.ArrayList)6 Downloader (de.danoeh.antennapod.core.service.download.Downloader)5 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)4 Feed (de.danoeh.antennapod.model.feed.Feed)4 File (java.io.File)4 Cursor (android.database.Cursor)3 DownloadStatusComparator (de.danoeh.antennapod.core.util.comparator.DownloadStatusComparator)3 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)3 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)3 Log (android.util.Log)2 View (android.view.View)2 ListFragment (androidx.fragment.app.ListFragment)2 R (de.danoeh.antennapod.R)2 MainActivity (de.danoeh.antennapod.activity.MainActivity)2 DownloadService (de.danoeh.antennapod.core.service.download.DownloadService)2 DBReader (de.danoeh.antennapod.core.storage.DBReader)2 List (java.util.List)2 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1