1 |
torben |
237 |
package dk.thoerup.traininfo;
|
2 |
|
|
|
3 |
torben |
486 |
import java.util.HashMap;
|
4 |
torben |
237 |
import java.util.List;
|
5 |
torben |
486 |
import java.util.Map;
|
6 |
torben |
237 |
|
7 |
|
|
import android.content.Context;
|
8 |
|
|
import android.view.LayoutInflater;
|
9 |
|
|
import android.view.View;
|
10 |
|
|
import android.view.ViewGroup;
|
11 |
|
|
import android.widget.BaseAdapter;
|
12 |
torben |
244 |
import android.widget.ImageView;
|
13 |
torben |
237 |
import android.widget.TextView;
|
14 |
torben |
1066 |
import dk.thoerup.android.traininfo.common.DepartureEntry;
|
15 |
torben |
237 |
|
16 |
|
|
public class DepartureListAdapter extends BaseAdapter {
|
17 |
|
|
|
18 |
torben |
1434 |
boolean showDetails = false;
|
19 |
torben |
981 |
private List<DepartureEntry> departures;
|
20 |
torben |
237 |
LayoutInflater inflater;
|
21 |
|
|
Context context;
|
22 |
torben |
486 |
|
23 |
|
|
static Map<String,Integer> imageMap = new HashMap<String,Integer>();
|
24 |
|
|
static {
|
25 |
|
|
buildImageMap();
|
26 |
|
|
}
|
27 |
|
|
|
28 |
torben |
237 |
public DepartureListAdapter(Context context) {
|
29 |
|
|
super();
|
30 |
|
|
this.context = context;
|
31 |
|
|
|
32 |
torben |
1434 |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
33 |
torben |
237 |
}
|
34 |
torben |
1437 |
|
35 |
|
|
|
36 |
torben |
1434 |
public void toggleShowDetails() {
|
37 |
|
|
showDetails = !showDetails;
|
38 |
|
|
notifyDataSetChanged();
|
39 |
|
|
}
|
40 |
|
|
|
41 |
torben |
981 |
public void setDepartures(List<DepartureEntry> departures) {
|
42 |
torben |
237 |
this.departures = departures;
|
43 |
|
|
notifyDataSetChanged();
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
@Override
|
47 |
|
|
public int getCount() {
|
48 |
|
|
if (departures != null)
|
49 |
|
|
return departures.size();
|
50 |
|
|
else
|
51 |
|
|
return 0;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
torben |
981 |
public DepartureEntry getDeparture(int position) {
|
55 |
torben |
237 |
return departures.get(position);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
@Override
|
59 |
|
|
public Object getItem(int position) {
|
60 |
|
|
return null;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
@Override
|
64 |
|
|
public long getItemId(int position) {
|
65 |
|
|
return position;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
@Override
|
69 |
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
70 |
torben |
981 |
DepartureEntry station = departures.get(position);
|
71 |
torben |
237 |
|
72 |
torben |
491 |
View root = inflater.inflate(R.layout.departurerow , parent, false);
|
73 |
torben |
237 |
|
74 |
|
|
((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
|
75 |
|
|
((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
|
76 |
|
|
|
77 |
torben |
1066 |
|
78 |
|
|
if ( (station.getStatus() != null && station.getStatus().length() > 0) || (station.getNote() != null && station.getNote().length() > 0) ) {
|
79 |
torben |
250 |
ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
|
80 |
torben |
483 |
|
81 |
torben |
499 |
|
82 |
torben |
1066 |
String status = (station.getStatus() != null) ? station.getStatus().toLowerCase() : "";
|
83 |
|
|
String note = (station.getNote() != null) ? station.getNote().toLowerCase() : "";
|
84 |
|
|
|
85 |
torben |
483 |
int iconID;
|
86 |
torben |
499 |
if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) {
|
87 |
torben |
483 |
iconID = R.drawable.warn20;
|
88 |
torben |
499 |
} else if (note.indexOf("kører kun til") > -1 || note.indexOf("afgår fra") > -1) { //If these strings are present, the train only covers part of the line
|
89 |
|
|
iconID = R.drawable.warnyellow20;
|
90 |
torben |
483 |
} else {
|
91 |
|
|
iconID = R.drawable.info20;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
image.setImageResource( iconID );
|
95 |
torben |
244 |
}
|
96 |
torben |
237 |
|
97 |
torben |
250 |
ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
|
98 |
torben |
351 |
String trainNumber = station.getTrainNumber().trim();
|
99 |
torben |
1434 |
String trainParts[] = trainNumber.split(" ");
|
100 |
|
|
String code = trainParts[0].toLowerCase();
|
101 |
torben |
486 |
|
102 |
torben |
1434 |
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 |
torben |
486 |
Integer imageId = imageMap.get(code);
|
109 |
|
|
if (imageId != null) {
|
110 |
|
|
typeIcon.setImageResource(imageId);
|
111 |
|
|
} else {
|
112 |
torben |
333 |
typeIcon.setImageResource(R.drawable.unknown);
|
113 |
torben |
486 |
}
|
114 |
torben |
250 |
|
115 |
torben |
237 |
return root;
|
116 |
|
|
}
|
117 |
torben |
486 |
|
118 |
torben |
1434 |
//TODO: all these traintypes / icons should be explained somewhere
|
119 |
torben |
486 |
private static void buildImageMap() {
|
120 |
torben |
1454 |
imageMap.put("ec", R.drawable.ec); //EC = EuroCity
|
121 |
|
|
// Missing FP ?
|
122 |
|
|
imageMap.put("ic", R.drawable.ic); //IC = Intercity
|
123 |
|
|
imageMap.put("il", R.drawable.il); //IntercityLyn Nonstop
|
124 |
|
|
// Missing Int ?
|
125 |
|
|
// Missing IR ?
|
126 |
torben |
486 |
imageMap.put("l", R.drawable.lyn); //L = Lyn
|
127 |
|
|
imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen)
|
128 |
torben |
1454 |
// Missing PX
|
129 |
|
|
imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva
|
130 |
|
|
imageMap.put("re", R.drawable.re); //RE = Regionaltog
|
131 |
torben |
486 |
imageMap.put("ør", R.drawable.or); //ØR = Øresundstog
|
132 |
torben |
1454 |
|
133 |
|
|
imageMap.put("sj", R.drawable.sj); //SJ=Svenska Jernbaner -- not mentioned on bane.dk
|
134 |
|
|
imageMap.put("ie", R.drawable.ie); //what's this ?? -- not mentioned on bane.dk
|
135 |
torben |
486 |
|
136 |
torben |
1454 |
//Missing IB ? -- not mentioned on bane.dk
|
137 |
|
|
//Missing RX ? -- not mentioned on bane.dk
|
138 |
|
|
|
139 |
|
|
|
140 |
torben |
486 |
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
|
142 |
|
|
imageMap.put("bx", R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d
|
143 |
|
|
imageMap.put("c", R.drawable.stog_c); //S-Tog:C banen #f89734
|
144 |
|
|
imageMap.put("e", R.drawable.stog_e); //S-Tog:E banen #837eba
|
145 |
|
|
imageMap.put("f", R.drawable.stog_f); //S-Tog:F banen #ffc32d
|
146 |
|
|
imageMap.put("h", R.drawable.stog_h); //S-Tog:H banen #f05737
|
147 |
|
|
|
148 |
torben |
237 |
|
149 |
torben |
486 |
|
150 |
|
|
}
|
151 |
|
|
|
152 |
torben |
237 |
}
|