1 |
package dk.thoerup.traininfo; |
package dk.thoerup.traininfo; |
2 |
|
|
|
import java.util.List; |
|
|
|
|
3 |
import android.content.Context; |
import android.content.Context; |
4 |
|
import android.util.Log; |
5 |
import android.view.LayoutInflater; |
import android.view.LayoutInflater; |
6 |
import android.view.View; |
import android.view.View; |
7 |
import android.view.ViewGroup; |
import android.view.ViewGroup; |
8 |
import android.widget.BaseAdapter; |
import android.widget.BaseAdapter; |
9 |
import android.widget.TextView; |
import android.widget.TextView; |
10 |
|
import dk.thoerup.android.traininfo.common.TimetableBean; |
11 |
|
import dk.thoerup.android.traininfo.common.TimetableEntry; |
12 |
|
|
13 |
public class TimetableListAdapter extends BaseAdapter { |
public class TimetableListAdapter extends BaseAdapter { |
14 |
|
|
15 |
private List<TimetableBean> timetable; |
private TimetableBean timetable; |
16 |
LayoutInflater inflater; |
LayoutInflater inflater; |
17 |
Context context; |
Context context; |
18 |
|
|
19 |
@Override |
@Override |
20 |
public boolean isEnabled(int position) { |
public boolean isEnabled(int position) { |
21 |
return false; |
return ( timetable.entries.get(position).getStationId() != -1 ); |
22 |
} |
} |
23 |
|
|
24 |
public TimetableListAdapter(Context context) { |
public TimetableListAdapter(Context context) { |
28 |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
29 |
} |
} |
30 |
|
|
31 |
public void setTimetable(List<TimetableBean> timetable) { |
public void setTimetable(TimetableBean timetable) { |
32 |
this.timetable = timetable; |
this.timetable = timetable; |
33 |
notifyDataSetChanged(); |
notifyDataSetChanged(); |
34 |
} |
} |
36 |
@Override |
@Override |
37 |
public int getCount() { |
public int getCount() { |
38 |
if (timetable != null) |
if (timetable != null) |
39 |
return timetable.size(); |
return timetable.entries.size(); |
40 |
else |
else |
41 |
return 0; |
return 0; |
42 |
} |
} |
51 |
return position; |
return position; |
52 |
} |
} |
53 |
|
|
54 |
|
String getTranslated(String str) { |
55 |
|
if (str == null) |
56 |
|
return str; |
57 |
|
|
58 |
|
str = str.replace("Aflyst", context.getString(R.string.timetablelist_cancel) ); |
59 |
|
return str; |
60 |
|
} |
61 |
|
|
62 |
@Override |
@Override |
63 |
public View getView(int position, View convertView, ViewGroup parent) { |
public View getView(int position, View convertView, ViewGroup parent) { |
64 |
TimetableBean timetableBean = timetable.get(position); |
TimetableEntry entry = timetable.entries.get(position); |
65 |
|
|
66 |
View root = inflater.inflate(R.layout.timetablerow , parent, false); |
View root = inflater.inflate(R.layout.timetablerow , parent, false); |
67 |
|
|
68 |
TextView station = (TextView) root.findViewById(R.id.Station); |
TextView station = (TextView) root.findViewById(R.id.Station); |
69 |
station.setText(timetableBean.getStation()); |
station.setText( entry.getStation() ); |
70 |
|
|
71 |
TextView arrival = (TextView) root.findViewById(R.id.Arrival); |
TextView arrival = (TextView) root.findViewById(R.id.Arrival); |
72 |
arrival.setText(timetableBean.getArrival()); |
arrival.setText( getTranslated(entry.getArrival()) ); |
73 |
|
|
74 |
TextView departure = (TextView) root.findViewById(R.id.Departure); |
TextView departure = (TextView) root.findViewById(R.id.Departure); |
75 |
departure.setText(timetableBean.getDeparture()); |
departure.setText( getTranslated(entry.getDeparture()) ); |
76 |
|
|
77 |
|
|
78 |
if (timetableBean.isCurrent()) { |
if (entry.isCurrent()) { |
79 |
final int bgcolor = 0xFFFFFFFF; |
final int bgcolor = 0xFFFFFFFF; |
80 |
final int fgcolor = 0xFF000000; |
final int fgcolor = 0xFF000000; |
81 |
|
|