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 |
private List<DepartureBean> departures; |
boolean showDetails = false; |
19 |
|
private List<DepartureEntry> departures; |
20 |
LayoutInflater inflater; |
LayoutInflater inflater; |
21 |
Context context; |
Context context; |
22 |
|
|
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 void setDepartures(List<DepartureBean> departures) { |
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) { |
49 |
this.departures = departures; |
this.departures = departures; |
50 |
notifyDataSetChanged(); |
notifyDataSetChanged(); |
51 |
} |
} |
58 |
return 0; |
return 0; |
59 |
} |
} |
60 |
|
|
61 |
public DepartureBean getDeparture(int position) { |
public DepartureEntry getDeparture(int position) { |
62 |
return departures.get(position); |
return departures.get(position); |
63 |
} |
} |
64 |
|
|
74 |
|
|
75 |
@Override |
@Override |
76 |
public View getView(int position, View convertView, ViewGroup parent) { |
public View getView(int position, View convertView, ViewGroup parent) { |
77 |
DepartureBean station = departures.get(position); |
DepartureEntry station = departures.get(position); |
78 |
|
|
79 |
View root = inflater.inflate(R.layout.departurerow , parent, false); |
View root = inflater.inflate(R.layout.departurerow , parent, false); |
80 |
|
|
81 |
((TextView) root.findViewById(R.id.Time)).setText(station.getTime()); |
((TextView) root.findViewById(R.id.Time)).setText(station.getTime()); |
82 |
((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination()); |
((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination()); |
83 |
|
|
84 |
if (station.getStatus().length() > 0 || station.getNote().length() > 0) { |
|
85 |
|
if ( (station.getStatus() != null && station.getStatus().length() > 0) || (station.getNote() != null && station.getNote().length() > 0) ) { |
86 |
ImageView image = (ImageView) root.findViewById(R.id.InfoIcon); |
ImageView image = (ImageView) root.findViewById(R.id.InfoIcon); |
87 |
|
|
88 |
|
|
89 |
|
String status = (station.getStatus() != null) ? station.getStatus().toLowerCase() : ""; |
90 |
|
String note = (station.getNote() != null) ? station.getNote().toLowerCase() : ""; |
91 |
|
|
92 |
int iconID; |
int iconID; |
93 |
if (station.getStatus().toLowerCase().indexOf("aflyst") > -1 || |
if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) { |
|
station.getNote().toLowerCase().indexOf("aflyst") > -1 ) { |
|
94 |
iconID = R.drawable.warn20; |
iconID = R.drawable.warn20; |
95 |
|
} 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 |
96 |
|
iconID = R.drawable.warnyellow20; |
97 |
} else { |
} else { |
98 |
iconID = R.drawable.info20; |
iconID = R.drawable.info20; |
99 |
} |
} |
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 |
132 |
imageMap.put("ør", R.drawable.or); //ØR = Øresundstog |
imageMap.put("ør", R.drawable.or); //ØR = Øresundstog |
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); |
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 |