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 |
|
public void setShowDetails(boolean showDetails) { |
36 |
|
this.showDetails = showDetails; |
37 |
|
} |
38 |
|
|
39 |
|
public boolean getShowDetails() { |
40 |
|
return showDetails; |
41 |
|
} |
42 |
|
|
43 |
|
public void toggleShowDetails() { |
44 |
|
showDetails = !showDetails; |
45 |
|
notifyDataSetChanged(); |
46 |
} |
} |
47 |
|
|
48 |
public void setDepartures(List<DepartureEntry> departures) { |
public void setDepartures(List<DepartureEntry> departures) { |
103 |
|
|
104 |
ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); |
ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); |
105 |
String trainNumber = station.getTrainNumber().trim(); |
String trainNumber = station.getTrainNumber().trim(); |
106 |
String code = trainNumber.split(" ")[0].toLowerCase(); |
String trainParts[] = trainNumber.split(" "); |
107 |
|
String code = trainParts[0].toLowerCase(); |
108 |
|
|
109 |
|
if (showDetails) { |
110 |
|
root.findViewById(R.id.departureRow2).setVisibility( View.VISIBLE ); |
111 |
|
((TextView) root.findViewById(R.id.TrainNumber)).setText(trainNumber); |
112 |
|
((TextView) root.findViewById(R.id.Origin)).setText( station.getOrigin() ); |
113 |
|
} |
114 |
|
|
115 |
Integer imageId = imageMap.get(code); |
Integer imageId = imageMap.get(code); |
116 |
if (imageId != null) { |
if (imageId != null) { |
117 |
typeIcon.setImageResource(imageId); |
typeIcon.setImageResource(imageId); |
122 |
return root; |
return root; |
123 |
} |
} |
124 |
|
|
125 |
|
//TODO: all these traintypes / icons should be explained somewhere |
126 |
private static void buildImageMap() { |
private static void buildImageMap() { |
127 |
imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva |
imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva |
128 |
imageMap.put("re", R.drawable.re); //RE = Regionaltog |
imageMap.put("re", R.drawable.re); //RE = Regionaltog |
133 |
imageMap.put("ec", R.drawable.ec); //EC = EuroCity |
imageMap.put("ec", R.drawable.ec); //EC = EuroCity |
134 |
imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner |
imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner |
135 |
imageMap.put("ie", R.drawable.ie); |
imageMap.put("ie", R.drawable.ie); |
136 |
|
//TODO: missing IL: IntercityLyn Nonstop |
137 |
|
|
138 |
imageMap.put("a", R.drawable.stog_a); //S-Tog: A banen #00b5f1 |
imageMap.put("a", R.drawable.stog_a); //S-Tog: A banen #00b5f1 |
139 |
imageMap.put("b", R.drawable.stog_b); //S-Tog:B banen #5aba52 |
imageMap.put("b", R.drawable.stog_b); //S-Tog:B banen #5aba52 |