Refactor alerts
This commit is contained in:
parent
40fa398dd1
commit
ef54e18cc7
@ -31,6 +31,8 @@ import org.kordamp.ikonli.javafx.FontIcon;
|
|||||||
|
|
||||||
public class MainController implements Initializable {
|
public class MainController implements Initializable {
|
||||||
|
|
||||||
|
private static final double MIN_DURATION = 5.0;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button btnMarkStart, btnMarkEnd, btnBackward, btnPlay, btnForward, btnSend;
|
private Button btnMarkStart, btnMarkEnd, btnBackward, btnPlay, btnForward, btnSend;
|
||||||
|
|
||||||
@ -74,18 +76,14 @@ public class MainController implements Initializable {
|
|||||||
data.metadata = clipView.getMetadata();
|
data.metadata = clipView.getMetadata();
|
||||||
data.startTime = clipView.getClipPartStart();
|
data.startTime = clipView.getClipPartStart();
|
||||||
data.endTime = clipView.getClipPartEnd();
|
data.endTime = clipView.getClipPartEnd();
|
||||||
if(data.endTime - data.startTime > 5.0) {
|
if (data.endTime - data.startTime > MIN_DURATION) {
|
||||||
btnSend.setDisable(true);
|
btnSend.setDisable(true);
|
||||||
CompletableFuture.completedFuture(data)
|
CompletableFuture.completedFuture(data)
|
||||||
.thenApplyAsync(new OpusConvertTask())
|
.thenApplyAsync(new OpusConvertTask())
|
||||||
.thenApplyAsync(new SendTelegramVoiceTask())
|
.thenApplyAsync(new SendTelegramVoiceTask())
|
||||||
.handleAsync(this::handleVoiceSend);
|
.handleAsync(this::handleVoiceSend);
|
||||||
} else {
|
} else {
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
alertError(Main.getResources().getString("zero_file_length"));
|
||||||
alert.setTitle(Main.getResources().getString("error"));
|
|
||||||
alert.setHeaderText(null);
|
|
||||||
alert.setContentText(Main.getResources().getString("zero_file_length"));
|
|
||||||
alert.showAndWait();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -189,15 +187,19 @@ public class MainController implements Initializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void alertError(Throwable ex) {
|
private void alertError(Throwable ex) {
|
||||||
Alert alert = new Alert(AlertType.ERROR);
|
|
||||||
alert.setTitle(Main.getResources().getString("error"));
|
|
||||||
alert.setHeaderText(null);
|
|
||||||
final String message;
|
final String message;
|
||||||
if ((ex instanceof CompletionException) && (ex.getCause() != null)) {
|
if ((ex instanceof CompletionException) && (ex.getCause() != null)) {
|
||||||
message = ex.getCause().getLocalizedMessage();
|
message = ex.getCause().getLocalizedMessage();
|
||||||
} else {
|
} else {
|
||||||
message = ex.getLocalizedMessage();
|
message = ex.getLocalizedMessage();
|
||||||
}
|
}
|
||||||
|
alertError(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void alertError(String message) {
|
||||||
|
Alert alert = new Alert(AlertType.ERROR);
|
||||||
|
alert.setTitle(Main.getResources().getString("error"));
|
||||||
|
alert.setHeaderText(null);
|
||||||
alert.setContentText(message);
|
alert.setContentText(message);
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user