1 |
|
package com.dreamcatcher.bicycle.adapter; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
|
5 |
|
import android.view.LayoutInflater; |
6 |
|
import android.view.View; |
7 |
|
import android.view.ViewGroup; |
8 |
|
import android.widget.BaseAdapter; |
9 |
|
import android.widget.LinearLayout; |
10 |
|
import android.widget.TextView; |
11 |
|
|
12 |
|
import com.dreamcatcher.bicycle.BicycleApp; |
13 |
|
import com.dreamcatcher.bicycle.R; |
14 |
|
import com.dreamcatcher.bicycle.dataset.BicycleDataset; |
15 |
|
import com.dreamcatcher.bicycle.util.GlobalSetting; |
16 |
|
import com.dreamcatcher.bicycle.util.Utils; |
17 |
|
import com.dreamcatcher.bicycle.vo.BicycleStationInfo; |
18 |
|
import com.dreamcatcher.bicycle.vo.CitySetting; |
19 |
|
|
|
|
| 87,8% |
Uncovered Elements: 5 (41) |
Complexity: 9 |
Complexity Density: 0,31 |
|
20 |
|
public class BicycleListAdapter extends BaseAdapter { |
21 |
|
private ArrayList<BicycleStationInfo> mBicycleStationInfos = null; |
22 |
|
private BicycleDataset mBicycleDataset = null; |
23 |
|
private LayoutInflater mInflater; |
24 |
|
private CitySetting mCitySetting = null; |
25 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
26 |
1
|
public BicycleListAdapter(){... |
27 |
1
|
mBicycleDataset = BicycleDataset.getInstance(); |
28 |
1
|
mBicycleStationInfos = mBicycleDataset.getBicycleStationInfos(); |
29 |
1
|
mInflater = LayoutInflater.from(BicycleApp.getInstance()); |
30 |
1
|
mCitySetting = GlobalSetting.getInstance().getCitySetting(); |
31 |
|
} |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
33 |
2
|
public void updateDataset(){... |
34 |
2
|
mBicycleStationInfos = mBicycleDataset.getBicycleStationInfos(); |
35 |
2
|
mCitySetting = GlobalSetting.getInstance().getCitySetting(); |
36 |
2
|
this.notifyDataSetChanged(); |
37 |
|
} |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
39 |
172
|
public int getCount() {... |
40 |
172
|
return mBicycleStationInfos.size(); |
41 |
|
} |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
43 |
0
|
public Object getItem(int position) { ... |
44 |
0
|
return mBicycleStationInfos.get(position); |
45 |
|
} |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
10
|
public long getItemId(int position) { ... |
48 |
10
|
return position; |
49 |
|
} |
50 |
|
|
|
|
| 88% |
Uncovered Elements: 3 (25) |
Complexity: 4 |
Complexity Density: 0,21 |
|
51 |
218
|
public View getView(int position, View convertView, ViewGroup parent) {... |
52 |
218
|
ViewHolder holder = null; |
53 |
218
|
if(convertView == null){ |
54 |
14
|
convertView = mInflater.inflate(R.layout.bicycle_listitem, parent, false); |
55 |
14
|
holder = new ViewHolder(convertView); |
56 |
14
|
convertView.setTag(holder); |
57 |
|
}else{ |
58 |
204
|
holder = (ViewHolder) convertView.getTag(); |
59 |
|
} |
60 |
|
|
61 |
218
|
BicycleStationInfo bicycleStationInfo = mBicycleStationInfos.get(position); |
62 |
218
|
if(bicycleStationInfo != null){ |
63 |
218
|
holder.bicycleIndex.setText(String.valueOf(position + 1)); |
64 |
218
|
holder.bicycleName.setText(bicycleStationInfo.getName()); |
65 |
|
|
66 |
218
|
if(mCitySetting.isShowBicycleNumber()){ |
67 |
218
|
String avaibike = Utils.getText(R.string.list_avaibike); |
68 |
218
|
String avaipark = Utils.getText(R.string.list_avaipark); |
69 |
218
|
holder.availableBicycles.setText(avaibike + bicycleStationInfo.getAvailable()); |
70 |
218
|
holder.availableParks.setText(avaipark + String.valueOf(bicycleStationInfo.getCapacity() - bicycleStationInfo.getAvailable())); |
71 |
218
|
holder.bicycleNumberLine.setVisibility(View.VISIBLE); |
72 |
|
}else{ |
73 |
0
|
holder.bicycleNumberLine.setVisibility(View.GONE); |
74 |
|
} |
75 |
218
|
holder.address.setText(bicycleStationInfo.getAddress()); |
76 |
|
} |
77 |
|
|
78 |
218
|
return convertView; |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,17 |
|
81 |
|
private static class ViewHolder{ |
82 |
|
public TextView bicycleIndex; |
83 |
|
public TextView bicycleName; |
84 |
|
public TextView availableBicycles; |
85 |
|
public TextView availableParks; |
86 |
|
public TextView address; |
87 |
|
public LinearLayout bicycleNumberLine; |
88 |
|
|
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
90 |
14
|
public ViewHolder(View parent){... |
91 |
14
|
bicycleIndex = (TextView) parent.findViewById(R.id.bicycle_listview_index); |
92 |
14
|
bicycleName = (TextView) parent.findViewById(R.id.bicycle_listview_name); |
93 |
14
|
availableBicycles = (TextView) parent.findViewById(R.id.bicycle_listview_avaibike); |
94 |
14
|
availableParks = (TextView) parent.findViewById(R.id.bicycle_listview_avaipark); |
95 |
14
|
address = (TextView) parent.findViewById(R.id.bicycle_listview_address); |
96 |
14
|
bicycleNumberLine = (LinearLayout) parent.findViewById(R.id.bicycle_listview_count_line); |
97 |
|
} |
98 |
|
} |
99 |
|
|
100 |
|
} |