blob: 66fa79a4e56240cb51319476aea1395eb397f105 (
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
|
package de.danoeh.antennapod.adapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.discovery.PodcastSearchResult;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
public class FeedDiscoverAdapter extends BaseAdapter {
private final WeakReference<MainActivity> mainActivityRef;
private final List<PodcastSearchResult> data = new ArrayList<>();
public FeedDiscoverAdapter(MainActivity mainActivity) {
this.mainActivityRef = new WeakReference<>(mainActivity);
}
public void updateData(List<PodcastSearchResult> newData) {
data.clear();
data.addAll(newData);
notifyDataSetChanged();
}
@Override
public int getCount() {
return data.size();
}
@Override
public PodcastSearchResult getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder;
if (convertView == null) {
convertView = View.inflate(mainActivityRef.get(), R.layout.quick_feed_discovery_item, null);
holder = new Holder();
holder.imageView = convertView.findViewById(R.id.discovery_cover);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
final PodcastSearchResult podcast = getItem(position);
holder.imageView.setContentDescription(podcast.title);
Glide.with(mainActivityRef.get())
.load(podcast.imageUrl)
.apply(new RequestOptions()
.placeholder(R.color.light_gray)
.fitCenter()
.dontAnimate())
.into(holder.imageView);
return convertView;
}
static class Holder {
ImageView imageView;
}
}
|