1 |
torben |
362 |
package dk.thoerup.traininfo; |
2 |
|
|
|
3 |
|
|
import android.content.Context; |
4 |
|
|
import android.view.LayoutInflater; |
5 |
|
|
import android.view.View; |
6 |
|
|
import android.view.ViewGroup; |
7 |
|
|
import android.widget.BaseAdapter; |
8 |
torben |
365 |
import android.widget.TextView; |
9 |
torben |
1066 |
import dk.thoerup.android.traininfo.common.TimetableBean; |
10 |
|
|
import dk.thoerup.android.traininfo.common.TimetableEntry; |
11 |
torben |
362 |
|
12 |
|
|
public class TimetableListAdapter extends BaseAdapter { |
13 |
|
|
|
14 |
torben |
1066 |
private TimetableBean timetable; |
15 |
torben |
362 |
LayoutInflater inflater; |
16 |
|
|
Context context; |
17 |
|
|
|
18 |
torben |
366 |
@Override |
19 |
|
|
public boolean isEnabled(int position) { |
20 |
torben |
1416 |
return ( timetable.entries.get(position).getStationEntry() != null ); |
21 |
torben |
366 |
} |
22 |
|
|
|
23 |
torben |
362 |
public TimetableListAdapter(Context context) { |
24 |
|
|
super(); |
25 |
|
|
this.context = context; |
26 |
|
|
|
27 |
|
|
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
28 |
|
|
} |
29 |
|
|
|
30 |
torben |
1066 |
public void setTimetable(TimetableBean timetable) { |
31 |
torben |
362 |
this.timetable = timetable; |
32 |
|
|
notifyDataSetChanged(); |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
@Override |
36 |
|
|
public int getCount() { |
37 |
|
|
if (timetable != null) |
38 |
torben |
1066 |
return timetable.entries.size(); |
39 |
torben |
362 |
else |
40 |
|
|
return 0; |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
@Override |
44 |
|
|
public Object getItem(int position) { |
45 |
|
|
return null; |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
@Override |
49 |
|
|
public long getItemId(int position) { |
50 |
|
|
return position; |
51 |
|
|
} |
52 |
|
|
|
53 |
torben |
1257 |
String getTranslated(String str) { |
54 |
|
|
if (str == null) |
55 |
|
|
return str; |
56 |
|
|
|
57 |
|
|
str = str.replace("Aflyst", context.getString(R.string.timetablelist_cancel) ); |
58 |
|
|
return str; |
59 |
|
|
} |
60 |
|
|
|
61 |
torben |
362 |
@Override |
62 |
|
|
public View getView(int position, View convertView, ViewGroup parent) { |
63 |
torben |
1066 |
TimetableEntry entry = timetable.entries.get(position); |
64 |
torben |
365 |
|
65 |
torben |
491 |
View root = inflater.inflate(R.layout.timetablerow , parent, false); |
66 |
torben |
365 |
|
67 |
|
|
TextView station = (TextView) root.findViewById(R.id.Station); |
68 |
torben |
1257 |
station.setText( entry.getStation() ); |
69 |
torben |
365 |
|
70 |
|
|
TextView arrival = (TextView) root.findViewById(R.id.Arrival); |
71 |
torben |
1257 |
arrival.setText( getTranslated(entry.getArrival()) ); |
72 |
torben |
365 |
|
73 |
|
|
TextView departure = (TextView) root.findViewById(R.id.Departure); |
74 |
torben |
1257 |
departure.setText( getTranslated(entry.getDeparture()) ); |
75 |
torben |
365 |
|
76 |
|
|
|
77 |
torben |
1066 |
if (entry.isCurrent()) { |
78 |
torben |
365 |
final int bgcolor = 0xFFFFFFFF; |
79 |
|
|
final int fgcolor = 0xFF000000; |
80 |
|
|
|
81 |
|
|
station.setTextColor(fgcolor); |
82 |
|
|
arrival.setTextColor(fgcolor); |
83 |
|
|
departure.setTextColor(fgcolor); |
84 |
|
|
root.setBackgroundColor(bgcolor); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
return root; |
88 |
torben |
362 |
} |
89 |
|
|
|
90 |
|
|
} |