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;
}
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);
});
}
}
}
}
Aggregations