implemented contact search
This commit is contained in:
parent
cc9e3a2afe
commit
f339b8ed99
@ -15,6 +15,7 @@ import java.util.logging.Logger;
|
|||||||
import javafx.animation.RotateTransition;
|
import javafx.animation.RotateTransition;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.transformation.FilteredList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
@ -110,6 +111,9 @@ public final class ChatScene implements Restorable {
|
|||||||
@FXML
|
@FXML
|
||||||
private ImageView recipientProfilePic;
|
private ImageView recipientProfilePic;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextArea contactSearch;
|
||||||
|
|
||||||
private LocalDB localDB;
|
private LocalDB localDB;
|
||||||
private Client client;
|
private Client client;
|
||||||
private WriteProxy writeProxy;
|
private WriteProxy writeProxy;
|
||||||
@ -128,6 +132,8 @@ public final class ChatScene implements Restorable {
|
|||||||
private static final Image DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20);
|
private static final Image DEFAULT_ATTACHMENT_VIEW_IMAGE = IconUtil.loadIconThemeSensitive("attachment_present", 20);
|
||||||
private static final int MAX_MESSAGE_LENGTH = 255;
|
private static final int MAX_MESSAGE_LENGTH = 255;
|
||||||
private static final int DEFAULT_ICON_SIZE = 16;
|
private static final int DEFAULT_ICON_SIZE = 16;
|
||||||
|
|
||||||
|
private FilteredList<? extends Chat> chats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the appearance of certain visual components.
|
* Initializes the appearance of certain visual components.
|
||||||
@ -239,8 +245,9 @@ public final class ChatScene implements Restorable {
|
|||||||
this.localDB = localDB;
|
this.localDB = localDB;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.writeProxy = writeProxy;
|
this.writeProxy = writeProxy;
|
||||||
|
|
||||||
chatList.setItems(FXCollections.observableList(localDB.getChats()));
|
chats = new FilteredList<>(FXCollections.observableList(localDB.getChats()));
|
||||||
|
chatList.setItems(chats);
|
||||||
contactLabel.setText(localDB.getUser().getName());
|
contactLabel.setText(localDB.getUser().getName());
|
||||||
MessageControl.setLocalDB(localDB);
|
MessageControl.setLocalDB(localDB);
|
||||||
if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info");
|
if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info");
|
||||||
@ -544,8 +551,8 @@ public final class ChatScene implements Restorable {
|
|||||||
currentChat.insert(message);
|
currentChat.insert(message);
|
||||||
// Moving currentChat to the top
|
// Moving currentChat to the top
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
chatList.getItems().remove(currentChat);
|
chats.getSource().remove(currentChat);
|
||||||
chatList.getItems().add(0, currentChat);
|
chats.getSource().add(0, currentChat);
|
||||||
chatList.getSelectionModel().select(0);
|
chatList.getSelectionModel().select(0);
|
||||||
localDB.getChats().remove(currentChat);
|
localDB.getChats().remove(currentChat);
|
||||||
localDB.getChats().add(0, currentChat);
|
localDB.getChats().add(0, currentChat);
|
||||||
@ -616,4 +623,10 @@ public final class ChatScene implements Restorable {
|
|||||||
updateRemainingCharsLabel();
|
updateRemainingCharsLabel();
|
||||||
postButton.setDisable(messageText.isBlank());
|
postButton.setDisable(messageText.isBlank());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void searchContacts() {
|
||||||
|
chats.setPredicate(contactSearch.getText().isBlank() ? c -> true
|
||||||
|
: c -> c.getRecipient().getName().toLowerCase().contains(contactSearch.getText().toLowerCase()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,21 +30,37 @@
|
|||||||
<RowConstraints maxHeight="120.0" minHeight="-Infinity" prefHeight="83.333251953125" vgrow="NEVER" />
|
<RowConstraints maxHeight="120.0" minHeight="-Infinity" prefHeight="83.333251953125" vgrow="NEVER" />
|
||||||
</rowConstraints>
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<ListView id="chatList" fx:id="chatList" focusTraversable="false" onMouseClicked="#chatListClicked" prefHeight="211.0" prefWidth="300.0" GridPane.rowIndex="1" GridPane.rowSpan="2147483647">
|
<VBox prefWidth="316.0" GridPane.rowIndex="1" GridPane.rowSpan="2147483647">
|
||||||
<GridPane.margin>
|
<GridPane.margin>
|
||||||
<Insets right="1.0" />
|
<Insets right="1.0" />
|
||||||
</GridPane.margin>
|
</GridPane.margin>
|
||||||
<padding>
|
<children>
|
||||||
<Insets bottom="5.0" left="5.0" right="2.0" top="5.0" />
|
<VBox maxHeight="-Infinity" minHeight="-Infinity" prefHeight="60.0" prefWidth="316.0">
|
||||||
</padding>
|
<children>
|
||||||
<contextMenu>
|
<TextArea fx:id="contactSearch" onInputMethodTextChanged="#searchContacts" onKeyTyped="#searchContacts" focusTraversable="false" maxHeight="30.0" minHeight="30.0" prefHeight="30.0" prefWidth="200.0" promptText="Search Contacts">
|
||||||
<ContextMenu anchorLocation="CONTENT_TOP_LEFT">
|
<font>
|
||||||
<items>
|
<Font size="14.0" />
|
||||||
<MenuItem fx:id="deleteContactMenuItem" mnemonicParsing="false" onAction="#deleteContact" text="Delete" />
|
</font>
|
||||||
</items>
|
<VBox.margin>
|
||||||
</ContextMenu>
|
<Insets left="10.0" right="10.0" />
|
||||||
</contextMenu>
|
</VBox.margin>
|
||||||
</ListView>
|
</TextArea>
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
<ListView id="chatList" fx:id="chatList" focusTraversable="false" onMouseClicked="#chatListClicked" prefWidth="316.0" VBox.vgrow="ALWAYS">
|
||||||
|
<contextMenu>
|
||||||
|
<ContextMenu anchorLocation="CONTENT_TOP_LEFT">
|
||||||
|
<items>
|
||||||
|
<MenuItem fx:id="deleteContactMenuItem" mnemonicParsing="false" onAction="#deleteContact" text="Delete" />
|
||||||
|
</items>
|
||||||
|
</ContextMenu>
|
||||||
|
</contextMenu>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="2.0" top="5.0" />
|
||||||
|
</padding>
|
||||||
|
</ListView>
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
<HBox id="topBar" alignment="CENTER_LEFT" prefHeight="100.0">
|
<HBox id="topBar" alignment="CENTER_LEFT" prefHeight="100.0">
|
||||||
<children>
|
<children>
|
||||||
<ImageView id="profilePic" fx:id="clientProfilePic" fitHeight="43.0" fitWidth="43.0" pickOnBounds="true" preserveRatio="true">
|
<ImageView id="profilePic" fx:id="clientProfilePic" fitHeight="43.0" fitWidth="43.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
Reference in New Issue
Block a user