forked from j62/ctbrec
Start recording only if the user clicked on OK in the record until
dialog
This commit is contained in:
parent
9d5d719e3c
commit
f577983305
|
@ -8,6 +8,7 @@ import java.security.NoSuchAlgorithmException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -36,6 +37,9 @@ public class SetStopDateAction {
|
||||||
private Model model;
|
private Model model;
|
||||||
private Recorder recorder;
|
private Recorder recorder;
|
||||||
|
|
||||||
|
private RadioButton pauseButton;
|
||||||
|
private DateTimePicker datePicker;
|
||||||
|
|
||||||
public SetStopDateAction(Node source, Model model, Recorder recorder) {
|
public SetStopDateAction(Node source, Model model, Recorder recorder) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
@ -44,7 +48,7 @@ public class SetStopDateAction {
|
||||||
|
|
||||||
public CompletableFuture<Boolean> execute() {
|
public CompletableFuture<Boolean> execute() {
|
||||||
source.setCursor(Cursor.WAIT);
|
source.setCursor(Cursor.WAIT);
|
||||||
var datePicker = new DateTimePicker();
|
datePicker = new DateTimePicker();
|
||||||
var gridPane = new GridPane();
|
var gridPane = new GridPane();
|
||||||
gridPane.setHgap(10);
|
gridPane.setHgap(10);
|
||||||
gridPane.setVgap(10);
|
gridPane.setVgap(10);
|
||||||
|
@ -53,7 +57,7 @@ public class SetStopDateAction {
|
||||||
gridPane.add(datePicker, 1, 0);
|
gridPane.add(datePicker, 1, 0);
|
||||||
gridPane.add(new Label("And then"), 0, 1);
|
gridPane.add(new Label("And then"), 0, 1);
|
||||||
var toggleGroup = new ToggleGroup();
|
var toggleGroup = new ToggleGroup();
|
||||||
var pauseButton = new RadioButton("pause recording");
|
pauseButton = new RadioButton("pause recording");
|
||||||
pauseButton.setSelected(model.getRecordUntilSubsequentAction() == PAUSE);
|
pauseButton.setSelected(model.getRecordUntilSubsequentAction() == PAUSE);
|
||||||
pauseButton.setToggleGroup(toggleGroup);
|
pauseButton.setToggleGroup(toggleGroup);
|
||||||
var removeButton = new RadioButton("remove model");
|
var removeButton = new RadioButton("remove model");
|
||||||
|
@ -69,18 +73,13 @@ public class SetStopDateAction {
|
||||||
datePicker.setDateTimeValue(localDate);
|
datePicker.setDateTimeValue(localDate);
|
||||||
}
|
}
|
||||||
boolean userClickedOk = Dialogs.showCustomInput(source.getScene(), "Stop Recording of " + model.getDisplayName() + " at", gridPane);
|
boolean userClickedOk = Dialogs.showCustomInput(source.getScene(), "Stop Recording of " + model.getDisplayName() + " at", gridPane);
|
||||||
|
return createAsyncTask(userClickedOk);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompletableFuture<Boolean> createAsyncTask(boolean userClickedOk) {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
if (userClickedOk) {
|
if (userClickedOk) {
|
||||||
SubsequentAction action = pauseButton.isSelected() ? PAUSE : REMOVE;
|
setRecordingTimeLimit();
|
||||||
LOG.info("Stop at {} and {}", datePicker.getDateTimeValue(), action);
|
|
||||||
var stopAt = Instant.from(datePicker.getDateTimeValue().atZone(ZoneId.systemDefault()));
|
|
||||||
model.setRecordUntil(stopAt);
|
|
||||||
model.setRecordUntilSubsequentAction(action);
|
|
||||||
try {
|
|
||||||
recorder.stopRecordingAt(model);
|
|
||||||
} catch (InvalidKeyException | NoSuchAlgorithmException | IOException e) {
|
|
||||||
Dialogs.showError(source.getScene(), "Error", "Couln't set stop date", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, GlobalThreadPool.get()).whenComplete((r, e) -> {
|
}, GlobalThreadPool.get()).whenComplete((r, e) -> {
|
||||||
|
@ -91,6 +90,32 @@ public class SetStopDateAction {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setRecordingTimeLimit() {
|
||||||
|
SubsequentAction action = pauseButton.isSelected() ? PAUSE : REMOVE;
|
||||||
|
LOG.info("Stop at {} and {}", datePicker.getDateTimeValue(), action);
|
||||||
|
var stopAt = Instant.from(datePicker.getDateTimeValue().atZone(ZoneId.systemDefault()));
|
||||||
|
model.setRecordUntil(stopAt);
|
||||||
|
model.setRecordUntilSubsequentAction(action);
|
||||||
|
try {
|
||||||
|
if (!recorder.isTracked(model)) {
|
||||||
|
new StartRecordingAction(source, List.of(model), recorder).execute(m -> {
|
||||||
|
try {
|
||||||
|
recorder.stopRecordingAt(m);
|
||||||
|
} catch (InvalidKeyException | NoSuchAlgorithmException | IOException e1) {
|
||||||
|
showError(e1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
recorder.stopRecordingAt(model);
|
||||||
|
}
|
||||||
|
} catch (InvalidKeyException | NoSuchAlgorithmException | IOException e) {
|
||||||
|
showError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showError(Exception e) {
|
||||||
|
Dialogs.showError(source.getScene(), "Error", "Couln't set stop date", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,7 +403,6 @@ public class ModelMenuContributor {
|
||||||
m.setMarkedForLaterRecording(false);
|
m.setMarkedForLaterRecording(false);
|
||||||
m.setSuspended(false);
|
m.setSuspended(false);
|
||||||
});
|
});
|
||||||
startStopAction(selectedModels, true);
|
|
||||||
selectedModels.forEach(m -> new SetStopDateAction(source, m, recorder).execute() //
|
selectedModels.forEach(m -> new SetStopDateAction(source, m, recorder).execute() //
|
||||||
.thenAccept(b -> executeCallback()));
|
.thenAccept(b -> executeCallback()));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue