-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomListAdapter.java
142 lines (118 loc) · 5.21 KB
/
CustomListAdapter.java
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package com.cajor.dk.dlna;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;
public class CustomListAdapter extends ArrayAdapter<CustomListItem>
{
private final int layout;
private Context context;
public CustomListAdapter(Context context)
{
super(context, 0);
this.layout = R.layout.list;
this.context = context;
}
@Override
public View getView(final int position, final View convertView, final ViewGroup parent)
{
final View view = getWorkingView(convertView);
final ViewHolder viewHolder = getViewHolder(view);
final CustomListItem entry = getItem(position);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (!prefs.getBoolean("settings_show_icons", true)) {
viewHolder.imageView.setImageResource(android.R.color.transparent);
viewHolder.imageView.setVisibility(View.GONE);
viewHolder.containerView.setPadding(16,
viewHolder.containerView.getPaddingTop(),
viewHolder.containerView.getPaddingRight(),
viewHolder.containerView.getPaddingBottom());
} else {
if (entry.getHideIcon()) {
viewHolder.imageView.setImageResource(android.R.color.transparent);
viewHolder.imageView.setVisibility(View.GONE);
viewHolder.containerView.setPadding(16,
viewHolder.containerView.getPaddingTop(),
viewHolder.containerView.getPaddingRight(),
viewHolder.containerView.getPaddingBottom());
} else {
String iconUrl = entry.getIconUrl();
if (iconUrl != null && prefs.getBoolean("settings_show_device_icons", true)) {
UrlImageViewHelper.setUrlDrawable(viewHolder.imageView, iconUrl, entry.getIcon());
} else {
viewHolder.imageView.setImageResource(entry.getIcon());
}
viewHolder.imageView.setVisibility(View.VISIBLE);
viewHolder.containerView.setPadding(0,
viewHolder.containerView.getPaddingTop(),
viewHolder.containerView.getPaddingRight(),
viewHolder.containerView.getPaddingBottom());
}
}
viewHolder.titleView.setText(entry.getTitle());
String description = entry.getDescription();
if (description == null)
viewHolder.description2View.setVisibility(View.GONE);
else {
viewHolder.description2View.setVisibility(View.VISIBLE);
viewHolder.descriptionView.setText(description);
}
String description2 = entry.getDescription2();
if (description2 == null)
viewHolder.description2View.setVisibility(View.GONE);
else {
viewHolder.description2View.setVisibility(View.VISIBLE);
viewHolder.description2View.setText(description2);
}
return view;
}
private View getWorkingView(final View convertView)
{
View workingView;
if(null == convertView)
{
final Context context = getContext();
final LayoutInflater inflater =
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
workingView = inflater.inflate(layout, null);
}
else
workingView = convertView;
return workingView;
}
private ViewHolder getViewHolder(final View workingView)
{
// The viewHolder allows us to avoid re-looking up view references
// Since views are recycled, these references will never change
final Object tag = workingView.getTag();
ViewHolder viewHolder;
if(null == tag || !(tag instanceof ViewHolder))
{
viewHolder = new ViewHolder();
viewHolder.imageView = (ImageView)workingView.findViewById(R.id.icon);
viewHolder.titleView = (TextView)workingView.findViewById(R.id.title);
viewHolder.containerView = (RelativeLayout)workingView.findViewById(R.id.container);
viewHolder.descriptionView = (TextView)workingView.findViewById(R.id.description);
viewHolder.description2View = (TextView)workingView.findViewById(R.id.description2);
workingView.setTag(viewHolder);
}
else
viewHolder = (ViewHolder) tag;
return viewHolder;
}
private static class ViewHolder
{
public TextView titleView;
public RelativeLayout containerView;
public TextView descriptionView;
public TextView description2View;
public ImageView imageView;
}
}