Added attachment icons and notified user if an attachment is present

This commit is contained in:
delvh 2020-07-05 23:25:07 +02:00
parent 6a1bdc5fbb
commit 8abd895324
7 changed files with 46 additions and 15 deletions

View File

@ -79,6 +79,9 @@ public final class ChatScene implements Restorable {
@FXML
private MenuItem deleteContactMenuItem;
@FXML
private ImageView attachmentView;
private LocalDB localDB;
private Client client;
private WriteProxy writeProxy;
@ -264,9 +267,15 @@ public final class ChatScene implements Restorable {
} else {
pendingAttachment = new Attachment(recorder.finish(), AttachmentType.VOICE);
recording = false;
Platform.runLater(() -> { voiceButton.setText("Record Voice Message"); checkPostConditions(false); });
Platform.runLater(() -> {
voiceButton.setText("Record Voice Message");
checkPostConditions(false);
attachmentView.setImage(IconUtil.load(settings.getCurrentTheme().equals("dark") ? "/icons/attachment_present_white.png"
: "/icons/attachment_present_black.png", 20));
attachmentView.setVisible(true);
});
}
} catch (EnvoyException e) {
} catch (final EnvoyException e) {
logger.log(Level.SEVERE, "Could not record audio: ", e);
Platform.runLater(new Alert(AlertType.ERROR, "Could not record audio")::showAndWait);
}
@ -359,12 +368,13 @@ public final class ChatScene implements Restorable {
final var text = messageTextArea.getText().strip();
try {
// Create and send message
var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator()).setText(text);
final var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator())
.setText(text);
if (pendingAttachment != null) {
builder.setAttachment(pendingAttachment);
pendingAttachment = null;
}
var message = builder.build();
final var message = builder.build();
// Send message
writeProxy.writeMessage(message);

View File

@ -11,7 +11,7 @@
}
.button:pressed {
-fx-background-color: darkgray;
-fx-background-color: darkviolet;
}
.button:disabled {

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.geometry.Rectangle2D?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.ContextMenu?>
@ -9,6 +10,7 @@
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
@ -23,6 +25,9 @@
prefWidth="160.0" />
<ColumnConstraints hgrow="ALWAYS"
maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="357.0" />
<ColumnConstraints hgrow="ALWAYS"
maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="7.0"
prefWidth="357.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="-Infinity"
@ -43,7 +48,7 @@
prefHeight="211.0" prefWidth="300.0" GridPane.rowIndex="1"
GridPane.rowSpan="2147483647">
<GridPane.margin>
<Insets bottom="10.0" left="10.0" />
<Insets bottom="5.0" left="10.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
@ -68,8 +73,8 @@
</Label>
<Button fx:id="settingsButton" mnemonicParsing="true"
onAction="#settingsButtonClicked" text="_Settings"
GridPane.columnIndex="1" GridPane.halignment="RIGHT"
GridPane.valignment="CENTER">
GridPane.columnIndex="1" GridPane.columnSpan="2147483647"
GridPane.halignment="RIGHT" GridPane.valignment="CENTER">
<GridPane.margin>
<Insets bottom="10.0" right="10.0" top="10.0" />
</GridPane.margin>
@ -105,17 +110,21 @@
</contextMenu>
</ListView>
<ButtonBar prefWidth="436.0" GridPane.columnIndex="1"
GridPane.halignment="CENTER" GridPane.rowIndex="5"
GridPane.valignment="BOTTOM">
GridPane.columnSpan="2147483647" GridPane.halignment="CENTER"
GridPane.rowIndex="5" GridPane.valignment="BOTTOM">
<GridPane.margin>
<Insets right="10.0" top="5.0" />
<Insets right="10.0" />
</GridPane.margin>
<buttons>
<Button fx:id="voiceButton" disable="true"
onAction="#voiceButtonClicked" text="_Record Voice Message" />
onAction="#voiceButtonClicked" text="_Record Voice Message">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
<Button fx:id="postButton" defaultButton="true"
disable="true" mnemonicParsing="true" onAction="#postMessage"
prefHeight="10.0" prefWidth="75.0" text="_Post">
text="_Post">
<tooltip>
<Tooltip anchorLocation="WINDOW_TOP_LEFT" autoHide="true"
maxWidth="350.0"
@ -140,7 +149,8 @@
onInputMethodTextChanged="#messageTextUpdated"
onKeyPressed="#checkPostConditions" onKeyTyped="#checkKeyCombination"
prefHeight="200.0" prefWidth="200.0" wrapText="true"
GridPane.columnIndex="1" GridPane.rowIndex="4">
GridPane.columnIndex="1" GridPane.columnSpan="2147483647"
GridPane.rowIndex="4">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="10.0" top="3.0" />
</GridPane.margin>
@ -156,7 +166,7 @@
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<GridPane.margin>
<Insets bottom="10.0" left="10.0" right="5.0" top="5.0" />
<Insets bottom="10.0" left="10.0" right="5.0" />
</GridPane.margin>
</Button>
<Label id="remainingCharsLabel" fx:id="remainingChars"
@ -189,5 +199,16 @@
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label>
<ImageView fx:id="attachmentView" pickOnBounds="true"
preserveRatio="true" visible="false" GridPane.columnIndex="1"
GridPane.columnSpan="2147483647" GridPane.halignment="RIGHT"
GridPane.rowIndex="3">
<viewport>
<Rectangle2D height="20.0" width="20.0" />
</viewport>
<GridPane.margin>
<Insets bottom="5.0" right="10.0" top="5.0" />
</GridPane.margin>
</ImageView>
</children>
</GridPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB