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.ImageView; |
10 |
|
import android.widget.TextView; |
11 |
|
|
12 |
|
import com.dreamcatcher.bicycle.BicycleApp; |
13 |
|
import com.dreamcatcher.bicycle.R; |
14 |
|
import com.dreamcatcher.bicycle.core.BicycleService; |
15 |
|
import com.dreamcatcher.bicycle.dataset.BicycleDataset; |
16 |
|
import com.dreamcatcher.bicycle.interfaces.ISettingService; |
17 |
|
import com.dreamcatcher.bicycle.util.Constants; |
18 |
|
import com.dreamcatcher.bicycle.util.Utils; |
19 |
|
import com.dreamcatcher.bicycle.vo.BicycleStationInfo; |
20 |
|
|
|
|
| 67,7% |
Uncovered Elements: 30 (93) |
Complexity: 25 |
Complexity Density: 0,45 |
|
21 |
|
public class FavoriteSettingAdapter extends BaseAdapter { |
22 |
|
private ArrayList<BicycleStationInfo> mBicycleStationInfos = null; |
23 |
|
private BicycleDataset mBicycleDataset = null; |
24 |
|
private LayoutInflater mInflater; |
25 |
|
private boolean[] mCheckResult = null; |
26 |
|
private int[] mAllIds = null; |
27 |
|
private ISettingService mSettingService = null; |
28 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
29 |
1
|
public FavoriteSettingAdapter(){... |
30 |
1
|
mBicycleDataset = BicycleDataset.getInstance(); |
31 |
1
|
mBicycleStationInfos = mBicycleDataset.getBicycleStationInfos(); |
32 |
1
|
mInflater = LayoutInflater.from(BicycleApp.getInstance()); |
33 |
1
|
mCheckResult = new boolean[mBicycleStationInfos.size()]; |
34 |
1
|
mAllIds = new int[mBicycleStationInfos.size()]; |
35 |
1
|
mSettingService = BicycleService.getInstance().getSettingService(); |
36 |
1
|
initFavoriteIds(); |
37 |
1
|
initSelected(); |
38 |
|
} |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
40 |
1
|
private void initFavoriteIds(){... |
41 |
69
|
for(int i = 0, n = mBicycleStationInfos.size(); i < n; i++){ |
42 |
68
|
mAllIds[i] = mBicycleStationInfos.get(i).getId(); |
43 |
|
} |
44 |
|
} |
45 |
|
|
|
|
| 30,8% |
Uncovered Elements: 9 (13) |
Complexity: 5 |
Complexity Density: 0,71 |
|
46 |
1
|
private void initSelected(){... |
47 |
1
|
String favoriteIds = Utils.getStringDataFromLocal(Constants.LocalStoreTag.FAVORITE_IDS); |
48 |
1
|
if(favoriteIds == null || favoriteIds.equals("")){ |
49 |
1
|
return; |
50 |
|
} |
51 |
0
|
String[] favoriteIdArray = favoriteIds.split("\\|"); |
52 |
0
|
for(int i = 0, n = mAllIds.length; i < n; i++){ |
53 |
0
|
if(isInArray(mAllIds[i], favoriteIdArray)){ |
54 |
0
|
mCheckResult[i] = true; |
55 |
|
} |
56 |
|
} |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
59 |
0
|
private boolean isInArray(int index, String[] idArray){... |
60 |
0
|
boolean result = false; |
61 |
0
|
for(String id : idArray){ |
62 |
0
|
if(Integer.parseInt(id) == index){ |
63 |
0
|
result = true; |
64 |
0
|
break; |
65 |
|
} |
66 |
|
} |
67 |
0
|
return result; |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
75
|
public int getCount() { ... |
71 |
75
|
return mBicycleStationInfos.size(); |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
0
|
public BicycleStationInfo getItem(int position) {... |
75 |
|
|
76 |
0
|
return mBicycleStationInfos.get(position); |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
24
|
public long getItemId(int position) {... |
80 |
24
|
return position; |
81 |
|
} |
82 |
|
|
|
|
| 95,2% |
Uncovered Elements: 1 (21) |
Complexity: 4 |
Complexity Density: 0,27 |
|
83 |
157
|
public View getView(int position, View convertView, ViewGroup parent) {... |
84 |
157
|
ViewHolder viewHolder = null; |
85 |
157
|
if(convertView == null){ |
86 |
12
|
convertView = mInflater.inflate(R.layout.favorite_setting_listitem, parent, false); |
87 |
12
|
viewHolder = new ViewHolder(convertView); |
88 |
12
|
convertView.setTag(viewHolder); |
89 |
|
}else { |
90 |
145
|
viewHolder = (ViewHolder) convertView.getTag(); |
91 |
|
} |
92 |
|
|
93 |
157
|
BicycleStationInfo bicycleStationInfo = mBicycleStationInfos.get(position); |
94 |
157
|
if(bicycleStationInfo != null){ |
95 |
157
|
viewHolder.bicycleIndex.setText(String.valueOf(position + 1)); |
96 |
157
|
viewHolder.bicycleName.setText(bicycleStationInfo.getName()); |
97 |
157
|
viewHolder.bicycleAddress.setText(bicycleStationInfo.getAddress()); |
98 |
157
|
if(mCheckResult[position]){ |
99 |
20
|
viewHolder.checkImage.setSelected(true); |
100 |
|
}else { |
101 |
137
|
viewHolder.checkImage.setSelected(false); |
102 |
|
} |
103 |
|
} |
104 |
157
|
return convertView; |
105 |
|
} |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
107 |
0
|
public void setAllSelected(boolean selected){... |
108 |
0
|
for(int i = 0, n = mCheckResult.length; i < n;i++){ |
109 |
0
|
mCheckResult[i] = selected; |
110 |
|
} |
111 |
0
|
this.notifyDataSetChanged(); |
112 |
0
|
this.updateFavoriteIdsToLocal(); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
115 |
8
|
public void setSingleSelected(int index){... |
116 |
8
|
mCheckResult[index] = !mCheckResult[index]; |
117 |
8
|
this.notifyDataSetChanged(); |
118 |
8
|
this.updateFavoriteIdsToLocal(); |
119 |
|
} |
120 |
|
|
|
|
| 87,5% |
Uncovered Elements: 2 (16) |
Complexity: 5 |
Complexity Density: 0,62 |
|
121 |
8
|
private void updateFavoriteIdsToLocal(){... |
122 |
8
|
StringBuilder stringBuilder = new StringBuilder(); |
123 |
8
|
if(mCheckResult.length > 0){ |
124 |
8
|
if(mCheckResult[0]){ |
125 |
8
|
stringBuilder.append(mAllIds[0]); |
126 |
|
} |
127 |
|
} |
128 |
544
|
for(int i = 1, n = mCheckResult.length; i < n; i++){ |
129 |
536
|
if(mCheckResult[i]){ |
130 |
20
|
stringBuilder.append(mAllIds[i]).append("|"); |
131 |
|
} |
132 |
|
} |
133 |
8
|
mSettingService.changeFavoriteIds(stringBuilder.toString()); |
134 |
|
} |
135 |
|
|
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,25 |
|
137 |
|
private static class ViewHolder{ |
138 |
|
public TextView bicycleIndex; |
139 |
|
public TextView bicycleName; |
140 |
|
public TextView bicycleAddress; |
141 |
|
public ImageView checkImage; |
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
143 |
12
|
public ViewHolder(View parent){... |
144 |
12
|
bicycleIndex = (TextView) parent.findViewById(R.id.favorite_setting_listitem_index); |
145 |
12
|
bicycleName = (TextView) parent.findViewById(R.id.favorite_setting_listitem_name); |
146 |
12
|
bicycleAddress = (TextView) parent.findViewById(R.id.favorite_setting_listitem_address); |
147 |
12
|
checkImage = (ImageView) parent.findViewById(R.id.favorite_setting_listitem_favorite_image); |
148 |
|
} |
149 |
|
} |
150 |
|
} |