Adjusted ChatControl constructor and added Javadoc

This commit is contained in:
DieGurke 2020-07-12 14:46:35 +02:00
parent d2ec04b568
commit 7b6b3a28f3
3 changed files with 14 additions and 5 deletions

View File

@ -114,8 +114,17 @@ public class Chat implements Serializable {
messages.add(0, message); messages.add(0, message);
} }
/**
* Increments the unreadMessagesAmount by 1
*
* @since Envoy Client v0.1-beta
*/
public void incrementUnreadAmount() { unreadAmount++; } public void incrementUnreadAmount() { unreadAmount++; }
/**
* @return the amount of unreadMesages in this chat
* @since Envoy Client v0.1-beta
*/
public int getUnreadAmount() { return unreadAmount; } public int getUnreadAmount() { return unreadAmount; }
/** /**

View File

@ -22,10 +22,10 @@ import envoy.data.User;
public class ChatControl extends HBox { public class ChatControl extends HBox {
/** /**
* @param contact the contact that should be formatted * @param chat the chat to display
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public ChatControl(Chat chat, int unreadMessagesAmount) { public ChatControl(Chat chat) {
// Container with contact name // Container with contact name
final var vBox = new VBox(); final var vBox = new VBox();
final var nameLabel = new Label(chat.getRecipient().getName()); final var nameLabel = new Label(chat.getRecipient().getName());
@ -41,11 +41,11 @@ public class ChatControl extends HBox {
vBox.getChildren().add(new Label(((Group) chat.getRecipient()).getContacts().size() + " members")); vBox.getChildren().add(new Label(((Group) chat.getRecipient()).getContacts().size() + " members"));
getChildren().add(vBox); getChildren().add(vBox);
if (unreadMessagesAmount != 0) { if (chat.getUnreadAmount() != 0) {
Region spacing = new Region(); Region spacing = new Region();
setHgrow(spacing, Priority.ALWAYS); setHgrow(spacing, Priority.ALWAYS);
getChildren().add(spacing); getChildren().add(spacing);
final var unreadMessagesLabel = new Label("" + unreadMessagesAmount); final var unreadMessagesLabel = new Label(Integer.toString(chat.getUnreadAmount()));
unreadMessagesLabel.setMinSize(15, 15); unreadMessagesLabel.setMinSize(15, 15);
var vBox2 = new VBox(); var vBox2 = new VBox();
vBox2.setAlignment(Pos.CENTER_RIGHT); vBox2.setAlignment(Pos.CENTER_RIGHT);

View File

@ -36,7 +36,7 @@ public class ContactListCellFactory extends ListCell<Chat> {
setText(null); setText(null);
setGraphic(null); setGraphic(null);
} else { } else {
final var control = new ChatControl(chat, chat.getUnreadAmount()); final var control = new ChatControl(chat);
prefWidthProperty().bind(listView.widthProperty().subtract(40)); prefWidthProperty().bind(listView.widthProperty().subtract(40));
setGraphic(control); setGraphic(control);
} }