--- android/TrainInfo/src/dk/thoerup/traininfo/TimetableListAdapter.java 2009/09/30 09:14:27 365 +++ android/TrainInfo/src/dk/thoerup/traininfo/TimetableListAdapter.java 2011/04/04 15:28:12 1257 @@ -1,7 +1,5 @@ package dk.thoerup.traininfo; -import java.util.List; - import android.content.Context; import android.util.Log; import android.view.LayoutInflater; @@ -9,13 +7,20 @@ import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; +import dk.thoerup.android.traininfo.common.TimetableBean; +import dk.thoerup.android.traininfo.common.TimetableEntry; public class TimetableListAdapter extends BaseAdapter { - private List timetable; + private TimetableBean timetable; LayoutInflater inflater; Context context; + @Override + public boolean isEnabled(int position) { + return ( timetable.entries.get(position).getStationId() != -1 ); + } + public TimetableListAdapter(Context context) { super(); this.context = context; @@ -23,7 +28,7 @@ inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } - public void setTimetable(List timetable) { + public void setTimetable(TimetableBean timetable) { this.timetable = timetable; notifyDataSetChanged(); } @@ -31,7 +36,7 @@ @Override public int getCount() { if (timetable != null) - return timetable.size(); + return timetable.entries.size(); else return 0; } @@ -46,23 +51,31 @@ return position; } + String getTranslated(String str) { + if (str == null) + return str; + + str = str.replace("Aflyst", context.getString(R.string.timetablelist_cancel) ); + return str; + } + @Override public View getView(int position, View convertView, ViewGroup parent) { - TimetableBean timetableBean = timetable.get(position); + TimetableEntry entry = timetable.entries.get(position); View root = inflater.inflate(R.layout.timetablerow , parent, false); TextView station = (TextView) root.findViewById(R.id.Station); - station.setText(timetableBean.getStation()); + station.setText( entry.getStation() ); TextView arrival = (TextView) root.findViewById(R.id.Arrival); - arrival.setText(timetableBean.getArrival()); + arrival.setText( getTranslated(entry.getArrival()) ); TextView departure = (TextView) root.findViewById(R.id.Departure); - departure.setText(timetableBean.getDeparture()); + departure.setText( getTranslated(entry.getDeparture()) ); - if (timetableBean.isCurrent()) { + if (entry.isCurrent()) { final int bgcolor = 0xFFFFFFFF; final int fgcolor = 0xFF000000; @@ -70,8 +83,6 @@ arrival.setTextColor(fgcolor); departure.setTextColor(fgcolor); root.setBackgroundColor(bgcolor); - - Log.e("Current","current"); } return root;