blob: 1968c0b620ebdabecbe80b38d822486032f23421 (
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
package de.danoeh.antennapod.adapter.itunes;
import android.content.Context;
import androidx.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.FitCenter;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import de.danoeh.antennapod.discovery.PodcastSearchResult;
import java.util.List;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> {
/**
* Related Context
*/
private final Context context;
/**
* List holding the podcasts found in the search
*/
private final List<PodcastSearchResult> data;
/**
* Constructor.
*
* @param context Related context
* @param objects Search result
*/
public ItunesAdapter(Context context, List<PodcastSearchResult> objects) {
super(context, 0, objects);
this.data = objects;
this.context = context;
}
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
//Current podcast
PodcastSearchResult podcast = data.get(position);
//ViewHolder
PodcastViewHolder viewHolder;
//Resulting view
View view;
//Handle view holder stuff
if(convertView == null) {
view = ((MainActivity) context).getLayoutInflater()
.inflate(R.layout.itunes_podcast_listitem, parent, false);
viewHolder = new PodcastViewHolder(view);
view.setTag(viewHolder);
} else {
view = convertView;
viewHolder = (PodcastViewHolder) view.getTag();
}
// Set the title
viewHolder.titleView.setText(podcast.title);
if (podcast.author != null && ! podcast.author.trim().isEmpty()) {
viewHolder.authorView.setText(podcast.author);
viewHolder.authorView.setVisibility(View.VISIBLE);
} else if (podcast.feedUrl != null && !podcast.feedUrl.contains("itunes.apple.com")) {
viewHolder.authorView.setText(podcast.feedUrl);
viewHolder.authorView.setVisibility(View.VISIBLE);
} else {
viewHolder.authorView.setVisibility(View.GONE);
}
//Update the empty imageView with the image from the feed
Glide.with(context)
.load(podcast.imageUrl)
.apply(new RequestOptions()
.placeholder(R.color.light_gray)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.transforms(new FitCenter(),
new RoundedCorners((int) (4 * context.getResources().getDisplayMetrics().density)))
.dontAnimate())
.into(viewHolder.coverView);
//Feed the grid view
return view;
}
/**
* View holder object for the GridView
*/
static class PodcastViewHolder {
/**
* ImageView holding the Podcast image
*/
final ImageView coverView;
/**
* TextView holding the Podcast title
*/
final TextView titleView;
final TextView authorView;
/**
* Constructor
* @param view GridView cell
*/
PodcastViewHolder(View view){
coverView = view.findViewById(R.id.imgvCover);
titleView = view.findViewById(R.id.txtvTitle);
authorView = view.findViewById(R.id.txtvAuthor);
}
}
}
|