1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package net.sourceforge.subsonic.androidapp.util; |
20 |
|
|
21 |
|
import net.sourceforge.subsonic.androidapp.domain.Artist; |
22 |
|
import net.sourceforge.subsonic.androidapp.R; |
23 |
|
import android.widget.ArrayAdapter; |
24 |
|
import android.widget.SectionIndexer; |
25 |
|
import android.content.Context; |
26 |
|
|
27 |
|
import java.util.List; |
28 |
|
import java.util.Set; |
29 |
|
import java.util.LinkedHashSet; |
30 |
|
import java.util.ArrayList; |
31 |
|
|
32 |
|
|
33 |
|
@author |
34 |
|
|
|
|
| 55,2% |
Uncovered Elements: 13 (29) |
Complexity: 8 |
Complexity Density: 0,47 |
|
35 |
|
public class ArtistAdapter extends ArrayAdapter<Artist> implements SectionIndexer { |
36 |
|
|
37 |
|
|
38 |
|
private final Object[] sections; |
39 |
|
private final Integer[] positions; |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 3 |
Complexity Density: 0,27 |
|
41 |
4
|
public ArtistAdapter(Context context, List<Artist> artists) {... |
42 |
4
|
super(context, R.layout.artist_list_item, artists); |
43 |
|
|
44 |
4
|
Set<String> sectionSet = new LinkedHashSet<String>(30); |
45 |
4
|
List<Integer> positionList = new ArrayList<Integer>(30); |
46 |
78
|
for (int i = 0; i < artists.size(); i++) { |
47 |
74
|
Artist artist = artists.get(i); |
48 |
74
|
String index = artist.getIndex(); |
49 |
74
|
if (!sectionSet.contains(index)) { |
50 |
37
|
sectionSet.add(index); |
51 |
37
|
positionList.add(i); |
52 |
|
} |
53 |
|
} |
54 |
4
|
sections = sectionSet.toArray(new Object[sectionSet.size()]); |
55 |
4
|
positions = positionList.toArray(new Integer[positionList.size()]); |
56 |
|
} |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0
|
@Override... |
59 |
|
public Object[] getSections() { |
60 |
0
|
return sections; |
61 |
|
} |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
0
|
@Override... |
64 |
|
public int getPositionForSection(int section) { |
65 |
0
|
return positions[section]; |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0,75 |
|
68 |
0
|
@Override... |
69 |
|
public int getSectionForPosition(int pos) { |
70 |
0
|
for (int i = 0; i < sections.length - 1; i++) { |
71 |
0
|
if (pos < positions[i + 1]) { |
72 |
0
|
return i; |
73 |
|
} |
74 |
|
} |
75 |
0
|
return sections.length - 1; |
76 |
|
} |
77 |
|
} |