forked from j62/ctbrec
1
0
Fork 0

Code cleanup

This commit is contained in:
0xboobface 2020-01-03 12:26:37 +01:00
parent e14296bc1b
commit 41e2e5ce54
1 changed files with 29 additions and 39 deletions

View File

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