File tree 2 files changed +29
-2
lines changed
app/src/cc/arduino/contributions/libraries/ui 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 29
29
30
30
package cc .arduino .contributions .libraries .ui ;
31
31
32
+ import cc .arduino .contributions .libraries .ContributedLibrary ;
33
+
32
34
import java .util .Comparator ;
33
35
34
36
public class ContributedLibraryReleasesComparator implements Comparator <ContributedLibraryReleases > {
35
37
38
+ private final String firstType ;
39
+
40
+ public ContributedLibraryReleasesComparator (String firstType ) {
41
+ this .firstType = firstType ;
42
+ }
43
+
36
44
@ Override
37
45
public int compare (ContributedLibraryReleases o1 , ContributedLibraryReleases o2 ) {
38
- return o1 .getLibrary ().getName ().compareToIgnoreCase (o2 .getLibrary ().getName ());
46
+ ContributedLibrary lib1 = o1 .getLibrary ();
47
+ ContributedLibrary lib2 = o2 .getLibrary ();
48
+
49
+ if (lib1 .getTypes () == null || lib2 .getTypes () == null ) {
50
+ return compareName (lib1 , lib2 );
51
+ }
52
+ if (lib1 .getTypes ().contains (firstType ) && lib2 .getTypes ().contains (firstType )) {
53
+ return compareName (lib1 , lib2 );
54
+ }
55
+ if (lib1 .getTypes ().contains (firstType )) {
56
+ return -1 ;
57
+ }
58
+ if (lib2 .getTypes ().contains (firstType )) {
59
+ return 1 ;
60
+ }
61
+ return compareName (lib1 , lib2 );
62
+ }
63
+
64
+ private int compareName (ContributedLibrary lib1 , ContributedLibrary lib2 ) {
65
+ return lib1 .getName ().compareToIgnoreCase (lib2 .getName ());
39
66
}
40
67
41
68
}
Original file line number Diff line number Diff line change @@ -204,7 +204,7 @@ private void updateContributions() {
204
204
contributions .clear ();
205
205
indexer .getIndex ().getLibraries ().forEach (this ::applyFilterToLibrary );
206
206
indexer .getInstalledLibraries ().forEach (this ::applyFilterToLibrary );
207
- Collections .sort (contributions , new ContributedLibraryReleasesComparator ());
207
+ Collections .sort (contributions , new ContributedLibraryReleasesComparator ("Arduino" ));
208
208
}
209
209
210
210
}
You can’t perform that action at this time.
0 commit comments