summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
blob: eae1632312d4f4b78f95da79a69333e9a9484e18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package de.danoeh.antennapod.adapter;

import java.text.DateFormat;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.danoeh.antennapod.asynctask.DownloadStatus;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.feed.FeedFile;
import de.danoeh.antennapod.feed.FeedImage;
import de.danoeh.antennapod.feed.FeedMedia;
import de.danoeh.antennapod.util.DownloadError;
import de.danoeh.antennapod.R;

/** Displays a list of DownloadStatus entries. */
public class DownloadLogAdapter extends ArrayAdapter<DownloadStatus> {

	public DownloadLogAdapter(Context context, int textViewResourceId,
			List<DownloadStatus> objects) {
		super(context, textViewResourceId, objects);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		DownloadStatus status = getItem(position);
		FeedFile feedfile = status.getFeedFile();
		if (convertView == null) {
			holder = new Holder();
			LayoutInflater inflater = (LayoutInflater) getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.downloadlog_item, null);
			holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
			holder.type = (TextView) convertView.findViewById(R.id.txtvType);
			holder.date = (TextView) convertView.findViewById(R.id.txtvDate);
			holder.successful = (TextView) convertView
					.findViewById(R.id.txtvStatus);
			holder.reason = (TextView) convertView
					.findViewById(R.id.txtvReason);

			if (feedfile.getClass() == Feed.class) {
				holder.type.setText(R.string.download_type_feed);
			} else if (feedfile.getClass() == FeedMedia.class) {
				holder.type.setText(R.string.download_type_media);
			} else if (feedfile.getClass() == FeedImage.class) {
				holder.type.setText(R.string.download_type_image);
			}
			if (status.getTitle() != null) {
				holder.title.setText(status.getTitle());
			} else {
				holder.title.setText(R.string.download_log_title_unknown);
			}
			holder.date.setText(DateUtils.formatSameDayTime(status
					.getCompletionDate().getTime(), System.currentTimeMillis(),
					DateFormat.SHORT, DateFormat.SHORT));
			if (status.isSuccessful()) {
				holder.successful.setTextColor(convertView.getResources()
						.getColor(R.color.download_success_green));
				holder.successful.setText(R.string.download_successful);
				holder.reason.setVisibility(View.GONE);
			} else {
				holder.successful.setTextColor(convertView.getResources()
						.getColor(R.color.download_failed_red));
				holder.successful.setText(R.string.download_failed);
				String reasonText = DownloadError.getErrorString(
						getContext(), status.getReason());
				if (status.getReasonDetailed() != null) {
					reasonText += ": " + status.getReasonDetailed();
				}
				holder.reason.setText(reasonText);
			}
		} else {
			holder = (Holder) convertView.getTag();
		}

		return convertView;
	}

	static class Holder {
		TextView title;
		TextView type;
		TextView date;
		TextView successful;
		TextView reason;
	}

}