--- android/TrainInfo/src/dk/thoerup/traininfo/DepartureListAdapter.java 2009/08/10 16:58:22 253 +++ android/TrainInfo/src/dk/thoerup/traininfo/DepartureListAdapter.java 2013/03/30 10:31:12 1963 @@ -1,6 +1,8 @@ package dk.thoerup.traininfo; +import java.util.HashMap; import java.util.List; +import java.util.Map; import android.content.Context; import android.view.LayoutInflater; @@ -9,20 +11,34 @@ 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; + + static Map imageMap = new HashMap(); + static { + buildImageMap(); + } + public DepartureListAdapter(Context context) { 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(); } @@ -35,7 +51,7 @@ return 0; } - public DepartureBean getDeparture(int position) { + public DepartureEntry getDeparture(int position) { return departures.get(position); } @@ -51,40 +67,90 @@ @Override public View getView(int position, View convertView, ViewGroup parent) { - DepartureBean station = departures.get(position); + 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) { + //Platform source'n TritInfo er ikke perfekt - så brug den ikke indtil videre + //((TextView) root.findViewById(R.id.Platform)).setText(station.getPlatform()); + + if ( (station.getStatus() != null && station.getStatus().length() > 0) || (station.getNote() != null && station.getNote().length() > 0) ) { ImageView image = (ImageView) root.findViewById(R.id.InfoIcon); - image.setImageResource(R.drawable.info20); + + + String status = (station.getStatus() != null) ? station.getStatus().toLowerCase() : ""; + String note = (station.getNote() != null) ? station.getNote().toLowerCase() : ""; + + int iconID; + 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; + } + + image.setImageResource( iconID ); } ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); - String trainNumber = station.getTrainNumber(); - if (trainNumber.length() >= 2) { - if ( trainNumber.substring(0, 2).equalsIgnoreCase("ra")) { //ra = regionaltog arriva - typeIcon.setImageResource(R.drawable.retog); - } else if ( trainNumber.substring(0, 2).equalsIgnoreCase("re")) { - typeIcon.setImageResource(R.drawable.retog); - } else if (trainNumber.substring(0,1).equalsIgnoreCase("l")) { - typeIcon.setImageResource(R.drawable.lyntog); - } else if (trainNumber.substring(0,2).equalsIgnoreCase("ic")) { - typeIcon.setImageResource(R.drawable.ictog); - } else if (trainNumber.substring(0,2).equalsIgnoreCase("pp")) { - typeIcon.setImageResource(R.drawable.pptog); - } - } else { - //if each line needs seperate icons, switch on the first(and only( character - typeIcon.setImageResource(R.drawable.stog); + String trainNumber = station.getTrainNumber().trim(); + 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); + } else { + typeIcon.setImageResource(R.drawable.unknown); + } return root; } + + //TODO: all these traintypes / icons should be explained somewhere + private static void buildImageMap() { + imageMap.put("ec", R.drawable.ec); //EC = EuroCity + // Missing FP ? + imageMap.put("ic", R.drawable.ic); //IC = Intercity + imageMap.put("il", R.drawable.il); //IntercityLyn Nonstop + // Missing Int ? + // Missing IR ? + imageMap.put("l", R.drawable.lyn); //L = Lyn + imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen) + // Missing PX + imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva + imageMap.put("re", R.drawable.re); //RE = Regionaltog + imageMap.put("ør", R.drawable.or); //ØR = Øresundstog + + imageMap.put("sj", R.drawable.sj); //SJ=Svenska Jernbaner -- not mentioned on bane.dk + imageMap.put("ie", R.drawable.ie); //what's this ?? -- not mentioned on bane.dk + + //Missing IB ? -- not mentioned on bane.dk + //Missing RX ? -- not mentioned on bane.dk + + for (int i=0; i<=5; i++) { + String add = (i==0) ? "" : "" + i; + + imageMap.put("a" + add, R.drawable.stog_a); //S-Tog: A banen #00b5f1 + imageMap.put("b" + add, R.drawable.stog_b); //S-Tog:B banen #5aba52 + imageMap.put("bx" + add, R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d + imageMap.put("c" + add, R.drawable.stog_c); //S-Tog:C banen #f89734 + imageMap.put("e" + add, R.drawable.stog_e); //S-Tog:E banen #837eba + imageMap.put("f" + add, R.drawable.stog_f); //S-Tog:F banen #ffc32d + imageMap.put("h" + add, R.drawable.stog_h); //S-Tog:H banen #f05737 + } + + + } }