Add Ability to Change the User Status Freely #90

Merged
delvh merged 7 commits from f/change-user-status into develop 2020-10-10 14:16:29 +02:00
6 changed files with 75 additions and 36 deletions
Showing only changes of commit 3810fdef02 - Show all commits

View File

@ -2,9 +2,8 @@ package envoy.client.ui.control;
import javafx.geometry.*; import javafx.geometry.*;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.image.*; import javafx.scene.image.Image;
import javafx.scene.layout.*; import javafx.scene.layout.*;
import javafx.scene.shape.Rectangle;
import envoy.client.data.*; import envoy.client.data.*;
import envoy.client.util.IconUtil; import envoy.client.util.IconUtil;
@ -23,6 +22,8 @@ public final class ChatControl extends HBox {
groupIcon = IconUtil.loadIconThemeSensitive("group_icon", 32); groupIcon = IconUtil.loadIconThemeSensitive("group_icon", 32);
/** /**
* Creates a new {@code ChatControl}.
*
* @param chat the chat to display * @param chat the chat to display
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
@ -31,13 +32,7 @@ public final class ChatControl extends HBox {
setPadding(new Insets(0, 0, 3, 0)); setPadding(new Insets(0, 0, 3, 0));
// Profile picture // Profile picture
ImageView contactProfilePic = new ImageView(chat instanceof GroupChat ? groupIcon : userIcon); final var contactProfilePic = new ProfilePicImageView(chat instanceof GroupChat ? groupIcon : userIcon, 32);
kske marked this conversation as resolved
Review

As we are using a dedicated component for this, why not handle the selection of the correct profile picture inside ProfilePicImageView?

As we are using a dedicated component for this, why not handle the selection of the correct profile picture inside `ProfilePicImageView`?
Review

Well, if I do that right inside this branch, then I'll add a (transient) Image to Chat (that will be for now always null) whose value I'm going to null check inside the mentioned constructor. Should I really do that here?

Well, if I do that right inside this branch, then I'll add a (transient) Image to Chat (that will be for now always null) whose value I'm going to null check inside the mentioned constructor. Should I really do that here?
Review

I don't see why the solution would be that complicated, but you might also resolve this in a separate branch.

I don't see why the solution would be that complicated, but you might also resolve this in a separate branch.
final var clip = new Rectangle();
clip.setWidth(32);
clip.setHeight(32);
clip.setArcHeight(32);
clip.setArcWidth(32);
contactProfilePic.setClip(clip);
getChildren().add(contactProfilePic); getChildren().add(contactProfilePic);
// Spacing // Spacing

View File

@ -26,14 +26,8 @@ public final class ContactControl extends VBox {
getChildren().add(nameLabel); getChildren().add(nameLabel);
// Online status (user) or member count (group) // Online status (user) or member count (group)
if (contact instanceof User) { getChildren().add(contact instanceof User ? new UserStatusLabel((User) contact) : new GroupSizeLabel((Group) contact));
Outdated
Review

I did not locate the source of the problem, but the group size label changes its color occasionally when a member of the group changes his status to "busy".

If this is intended, how would we go about multiple group members with different statuses?

I did not locate the source of the problem, but the group size label changes its color occasionally when a member of the group changes his status to "busy". If this is intended, how would we go about multiple group members with different statuses?
Outdated
Review

Wait what? How's that possible? That shouldn't be possible at all.

Wait what? How's that possible? That shouldn't be possible at all.
Outdated
Review

I'd love to hear how that problem is caused because I have no clue what could cause it.

I'd love to hear how that problem is caused because I have no clue what could cause it.
Outdated
Review

Are you sure you managed to change the color of the group size label?
I've tried reproducing using the instructions you just gave, but could not reproduce it.

Are you sure you managed to change the color of the group size label? I've tried reproducing using the instructions you just gave, but could not reproduce it.
Outdated
Review

I will provide some screenshots in a few hours.

I will provide some screenshots in a few hours.
Outdated
Review

How to reproduce:

Preparation:

  • 2 users inside a group

Step-by-step reproduction:

  1. Start the server and both clients
  2. Select the group chat in Client A and the chat with Client A in Client B
  3. Change the status of Client A to "busy"
  4. Select the group chat in Client B
  5. Observe the red member count over the chat list

grafik

There might be a more general reproduction, however this is what I tried at the moment.

How to reproduce: Preparation: - 2 users inside a group Step-by-step reproduction: 1. Start the server and both clients 2. Select the group chat in Client A and the chat with Client A in Client B 3. Change the status of Client A to "busy" 4. Select the group chat in Client B 5. Observe the red member count over the chat list ![grafik](/attachments/66a0e9b5-d075-4a52-a4d1-53c3a7e15ae6) There might be a more general reproduction, however this is what I tried at the moment.
Outdated
Review

The issue is that you rejected my idea to use a separate component (ContactControl) there. That would have prevented that.

The issue is that you rejected my idea to use a separate component (ContactControl) there. That would have prevented that.
Outdated
Review

Because we had a case here of not reinitializing the value correctly.

Because we had a case here of not reinitializing the value correctly.
final var status = ((User) contact).getStatus().toString();
final var statusLabel = new Label(status);
statusLabel.getStyleClass().add(status.toLowerCase());
getChildren().add(statusLabel);
} else {
getChildren().add(new Label(contact.getContacts().size() + " members"));
}
getStyleClass().add("list-element"); getStyleClass().add("list-element");
} }
} }

View File

@ -0,0 +1,20 @@
package envoy.client.ui.control;
import javafx.scene.control.Label;
import envoy.data.Group;
/**
* Displays the amount of members in a {@link Group}.
*
* @author Leon Hofmeister
* @since Envoy Client v0.3-beta
*/
public final class GroupSizeLabel extends Label {
/**
* @param recipient the group whose members to show
* @since Envoy Client v0.3-beta
*/
public GroupSizeLabel(Group recipient) { super(recipient.getContacts().size() + " members"); }
}

View File

@ -0,0 +1,23 @@
package envoy.client.ui.control;
import javafx.scene.control.Label;
import envoy.data.User;
/**
* Displays the status of a {@link User}.
*
* @author Leon Hofmeister
* @since Envoy Client v0.3-beta
*/
public final class UserStatusLabel extends Label {
/**
* @param user the user whose status to display
* @since Envoy Client v0.3-beta
*/
public UserStatusLabel(User user) {
super(user.getStatus().toString());
getStyleClass().add(user.getStatus().toString().toLowerCase());
}
}

View File

@ -51,12 +51,6 @@ import dev.kske.eventbus.Event;
*/ */
public final class ChatScene implements EventListener, Restorable { public final class ChatScene implements EventListener, Restorable {
@FXML
private GridPane scene;
@FXML
private Label contactLabel;
@FXML @FXML
private ListView<Message> messageList; private ListView<Message> messageList;
@ -85,7 +79,7 @@ public final class ChatScene implements EventListener, Restorable {
private Button newContactButton; private Button newContactButton;
@FXML @FXML
private TextArea messageTextArea; private Label contactLabel;
@FXML @FXML
private Label remainingChars; private Label remainingChars;
@ -93,24 +87,27 @@ public final class ChatScene implements EventListener, Restorable {
@FXML @FXML
private Label infoLabel; private Label infoLabel;
@FXML
private MenuItem deleteContactMenuItem;
@FXML
private ImageView attachmentView;
@FXML @FXML
private Label topBarContactLabel; private Label topBarContactLabel;
@FXML @FXML
private Label topBarStatusLabel; private Label topBarStatusLabel;
@FXML
private MenuItem deleteContactMenuItem;
@FXML
private ImageView attachmentView;
@FXML @FXML
private ImageView clientProfilePic; private ImageView clientProfilePic;
@FXML @FXML
private ImageView recipientProfilePic; private ImageView recipientProfilePic;
@FXML
private TextArea messageTextArea;
@FXML @FXML
private TextArea contactSearch; private TextArea contactSearch;
@ -251,8 +248,17 @@ public final class ChatScene implements EventListener, Restorable {
.ifPresent(msg -> Platform.runLater(messageList::refresh)); .ifPresent(msg -> Platform.runLater(messageList::refresh));
} }
@Event(eventType = UserStatusChange.class) @Event
private void onUserStatusChange() { Platform.runLater(chatList::refresh); } private void onUserStatusChange(UserStatusChange statusChange) {
Platform.runLater(() -> {
chatList.refresh();
if (currentChat != null && currentChat.getRecipient().getID() == statusChange.getID()) {
topBarStatusLabel.getStyleClass().clear();
topBarStatusLabel.setText(statusChange.get().toString());
topBarStatusLabel.getStyleClass().add(statusChange.get().toString().toLowerCase());
}
});
}
@Event @Event
private void onContactOperation(ContactOperation operation) { private void onContactOperation(ContactOperation operation) {

View File

@ -22,9 +22,10 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.stage.Screen?> <?import javafx.stage.Screen?>
<GridPane fx:id="scene" maxHeight="-Infinity" <GridPane maxHeight="-Infinity" maxWidth="-Infinity"
maxWidth="-Infinity" minHeight="400.0" minWidth="500.0" minHeight="400.0" minWidth="500.0"
prefHeight="${screen.visualBounds.height}" prefWidth="${screen.visualBounds.width}" prefHeight="${screen.visualBounds.height}"
prefWidth="${screen.visualBounds.width}"
xmlns="http://javafx.com/javafx/11.0.1" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="envoy.client.ui.controller.ChatScene"> fx:controller="envoy.client.ui.controller.ChatScene">