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 961527e663
commit 90df627831
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.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import envoy.client.data.Chat;
import envoy.client.data.LocalDB;
@ -62,6 +63,9 @@ public final class ChatScene {
@FXML
private Label remainingChars;
@FXML
private Label infoLabel;
@FXML
private MenuItem deleteContactMenuItem;
@ -70,6 +74,8 @@ public final class ChatScene {
private WriteProxy writeProxy;
private SceneContext sceneContext;
private boolean postingPermanentlyDisabled = false;
private Chat currentChat;
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())));
contactLabel.setText(localDB.getUser().getName());
MessageListCell.setUser(localDB.getUser());
if (!client.isOnline()) updateInfoLabel("You are offline", Color.YELLOW);
}
/**
@ -244,10 +251,15 @@ public final class ChatScene {
*/
@FXML
private void checkPostConditions(KeyEvent e) {
if (!postButton.isDisabled() && (settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
|| !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown()))
postMessage();
postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null);
if (!postingPermanentlyDisabled) {
if (!postButton.isDisabled() && (settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
|| !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown()))
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
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();
if (text.isBlank()) throw new IllegalArgumentException("A message without visible text can not be sent.");
try {
@ -322,6 +340,19 @@ public final class ChatScene {
*/
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
@FXML

View File

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

View File

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