Skip to content

Commit ceef83d

Browse files
author
Federico Fissore
committed
Libraries that contain type "Arduino" are now listed at the top. Fixes #4195
1 parent bfeb994 commit ceef83d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryReleasesComparator.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,40 @@
2929

3030
package cc.arduino.contributions.libraries.ui;
3131

32+
import cc.arduino.contributions.libraries.ContributedLibrary;
33+
3234
import java.util.Comparator;
3335

3436
public 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
}

app/src/cc/arduino/contributions/libraries/ui/LibrariesIndexTableModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)