11 |
import android.widget.BaseAdapter; |
import android.widget.BaseAdapter; |
12 |
import android.widget.ImageView; |
import android.widget.ImageView; |
13 |
import android.widget.TextView; |
import android.widget.TextView; |
14 |
|
import dk.thoerup.android.traininfo.common.DepartureEntry; |
15 |
|
|
16 |
public class DepartureListAdapter extends BaseAdapter { |
public class DepartureListAdapter extends BaseAdapter { |
17 |
|
|
18 |
|
boolean showDetails = false; |
19 |
private List<DepartureEntry> departures; |
private List<DepartureEntry> departures; |
20 |
LayoutInflater inflater; |
LayoutInflater inflater; |
21 |
Context context; |
Context context; |
29 |
super(); |
super(); |
30 |
this.context = context; |
this.context = context; |
31 |
|
|
32 |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
33 |
|
} |
34 |
|
|
35 |
|
|
36 |
|
public void toggleShowDetails() { |
37 |
|
showDetails = !showDetails; |
38 |
|
notifyDataSetChanged(); |
39 |
} |
} |
40 |
|
|
41 |
public void setDepartures(List<DepartureEntry> departures) { |
public void setDepartures(List<DepartureEntry> departures) { |
74 |
((TextView) root.findViewById(R.id.Time)).setText(station.getTime()); |
((TextView) root.findViewById(R.id.Time)).setText(station.getTime()); |
75 |
((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination()); |
((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination()); |
76 |
|
|
77 |
if (station.getStatus().length() > 0 || station.getNote().length() > 0) { |
|
78 |
|
if ( (station.getStatus() != null && station.getStatus().length() > 0) || (station.getNote() != null && station.getNote().length() > 0) ) { |
79 |
ImageView image = (ImageView) root.findViewById(R.id.InfoIcon); |
ImageView image = (ImageView) root.findViewById(R.id.InfoIcon); |
80 |
|
|
81 |
String status = station.getStatus().toLowerCase(); |
|
82 |
String note = station.getNote().toLowerCase(); |
String status = (station.getStatus() != null) ? station.getStatus().toLowerCase() : ""; |
83 |
|
String note = (station.getNote() != null) ? station.getNote().toLowerCase() : ""; |
84 |
|
|
85 |
int iconID; |
int iconID; |
86 |
if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) { |
if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) { |
96 |
|
|
97 |
ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); |
ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); |
98 |
String trainNumber = station.getTrainNumber().trim(); |
String trainNumber = station.getTrainNumber().trim(); |
99 |
String code = trainNumber.split(" ")[0].toLowerCase(); |
String trainParts[] = trainNumber.split(" "); |
100 |
|
String code = trainParts[0].toLowerCase(); |
101 |
|
|
102 |
|
if (showDetails) { |
103 |
|
root.findViewById(R.id.departureRow2).setVisibility( View.VISIBLE ); |
104 |
|
((TextView) root.findViewById(R.id.TrainNumber)).setText(trainNumber); |
105 |
|
((TextView) root.findViewById(R.id.Origin)).setText( station.getOrigin() ); |
106 |
|
} |
107 |
|
|
108 |
Integer imageId = imageMap.get(code); |
Integer imageId = imageMap.get(code); |
109 |
if (imageId != null) { |
if (imageId != null) { |
110 |
typeIcon.setImageResource(imageId); |
typeIcon.setImageResource(imageId); |
115 |
return root; |
return root; |
116 |
} |
} |
117 |
|
|
118 |
|
//TODO: all these traintypes / icons should be explained somewhere |
119 |
private static void buildImageMap() { |
private static void buildImageMap() { |
120 |
imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva |
imageMap.put("ec", R.drawable.ec); //EC = EuroCity |
121 |
imageMap.put("re", R.drawable.re); //RE = Regionaltog |
// Missing FP ? |
|
imageMap.put("l", R.drawable.lyn); //L = Lyn |
|
122 |
imageMap.put("ic", R.drawable.ic); //IC = Intercity |
imageMap.put("ic", R.drawable.ic); //IC = Intercity |
123 |
|
imageMap.put("il", R.drawable.il); //IntercityLyn Nonstop |
124 |
|
// Missing Int ? |
125 |
|
// Missing IR ? |
126 |
|
imageMap.put("l", R.drawable.lyn); //L = Lyn |
127 |
imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen) |
imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen) |
128 |
|
// Missing PX |
129 |
|
imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva |
130 |
|
imageMap.put("re", R.drawable.re); //RE = Regionaltog |
131 |
imageMap.put("ør", R.drawable.or); //ØR = Øresundstog |
imageMap.put("ør", R.drawable.or); //ØR = Øresundstog |
132 |
imageMap.put("ec", R.drawable.ec); //EC = EuroCity |
|
133 |
imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner |
imageMap.put("sj", R.drawable.sj); //SJ=Svenska Jernbaner -- not mentioned on bane.dk |
134 |
imageMap.put("ie", R.drawable.ie); |
imageMap.put("ie", R.drawable.ie); //what's this ?? -- not mentioned on bane.dk |
135 |
|
|
136 |
|
//Missing IB ? -- not mentioned on bane.dk |
137 |
|
//Missing RX ? -- not mentioned on bane.dk |
138 |
|
|
139 |
|
|
140 |
imageMap.put("a", R.drawable.stog_a); //S-Tog: A banen #00b5f1 |
imageMap.put("a", R.drawable.stog_a); //S-Tog: A banen #00b5f1 |
141 |
imageMap.put("b", R.drawable.stog_b); //S-Tog:B banen #5aba52 |
imageMap.put("b", R.drawable.stog_b); //S-Tog:B banen #5aba52 |