forked from j62/ctbrec
1
0
Fork 0

Code cleanup

This commit is contained in:
0xb00bface 2020-11-28 17:41:56 +01:00
parent 5c3755dedc
commit 267e3394b5
1 changed files with 18 additions and 42 deletions

View File

@ -13,6 +13,7 @@ import ctbrec.ui.CamrecApplication;
import ctbrec.ui.SiteUiFactory; import ctbrec.ui.SiteUiFactory;
import ctbrec.ui.StreamSourceSelectionDialog; import ctbrec.ui.StreamSourceSelectionDialog;
import ctbrec.ui.action.PlayAction; import ctbrec.ui.action.PlayAction;
import ctbrec.ui.controls.Dialogs;
import ctbrec.ui.controls.PausedIndicator; import ctbrec.ui.controls.PausedIndicator;
import ctbrec.ui.controls.StreamPreview; import ctbrec.ui.controls.StreamPreview;
import javafx.animation.FadeTransition; import javafx.animation.FadeTransition;
@ -22,7 +23,6 @@ import javafx.animation.Transition;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.BooleanProperty; import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.geometry.Insets; import javafx.geometry.Insets;
@ -236,7 +236,7 @@ public class ThumbCell extends StackPane {
play.setStyle("-fx-background-color: black;"); play.setStyle("-fx-background-color: black;");
previewTrigger.getChildren().add(play); previewTrigger.getChildren().add(play);
Circle clip = new Circle(s / 2); Circle clip = new Circle(s / 2.0);
clip.setTranslateX(clip.getRadius()); clip.setTranslateX(clip.getRadius());
clip.setTranslateY(clip.getRadius()); clip.setTranslateY(clip.getRadius());
previewTrigger.setClip(clip); previewTrigger.setClip(clip);
@ -287,8 +287,7 @@ public class ThumbCell extends StackPane {
resolution = resolutionCache.get(model); resolution = resolutionCache.get(model);
resolutionBackgroundColor = resolutionOnlineColor; resolutionBackgroundColor = resolutionOnlineColor;
final int w = resolution[1]; final int w = resolution[1];
String width = w != Integer.MAX_VALUE ? Integer.toString(w) : "HD"; tagText = w != Integer.MAX_VALUE ? Integer.toString(w) : "HD";
tagText = width;
if (w == 0) { if (w == 0) {
State state = model.getOnlineState(false); State state = model.getOnlineState(false);
tagText = state.name(); tagText = state.name();
@ -364,7 +363,7 @@ public class ThumbCell extends StackPane {
setThumbWidth(Config.getInstance().getSettings().thumbWidth); setThumbWidth(Config.getInstance().getSettings().thumbWidth);
}); });
} else { } else {
img.progressProperty().addListener((ChangeListener<Number>) (observable, oldValue, newValue) -> { img.progressProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.doubleValue() == 1.0) { if (newValue.doubleValue() == 1.0) {
iv.setImage(img); iv.setImage(img);
setThumbWidth(Config.getInstance().getSettings().thumbWidth); setThumbWidth(Config.getInstance().getSettings().thumbWidth);
@ -403,13 +402,13 @@ public class ThumbCell extends StackPane {
private void setRecording(boolean recording) { private void setRecording(boolean recording) {
this.recording = recording; this.recording = recording;
Color c;
if (recording) { if (recording) {
Color c = mouseHovering ? colorHighlight : colorRecording; c = mouseHovering ? colorHighlight : colorRecording;
nameBackground.setFill(c);
} else { } else {
Color c = mouseHovering ? colorHighlight : colorNormal; c = mouseHovering ? colorHighlight : colorNormal;
nameBackground.setFill(c);
} }
nameBackground.setFill(c);
updateRecordingIndicator(); updateRecordingIndicator();
} }
@ -430,7 +429,7 @@ public class ThumbCell extends StackPane {
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, true);
return null; return null;
}; };
Function<Throwable, Void> onFail = throwable -> { Function<Throwable, Void> onFail = throwable -> {
@ -484,13 +483,7 @@ public class ThumbCell extends StackPane {
} }
} catch (Exception e1) { } catch (Exception e1) {
LOG.error(COULDNT_START_STOP_RECORDING, e1); LOG.error(COULDNT_START_STOP_RECORDING, e1);
Platform.runLater(() -> { Dialogs.showError(getScene(), COULDNT_START_STOP_RECORDING, "I/O error while starting/stopping the recording: ", e1);
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
alert.setTitle(ERROR);
alert.setHeaderText(COULDNT_START_STOP_RECORDING);
alert.setContentText("I/O error while starting/stopping the recording: " + e1.getLocalizedMessage());
alert.showAndWait();
});
} finally { } finally {
setCursor(Cursor.DEFAULT); setCursor(Cursor.DEFAULT);
} }
@ -507,13 +500,7 @@ public class ThumbCell extends StackPane {
if (followed) { if (followed) {
return true; return true;
} else { } else {
Platform.runLater(() -> { Dialogs.showError(getScene(), "Couldn't follow model", "", null);
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
alert.setTitle(ERROR);
alert.setHeaderText("Couldn't follow model");
alert.setContentText("");
alert.showAndWait();
});
return false; return false;
} }
} else { } else {
@ -523,25 +510,14 @@ public class ThumbCell extends StackPane {
Platform.runLater(() -> thumbCellList.remove(ThumbCell.this)); Platform.runLater(() -> thumbCellList.remove(ThumbCell.this));
return true; return true;
} else { } else {
Platform.runLater(() -> { Dialogs.showError(getScene(), "Couldn't unfollow model", "", null);
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
alert.setTitle(ERROR);
alert.setHeaderText("Couldn't unfollow model");
alert.setContentText("");
alert.showAndWait();
});
return false; return false;
} }
} }
} catch (Exception e1) { } catch (Exception e1) {
LOG.error("Couldn't follow/unfollow model {}", model.getName(), e1); LOG.error("Couldn't follow/unfollow model {}", model.getName(), e1);
Platform.runLater(() -> { String msg = "I/O error while following/unfollowing model " + model.getName() + ": ";
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene()); Dialogs.showError(getScene(), "Couldn't follow/unfollow model", msg, e1);
alert.setTitle(ERROR);
alert.setHeaderText("Couldn't follow/unfollow model");
alert.setContentText("I/O error while following/unfollowing model " + model.getName() + ": " + e1.getLocalizedMessage());
alert.showAndWait();
});
return false; return false;
} finally { } finally {
setCursor(Cursor.DEFAULT); setCursor(Cursor.DEFAULT);
@ -616,8 +592,8 @@ public class ThumbCell extends StackPane {
public void setThumbWidth(int width) { public void setThumbWidth(int width) {
int height = (int) (width * imgAspectRatio); int height = (int) (width * imgAspectRatio);
setSize(width, height); setSize(width, height);
iv.prefHeight(height); iv.prefHeight(width);
iv.prefWidth(width); iv.prefWidth(height);
} }
private void setSize(int w, int h) { private void setSize(int w, int h) {
@ -638,8 +614,8 @@ public class ThumbCell extends StackPane {
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.0);
topic.setWrappingWidth(w - margin * 2); topic.setWrappingWidth(w - margin * 2.0);
streamPreview.resizeTo(w, h); streamPreview.resizeTo(w, h);