1 |
torben |
237 |
package dk.thoerup.traininfo;
|
2 |
|
|
|
3 |
|
|
import java.util.List;
|
4 |
|
|
|
5 |
|
|
import android.content.Context;
|
6 |
|
|
import android.view.LayoutInflater;
|
7 |
|
|
import android.view.View;
|
8 |
|
|
import android.view.ViewGroup;
|
9 |
|
|
import android.widget.BaseAdapter;
|
10 |
torben |
244 |
import android.widget.ImageView;
|
11 |
torben |
237 |
import android.widget.TextView;
|
12 |
|
|
|
13 |
|
|
public class DepartureListAdapter extends BaseAdapter {
|
14 |
|
|
|
15 |
|
|
private List<DepartureBean> departures;
|
16 |
|
|
LayoutInflater inflater;
|
17 |
|
|
Context context;
|
18 |
|
|
public DepartureListAdapter(Context context) {
|
19 |
|
|
super();
|
20 |
|
|
this.context = context;
|
21 |
|
|
|
22 |
|
|
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
public void setDepartures(List<DepartureBean> departures) {
|
26 |
|
|
this.departures = departures;
|
27 |
|
|
notifyDataSetChanged();
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
@Override
|
31 |
|
|
public int getCount() {
|
32 |
|
|
if (departures != null)
|
33 |
|
|
return departures.size();
|
34 |
|
|
else
|
35 |
|
|
return 0;
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
public DepartureBean getDeparture(int position) {
|
39 |
|
|
return departures.get(position);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
@Override
|
43 |
|
|
public Object getItem(int position) {
|
44 |
|
|
return null;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
@Override
|
48 |
|
|
public long getItemId(int position) {
|
49 |
|
|
return position;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
@Override
|
53 |
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
54 |
|
|
DepartureBean station = departures.get(position);
|
55 |
|
|
|
56 |
|
|
View root = inflater.inflate(R.layout.departurerow , parent, false);
|
57 |
|
|
|
58 |
|
|
((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
|
59 |
|
|
((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
|
60 |
|
|
|
61 |
torben |
244 |
if (station.getStatus().length() > 0 || station.getNote().length() > 0) {
|
62 |
torben |
250 |
ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
|
63 |
torben |
244 |
image.setImageResource(R.drawable.info20);
|
64 |
|
|
}
|
65 |
torben |
237 |
|
66 |
torben |
250 |
ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
|
67 |
|
|
String trainNumber = station.getTrainNumber();
|
68 |
|
|
if ( trainNumber.substring(0, 2).equalsIgnoreCase("ra")) {
|
69 |
|
|
typeIcon.setImageResource(R.drawable.retog);
|
70 |
|
|
} else if (trainNumber.substring(0,1).equalsIgnoreCase("l")) {
|
71 |
|
|
typeIcon.setImageResource(R.drawable.lyntog);
|
72 |
|
|
} else if (trainNumber.substring(0,2).equalsIgnoreCase("ic")) {
|
73 |
|
|
typeIcon.setImageResource(R.drawable.ictog);
|
74 |
|
|
} else if (trainNumber.substring(0,2).equalsIgnoreCase("pp")) {
|
75 |
|
|
typeIcon.setImageResource(R.drawable.pptog);
|
76 |
|
|
} else if (trainNumber.substring(0,2).equalsIgnoreCase("a ")) {
|
77 |
|
|
typeIcon.setImageResource(R.drawable.stog);
|
78 |
|
|
} else if (trainNumber.substring(0,2).equalsIgnoreCase("b ")) {
|
79 |
|
|
typeIcon.setImageResource(R.drawable.stog);
|
80 |
|
|
} else if (trainNumber.substring(0,2).equalsIgnoreCase("c ")) {
|
81 |
|
|
typeIcon.setImageResource(R.drawable.stog);
|
82 |
|
|
} else if (trainNumber.substring(0,2).equalsIgnoreCase("d ")) {
|
83 |
|
|
typeIcon.setImageResource(R.drawable.stog);
|
84 |
|
|
} else if (trainNumber.substring(0,2).equalsIgnoreCase("e ")) {
|
85 |
|
|
typeIcon.setImageResource(R.drawable.stog);
|
86 |
|
|
}
|
87 |
torben |
244 |
|
88 |
torben |
250 |
|
89 |
|
|
|
90 |
torben |
237 |
return root;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
}
|