Implemented notification of user if he can no longer send messages

This only occurs when he is in offline mode and runs out of messageIDs
to use.
Additionally implemented:
- automatically disabled user of posting after that condition is reached
- an infoLabel used to commjunicate some events with the user
- (in parts) a new UI design
This commit is contained in:
delvh 2020-06-26 23:16:03 +02:00
parent 5fc341ad53
commit f61561d4b2
3 changed files with 78 additions and 39 deletions

View File

@ -16,6 +16,7 @@ import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import envoy.client.data.Chat; import envoy.client.data.Chat;
import envoy.client.data.LocalDB; import envoy.client.data.LocalDB;
@ -62,6 +63,9 @@ public final class ChatScene {
@FXML @FXML
private Label remainingChars; private Label remainingChars;
@FXML
private Label infoLabel;
@FXML @FXML
private MenuItem deleteContactMenuItem; private MenuItem deleteContactMenuItem;
@ -70,6 +74,8 @@ public final class ChatScene {
private WriteProxy writeProxy; private WriteProxy writeProxy;
private SceneContext sceneContext; private SceneContext sceneContext;
private boolean postingPermanentlyDisabled = false;
private Chat currentChat; private Chat currentChat;
private static final Settings settings = Settings.getInstance(); private static final Settings settings = Settings.getInstance();
@ -165,6 +171,7 @@ public final class ChatScene {
userList.setItems(FXCollections.observableList(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList()))); userList.setItems(FXCollections.observableList(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList())));
contactLabel.setText(localDB.getUser().getName()); contactLabel.setText(localDB.getUser().getName());
MessageListCell.setUser(localDB.getUser()); MessageListCell.setUser(localDB.getUser());
if (!client.isOnline()) updateInfoLabel("You are offline", Color.YELLOW);
} }
/** /**
@ -244,10 +251,15 @@ public final class ChatScene {
*/ */
@FXML @FXML
private void checkPostConditions(KeyEvent e) { private void checkPostConditions(KeyEvent e) {
if (!postButton.isDisabled() && (settings.isEnterToSend() && e.getCode() == KeyCode.ENTER if (!postingPermanentlyDisabled) {
|| !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown())) if (!postButton.isDisabled() && (settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
postMessage(); || !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown()))
postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null); postMessage();
postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null);
} else if (!infoLabel.getText().equals("You need to go online to send more messages"))
// Informing the user that he is a f*cking moron and should use Envoy online
// because he ran out of messageIDs to use
updateInfoLabel("You need to go online to send more messages", Color.RED);
} }
/** /**
@ -286,6 +298,12 @@ public final class ChatScene {
*/ */
@FXML @FXML
private void postMessage() { private void postMessage() {
postingPermanentlyDisabled = !(client.isOnline() || localDB.getIDGenerator().hasNext());
if (postingPermanentlyDisabled) {
postButton.setDisable(true);
updateInfoLabel("You need to go online to send more messages", Color.RED);
return;
}
final var text = messageTextArea.getText().strip(); final var text = messageTextArea.getText().strip();
if (text.isBlank()) throw new IllegalArgumentException("A message without visible text can not be sent."); if (text.isBlank()) throw new IllegalArgumentException("A message without visible text can not be sent.");
try { try {
@ -322,6 +340,19 @@ public final class ChatScene {
*/ */
private void scrollToMessageListEnd() { messageList.scrollTo(messageList.getItems().size() - 1); } private void scrollToMessageListEnd() { messageList.scrollTo(messageList.getItems().size() - 1); }
/**
* Updates the {@code infoLabel}.
*
* @param text the text to use
* @param textfill the color in which to display information
* @since Envoy Client v0.1-beta
*/
private void updateInfoLabel(String text, Paint textfill) {
infoLabel.setText(text);
infoLabel.setTextFill(textfill);
infoLabel.setVisible(true);
}
// Context menu actions // Context menu actions
@FXML @FXML

View File

@ -115,8 +115,7 @@ public final class LoginScene {
if (registerCheckBox.isSelected() && !passwordField.getText().equals(repeatPasswordField.getText())) { if (registerCheckBox.isSelected() && !passwordField.getText().equals(repeatPasswordField.getText())) {
new Alert(AlertType.ERROR, "The entered password is unequal to the repeated one").showAndWait(); new Alert(AlertType.ERROR, "The entered password is unequal to the repeated one").showAndWait();
repeatPasswordField.clear(); repeatPasswordField.clear();
} } else performHandshake(
else performHandshake(
new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), registerCheckBox.isSelected(), Startup.VERSION)); new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), registerCheckBox.isSelected(), Startup.VERSION));
} }
@ -190,9 +189,8 @@ public final class LoginScene {
localDB.synchronize(); localDB.synchronize();
if (client.isOnline()) { if (client.isOnline()) writeProxy.flushCache();
writeProxy.flushCache(); else
} else
// Set all contacts to offline mode // Set all contacts to offline mode
localDB.getChats() localDB.getChats()
.stream() .stream()

View File

@ -19,27 +19,27 @@
fx:controller="envoy.client.ui.controller.ChatScene"> fx:controller="envoy.client.ui.controller.ChatScene">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" <ColumnConstraints hgrow="SOMETIMES"
maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="20.0" maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="25.0"
prefWidth="161.0" /> prefWidth="161.0" />
<ColumnConstraints hgrow="SOMETIMES" <ColumnConstraints hgrow="SOMETIMES"
maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="65.0" maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="65.0"
prefWidth="357.0" /> prefWidth="357.0" />
<ColumnConstraints hgrow="SOMETIMES" <ColumnConstraints hgrow="SOMETIMES" maxWidth="10.0"
maxWidth="1.7976931348623157E308" minWidth="6.285736083984375" minWidth="10.0" percentWidth="10.0" prefWidth="10.0" />
percentWidth="15.0" prefWidth="48.000030517578125" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints maxHeight="1.7976931348623157E308" <RowConstraints maxHeight="1.7976931348623157E308"
minHeight="10.0" percentHeight="10.0" prefHeight="70.0" minHeight="10.0" percentHeight="10.0" prefHeight="70.0"
vgrow="SOMETIMES" /> vgrow="SOMETIMES" />
<RowConstraints maxHeight="1.7976931348623157E308" <RowConstraints maxHeight="1.7976931348623157E308"
minHeight="10.0" percentHeight="70.0" prefHeight="326.2857404436384" minHeight="10.0" percentHeight="7.0" vgrow="SOMETIMES" />
vgrow="SOMETIMES" />
<RowConstraints maxHeight="1.7976931348623157E308" <RowConstraints maxHeight="1.7976931348623157E308"
minHeight="10.0" percentHeight="5.0" prefHeight="50.0" minHeight="10.0" percentHeight="60.0" prefHeight="50.0"
vgrow="SOMETIMES" /> vgrow="SOMETIMES" />
<RowConstraints maxHeight="50.0" minHeight="10.0"
percentHeight="2.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="1.7976931348623157E308" <RowConstraints maxHeight="1.7976931348623157E308"
minHeight="10.0" percentHeight="15.0" prefHeight="100.0" minHeight="10.0" percentHeight="21.0" prefHeight="100.0"
vgrow="SOMETIMES" /> vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
@ -56,7 +56,7 @@
<ContextMenu anchorLocation="CONTENT_TOP_LEFT"> <ContextMenu anchorLocation="CONTENT_TOP_LEFT">
<items> <items>
<MenuItem fx:id="deleteContactMenuItem" <MenuItem fx:id="deleteContactMenuItem"
mnemonicParsing="false" text="Delete" onAction="#deleteContact" /> mnemonicParsing="false" onAction="#deleteContact" text="Delete" />
</items> </items>
</ContextMenu> </ContextMenu>
</contextMenu> </contextMenu>
@ -72,8 +72,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.columnSpan="2" GridPane.halignment="RIGHT" GridPane.columnIndex="1" GridPane.columnSpan="2"
GridPane.valignment="CENTER"> GridPane.halignment="RIGHT" GridPane.valignment="CENTER">
<GridPane.margin> <GridPane.margin>
<Insets bottom="10.0" left="5.0" right="10.0" top="10.0" /> <Insets bottom="10.0" left="5.0" right="10.0" top="10.0" />
</GridPane.margin> </GridPane.margin>
@ -82,7 +82,7 @@
</padding> </padding>
</Button> </Button>
<ListView fx:id="messageList" prefHeight="257.0" <ListView fx:id="messageList" prefHeight="257.0"
prefWidth="155.0" GridPane.columnIndex="1" GridPane.columnSpan="2" prefWidth="465.0" GridPane.columnIndex="1" GridPane.columnSpan="2"
GridPane.rowIndex="1" GridPane.rowSpan="2"> GridPane.rowIndex="1" GridPane.rowSpan="2">
<GridPane.margin> <GridPane.margin>
<Insets bottom="5.0" left="5.0" right="10.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="10.0" top="5.0" />
@ -93,25 +93,25 @@
<contextMenu> <contextMenu>
<ContextMenu anchorLocation="CONTENT_TOP_LEFT"> <ContextMenu anchorLocation="CONTENT_TOP_LEFT">
<items> <items>
<MenuItem mnemonicParsing="false" text="Copy" <MenuItem mnemonicParsing="false" onAction="#copyMessage"
onAction="#copyMessage" /> text="Copy" />
<MenuItem mnemonicParsing="false" text="Delete" <MenuItem mnemonicParsing="false"
onAction="#deleteMessage" /> onAction="#deleteMessage" text="Delete" />
<MenuItem mnemonicParsing="false" text="Forward" <MenuItem mnemonicParsing="false"
onAction="#forwardMessage" /> onAction="#forwardMessage" text="Forward" />
<MenuItem mnemonicParsing="false" text="Quote" <MenuItem mnemonicParsing="false"
onAction="#quoteMessage" /> onAction="#quoteMessage" text="Quote" />
</items> </items>
</ContextMenu> </ContextMenu>
</contextMenu> </contextMenu>
</ListView> </ListView>
<Button fx:id="postButton" defaultButton="true" disable="true" <Button fx:id="postButton" defaultButton="true" disable="true"
mnemonicParsing="true" onAction="#postMessage" prefHeight="10.0" mnemonicParsing="true" onAction="#postMessage" prefHeight="10.0"
prefWidth="65.0" text="_Post" GridPane.columnIndex="2" prefWidth="75.0" text="_Post" GridPane.columnIndex="2"
GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="4"
GridPane.valignment="CENTER"> GridPane.valignment="BOTTOM">
<GridPane.margin> <GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0"/> <Insets bottom="10.0" left="5.0" right="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" />
@ -125,8 +125,8 @@
<contextMenu> <contextMenu>
<ContextMenu anchorLocation="CONTENT_TOP_LEFT"> <ContextMenu anchorLocation="CONTENT_TOP_LEFT">
<items> <items>
<MenuItem mnemonicParsing="false" text="Copy and Send" <MenuItem mnemonicParsing="false"
onAction="#copyAndPostMessage" /> onAction="#copyAndPostMessage" text="Copy and Send" />
</items> </items>
</ContextMenu> </ContextMenu>
</contextMenu> </contextMenu>
@ -135,7 +135,7 @@
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="3"> GridPane.columnIndex="1" GridPane.rowIndex="4">
<GridPane.margin> <GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="10.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin> </GridPane.margin>
@ -145,20 +145,20 @@
</TextArea> </TextArea>
<Button mnemonicParsing="true" <Button mnemonicParsing="true"
onAction="#addContactButtonClicked" text="_Add Contacts" onAction="#addContactButtonClicked" text="_Add Contacts"
GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="4"
GridPane.valignment="CENTER"> GridPane.valignment="CENTER">
<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" />
</padding> </padding>
<GridPane.margin> <GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="10.0" right="5.0" top="5.0" />
</GridPane.margin> </GridPane.margin>
</Button> </Button>
<Label id="remainingCharsLabel" fx:id="remainingChars" <Label id="remainingCharsLabel" fx:id="remainingChars"
ellipsisString="" maxHeight="30.0" maxWidth="180.0" prefHeight="30.0" ellipsisString="" maxHeight="30.0" maxWidth="180.0" prefHeight="30.0"
prefWidth="180.0" text="remaining chars: 0/x" textFill="LIME" prefWidth="180.0" text="remaining chars: 0/x" textFill="LIME"
textOverrun="LEADING_WORD_ELLIPSIS" visible="false" textOverrun="LEADING_WORD_ELLIPSIS" visible="false"
GridPane.columnIndex="1" GridPane.rowIndex="2"> GridPane.columnIndex="1" GridPane.rowIndex="3">
<GridPane.margin> <GridPane.margin>
<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" />
</GridPane.margin> </GridPane.margin>
@ -174,5 +174,15 @@
wrapText="true" /> wrapText="true" />
</tooltip> </tooltip>
</Label> </Label>
<Label fx:id="infoLabel" text="Something happened"
textFill="#faa007" visible="false" GridPane.columnIndex="1"
GridPane.rowIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label>
</children> </children>
</GridPane> </GridPane>