Add Ability to Change the User Status Freely #90
@ -15,11 +15,14 @@ import envoy.data.*;
|
|||||||
*/
|
*/
|
||||||
public final class ContactControl extends VBox {
|
public final class ContactControl extends VBox {
|
||||||
|
|
||||||
|
private final Contact contact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param contact the contact to display
|
* @param contact the contact to display
|
||||||
* @since Envoy Client v0.2-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public ContactControl(Contact contact) {
|
public ContactControl(Contact contact) {
|
||||||
|
this.contact = contact;
|
||||||
|
|
||||||
// Name label
|
// Name label
|
||||||
final var nameLabel = new Label(contact.getName());
|
final var nameLabel = new Label(contact.getName());
|
||||||
@ -30,4 +33,19 @@ public final class ContactControl extends VBox {
|
|||||||
|
|
||||||
getStyleClass().add("list-element");
|
getStyleClass().add("list-element");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces the info label of this {@code ContactControl} with an updated
|
||||||
|
* version.
|
||||||
|
* <p>
|
||||||
|
* This method should be called when the status of the underlying user or the
|
||||||
|
* size of the underlying group has changed.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.3-beta
|
||||||
|
* @apiNote will produce buggy results if contact control gets updated so that
|
||||||
|
* the info label is no longer on index 1.
|
||||||
|
*/
|
||||||
|
public void replaceInfoLabel() {
|
||||||
|
getChildren().set(1, contact instanceof User ? new UserStatusLabel((User) contact) : new GroupSizeLabel((Group) contact));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,6 +261,8 @@ public final class ChatScene implements EventListener, Restorable {
|
|||||||
private void onUserStatusChange(UserStatusChange statusChange) {
|
private void onUserStatusChange(UserStatusChange statusChange) {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
chatList.refresh();
|
chatList.refresh();
|
||||||
|
|
||||||
|
// Replacing the display in the top bar
|
||||||
if (currentChat != null && currentChat.getRecipient().getID() == statusChange.getID()) {
|
if (currentChat != null && currentChat.getRecipient().getID() == statusChange.getID()) {
|
||||||
topBarStatusLabel.getStyleClass().clear();
|
topBarStatusLabel.getStyleClass().clear();
|
||||||
topBarStatusLabel.setText(statusChange.get().toString());
|
topBarStatusLabel.setText(statusChange.get().toString());
|
||||||
@ -718,10 +720,17 @@ public final class ChatScene implements EventListener, Restorable {
|
|||||||
|
|
||||||
@Event(eventType = OwnStatusChange.class, priority = 50)
|
@Event(eventType = OwnStatusChange.class, priority = 50)
|
||||||
private void generateOwnStatusControl() {
|
private void generateOwnStatusControl() {
|
||||||
delvh marked this conversation as resolved
|
|||||||
|
|
||||||
mpk
commented
I do not see the point of doing this as you can just check if it is null if I understand that correctly. If not please correct and explane the exact purpose to me. I do not see the point of doing this as you can just check if it is null if I understand that correctly. If not please correct and explane the exact purpose to me.
delvh
commented
As you can see a few lines above, this method is annotated with an Event: It gets called every time the user changes his own status. But thinking about it, it may be possible, however I do not know if it'll work as bug-free as this implementation: As soon as you initialize this variable somewhere else, you might encounter a bug that duplicates it. As you can see a few lines above, this method is annotated with an Event: It gets called every time the user changes his own status.
Hence I always have to replace it then.
And for the first part: I cannot do that because initially this component is no part of the HBox (you remember, the thing with importing the by now outdated jar into the SceneBuilder...). To avoid that, it gets dynamically added.
But thinking about it, it may be possible, however I do not know if it'll work as bug-free as this implementation: As soon as you initialize this variable somewhere else, you might encounter a bug that duplicates it.
kske
commented
What if, instead of regenerating the whole control, we would just change the displayed information in the event handler? What if, instead of regenerating the whole control, we would just change the displayed information in the event handler?
delvh
commented
It could be possible if we make some changes to the underlying It could be possible if we make some changes to the underlying `ContactControl`.
The question however is: Should it be done?
delvh
commented
Oh, and also: there is a difference between ownUserControl and ownContactControl. Oh, and also: there is a difference between ownUserControl and ownContactControl.
delvh
commented
Better? Better?
mpk
commented
Yes better Yes better
|
|||||||
|
// Update the own user status if present
|
||||||
|
if (ownContactControl.getChildren().get(0) instanceof ContactControl)
|
||||||
|
((ContactControl) ownContactControl.getChildren().get(0)).replaceInfoLabel();
|
||||||
|
else {
|
||||||
|
|
||||||
|
// Else prepend it to the HBox children
|
||||||
final var ownUserControl = new ContactControl(localDB.getUser());
|
final var ownUserControl = new ContactControl(localDB.getUser());
|
||||||
ownUserControl.setAlignment(Pos.CENTER_LEFT);
|
ownUserControl.setAlignment(Pos.CENTER_LEFT);
|
||||||
if (ownContactControl.getChildren().get(0) instanceof ContactControl) ownContactControl.getChildren().set(0, ownUserControl);
|
ownContactControl.getChildren().add(0, ownUserControl);
|
||||||
else ownContactControl.getChildren().add(0, ownUserControl);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context menu actions
|
// Context menu actions
|
||||||
|
@ -46,14 +46,19 @@ public final class UserUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies the application that the status of the currently logged in user has
|
* Notifies the application that the status of the currently logged in user has
|
||||||
* changed
|
* changed.
|
||||||
*
|
*
|
||||||
* @param newStatus the new status
|
* @param newStatus the new status
|
||||||
* @since Envoy Client v0.3-beta
|
* @since Envoy Client v0.3-beta
|
||||||
*/
|
*/
|
||||||
public static void changeStatus(UserStatus newStatus) {
|
public static void changeStatus(UserStatus newStatus) {
|
||||||
|
|
||||||
|
// Sending the already active status is a valid action
|
||||||
|
if (newStatus.equals(Context.getInstance().getLocalDB().getUser().getStatus())) return;
|
||||||
|
else {
|
||||||
EventBus.getInstance().dispatch(new OwnStatusChange(newStatus));
|
EventBus.getInstance().dispatch(new OwnStatusChange(newStatus));
|
||||||
if (Context.getInstance().getClient().isOnline())
|
if (Context.getInstance().getClient().isOnline())
|
||||||
Context.getInstance().getClient().send(new UserStatusChange(Context.getInstance().getLocalDB().getUser().getID(), newStatus));
|
Context.getInstance().getClient().send(new UserStatusChange(Context.getInstance().getLocalDB().getUser().getID(), newStatus));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
You could annotate this as an event handler directly.