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