From 4482184979a9f996cc9bf18d4821e7c57dd8cd45 Mon Sep 17 00:00:00 2001 From: Alessandro Schwaiger Date: Thu, 13 Jun 2024 15:50:21 +0200 Subject: [PATCH 1/4] Use try-with-resources for executorService --- .../online/hatsunemiku/tachideskvaadinui/view/SearchView.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java b/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java index e54ba7a..5a160f4 100644 --- a/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java +++ b/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java @@ -348,9 +348,7 @@ private void searchSources(String query, Map> langGroupedSo searchTasks.add(runnable); } - // When upgrading to Java 21 put the executor in a try-with-resources block instead - var executor = Executors.newCachedThreadPool(); - try { + try (var executor = Executors.newCachedThreadPool()) { executor.invokeAll(searchTasks); executor.shutdown(); } catch (InterruptedException e) { From 18db89c5c32457c0206c5d096e287ac9090143f3 Mon Sep 17 00:00:00 2001 From: Alessandro Schwaiger Date: Thu, 13 Jun 2024 15:55:16 +0200 Subject: [PATCH 2/4] Fix JAVA-D1001 --- .../tachideskvaadinui/view/SearchView.java | 140 +++++++++--------- 1 file changed, 68 insertions(+), 72 deletions(-) diff --git a/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java b/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java index 5a160f4..fbbc494 100644 --- a/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java +++ b/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java @@ -68,12 +68,12 @@ public class SearchView extends StandardLayout implements HasUrlParameter { - UI ui = getUI().orElse(UI.getCurrent()); + malImportBtn.addClickListener(e -> { + UI ui = getUI().orElse(UI.getCurrent()); - if (ui == null) { - return; - } + if (ui == null) { + return; + } - ui.navigate(MALView.class); - }); + ui.navigate(MALView.class); + }); return malImportBtn; } /** - * Retrieves the "Import from AniList" button. This button is used to navigate to the {@link - * AniListView}. + * Retrieves the "Import from AniList" button. This button is used to navigate to the + * {@link AniListView}. * * @return The button that navigates to the {@link AniListView} */ @NotNull private Button getALImportBtn() { Button importBtn = new Button("Import from AniList", VaadinIcon.DOWNLOAD.create()); - importBtn.addClickListener( - e -> { - UI ui = UI.getCurrent(); + importBtn.addClickListener(e -> { + UI ui = UI.getCurrent(); - if (ui == null) { - if (getUI().isEmpty()) { - log.error("UI is not present"); - return; - } + if (ui == null) { + if (getUI().isEmpty()) { + log.error("UI is not present"); + return; + } - ui = getUI().get(); - } + ui = getUI().get(); + } - ui.navigate(AniListView.class); - }); + ui.navigate(AniListView.class); + }); return importBtn; } @@ -171,13 +170,12 @@ private ComboBox createLanguageComboBox(SourceService sourceService) { } } - langFilter.addValueChangeListener( - e -> { - if (!e.isFromClient()) { - return; - } - runSearch(searchField); - }); + langFilter.addValueChangeListener(e -> { + if (!e.isFromClient()) { + return; + } + runSearch(searchField); + }); return langFilter; } @@ -208,34 +206,28 @@ private void runSearch(SuperTextField searchField) { CompletableFuture future = CompletableFuture.runAsync(() -> search(searchField.getValue())); - future - .thenRun( - () -> { - var ui = getUI(); - - if (ui.isEmpty()) { - log.error("UI is not present"); - return; - } - - if (!ui.get().isAttached()) { - log.debug("UI is not attached anymore"); - return; - } - - ui.get() - .access( - () -> { - searchField.setSuffixComponent(null); - searchField.setReadOnly(false); - langFilter.setReadOnly(false); - }); - }) - .exceptionally( - ex -> { - log.error("Error searching", ex); - return null; - }); + future.thenRun(() -> { + var ui = getUI(); + + if (ui.isEmpty()) { + log.error("UI is not present"); + return; + } + + if (!ui.get().isAttached()) { + log.debug("UI is not attached anymore"); + return; + } + + ui.get().access(() -> { + searchField.setSuffixComponent(null); + searchField.setReadOnly(false); + langFilter.setReadOnly(false); + }); + }).exceptionally(ex -> { + log.error("Error searching", ex); + return null; + }); } private Div getLoadingDiv() { @@ -255,10 +247,9 @@ private Div getLoadingDiv() { public void search(String query) { var sources = sourceService.getSources(); - var langGroupedSources = - sources.stream() - .sorted((a, b) -> a.getDisplayName().compareToIgnoreCase(b.getDisplayName())) - .collect(Collectors.groupingBy(Source::getLang)); + var langGroupedSources = sources.stream() + .sorted((a, b) -> a.getDisplayName().compareToIgnoreCase(b.getDisplayName())) + .collect(Collectors.groupingBy(Source::getLang)); searchSources(query, langGroupedSources); } @@ -266,7 +257,7 @@ public void search(String query) { /** * Adds a search result to the user interface. * - * @param source the source of the search result + * @param source the source of the search result * @param mangaList the list of manga from the search result * @return true if the search result was successfully added, otherwise false */ @@ -327,6 +318,12 @@ private Div createSearchResultDiv(Source source, List mangaList) { return searchResult; } + /** + * Searches for manga in the specified sources + * + * @param query the search query + * @param langGroupedSources the sources grouped by language + */ private void searchSources(String query, Map> langGroupedSources) { for (var langSet : langGroupedSources.entrySet()) { @@ -340,11 +337,10 @@ private void searchSources(String query, Map> langGroupedSo List> searchTasks = new ArrayList<>(); for (var source : langSources) { - Callable runnable = - () -> { - searchSource(query, source); - return null; - }; + Callable runnable = () -> { + searchSource(query, source); + return null; + }; searchTasks.add(runnable); } From 4de99c19389fb07461af1b30d3bad0b7db8d111e Mon Sep 17 00:00:00 2001 From: Alessandro Schwaiger Date: Thu, 13 Jun 2024 15:55:27 +0200 Subject: [PATCH 3/4] Fix styles.css having invalid import --- src/main/frontend/themes/miku/styles.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/frontend/themes/miku/styles.css b/src/main/frontend/themes/miku/styles.css index 1560283..1c819fc 100644 --- a/src/main/frontend/themes/miku/styles.css +++ b/src/main/frontend/themes/miku/styles.css @@ -1,4 +1,3 @@ -@import "theme-editor.css"; /* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this From 8e3e4d09f4ad7b2f84ff17e7893d650cde183d3f Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:55:50 +0000 Subject: [PATCH 4/4] style: format code with Google Java Format This commit fixes the style issues introduced in 4de99c1 according to the output from Google Java Format. Details: https://github.com/Suwayomi/Suwayomi-VaadinUI/pull/127 --- .../tachideskvaadinui/view/SearchView.java | 136 ++++++++++-------- 1 file changed, 73 insertions(+), 63 deletions(-) diff --git a/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java b/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java index fbbc494..a8b0909 100644 --- a/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java +++ b/src/main/java/online/hatsunemiku/tachideskvaadinui/view/SearchView.java @@ -68,12 +68,12 @@ public class SearchView extends StandardLayout implements HasUrlParameter { - UI ui = getUI().orElse(UI.getCurrent()); + malImportBtn.addClickListener( + e -> { + UI ui = getUI().orElse(UI.getCurrent()); - if (ui == null) { - return; - } + if (ui == null) { + return; + } - ui.navigate(MALView.class); - }); + ui.navigate(MALView.class); + }); return malImportBtn; } /** - * Retrieves the "Import from AniList" button. This button is used to navigate to the - * {@link AniListView}. + * Retrieves the "Import from AniList" button. This button is used to navigate to the {@link + * AniListView}. * * @return The button that navigates to the {@link AniListView} */ @NotNull private Button getALImportBtn() { Button importBtn = new Button("Import from AniList", VaadinIcon.DOWNLOAD.create()); - importBtn.addClickListener(e -> { - UI ui = UI.getCurrent(); + importBtn.addClickListener( + e -> { + UI ui = UI.getCurrent(); - if (ui == null) { - if (getUI().isEmpty()) { - log.error("UI is not present"); - return; - } + if (ui == null) { + if (getUI().isEmpty()) { + log.error("UI is not present"); + return; + } - ui = getUI().get(); - } + ui = getUI().get(); + } - ui.navigate(AniListView.class); - }); + ui.navigate(AniListView.class); + }); return importBtn; } @@ -170,12 +171,13 @@ private ComboBox createLanguageComboBox(SourceService sourceService) { } } - langFilter.addValueChangeListener(e -> { - if (!e.isFromClient()) { - return; - } - runSearch(searchField); - }); + langFilter.addValueChangeListener( + e -> { + if (!e.isFromClient()) { + return; + } + runSearch(searchField); + }); return langFilter; } @@ -206,28 +208,34 @@ private void runSearch(SuperTextField searchField) { CompletableFuture future = CompletableFuture.runAsync(() -> search(searchField.getValue())); - future.thenRun(() -> { - var ui = getUI(); - - if (ui.isEmpty()) { - log.error("UI is not present"); - return; - } - - if (!ui.get().isAttached()) { - log.debug("UI is not attached anymore"); - return; - } - - ui.get().access(() -> { - searchField.setSuffixComponent(null); - searchField.setReadOnly(false); - langFilter.setReadOnly(false); - }); - }).exceptionally(ex -> { - log.error("Error searching", ex); - return null; - }); + future + .thenRun( + () -> { + var ui = getUI(); + + if (ui.isEmpty()) { + log.error("UI is not present"); + return; + } + + if (!ui.get().isAttached()) { + log.debug("UI is not attached anymore"); + return; + } + + ui.get() + .access( + () -> { + searchField.setSuffixComponent(null); + searchField.setReadOnly(false); + langFilter.setReadOnly(false); + }); + }) + .exceptionally( + ex -> { + log.error("Error searching", ex); + return null; + }); } private Div getLoadingDiv() { @@ -247,9 +255,10 @@ private Div getLoadingDiv() { public void search(String query) { var sources = sourceService.getSources(); - var langGroupedSources = sources.stream() - .sorted((a, b) -> a.getDisplayName().compareToIgnoreCase(b.getDisplayName())) - .collect(Collectors.groupingBy(Source::getLang)); + var langGroupedSources = + sources.stream() + .sorted((a, b) -> a.getDisplayName().compareToIgnoreCase(b.getDisplayName())) + .collect(Collectors.groupingBy(Source::getLang)); searchSources(query, langGroupedSources); } @@ -257,7 +266,7 @@ public void search(String query) { /** * Adds a search result to the user interface. * - * @param source the source of the search result + * @param source the source of the search result * @param mangaList the list of manga from the search result * @return true if the search result was successfully added, otherwise false */ @@ -321,7 +330,7 @@ private Div createSearchResultDiv(Source source, List mangaList) { /** * Searches for manga in the specified sources * - * @param query the search query + * @param query the search query * @param langGroupedSources the sources grouped by language */ private void searchSources(String query, Map> langGroupedSources) { @@ -337,10 +346,11 @@ private void searchSources(String query, Map> langGroupedSo List> searchTasks = new ArrayList<>(); for (var source : langSources) { - Callable runnable = () -> { - searchSource(query, source); - return null; - }; + Callable runnable = + () -> { + searchSource(query, source); + return null; + }; searchTasks.add(runnable); }