File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
app/src/cc/arduino/contributions/libraries/ui Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 2929
3030package cc .arduino .contributions .libraries .ui ;
3131
32+ import cc .arduino .contributions .libraries .ContributedLibrary ;
33+
3234import java .util .Comparator ;
3335
3436public class ContributedLibraryReleasesComparator implements Comparator <ContributedLibraryReleases > {
3537
38+ private final String firstType ;
39+
40+ public ContributedLibraryReleasesComparator (String firstType ) {
41+ this .firstType = firstType ;
42+ }
43+
3644 @ Override
3745 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 ());
3966 }
4067
4168}
Original file line number Diff line number Diff line change @@ -204,7 +204,7 @@ private void updateContributions() {
204204 contributions .clear ();
205205 indexer .getIndex ().getLibraries ().forEach (this ::applyFilterToLibrary );
206206 indexer .getInstalledLibraries ().forEach (this ::applyFilterToLibrary );
207- Collections .sort (contributions , new ContributedLibraryReleasesComparator ());
207+ Collections .sort (contributions , new ContributedLibraryReleasesComparator ("Arduino" ));
208208 }
209209
210210}
You can’t perform that action at this time.
0 commit comments