Search in sources :

Example 1 with DownloadLogItemViewHolder

use of de.danoeh.antennapod.view.viewholder.DownloadLogItemViewHolder in project AntennaPod by AntennaPod.

the class DownloadLogAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    DownloadLogItemViewHolder holder;
    if (convertView == null) {
        holder = new DownloadLogItemViewHolder(context, parent);
        holder.itemView.setTag(holder);
    } else {
        holder = (DownloadLogItemViewHolder) convertView.getTag();
    }
    Object item = getItem(position);
    if (item instanceof DownloadStatus) {
        bind(holder, (DownloadStatus) item, position);
    } else if (item instanceof Downloader) {
        bind(holder, (Downloader) item, position);
    }
    return holder.itemView;
}
Also used : DownloadLogItemViewHolder(de.danoeh.antennapod.view.viewholder.DownloadLogItemViewHolder) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Downloader(de.danoeh.antennapod.core.service.download.Downloader)

Example 2 with DownloadLogItemViewHolder

use of de.danoeh.antennapod.view.viewholder.DownloadLogItemViewHolder 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)2 Downloader (de.danoeh.antennapod.core.service.download.Downloader)2 DownloadLogItemViewHolder (de.danoeh.antennapod.view.viewholder.DownloadLogItemViewHolder)2 Activity (android.app.Activity)1 DateUtils (android.text.format.DateUtils)1 Formatter (android.text.format.Formatter)1 Log (android.util.Log)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 BaseAdapter (android.widget.BaseAdapter)1 Toast (android.widget.Toast)1 ContextCompat (androidx.core.content.ContextCompat)1 ListFragment (androidx.fragment.app.ListFragment)1 R (de.danoeh.antennapod.R)1 MainActivity (de.danoeh.antennapod.activity.MainActivity)1 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)1 DownloadRequestCreator (de.danoeh.antennapod.core.service.download.DownloadRequestCreator)1 DownloadService (de.danoeh.antennapod.core.service.download.DownloadService)1 DBReader (de.danoeh.antennapod.core.storage.DBReader)1 DBTasks (de.danoeh.antennapod.core.storage.DBTasks)1