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); }