summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/danoeh/antennapod/adapter/SimpleIconListAdapter.java
blob: 2a3c3b850e512abe415116c5c969e3953bf5ae24 (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
package de.danoeh.antennapod.adapter;

import android.content.Context;
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.request.RequestOptions;
import de.danoeh.antennapod.R;

import java.util.ArrayList;

/**
 * Displays a list of items that have a subtitle and an icon.
 */
public class SimpleIconListAdapter extends ArrayAdapter<SimpleIconListAdapter.ListItem> {
    private final Context context;
    private final ArrayList<ListItem> developers;

    public SimpleIconListAdapter(Context context, ArrayList<ListItem> developers) {
        super(context, R.layout.simple_icon_list_item, developers);
        this.context = context;
        this.developers = developers;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        if (view == null) {
            view = View.inflate(context, R.layout.simple_icon_list_item, null);
        }

        ListItem item = developers.get(position);
        ((TextView) view.findViewById(R.id.title)).setText(item.title);
        ((TextView) view.findViewById(R.id.subtitle)).setText(item.subtitle);
        Glide.with(context)
                .load(item.imageUrl)
                .apply(new RequestOptions()
                        .diskCacheStrategy(DiskCacheStrategy.NONE)
                        .fitCenter()
                        .dontAnimate())
                .into(((ImageView) view.findViewById(R.id.icon)));
        return view;
    }

    public static class ListItem {
        final String title;
        final String subtitle;
        final String imageUrl;

        public ListItem(String title, String subtitle, String imageUrl) {
            this.title = title;
            this.subtitle = subtitle;
            this.imageUrl = imageUrl;
        }
    }
}