Merge branch 'refs/heads/Main-UI' into Connection-UI
# Conflicts: # src/main/java/org/to/telegramfinalproject/UI/ChatItemController.java # src/main/java/org/to/telegramfinalproject/UI/MainController.java
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,13 +16,74 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
public void setUnread(int unread) {
|
||||
@@ -30,4 +92,4 @@ public class ChatItemController {
|
||||
unreadCount.setManaged(show);
|
||||
if (show) unreadCount.setText(String.valueOf(unread));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,6 +245,10 @@ public class MainController {
|
||||
|
||||
String preview = chat.getLastMessagePreview() == null ? "" : chat.getLastMessagePreview();
|
||||
String timeText = formatChatTime(chat.getLastMessageTime());
|
||||
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, "/org/to/telegramfinalproject/Avatars/default_profile.png");
|
||||
|
||||
cc.setChatData(chat.getName(), preview, timeText, chat.getUnreadCount());
|
||||
item.setOnMouseClicked(e -> openChat(chat));
|
||||
|
||||
@@ -48,7 +48,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();
|
||||
|
||||
Reference in New Issue
Block a user