Skip to content

Commit

Permalink
- refactor filter model helper
Browse files Browse the repository at this point in the history
  • Loading branch information
derreisende77 committed May 14, 2024
1 parent 40bafee commit 00a623c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import mediathek.gui.tabs.tab_film.searchfilters.FinalStageFilterNoPatternWithDescription;
import mediathek.gui.tabs.tab_film.searchfilters.FinalStagePatternFilter;
import mediathek.gui.tabs.tab_film.searchfilters.FinalStagePatternFilterWithDescription;
import mediathek.javafx.filterpanel.FilmLengthSlider;
import mediathek.javafx.filterpanel.FilterActionPanel;
import mediathek.tool.Filter;
import mediathek.tool.models.TModelFilm;
Expand All @@ -33,43 +32,11 @@ public GuiFilmeModelHelper(@NotNull FilterActionPanel filterActionPanel,
this.searchFieldData = searchFieldData;
}

private String getFilterThema() {
String filterThema = filterActionPanel.getViewSettingsPane().themaComboBox.getSelectionModel().getSelectedItem();
if (filterThema == null) {
filterThema = "";
}

return filterThema;
}

@Override
protected boolean noFiltersAreSet() {
var filmLengthSlider = filterActionPanel.getFilmLengthSlider();

return filterActionPanel.getViewSettingsPane().senderCheckList.getCheckModel().isEmpty()
&& getFilterThema().isEmpty()
&& searchFieldData.isEmpty()
&& ((int) filmLengthSlider.getLowValue() == 0)
&& ((int) filmLengthSlider.getHighValue() == FilmLengthSlider.UNLIMITED_VALUE)
&& !filterActionPanel.isDontShowAbos()
&& !filterActionPanel.isShowUnseenOnly()
&& !filterActionPanel.isShowOnlyHighQuality()
&& !filterActionPanel.isShowSubtitlesOnly()
&& !filterActionPanel.isShowLivestreamsOnly()
&& !filterActionPanel.isShowNewOnly()
&& !filterActionPanel.isShowBookMarkedOnly()
&& !filterActionPanel.isDontShowTrailers()
&& !filterActionPanel.isDontShowSignLanguage()
&& !filterActionPanel.isDontShowAudioVersions();
}


private void performTableFiltering() {
arrIrgendwo = searchFieldData.evaluateThemaTitel();

calculateFilmLengthSliderValues();

final String filterThema = getFilterThema();
final ObservableList<String> selectedSenders = filterActionPanel.getViewSettingsPane().senderCheckList.getCheckModel().getCheckedItems();

if (filterActionPanel.isShowUnseenOnly())
Expand Down Expand Up @@ -101,15 +68,8 @@ private void performTableFiltering() {
if (filterActionPanel.isShowSubtitlesOnly()) {
stream = stream.filter(this::subtitleCheck);
}
if (!filterThema.isEmpty()) {
stream = stream.filter(film -> film.getThema().equalsIgnoreCase(filterThema));
}
if (maxLength < FilmLengthSlider.UNLIMITED_VALUE) {
stream = stream.filter(this::maxLengthCheck);
}
if (filterActionPanel.isShowUnseenOnly()) {
stream = stream.filter(this::seenCheck);
}

stream = applyCommonFilters(stream);
//perform min length filtering after all others may have reduced the available entries...
stream = stream.filter(this::minLengthCheck);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import mediathek.controller.history.SeenHistoryController;
import mediathek.daten.DatenFilm;
import mediathek.gui.tabs.tab_film.SearchFieldData;
import mediathek.javafx.filterpanel.FilmLengthSlider;
import mediathek.javafx.filterpanel.FilterActionPanel;

import javax.swing.table.TableModel;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

public abstract class GuiModelHelper {
protected SliderRange sliderRange;
Expand Down Expand Up @@ -34,7 +36,51 @@ protected boolean minLengthCheck(DatenFilm film) {
return filmLength >= sliderRange.minLengthInSeconds();
}

protected abstract boolean noFiltersAreSet();
protected String getFilterThema() {
String filterThema = filterActionPanel.getViewSettingsPane().themaComboBox.getSelectionModel().getSelectedItem();
if (filterThema == null) {
filterThema = "";
}

return filterThema;
}

protected Stream<DatenFilm> applyCommonFilters(Stream<DatenFilm> stream) {
final String filterThema = getFilterThema();
if (!filterThema.isEmpty()) {
stream = stream.filter(film -> film.getThema().equalsIgnoreCase(filterThema));
}
if (maxLength < FilmLengthSlider.UNLIMITED_VALUE) {
stream = stream.filter(this::maxLengthCheck);
}
if (filterActionPanel.isShowUnseenOnly()) {
stream = stream.filter(this::seenCheck);
}
//perform min length filtering after all others may have reduced the available entries...
stream = stream.filter(this::minLengthCheck);

return stream;
}

protected boolean noFiltersAreSet() {
var filmLengthSlider = filterActionPanel.getFilmLengthSlider();

return filterActionPanel.getViewSettingsPane().senderCheckList.getCheckModel().isEmpty()
&& getFilterThema().isEmpty()
&& searchFieldData.isEmpty()
&& ((int) filmLengthSlider.getLowValue() == 0)
&& ((int) filmLengthSlider.getHighValue() == FilmLengthSlider.UNLIMITED_VALUE)
&& !filterActionPanel.isDontShowAbos()
&& !filterActionPanel.isShowUnseenOnly()
&& !filterActionPanel.isShowOnlyHighQuality()
&& !filterActionPanel.isShowSubtitlesOnly()
&& !filterActionPanel.isShowLivestreamsOnly()
&& !filterActionPanel.isShowNewOnly()
&& !filterActionPanel.isShowBookMarkedOnly()
&& !filterActionPanel.isDontShowTrailers()
&& !filterActionPanel.isDontShowSignLanguage()
&& !filterActionPanel.isDontShowAudioVersions();
}

protected boolean seenCheck(DatenFilm film) {
return !historyController.hasBeenSeenFromCache(film);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import mediathek.daten.IndexedFilmList;
import mediathek.gui.tabs.tab_film.SearchFieldData;
import mediathek.gui.tasks.LuceneIndexKeys;
import mediathek.javafx.filterpanel.FilmLengthSlider;
import mediathek.javafx.filterpanel.FilterActionPanel;
import mediathek.javafx.filterpanel.ZeitraumSpinner;
import mediathek.mainwindow.MediathekGui;
Expand Down Expand Up @@ -54,34 +53,9 @@ public LuceneGuiFilmeModelHelper(@NotNull FilterActionPanel filterActionPanel,
this.searchFieldData = searchFieldData;
}

private String getFilterThema() {
String filterThema = filterActionPanel.getViewSettingsPane().themaComboBox.getSelectionModel().getSelectedItem();
if (filterThema == null) {
filterThema = "";
}

return filterThema;
}

@Override
protected boolean noFiltersAreSet() {
var filmLengthSlider = filterActionPanel.getFilmLengthSlider();

return filterActionPanel.getViewSettingsPane().senderCheckList.getCheckModel().isEmpty()
&& getFilterThema().isEmpty()
&& searchFieldData.isEmpty()
&& ((int) filmLengthSlider.getLowValue() == 0)
&& ((int) filmLengthSlider.getHighValue() == FilmLengthSlider.UNLIMITED_VALUE)
&& !filterActionPanel.isDontShowAbos()
&& !filterActionPanel.isShowUnseenOnly()
&& !filterActionPanel.isShowOnlyHighQuality()
&& !filterActionPanel.isShowSubtitlesOnly()
&& !filterActionPanel.isShowLivestreamsOnly()
&& !filterActionPanel.isShowNewOnly()
&& !filterActionPanel.isShowBookMarkedOnly()
&& !filterActionPanel.isDontShowTrailers()
&& !filterActionPanel.isDontShowSignLanguage()
&& !filterActionPanel.isDontShowAudioVersions()
return super.noFiltersAreSet()
&& filterActionPanel.zeitraumProperty().get().equalsIgnoreCase(ZeitraumSpinner.UNLIMITED_VALUE);
}

Expand Down Expand Up @@ -177,18 +151,7 @@ private TModelFilm performTableFiltering() {
if (filterActionPanel.isDontShowAbos())
stream = stream.filter(film -> film.getAbo() == null);

final String filterThema = getFilterThema();
if (!filterThema.isEmpty()) {
stream = stream.filter(film -> film.getThema().equalsIgnoreCase(filterThema));
}
if (maxLength < FilmLengthSlider.UNLIMITED_VALUE) {
stream = stream.filter(this::maxLengthCheck);
}
if (filterActionPanel.isShowUnseenOnly()) {
stream = stream.filter(this::seenCheck);
}
//perform min length filtering after all others may have reduced the available entries...
stream = stream.filter(this::minLengthCheck);
stream = applyCommonFilters(stream);

resultList = stream.collect(Collectors.toList());
//logger.trace("Resulting filmlist size after all filters applied: {}", resultList.size());
Expand Down

0 comments on commit 00a623c

Please sign in to comment.