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