1 |
package dk.thoerup.traininfo; |
package dk.thoerup.traininfo; |
2 |
|
|
3 |
|
import static dk.thoerup.traininfo.R.string.stationlistadapter_distance; |
4 |
|
|
5 |
import java.text.NumberFormat; |
import java.text.NumberFormat; |
6 |
import java.util.List; |
import java.util.List; |
7 |
|
|
11 |
import android.view.ViewGroup; |
import android.view.ViewGroup; |
12 |
import android.widget.BaseAdapter; |
import android.widget.BaseAdapter; |
13 |
import android.widget.TextView; |
import android.widget.TextView; |
14 |
import static dk.thoerup.traininfo.R.string.*; |
import dk.thoerup.android.traininfo.common.StationBean; |
15 |
|
import dk.thoerup.android.traininfo.common.StationBean.StationEntry; |
16 |
|
|
17 |
public class StationListAdapter extends BaseAdapter { |
public class StationListAdapter extends BaseAdapter { |
18 |
LayoutInflater inflater; |
LayoutInflater inflater; |
19 |
|
|
20 |
List<StationBean> stations; |
StationBean stations; |
21 |
Context context; |
Context context; |
22 |
NumberFormat number = NumberFormat.getNumberInstance(); |
NumberFormat number = NumberFormat.getNumberInstance(); |
23 |
|
|
33 |
@Override |
@Override |
34 |
public int getCount() { |
public int getCount() { |
35 |
if (stations != null) |
if (stations != null) |
36 |
return stations.size(); |
return stations.entries.size(); |
37 |
else |
else |
38 |
return 0; |
return 0; |
39 |
} |
} |
43 |
return null; |
return null; |
44 |
} |
} |
45 |
|
|
46 |
public StationBean getStation(int position) { |
public StationEntry getStation(int position) { |
47 |
return stations.get(position); |
return stations.entries.get(position); |
48 |
} |
} |
49 |
|
|
50 |
@Override |
@Override |
52 |
return position; |
return position; |
53 |
} |
} |
54 |
|
|
55 |
public void setStations(List<StationBean> stations) { |
public void setStations(StationBean stations) { |
56 |
this.stations = stations; |
this.stations = stations; |
57 |
notifyDataSetChanged(); |
notifyDataSetChanged(); |
58 |
} |
} |
59 |
|
|
60 |
@Override |
@Override |
61 |
public View getView(int position, View convertView, ViewGroup parent) { |
public View getView(int position, View convertView, ViewGroup parent) { |
62 |
StationBean station = stations.get(position); |
StationEntry station = stations.entries.get(position); |
63 |
|
|
64 |
View root = inflater.inflate(R.layout.stationrow , parent, false); |
View root = inflater.inflate(R.layout.stationrow , parent, false); |
65 |
TextView tview = (TextView) root.findViewById(R.id.stationName); |
TextView tview = (TextView) root.findViewById(R.id.stationName); |
66 |
tview.setText(station.getName()); |
tview.setText(station.getName()); |
67 |
|
|
68 |
tview = (TextView) root.findViewById(R.id.stationDistance); |
tview = (TextView) root.findViewById(R.id.stationDistance); |
69 |
if (station.getDistance() != 0) { |
if (station.getCalcdist() != 0) { |
70 |
tview.setText( context.getString(stationlistadapter_distance) + " " + number.format( (double)station.getDistance()/1000.0) + " km."); |
tview.setText( context.getString(stationlistadapter_distance) + " " + number.format( (double)station.getCalcdist()/1000.0) + " km."); |
71 |
} else { |
} else { |
72 |
tview.setVisibility(View.GONE); |
tview.setVisibility(View.GONE); |
73 |
} |
} |
74 |
|
|
75 |
root.findViewById(R.id.isregional).setVisibility( station.isRegional() ? View.VISIBLE : View.INVISIBLE ); |
root.findViewById(R.id.isregional).setVisibility( station.isRegional() ? View.VISIBLE : View.INVISIBLE ); |
76 |
root.findViewById(R.id.isstrain).setVisibility( station.isSTrain() ? View.VISIBLE : View.INVISIBLE ); |
root.findViewById(R.id.isstrain).setVisibility( station.isStrain() ? View.VISIBLE : View.INVISIBLE ); |
77 |
root.findViewById(R.id.ismetro).setVisibility( station.isMetro() ? View.VISIBLE : View.INVISIBLE ); |
root.findViewById(R.id.ismetro).setVisibility( station.isMetro() ? View.VISIBLE : View.INVISIBLE ); |
78 |
|
|
79 |
return root; |
return root; |