File tree Expand file tree Collapse file tree 6 files changed +137
-0
lines changed
app/src/cc/arduino/contributions Expand file tree Collapse file tree 6 files changed +137
-0
lines changed Original file line number Diff line number Diff line change
1
+ package cc .arduino .contributions .libraries .filters ;
2
+
3
+ import cc .arduino .contributions .VersionComparator ;
4
+ import cc .arduino .contributions .libraries .ContributedLibrary ;
5
+ import cc .arduino .contributions .libraries .LibrariesIndexer ;
6
+ import com .google .common .base .Predicate ;
7
+ import processing .app .packages .UserLibrary ;
8
+
9
+ import java .util .List ;
10
+
11
+ public class UpdatableLibraryPredicate implements Predicate <ContributedLibrary > {
12
+
13
+ private final LibrariesIndexer indexer ;
14
+ private final VersionComparator versionComparator ;
15
+
16
+ public UpdatableLibraryPredicate (LibrariesIndexer indexer ) {
17
+ this .indexer = indexer ;
18
+ this .versionComparator = new VersionComparator ();
19
+ }
20
+
21
+ @ Override
22
+ public boolean apply (ContributedLibrary contributedLibrary ) {
23
+ String libraryName = contributedLibrary .getName ();
24
+ UserLibrary installed = indexer .getInstalledLibraries ().getByName (libraryName );
25
+ if (installed == null ) {
26
+ return false ;
27
+ }
28
+ List <ContributedLibrary > libraries = indexer .getIndex ().find (libraryName );
29
+ return libraries .stream ()
30
+ .filter (library -> versionComparator .greaterThan (library .getParsedVersion (), installed .getParsedVersion ()))
31
+ .count () > 0 ;
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ package cc .arduino .contributions .libraries .ui ;
2
+
3
+ import cc .arduino .contributions .libraries .ContributedLibrary ;
4
+ import cc .arduino .contributions .libraries .LibrariesIndexer ;
5
+ import cc .arduino .contributions .libraries .filters .UpdatableLibraryPredicate ;
6
+ import cc .arduino .contributions .ui .DropdownItem ;
7
+ import com .google .common .base .Predicate ;
8
+
9
+ import static processing .app .I18n ._ ;
10
+
11
+ public class DropdownUpdatableLibrariesItem implements DropdownItem <ContributedLibrary > {
12
+
13
+ private final LibrariesIndexer indexer ;
14
+
15
+ public DropdownUpdatableLibrariesItem (LibrariesIndexer indexer ) {
16
+ this .indexer = indexer ;
17
+ }
18
+
19
+ @ Override
20
+ public Predicate <ContributedLibrary > getFilterPredicate () {
21
+ return new UpdatableLibraryPredicate (indexer );
22
+ }
23
+
24
+ @ Override
25
+ public String toString () {
26
+ return _ ("Updatable" );
27
+ }
28
+
29
+ @ Override
30
+ public boolean equals (Object obj ) {
31
+ return obj instanceof DropdownUpdatableLibrariesItem ;
32
+ }
33
+
34
+ }
Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ public void setIndexer(LibrariesIndexer indexer) {
165
165
typeFilter = null ;
166
166
typeChooser .removeAllItems ();
167
167
typeChooser .addItem (new DropdownAllItem ());
168
+ typeChooser .addItem (new DropdownUpdatableLibrariesItem (indexer ));
168
169
typeChooser .addItem (new DropdownInstalledLibraryItem (indexer .getIndex ()));
169
170
java .util .List <String > types = new LinkedList <String >(indexer .getIndex ().getTypes ());
170
171
Collections .sort (types , new LibraryTypeComparator ());
Original file line number Diff line number Diff line change
1
+ package cc .arduino .contributions .packages .filters ;
2
+
3
+ import cc .arduino .contributions .VersionComparator ;
4
+ import cc .arduino .contributions .packages .ContributedPlatform ;
5
+ import cc .arduino .contributions .packages .ContributionsIndexer ;
6
+ import com .google .common .base .Predicate ;
7
+
8
+ import java .util .List ;
9
+
10
+ public class UpdatablePlatformPredicate implements Predicate <ContributedPlatform > {
11
+
12
+ private final ContributionsIndexer indexer ;
13
+ private final VersionComparator versionComparator ;
14
+
15
+ public UpdatablePlatformPredicate (ContributionsIndexer indexer ) {
16
+ this .indexer = indexer ;
17
+ this .versionComparator = new VersionComparator ();
18
+ }
19
+
20
+ @ Override
21
+ public boolean apply (ContributedPlatform contributedPlatform ) {
22
+ String packageName = contributedPlatform .getParentPackage ().getName ();
23
+ String architecture = contributedPlatform .getArchitecture ();
24
+
25
+ ContributedPlatform installed = indexer .getInstalled (packageName , architecture );
26
+ if (installed == null ) {
27
+ return false ;
28
+ }
29
+
30
+ List <ContributedPlatform > platforms = indexer .getIndex ().findPlatforms (packageName , architecture );
31
+ return platforms .stream ()
32
+ .filter (platform -> versionComparator .greaterThan (platform .getParsedVersion (), installed .getParsedVersion ()))
33
+ .count () > 0 ;
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ public void setIndexer(ContributionsIndexer indexer) {
106
106
107
107
// Enable categories combo only if there are two or more choices
108
108
categoryChooser .addItem (new DropdownAllCoresItem ());
109
+ categoryChooser .addItem (new DropdownUpdatableCoresItem (indexer ));
109
110
Collection <String > categories = indexer .getCategories ();
110
111
for (String s : categories ) {
111
112
categoryChooser .addItem (new DropdownCoreOfCategoryItem (s ));
Original file line number Diff line number Diff line change
1
+ package cc .arduino .contributions .packages .ui ;
2
+
3
+ import cc .arduino .contributions .packages .ContributedPlatform ;
4
+ import cc .arduino .contributions .packages .ContributionsIndexer ;
5
+ import cc .arduino .contributions .packages .filters .UpdatablePlatformPredicate ;
6
+ import cc .arduino .contributions .ui .DropdownItem ;
7
+ import com .google .common .base .Predicate ;
8
+
9
+ import static processing .app .I18n ._ ;
10
+
11
+ public class DropdownUpdatableCoresItem implements DropdownItem <ContributedPlatform > {
12
+
13
+ private final ContributionsIndexer indexer ;
14
+
15
+ public DropdownUpdatableCoresItem (ContributionsIndexer indexer ) {
16
+ this .indexer = indexer ;
17
+ }
18
+
19
+ @ Override
20
+ public Predicate <ContributedPlatform > getFilterPredicate () {
21
+ return new UpdatablePlatformPredicate (indexer );
22
+ }
23
+
24
+ @ Override
25
+ public String toString () {
26
+ return _ ("Updatable" );
27
+ }
28
+
29
+ @ Override
30
+ public boolean equals (Object obj ) {
31
+ return obj instanceof DropdownUpdatableCoresItem ;
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments