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 ceec10d819
commit 3af3592e7a
7 changed files with 46 additions and 15 deletions

View File

@ -79,6 +79,9 @@ public final class ChatScene implements Restorable {
@FXML @FXML
private MenuItem deleteContactMenuItem; private MenuItem deleteContactMenuItem;
@FXML
private ImageView attachmentView;
private LocalDB localDB; private LocalDB localDB;
private Client client; private Client client;
private WriteProxy writeProxy; private WriteProxy writeProxy;
@ -264,9 +267,15 @@ public final class ChatScene implements Restorable {
} else { } else {
pendingAttachment = new Attachment(recorder.finish(), AttachmentType.VOICE); pendingAttachment = new Attachment(recorder.finish(), AttachmentType.VOICE);
recording = false; 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); logger.log(Level.SEVERE, "Could not record audio: ", e);
Platform.runLater(new Alert(AlertType.ERROR, "Could not record audio")::showAndWait); 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(); final var text = messageTextArea.getText().strip();
try { try {
// Create and send message // 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) { if (pendingAttachment != null) {
builder.setAttachment(pendingAttachment); builder.setAttachment(pendingAttachment);
pendingAttachment = null; pendingAttachment = null;
} }
var message = builder.build(); final var message = builder.build();
// Send message // Send message
writeProxy.writeMessage(message); writeProxy.writeMessage(message);

View File

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

View File

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