forked from j62/ctbrec
Code cleanup
This commit is contained in:
parent
5d9762a8f7
commit
e153a967f7
|
@ -58,7 +58,10 @@ import okhttp3.Response;
|
||||||
|
|
||||||
public class ThumbCell extends StackPane {
|
public class ThumbCell extends StackPane {
|
||||||
|
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(ThumbCell.class);
|
private static final String COULDNT_START_STOP_RECORDING = "Couldn't start/stop recording";
|
||||||
|
private static final String COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL = "Couldn't update resolution tag for model {} - {}";
|
||||||
|
private static final String ERROR = "Error";
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ThumbCell.class);
|
||||||
private static final Duration ANIMATION_DURATION = new Duration(250);
|
private static final Duration ANIMATION_DURATION = new Duration(250);
|
||||||
|
|
||||||
private Model model;
|
private Model model;
|
||||||
|
@ -78,8 +81,8 @@ public class ThumbCell extends StackPane {
|
||||||
private PauseIndicator pausedIndicator;
|
private PauseIndicator pausedIndicator;
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
ContextMenu popup;
|
ContextMenu popup;
|
||||||
private final Color colorNormal = Color.BLACK;
|
private static final Color colorNormal = Color.BLACK;
|
||||||
private final Color colorHighlight = Color.WHITE;
|
private static final Color colorHighlight = Color.WHITE;
|
||||||
private final Color colorRecording = new Color(0.8, 0.28, 0.28, .8);
|
private final Color colorRecording = new Color(0.8, 0.28, 0.28, .8);
|
||||||
private SimpleBooleanProperty selectionProperty = new SimpleBooleanProperty(false);
|
private SimpleBooleanProperty selectionProperty = new SimpleBooleanProperty(false);
|
||||||
private double imgAspectRatio = 3.0 / 4.0;
|
private double imgAspectRatio = 3.0 / 4.0;
|
||||||
|
@ -187,7 +190,7 @@ public class ThumbCell extends StackPane {
|
||||||
StackPane.setAlignment(selectionOverlay, Pos.TOP_LEFT);
|
StackPane.setAlignment(selectionOverlay, Pos.TOP_LEFT);
|
||||||
getChildren().add(selectionOverlay);
|
getChildren().add(selectionOverlay);
|
||||||
|
|
||||||
setOnMouseEntered((e) -> {
|
setOnMouseEntered(e -> {
|
||||||
mouseHovering = true;
|
mouseHovering = true;
|
||||||
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();
|
||||||
|
@ -197,7 +200,7 @@ public class ThumbCell extends StackPane {
|
||||||
resolutionTag.setVisible(false);
|
resolutionTag.setVisible(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setOnMouseExited((e) -> {
|
setOnMouseExited(e -> {
|
||||||
mouseHovering = false;
|
mouseHovering = false;
|
||||||
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();
|
||||||
|
@ -220,11 +223,11 @@ public class ThumbCell extends StackPane {
|
||||||
previewTrigger.setOpacity(.8);
|
previewTrigger.setOpacity(.8);
|
||||||
previewTrigger.setMaxSize(s, s);
|
previewTrigger.setMaxSize(s, s);
|
||||||
|
|
||||||
Polygon play = new Polygon(new double[] {
|
Polygon play = new Polygon(
|
||||||
16, 8,
|
16, 8,
|
||||||
26, 15,
|
26, 15,
|
||||||
16, 22
|
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);
|
||||||
|
@ -283,38 +286,38 @@ public class ThumbCell extends StackPane {
|
||||||
try {
|
try {
|
||||||
updateResolutionTag(resolution);
|
updateResolutionTag(resolution);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.debug("Couldn't update resolution tag for model {} - {}", model.getName(), e.getLocalizedMessage());
|
LOG.debug(COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL, model.getName(), e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ThumbOverviewTab.threadPool.submit(() -> {
|
ThumbOverviewTab.threadPool.submit(() -> {
|
||||||
try {
|
try {
|
||||||
ThumbOverviewTab.resolutionProcessing.add(model);
|
ThumbOverviewTab.resolutionProcessing.add(model);
|
||||||
int[] _resolution = model.getStreamResolution(false);
|
int[] res = model.getStreamResolution(false);
|
||||||
resolutionCache.put(model.getUrl(), _resolution);
|
resolutionCache.put(model.getUrl(), res);
|
||||||
updateResolutionTag(_resolution);
|
updateResolutionTag(res);
|
||||||
|
|
||||||
// the model is online, but the resolution is 0. probably something went wrong
|
// the model is online, but the resolution is 0. probably something went wrong
|
||||||
// when we first requested the stream info, so we remove this invalid value from the "cache"
|
// when we first requested the stream info, so we remove this invalid value from the "cache"
|
||||||
// so that it is requested again
|
// so that it is requested again
|
||||||
if (model.isOnline() && _resolution[1] == 0) {
|
if (model.isOnline() && res[1] == 0) {
|
||||||
LOG.trace("Removing invalid resolution value for {}", model.getName());
|
LOG.trace("Removing invalid resolution value for {}", model.getName());
|
||||||
model.invalidateCacheEntries();
|
model.invalidateCacheEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
LOG.debug("Couldn't 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("Couldn't 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("Couldn't 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("Couldn't update resolution tag for model {} - {}", model.getName(), e.getMessage());
|
LOG.debug(COULDNT_UPDATE_RESOLUTION_TAG_FOR_MODEL, model.getName(), e.getMessage());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
ThumbOverviewTab.resolutionProcessing.remove(model);
|
ThumbOverviewTab.resolutionProcessing.remove(model);
|
||||||
|
@ -331,7 +334,8 @@ public class ThumbCell extends StackPane {
|
||||||
LOG.trace("Model resolution {} {}x{}", model.getName(), resolution[0], resolution[1]);
|
LOG.trace("Model resolution {} {}x{}", model.getName(), resolution[0], resolution[1]);
|
||||||
LOG.trace("Resolution queue size: {}", ThumbOverviewTab.queue.size());
|
LOG.trace("Resolution queue size: {}", ThumbOverviewTab.queue.size());
|
||||||
final int w = resolution[1];
|
final int w = resolution[1];
|
||||||
tagText = w > 0 ? w != Integer.MAX_VALUE ? Integer.toString(w) : "HD" : state;
|
String width = w != Integer.MAX_VALUE ? Integer.toString(w) : "HD";
|
||||||
|
tagText = w > 0 ? width : state;
|
||||||
} else {
|
} else {
|
||||||
tagText = state;
|
tagText = state;
|
||||||
resolutionBackgroundColor = resolutionOfflineColor;
|
resolutionBackgroundColor = resolutionOfflineColor;
|
||||||
|
@ -366,14 +370,11 @@ public class ThumbCell extends StackPane {
|
||||||
setThumbWidth(Config.getInstance().getSettings().thumbWidth);
|
setThumbWidth(Config.getInstance().getSettings().thumbWidth);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
img.progressProperty().addListener(new ChangeListener<Number>() {
|
img.progressProperty().addListener((ChangeListener<Number>) (observable, oldValue, newValue) -> {
|
||||||
@Override
|
|
||||||
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number 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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -436,21 +437,21 @@ 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 = (model) -> {
|
Function<Model, Void> onSuccess = modl -> {
|
||||||
_startStopAction(model, start);
|
startStopActionAsync(modl, start);
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
Function<Throwable, Void> onFail = (throwable) -> {
|
Function<Throwable, Void> onFail = throwable -> {
|
||||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
||||||
alert.setTitle("Error");
|
alert.setTitle(ERROR);
|
||||||
alert.setHeaderText("Couldn't start/stop recording");
|
alert.setHeaderText(COULDNT_START_STOP_RECORDING);
|
||||||
alert.setContentText("I/O error while starting/stopping the recording: " + throwable.getLocalizedMessage());
|
alert.setContentText("I/O error while starting/stopping the recording: " + throwable.getLocalizedMessage());
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
StreamSourceSelectionDialog.show(getScene(), model, onSuccess, onFail);
|
StreamSourceSelectionDialog.show(getScene(), model, onSuccess, onFail);
|
||||||
} else {
|
} else {
|
||||||
_startStopAction(model, start);
|
startStopActionAsync(model, start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,7 +469,7 @@ public class ThumbCell extends StackPane {
|
||||||
LOG.error("Couldn't pause/resume recording", e1);
|
LOG.error("Couldn't pause/resume recording", e1);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
||||||
alert.setTitle("Error");
|
alert.setTitle(ERROR);
|
||||||
alert.setHeaderText("Couldn't pause/resume recording");
|
alert.setHeaderText("Couldn't pause/resume recording");
|
||||||
alert.setContentText("I/O error while pausing/resuming the recording: " + e1.getLocalizedMessage());
|
alert.setContentText("I/O error while pausing/resuming the recording: " + e1.getLocalizedMessage());
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
|
@ -479,7 +480,7 @@ public class ThumbCell extends StackPane {
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _startStopAction(Model model, boolean start) {
|
private void startStopActionAsync(Model model, boolean start) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
if(start) {
|
if(start) {
|
||||||
|
@ -490,11 +491,11 @@ public class ThumbCell extends StackPane {
|
||||||
setRecording(false);
|
setRecording(false);
|
||||||
}
|
}
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
LOG.error("Couldn't start/stop recording", e1);
|
LOG.error(COULDNT_START_STOP_RECORDING, e1);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
||||||
alert.setTitle("Error");
|
alert.setTitle(ERROR);
|
||||||
alert.setHeaderText("Couldn't start/stop recording");
|
alert.setHeaderText(COULDNT_START_STOP_RECORDING);
|
||||||
alert.setContentText("I/O error while starting/stopping the recording: " + e1.getLocalizedMessage());
|
alert.setContentText("I/O error while starting/stopping the recording: " + e1.getLocalizedMessage());
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
});
|
});
|
||||||
|
@ -516,7 +517,7 @@ public class ThumbCell extends StackPane {
|
||||||
} else {
|
} else {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
||||||
alert.setTitle("Error");
|
alert.setTitle(ERROR);
|
||||||
alert.setHeaderText("Couldn't follow model");
|
alert.setHeaderText("Couldn't follow model");
|
||||||
alert.setContentText("");
|
alert.setContentText("");
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
|
@ -532,7 +533,7 @@ public class ThumbCell extends StackPane {
|
||||||
} else {
|
} else {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
||||||
alert.setTitle("Error");
|
alert.setTitle(ERROR);
|
||||||
alert.setHeaderText("Couldn't unfollow model");
|
alert.setHeaderText("Couldn't unfollow model");
|
||||||
alert.setContentText("");
|
alert.setContentText("");
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
|
@ -544,7 +545,7 @@ public class ThumbCell extends StackPane {
|
||||||
LOG.error("Couldn't follow/unfollow model {}", model.getName(), e1);
|
LOG.error("Couldn't follow/unfollow model {}", model.getName(), e1);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene());
|
||||||
alert.setTitle("Error");
|
alert.setTitle(ERROR);
|
||||||
alert.setHeaderText("Couldn't follow/unfollow model");
|
alert.setHeaderText("Couldn't follow/unfollow model");
|
||||||
alert.setContentText("I/O error while following/unfollowing model " + model.getName() + ": " + e1.getLocalizedMessage());
|
alert.setContentText("I/O error while following/unfollowing model " + model.getName() + ": " + e1.getLocalizedMessage());
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
|
|
Loading…
Reference in New Issue