Browse Source

Fix username not updating on user list

Arnaud Vergnet 3 years ago
parent
commit
81673e44b3

+ 0
- 1
src/main/java/fr/insa/clavardator/ui/users/UserActiveIndicatorController.java View File

@@ -34,7 +34,6 @@ public class UserActiveIndicatorController implements Initializable {
34 34
 	private void onStateChange(PropertyChangeEvent propertyChangeEvent) {
35 35
 		if (propertyChangeEvent.getPropertyName().equals("state")) {
36 36
 			final PeerUser.State newState = (PeerUser.State) propertyChangeEvent.getNewValue();
37
-			Log.v(this.getClass().getSimpleName(), "User state updated to " + newState.toString());
38 37
 			Platform.runLater(() -> updateState(newState == PeerUser.State.CONNECTED));
39 38
 		}
40 39
 	}

+ 15
- 0
src/main/java/fr/insa/clavardator/ui/users/UserListItemController.java View File

@@ -3,9 +3,11 @@ package fr.insa.clavardator.ui.users;
3 3
 import com.jfoenix.controls.JFXButton;
4 4
 import fr.insa.clavardator.ui.ButtonPressEvent;
5 5
 import fr.insa.clavardator.users.PeerUser;
6
+import javafx.application.Platform;
6 7
 import javafx.fxml.FXML;
7 8
 import javafx.fxml.Initializable;
8 9
 
10
+import java.beans.PropertyChangeEvent;
9 11
 import java.net.URL;
10 12
 import java.util.ResourceBundle;
11 13
 
@@ -42,8 +44,21 @@ public class UserListItemController implements Initializable {
42 44
 		resetBackground();
43 45
 	}
44 46
 
47
+
48
+	private void onUsernameChange(PropertyChangeEvent propertyChangeEvent) {
49
+		if (propertyChangeEvent.getPropertyName().equals("username")) {
50
+			final String newUsername = (String) propertyChangeEvent.getNewValue();
51
+			Platform.runLater(() -> button.setText(newUsername));
52
+		}
53
+	}
54
+
45 55
 	public void setUser(PeerUser user) {
56
+		if (this.user != null) {
57
+			// remove old observer before setting new user
58
+			this.user.removeObserver(this::onUsernameChange);
59
+		}
46 60
 		this.user = user;
61
+		user.addObserver(this::onUsernameChange);
47 62
 		indicatorController.setUser(user);
48 63
 		button.setText(user.getUsername());
49 64
 		resetBackground();

Loading…
Cancel
Save