forked from j62/ctbrec
Code cleanup
This commit is contained in:
parent
e14296bc1b
commit
41e2e5ce54
|
@ -91,10 +91,7 @@ public class ThumbCell extends StackPane {
|
||||||
private boolean mouseHovering = false;
|
private boolean mouseHovering = false;
|
||||||
private boolean recording = false;
|
private boolean recording = false;
|
||||||
private static ExecutorService imageLoadingThreadPool = Executors.newFixedThreadPool(30);
|
private static ExecutorService imageLoadingThreadPool = Executors.newFixedThreadPool(30);
|
||||||
private static Cache<String, int[]> resolutionCache = CacheBuilder.newBuilder()
|
private static Cache<String, int[]> resolutionCache = CacheBuilder.newBuilder().expireAfterAccess(4, TimeUnit.HOURS).maximumSize(1000).build();
|
||||||
.expireAfterAccess(4, TimeUnit.HOURS)
|
|
||||||
.maximumSize(1000)
|
|
||||||
.build();
|
|
||||||
private ThumbOverviewTab parent;
|
private ThumbOverviewTab parent;
|
||||||
|
|
||||||
public ThumbCell(ThumbOverviewTab parent, Model model, Recorder recorder) {
|
public ThumbCell(ThumbOverviewTab parent, Model model, Recorder recorder) {
|
||||||
|
@ -130,7 +127,7 @@ public class ThumbCell extends StackPane {
|
||||||
getChildren().add(topicBackground);
|
getChildren().add(topicBackground);
|
||||||
|
|
||||||
resolutionBackground = new Rectangle(34, 16);
|
resolutionBackground = new Rectangle(34, 16);
|
||||||
resolutionBackground.setFill(resolutionOnlineColor );
|
resolutionBackground.setFill(resolutionOnlineColor);
|
||||||
resolutionBackground.setVisible(false);
|
resolutionBackground.setVisible(false);
|
||||||
resolutionBackground.setArcHeight(5);
|
resolutionBackground.setArcHeight(5);
|
||||||
resolutionBackground.setArcWidth(resolutionBackground.getArcHeight());
|
resolutionBackground.setArcWidth(resolutionBackground.getArcHeight());
|
||||||
|
@ -179,7 +176,7 @@ public class ThumbCell extends StackPane {
|
||||||
StackPane.setAlignment(pausedIndicator, Pos.TOP_LEFT);
|
StackPane.setAlignment(pausedIndicator, Pos.TOP_LEFT);
|
||||||
getChildren().add(pausedIndicator);
|
getChildren().add(pausedIndicator);
|
||||||
|
|
||||||
if(Config.getInstance().getSettings().livePreviews) {
|
if (Config.getInstance().getSettings().livePreviews) {
|
||||||
getChildren().add(createPreviewTrigger());
|
getChildren().add(createPreviewTrigger());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +192,7 @@ public class ThumbCell extends StackPane {
|
||||||
Color normal = recording ? colorRecording : colorNormal;
|
Color normal = recording ? colorRecording : colorNormal;
|
||||||
new ParallelTransition(changeColor(nameBackground, normal, colorHighlight), changeColor(name, colorHighlight, normal)).playFromStart();
|
new ParallelTransition(changeColor(nameBackground, normal, colorHighlight), changeColor(name, colorHighlight, normal)).playFromStart();
|
||||||
new ParallelTransition(changeOpacity(topicBackground, 0.7), changeOpacity(topic, 0.7)).playFromStart();
|
new ParallelTransition(changeOpacity(topicBackground, 0.7), changeOpacity(topic, 0.7)).playFromStart();
|
||||||
if(Config.getInstance().getSettings().determineResolution) {
|
if (Config.getInstance().getSettings().determineResolution) {
|
||||||
resolutionBackground.setVisible(false);
|
resolutionBackground.setVisible(false);
|
||||||
resolutionTag.setVisible(false);
|
resolutionTag.setVisible(false);
|
||||||
}
|
}
|
||||||
|
@ -205,7 +202,7 @@ public class ThumbCell extends StackPane {
|
||||||
Color normal = recording ? colorRecording : colorNormal;
|
Color normal = recording ? colorRecording : colorNormal;
|
||||||
new ParallelTransition(changeColor(nameBackground, colorHighlight, normal), changeColor(name, normal, colorHighlight)).playFromStart();
|
new ParallelTransition(changeColor(nameBackground, colorHighlight, normal), changeColor(name, normal, colorHighlight)).playFromStart();
|
||||||
new ParallelTransition(changeOpacity(topicBackground, 0), changeOpacity(topic, 0)).playFromStart();
|
new ParallelTransition(changeOpacity(topicBackground, 0), changeOpacity(topic, 0)).playFromStart();
|
||||||
if(Config.getInstance().getSettings().determineResolution && !resolutionTag.getText().isEmpty()) {
|
if (Config.getInstance().getSettings().determineResolution && !resolutionTag.getText().isEmpty()) {
|
||||||
resolutionBackground.setVisible(true);
|
resolutionBackground.setVisible(true);
|
||||||
resolutionTag.setVisible(true);
|
resolutionTag.setVisible(true);
|
||||||
}
|
}
|
||||||
|
@ -223,11 +220,7 @@ public class ThumbCell extends StackPane {
|
||||||
previewTrigger.setOpacity(.8);
|
previewTrigger.setOpacity(.8);
|
||||||
previewTrigger.setMaxSize(s, s);
|
previewTrigger.setMaxSize(s, s);
|
||||||
|
|
||||||
Polygon play = new Polygon(
|
Polygon play = new Polygon(16, 8, 26, 15, 16, 22);
|
||||||
16, 8,
|
|
||||||
26, 15,
|
|
||||||
16, 22
|
|
||||||
);
|
|
||||||
StackPane.setMargin(play, new Insets(0, 0, 0, 3));
|
StackPane.setMargin(play, new Insets(0, 0, 0, 3));
|
||||||
play.setStyle("-fx-background-color: black;");
|
play.setStyle("-fx-background-color: black;");
|
||||||
previewTrigger.getChildren().add(play);
|
previewTrigger.getChildren().add(play);
|
||||||
|
@ -254,7 +247,7 @@ public class ThumbCell extends StackPane {
|
||||||
streamPreview.startStream(model);
|
streamPreview.startStream(model);
|
||||||
recordingIndicator.setVisible(!visible);
|
recordingIndicator.setVisible(!visible);
|
||||||
pausedIndicator.setVisible(!visible);
|
pausedIndicator.setVisible(!visible);
|
||||||
if(!visible) {
|
if (!visible) {
|
||||||
updateRecordingIndicator();
|
updateRecordingIndicator();
|
||||||
}
|
}
|
||||||
previewTrigger.setCursor(visible ? Cursor.HAND : Cursor.DEFAULT);
|
previewTrigger.setCursor(visible ? Cursor.HAND : Cursor.DEFAULT);
|
||||||
|
@ -275,7 +268,7 @@ public class ThumbCell extends StackPane {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void determineResolution() {
|
private void determineResolution() {
|
||||||
if(ThumbOverviewTab.resolutionProcessing.contains(model)) {
|
if (ThumbOverviewTab.resolutionProcessing.contains(model)) {
|
||||||
LOG.trace("Already fetching resolution for model {}. Queue size {}", model.getName(), ThumbOverviewTab.resolutionProcessing.size());
|
LOG.trace("Already fetching resolution for model {}. Queue size {}", model.getName(), ThumbOverviewTab.resolutionProcessing.size());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -308,13 +301,13 @@ public class ThumbCell extends StackPane {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
LOG.debug(COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL, model.getName(), e1.getLocalizedMessage());
|
LOG.debug(COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL, model.getName(), e1.getLocalizedMessage());
|
||||||
} catch(InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
LOG.debug(COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL, model.getName(), e1.getLocalizedMessage());
|
LOG.debug(COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL, model.getName(), e1.getLocalizedMessage());
|
||||||
} catch(ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
if(e.getCause() instanceof EOFException) {
|
if (e.getCause() instanceof EOFException) {
|
||||||
LOG.debug("Couldn't update resolution tag for model {}. Playlist empty", model.getName());
|
LOG.debug("Couldn't update resolution tag for model {}. Playlist empty", model.getName());
|
||||||
} else if(e.getCause() instanceof ParseException) {
|
} else if (e.getCause() instanceof ParseException) {
|
||||||
LOG.debug(COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL, model.getName(), e.getMessage());
|
LOG.debug(COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL, model.getName(), e.getMessage());
|
||||||
} else {
|
} else {
|
||||||
LOG.debug(COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL, model.getName(), e.getMessage());
|
LOG.debug(COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL, model.getName(), e.getMessage());
|
||||||
|
@ -343,7 +336,7 @@ public class ThumbCell extends StackPane {
|
||||||
final Paint c = resolutionBackgroundColor;
|
final Paint c = resolutionBackgroundColor;
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
resolutionTag.setText(tagText);
|
resolutionTag.setText(tagText);
|
||||||
if(!mouseHovering) {
|
if (!mouseHovering) {
|
||||||
resolutionTag.setVisible(true);
|
resolutionTag.setVisible(true);
|
||||||
resolutionBackground.setVisible(true);
|
resolutionBackground.setVisible(true);
|
||||||
}
|
}
|
||||||
|
@ -357,10 +350,7 @@ public class ThumbCell extends StackPane {
|
||||||
boolean updateThumbs = Config.getInstance().getSettings().updateThumbnails;
|
boolean updateThumbs = Config.getInstance().getSettings().updateThumbnails;
|
||||||
if (updateThumbs || iv.getImage() == null) {
|
if (updateThumbs || iv.getImage() == null) {
|
||||||
imageLoadingThreadPool.submit(() -> {
|
imageLoadingThreadPool.submit(() -> {
|
||||||
Request req = new Request.Builder()
|
Request req = new Request.Builder().url(url).header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent).build();
|
||||||
.url(url)
|
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
|
||||||
.build();
|
|
||||||
try (Response resp = CamrecApplication.httpClient.execute(req)) {
|
try (Response resp = CamrecApplication.httpClient.execute(req)) {
|
||||||
if (resp.isSuccessful()) {
|
if (resp.isSuccessful()) {
|
||||||
Image img = new Image(resp.body().byteStream(), 0, 360, true, true);
|
Image img = new Image(resp.body().byteStream(), 0, 360, true, true);
|
||||||
|
@ -411,7 +401,7 @@ public class ThumbCell extends StackPane {
|
||||||
|
|
||||||
private void setRecording(boolean recording) {
|
private void setRecording(boolean recording) {
|
||||||
this.recording = recording;
|
this.recording = recording;
|
||||||
if(recording) {
|
if (recording) {
|
||||||
Color c = mouseHovering ? colorHighlight : colorRecording;
|
Color c = mouseHovering ? colorHighlight : colorRecording;
|
||||||
nameBackground.setFill(c);
|
nameBackground.setFill(c);
|
||||||
} else {
|
} else {
|
||||||
|
@ -423,7 +413,7 @@ public class ThumbCell extends StackPane {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRecordingIndicator() {
|
private void updateRecordingIndicator() {
|
||||||
if(recording) {
|
if (recording) {
|
||||||
recordingIndicator.setVisible(!model.isSuspended());
|
recordingIndicator.setVisible(!model.isSuspended());
|
||||||
pausedIndicator.setVisible(model.isSuspended());
|
pausedIndicator.setVisible(model.isSuspended());
|
||||||
} else {
|
} else {
|
||||||
|
@ -436,7 +426,7 @@ public class ThumbCell extends StackPane {
|
||||||
setCursor(Cursor.WAIT);
|
setCursor(Cursor.WAIT);
|
||||||
|
|
||||||
boolean selectSource = Config.getInstance().getSettings().chooseStreamQuality;
|
boolean selectSource = Config.getInstance().getSettings().chooseStreamQuality;
|
||||||
if(selectSource && start) {
|
if (selectSource && start) {
|
||||||
Function<Model, Void> onSuccess = modl -> {
|
Function<Model, Void> onSuccess = modl -> {
|
||||||
startStopActionAsync(modl, start);
|
startStopActionAsync(modl, start);
|
||||||
return null;
|
return null;
|
||||||
|
@ -459,7 +449,7 @@ public class ThumbCell extends StackPane {
|
||||||
setCursor(Cursor.WAIT);
|
setCursor(Cursor.WAIT);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
if(pause) {
|
if (pause) {
|
||||||
recorder.suspendRecording(model);
|
recorder.suspendRecording(model);
|
||||||
} else {
|
} else {
|
||||||
recorder.resumeRecording(model);
|
recorder.resumeRecording(model);
|
||||||
|
@ -483,7 +473,7 @@ public class ThumbCell extends StackPane {
|
||||||
private void startStopActionAsync(Model model, boolean start) {
|
private void startStopActionAsync(Model model, boolean start) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
if(start) {
|
if (start) {
|
||||||
recorder.startRecording(model);
|
recorder.startRecording(model);
|
||||||
setRecording(true);
|
setRecording(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -509,10 +499,10 @@ public class ThumbCell extends StackPane {
|
||||||
setCursor(Cursor.WAIT);
|
setCursor(Cursor.WAIT);
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
if(follow) {
|
if (follow) {
|
||||||
SiteUiFactory.getUi(model.getSite()).login();
|
SiteUiFactory.getUi(model.getSite()).login();
|
||||||
boolean followed = model.follow();
|
boolean followed = model.follow();
|
||||||
if(followed) {
|
if (followed) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
|
@ -527,7 +517,7 @@ public class ThumbCell extends StackPane {
|
||||||
} else {
|
} else {
|
||||||
SiteUiFactory.getUi(model.getSite()).login();
|
SiteUiFactory.getUi(model.getSite()).login();
|
||||||
boolean unfollowed = model.unfollow();
|
boolean unfollowed = model.unfollow();
|
||||||
if(unfollowed) {
|
if (unfollowed) {
|
||||||
Platform.runLater(() -> thumbCellList.remove(ThumbCell.this));
|
Platform.runLater(() -> thumbCellList.remove(ThumbCell.this));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -587,7 +577,7 @@ public class ThumbCell extends StackPane {
|
||||||
txt += model.getDescription() != null ? model.getDescription() : "";
|
txt += model.getDescription() != null ? model.getDescription() : "";
|
||||||
topic.setText(txt);
|
topic.setText(txt);
|
||||||
|
|
||||||
if(Config.getInstance().getSettings().determineResolution) {
|
if (Config.getInstance().getSettings().determineResolution) {
|
||||||
determineResolution();
|
determineResolution();
|
||||||
} else {
|
} else {
|
||||||
resolutionBackground.setVisible(false);
|
resolutionBackground.setVisible(false);
|
||||||
|
@ -628,9 +618,9 @@ public class ThumbCell extends StackPane {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSize(int w, int h) {
|
private void setSize(int w, int h) {
|
||||||
if(iv.getImage() != null) {
|
if (iv.getImage() != null) {
|
||||||
double aspectRatio = iv.getImage().getWidth() / iv.getImage().getHeight();
|
double aspectRatio = iv.getImage().getWidth() / iv.getImage().getHeight();
|
||||||
if(aspectRatio > 1) {
|
if (aspectRatio > 1) {
|
||||||
iv.setFitWidth(w);
|
iv.setFitWidth(w);
|
||||||
} else {
|
} else {
|
||||||
iv.setFitHeight(h);
|
iv.setFitHeight(h);
|
||||||
|
@ -642,11 +632,11 @@ public class ThumbCell extends StackPane {
|
||||||
nameBackground.setHeight(20);
|
nameBackground.setHeight(20);
|
||||||
topicBackground.setWidth(w);
|
topicBackground.setWidth(w);
|
||||||
topicBackground.setHeight(h - nameBackground.getHeight());
|
topicBackground.setHeight(h - nameBackground.getHeight());
|
||||||
topic.prefHeight(getHeight()-25);
|
topic.prefHeight(getHeight() - 25);
|
||||||
topic.maxHeight(getHeight()-25);
|
topic.maxHeight(getHeight() - 25);
|
||||||
int margin = 4;
|
int margin = 4;
|
||||||
topic.maxWidth(w-margin*2);
|
topic.maxWidth(w - margin * 2);
|
||||||
topic.setWrappingWidth(w-margin*2);
|
topic.setWrappingWidth(w - margin * 2);
|
||||||
|
|
||||||
streamPreview.resizeTo(w, h);
|
streamPreview.resizeTo(w, h);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue