Default user profile & saved messages & archived chat profile fixed.
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package org.to.telegramfinalproject.UI;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.shape.Circle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ChatItemController {
|
||||
|
||||
@@ -15,12 +16,73 @@ public class ChatItemController {
|
||||
@FXML private Label lastMessage;
|
||||
@FXML private Label chatTime;
|
||||
@FXML private Label unreadCount;
|
||||
@FXML private StackPane systemAvatar;
|
||||
@FXML private ImageView profileImageUser;
|
||||
@FXML private ImageView profileImageSystem;
|
||||
@FXML private Circle systemCircle;
|
||||
|
||||
public void setChatData(String name, String lastMsg, String time, int unread) {
|
||||
// Default avatar resource path
|
||||
private static final String DEFAULT_AVATAR =
|
||||
"/org/to/telegramfinalproject/Avatars/default_avatar.png";
|
||||
|
||||
/**
|
||||
* Set chat item data, including a profile image (or default).
|
||||
*
|
||||
* @param name Chat name
|
||||
* @param lastMsg Last message text
|
||||
* @param time Last message time
|
||||
* @param unread Unread message count
|
||||
* @param imageUrl Path/URL of profile image (can be null/empty)
|
||||
*/
|
||||
public void setChatData(String name, String lastMsg, String time, int unread, String imageUrl) {
|
||||
chatName.setText(name);
|
||||
lastMessage.setText(lastMsg);
|
||||
chatTime.setText(time);
|
||||
unreadCount.setVisible(unread > 0);
|
||||
unreadCount.setText(String.valueOf(unread));
|
||||
|
||||
// Unread count
|
||||
if (unread > 0) {
|
||||
unreadCount.setVisible(true);
|
||||
unreadCount.setText(String.valueOf(unread));
|
||||
} else {
|
||||
unreadCount.setVisible(false);
|
||||
}
|
||||
|
||||
// Reset all avatar states
|
||||
profileImageUser.setVisible(false);
|
||||
profileImageUser.setManaged(false);
|
||||
systemAvatar.setVisible(false);
|
||||
systemAvatar.setManaged(false);
|
||||
|
||||
if ("Saved Messages".equals(name)) {
|
||||
systemCircle.setFill(javafx.scene.paint.Color.web("#2ca4ff")); // Telegram blue
|
||||
profileImageSystem.setImage(new Image(
|
||||
Objects.requireNonNull(getClass().getResourceAsStream(
|
||||
"/org/to/telegramfinalproject/Icons/saved_messages_light.png"))
|
||||
));
|
||||
systemAvatar.setVisible(true);
|
||||
systemAvatar.setManaged(true);
|
||||
|
||||
} else if ("Archived Chats".equals(name)) {
|
||||
systemCircle.setFill(javafx.scene.paint.Color.web("#808080")); // gray
|
||||
profileImageSystem.setImage(new Image(
|
||||
Objects.requireNonNull(getClass().getResourceAsStream(
|
||||
"/org/to/telegramfinalproject/Icons/archived_chats_light.png"))
|
||||
));
|
||||
systemAvatar.setVisible(true);
|
||||
systemAvatar.setManaged(true);
|
||||
|
||||
} else if (imageUrl != null && !imageUrl.isEmpty()) {
|
||||
profileImageUser.setImage(new Image(imageUrl, true));
|
||||
profileImageUser.setVisible(true);
|
||||
profileImageUser.setManaged(true);
|
||||
|
||||
} else {
|
||||
profileImageUser.setImage(new Image(
|
||||
Objects.requireNonNull(getClass().getResourceAsStream(
|
||||
"/org/to/telegramfinalproject/Icons/default_profile.png"))
|
||||
));
|
||||
profileImageUser.setVisible(true);
|
||||
profileImageUser.setManaged(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class MainController {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/to/telegramfinalproject/Fxml/chat_item.fxml"));
|
||||
Node chatItem = loader.load();
|
||||
ChatItemController controller = loader.getController();
|
||||
controller.setChatData(name, lastMsg, time, unread);
|
||||
controller.setChatData(name, lastMsg, time, unread, "/org/to/telegramfinalproject/Avatars/default_profile.png");
|
||||
|
||||
chatItem.setOnMouseClicked(e -> openChat(name));
|
||||
chatListContainer.getChildren().add(chatItem);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class SidebarMenuController {
|
||||
@FXML
|
||||
public void initialize() {
|
||||
// Load default profile image
|
||||
Image profile = loadImage("/org/to/telegramfinalproject/Avatars/profile.png");
|
||||
Image profile = loadImage("/org/to/telegramfinalproject/Avatars/default_profile.png");
|
||||
if (profile != null) profileImage.setImage(profile);
|
||||
|
||||
setupButtonActions();
|
||||
|
||||
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
@@ -267,12 +267,6 @@
|
||||
-fx-cursor: hand;
|
||||
}
|
||||
|
||||
/* Avatar */
|
||||
.chat-avatar {
|
||||
-fx-background-radius: 50;
|
||||
-fx-border-radius: 50;
|
||||
}
|
||||
|
||||
/* Chat details */
|
||||
.chat-name {
|
||||
-fx-font-size: 14;
|
||||
|
||||
@@ -266,12 +266,6 @@
|
||||
-fx-cursor: hand;
|
||||
}
|
||||
|
||||
/* Avatar */
|
||||
.chat-avatar {
|
||||
-fx-background-radius: 50;
|
||||
-fx-border-radius: 50;
|
||||
}
|
||||
|
||||
/* Chat details */
|
||||
.chat-name {
|
||||
-fx-font-size: 14;
|
||||
|
||||
@@ -5,16 +5,40 @@
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<?import javafx.scene.shape.Circle?>
|
||||
<HBox xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="org.to.telegramfinalproject.UI.ChatItemController"
|
||||
spacing="10" alignment="CENTER_LEFT"
|
||||
styleClass="chat-item">
|
||||
|
||||
<!-- Profile Image -->
|
||||
<ImageView fx:id="profileImage"
|
||||
fitWidth="40" fitHeight="40"
|
||||
preserveRatio="true"
|
||||
styleClass="chat-avatar"/>
|
||||
<!-- Avatar container with fixed size -->
|
||||
<StackPane fx:id="avatarContainer"
|
||||
prefWidth="40" prefHeight="40"
|
||||
minWidth="40" minHeight="40"
|
||||
maxWidth="40" maxHeight="40"
|
||||
alignment="CENTER">
|
||||
|
||||
<!-- User profile image -->
|
||||
<ImageView fx:id="profileImageUser"
|
||||
fitWidth="60" fitHeight="60"
|
||||
preserveRatio="true"
|
||||
visible="true" managed="true"/>
|
||||
|
||||
<!-- System avatar (circle + icon) -->
|
||||
<StackPane fx:id="systemAvatar"
|
||||
prefWidth="40" prefHeight="40"
|
||||
visible="false" managed="false"
|
||||
alignment="CENTER">
|
||||
|
||||
<Circle fx:id="systemCircle"
|
||||
radius="20"
|
||||
fill="gray"/>
|
||||
|
||||
<ImageView fx:id="profileImageSystem"
|
||||
fitWidth="28" fitHeight="28"
|
||||
preserveRatio="true"/>
|
||||
</StackPane>
|
||||
</StackPane>
|
||||
|
||||
<!-- Chat Details -->
|
||||
<VBox alignment="CENTER_LEFT" HBox.hgrow="ALWAYS">
|
||||
|
||||
Reference in New Issue
Block a user