--- android/TrainInfo/src/dk/thoerup/traininfo/TimetableListAdapter.java 2009/09/29 21:30:16 362 +++ android/TrainInfo/src/dk/thoerup/traininfo/TimetableListAdapter.java 2011/05/02 16:08:01 1416 @@ -1,19 +1,26 @@ package dk.thoerup.traininfo; -import java.util.List; - import android.content.Context; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; 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).getStationEntry() != null ); + } + public TimetableListAdapter(Context context) { super(); this.context = context; @@ -21,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(); } @@ -29,7 +36,7 @@ @Override public int getCount() { if (timetable != null) - return timetable.size(); + return timetable.entries.size(); else return 0; } @@ -44,10 +51,41 @@ 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) { - // TODO Auto-generated method stub - return null; + 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( entry.getStation() ); + + TextView arrival = (TextView) root.findViewById(R.id.Arrival); + arrival.setText( getTranslated(entry.getArrival()) ); + + TextView departure = (TextView) root.findViewById(R.id.Departure); + departure.setText( getTranslated(entry.getDeparture()) ); + + + if (entry.isCurrent()) { + final int bgcolor = 0xFFFFFFFF; + final int fgcolor = 0xFF000000; + + station.setTextColor(fgcolor); + arrival.setTextColor(fgcolor); + departure.setTextColor(fgcolor); + root.setBackgroundColor(bgcolor); + } + + return root; } }