You can now filter by resolution

If the display of stream resolution is enabled in the settings, the filtering now takes the resolution into account.
So you can filter for "1080" and only get streams with a resolution of 1080p.
This commit is contained in:
0xboobface 2018-07-25 13:40:30 +02:00
parent 8aad31965d
commit 73159748cd
3 changed files with 56 additions and 32 deletions

View File

@ -11,6 +11,7 @@ public class Model {
private List<String> tags = new ArrayList<>();
private boolean online = false;
private int streamUrlIndex = -1;
private int streamResolution = -1;
public String getUrl() {
return url;
@ -68,6 +69,14 @@ public class Model {
this.streamUrlIndex = streamUrlIndex;
}
public int getStreamResolution() {
return streamResolution;
}
public void setStreamResolution(int streamResolution) {
this.streamResolution = streamResolution;
}
@Override
public int hashCode() {
final int prime = 31;

View File

@ -45,6 +45,8 @@ import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.ContextMenuEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
@ -222,10 +224,12 @@ public class ThumbCell extends StackPane {
LOG.trace("Resolution queue size: {}", ThumbOverviewTab.queue.size());
final int w = resolution[1];
Platform.runLater(() -> {
resolutionTag.setText(Integer.toString(w));
String _res = Integer.toString(w);
resolutionTag.setText(_res);
resolutionTag.setVisible(true);
resolutionBackground.setVisible(true);
resolutionBackground.setWidth(resolutionTag.getBoundsInLocal().getWidth() + 4);
model.setStreamResolution(w);
});
}
} catch (IOException | ParseException | PlaylistException | InterruptedException e) {
@ -236,8 +240,10 @@ public class ThumbCell extends StackPane {
});
} else {
ThumbOverviewTab.resolutionProcessing.remove(model);
String _res = Integer.toString(res[1]);
model.setStreamResolution(res[1]);
Platform.runLater(() -> {
resolutionTag.setText(Integer.toString(res[1]));
resolutionTag.setText(_res);
resolutionTag.setVisible(true);
resolutionBackground.setVisible(true);
resolutionBackground.setWidth(resolutionTag.getBoundsInLocal().getWidth() + 4);
@ -246,7 +252,7 @@ public class ThumbCell extends StackPane {
}
private void setImage(String url) {
if(!Objects.equals(System.getenv("CTBREC_THUMBS"), "0")) {
if(!Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
Image img = new Image(url, true);
// wait for the image to load, otherwise the ImageView replaces the current image with an "empty" image,
@ -277,12 +283,20 @@ public class ThumbCell extends StackPane {
MenuItem unfollow = new MenuItem("Unfollow");
unfollow.setOnAction((e) -> follow(false));
MenuItem copyUrl = new MenuItem("Copy URL");
copyUrl.setOnAction((e) -> {
final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent content = new ClipboardContent();
content.putString(model.getUrl());
clipboard.setContent(content);
});
ContextMenu contextMenu = new ContextMenu();
contextMenu.setAutoHide(true);
contextMenu.setHideOnEscape(true);
contextMenu.setAutoFix(true);
MenuItem followOrUnFollow = parent instanceof FollowedTab ? unfollow : follow;
contextMenu.getItems().addAll(openInPlayer, startStop , followOrUnFollow);
contextMenu.getItems().addAll(openInPlayer, startStop , followOrUnFollow, copyUrl);
return contextMenu;
}

View File

@ -85,7 +85,12 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
search.setPromptText("Filter");
search.textProperty().addListener( (observableValue, oldValue, newValue) -> {
filter = search.getText();
filter();
gridLock.lock();
try {
filter();
} finally {
gridLock.unlock();
}
});
BorderPane.setMargin(search, new Insets(5));
@ -238,38 +243,32 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
}
});
gridLock.lock();
try {
if (filter == null || filter.isEmpty()) {
for (ThumbCell thumbCell : filteredThumbCells) {
insert(thumbCell);
}
return;
if (filter == null || filter.isEmpty()) {
for (ThumbCell thumbCell : filteredThumbCells) {
insert(thumbCell);
}
return;
}
// remove the ones from grid, which don't match
for (Iterator<Node> iterator = grid.getChildren().iterator(); iterator.hasNext();) {
Node node = iterator.next();
ThumbCell cell = (ThumbCell) node;
Model m = cell.getModel();
if(!matches(m, filter)) {
iterator.remove();
filteredThumbCells.add(cell);
}
// remove the ones from grid, which don't match
for (Iterator<Node> iterator = grid.getChildren().iterator(); iterator.hasNext();) {
Node node = iterator.next();
ThumbCell cell = (ThumbCell) node;
Model m = cell.getModel();
if(!matches(m, filter)) {
iterator.remove();
filteredThumbCells.add(cell);
}
}
// add the ones, which might have been filtered before, but now match
for (Iterator<ThumbCell> iterator = filteredThumbCells.iterator(); iterator.hasNext();) {
ThumbCell thumbCell = iterator.next();
Model m = thumbCell.getModel();
if(matches(m, filter)) {
iterator.remove();
insert(thumbCell);
}
// add the ones, which might have been filtered before, but now match
for (Iterator<ThumbCell> iterator = filteredThumbCells.iterator(); iterator.hasNext();) {
ThumbCell thumbCell = iterator.next();
Model m = thumbCell.getModel();
if(matches(m, filter)) {
iterator.remove();
insert(thumbCell);
}
} finally {
gridLock.unlock();
}
}
@ -305,7 +304,9 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
for (String tag : m.getTags()) {
searchTextBuilder.append(tag).append(' ');
}
searchTextBuilder.append(m.getStreamResolution());
String searchText = searchTextBuilder.toString().trim();
LOG.debug("{} -> {}", m.getName(), searchText);
boolean tokensMissing = false;
for (String token : tokens) {
if(!searchText.contains(token)) {