|
@@ -1,5 +1,6 @@
|
1
|
1
|
package fr.insa.clavardator.ui.chat;
|
2
|
2
|
|
|
3
|
+import com.jfoenix.controls.JFXButton;
|
3
|
4
|
import com.jfoenix.controls.JFXTextField;
|
4
|
5
|
import fr.insa.clavardator.ui.ButtonPressEvent;
|
5
|
6
|
import fr.insa.clavardator.users.PeerUser;
|
|
@@ -23,6 +24,8 @@ public class ChatFooterController implements Initializable {
|
23
|
24
|
private HBox container;
|
24
|
25
|
@FXML
|
25
|
26
|
private JFXTextField textField;
|
|
27
|
+ @FXML
|
|
28
|
+ private JFXButton sendButton;
|
26
|
29
|
|
27
|
30
|
private List<ButtonPressEvent> attachmentListeners;
|
28
|
31
|
private List<ErrorCallback> sendErrorListeners;
|
|
@@ -42,12 +45,14 @@ public class ChatFooterController implements Initializable {
|
42
|
45
|
attachmentListeners.forEach(ButtonPressEvent::onPress);
|
43
|
46
|
}
|
44
|
47
|
public void onSend() {
|
45
|
|
- if (remoteUser != null) {
|
46
|
|
- remoteUser.sendTextMessage(textField.getText(), this::onSendError);
|
47
|
|
- } else {
|
48
|
|
- Log.e(this.getClass().getSimpleName(), "Error: remote user not set");
|
|
48
|
+ if(!textField.getText().isEmpty()) {
|
|
49
|
+ if (remoteUser != null) {
|
|
50
|
+ remoteUser.sendTextMessage(textField.getText(), this::onSendError);
|
|
51
|
+ } else {
|
|
52
|
+ Log.e(this.getClass().getSimpleName(), "Error: remote user not set");
|
|
53
|
+ }
|
|
54
|
+ textField.setText("");
|
49
|
55
|
}
|
50
|
|
- textField.setText("");
|
51
|
56
|
}
|
52
|
57
|
|
53
|
58
|
public void onSendError(Exception e) {
|
|
@@ -75,6 +80,7 @@ public class ChatFooterController implements Initializable {
|
75
|
80
|
|
76
|
81
|
public void onTextChange(ObservableValue<? extends String> observable, String oldText, String newText) {
|
77
|
82
|
saveText(newText);
|
|
83
|
+ sendButton.setDisable(isTextFieldEmpty());
|
78
|
84
|
}
|
79
|
85
|
|
80
|
86
|
@Override
|
|
@@ -86,19 +92,18 @@ public class ChatFooterController implements Initializable {
|
86
|
92
|
textField.setOnKeyPressed(event -> {
|
87
|
93
|
if (event.getCode() == KeyCode.ENTER) {
|
88
|
94
|
event.consume();
|
89
|
|
- if(!textField.getText().isEmpty()){
|
90
|
|
- onSend();
|
91
|
|
- }
|
|
95
|
+ onSend();
|
92
|
96
|
}
|
93
|
97
|
});
|
94
|
98
|
}
|
95
|
99
|
|
|
100
|
+ private boolean isTextFieldEmpty() {
|
|
101
|
+ return textField.getText().equals("");
|
|
102
|
+ }
|
|
103
|
+
|
96
|
104
|
public void setRemoteUser(PeerUser remoteUser) {
|
97
|
105
|
this.remoteUser = remoteUser;
|
98
|
106
|
textField.setText(findSavedText());
|
99
|
|
- }
|
100
|
|
-
|
101
|
|
- public interface SendMessageEvent {
|
102
|
|
- void onSend(String text);
|
|
107
|
+ sendButton.setDisable(isTextFieldEmpty());
|
103
|
108
|
}
|
104
|
109
|
}
|