--- android/TrainInfo/src/dk/thoerup/traininfo/DepartureListAdapter.java 2009/10/29 19:27:29 490 +++ android/TrainInfo/src/dk/thoerup/traininfo/DepartureListAdapter.java 2011/05/03 16:39:48 1437 @@ -5,17 +5,18 @@ import java.util.Map; 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.ImageView; import android.widget.TextView; +import dk.thoerup.android.traininfo.common.DepartureEntry; public class DepartureListAdapter extends BaseAdapter { - private List departures; + boolean showDetails = false; + private List departures; LayoutInflater inflater; Context context; @@ -28,11 +29,16 @@ super(); this.context = context; - inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + + public void toggleShowDetails() { + showDetails = !showDetails; + notifyDataSetChanged(); } - public void setDepartures(List departures) { + public void setDepartures(List departures) { this.departures = departures; notifyDataSetChanged(); } @@ -45,7 +51,7 @@ return 0; } - public DepartureBean getDeparture(int position) { + public DepartureEntry getDeparture(int position) { return departures.get(position); } @@ -61,27 +67,26 @@ @Override public View getView(int position, View convertView, ViewGroup parent) { - DepartureBean station = departures.get(position); - - - View root; - if (convertView == null || convertView.getId() != R.id.DepartureRow ) { - root = inflater.inflate(R.layout.departurerow , parent, false); - } else { - root = convertView; - } + DepartureEntry station = departures.get(position); + View root = inflater.inflate(R.layout.departurerow , parent, false); ((TextView) root.findViewById(R.id.Time)).setText(station.getTime()); ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination()); - if (station.getStatus().length() > 0 || station.getNote().length() > 0) { + + if ( (station.getStatus() != null && station.getStatus().length() > 0) || (station.getNote() != null && station.getNote().length() > 0) ) { ImageView image = (ImageView) root.findViewById(R.id.InfoIcon); + + String status = (station.getStatus() != null) ? station.getStatus().toLowerCase() : ""; + String note = (station.getNote() != null) ? station.getNote().toLowerCase() : ""; + int iconID; - if (station.getStatus().toLowerCase().indexOf("aflyst") > -1 || - station.getNote().toLowerCase().indexOf("aflyst") > -1 ) { + if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) { iconID = R.drawable.warn20; + } 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 + iconID = R.drawable.warnyellow20; } else { iconID = R.drawable.info20; } @@ -91,8 +96,15 @@ ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); String trainNumber = station.getTrainNumber().trim(); - String code = trainNumber.split(" ")[0].toLowerCase(); + String trainParts[] = trainNumber.split(" "); + String code = trainParts[0].toLowerCase(); + if (showDetails) { + root.findViewById(R.id.departureRow2).setVisibility( View.VISIBLE ); + ((TextView) root.findViewById(R.id.TrainNumber)).setText(trainNumber); + ((TextView) root.findViewById(R.id.Origin)).setText( station.getOrigin() ); + } + Integer imageId = imageMap.get(code); if (imageId != null) { typeIcon.setImageResource(imageId); @@ -103,6 +115,7 @@ return root; } + //TODO: all these traintypes / icons should be explained somewhere private static void buildImageMap() { imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva imageMap.put("re", R.drawable.re); //RE = Regionaltog @@ -112,6 +125,8 @@ imageMap.put("ør", R.drawable.or); //ØR = Øresundstog imageMap.put("ec", R.drawable.ec); //EC = EuroCity imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner + imageMap.put("ie", R.drawable.ie); + //TODO: missing IL: IntercityLyn Nonstop imageMap.put("a", R.drawable.stog_a); //S-Tog: A banen #00b5f1 imageMap.put("b", R.drawable.stog_b); //S-Tog:B banen #5aba52