Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added images/cross.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 23 additions & 5 deletions src/main/java/org/javaFX/EncryWindow.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package org.javaFX;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import org.javaFX.controller.DataHandler;
import org.javaFX.controller.impl.handler.InfoDialogHandler;
import org.javaFX.model.JUserState;
import org.javaFX.util.DelayAuthentication;

Expand All @@ -23,7 +27,7 @@ public class EncryWindow extends Application {
private BorderPane rootLayout;

private final String windowTitle = "ENCRY Telegram Client";
private final String pathToLogoImage = "file:/images/logo.png";
private final String pathToLogoImage = "images/logo.png";

private final static String pathToRootLayout = "view/rootLayout.fxml";

Expand All @@ -45,10 +49,10 @@ public class EncryWindow extends Application {

public final static String pathToStartWindowFXML = "view/startWindow.fxml";


private String currentWindowStr ;

private static String userPhoneNumber;
private static String userCountry;

private DataHandler rootLayoutHandler;

Expand All @@ -66,6 +70,13 @@ public void start(Stage primaryStage) {
initRootLayout();
launchStartWindow();
primaryStage.show();

primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent e) {
Platform.exit();
System.exit(0);
}});
}

public void launchStartWindow(){
Expand Down Expand Up @@ -152,12 +163,19 @@ public static String getUserPhoneNumber(){
}

public static void setUserPhoneNumber(String phoneNumber){
if(userPhoneNumber == null){
userPhoneNumber = phoneNumber;
}
userPhoneNumber = phoneNumber;
}

public static String getUserCountry(){
return userCountry;
}

public static void setUserCountry(String newUserCountry){
userCountry = newUserCountry;
}

public String getCurrentWindowStr() {
return currentWindowStr;
}

}
1 change: 1 addition & 0 deletions src/main/java/org/javaFX/controller/DialogController.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ public void closeDialog(){
getDialogStage().close();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import javafx.animation.AnimationTimer;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.util.Duration;
import org.encryfoundation.tg.javaIntegration.BackMsg;
import org.javaFX.EncryWindow;
Expand All @@ -12,15 +12,12 @@
import org.javaFX.util.observers.JWindowObserver;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;


public abstract class MainWindowBasicHandler extends DataHandler{

private final Duration duration = Duration.millis(5) ;

@FXML
protected TextArea searchMessageTextArea;

@FXML
protected TextArea sendMessageTextArea;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.javaFX.controller.impl.handler;

import javafx.animation.AnimationTimer;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
Expand All @@ -19,6 +21,7 @@
import org.javaFX.controller.MainWindowBasicHandler;
import org.javaFX.model.JChat;
import org.javaFX.model.nodes.VBoxChatCell;
import org.javaFX.model.nodes.VBoxDialogTextMessageCell;
import org.javaFX.model.nodes.VBoxMessageCell;
import org.javaFX.util.KeyboardHandler;

Expand All @@ -28,8 +31,8 @@

public class ChatsWindowHandler extends MainWindowBasicHandler {

private final String pathToBlueButton = "file:images/sendMessageBlue.png";
private final String pathToGreyButton ="file:images/sendMessage.png";
private final String pathToBlueButton = "images/sendMessageBlue.png";
private final String pathToGreyButton ="images/sendMessage.png";

@FXML
private ListView<VBoxChatCell> chatsListView;
Expand Down Expand Up @@ -70,13 +73,16 @@ public class ChatsWindowHandler extends MainWindowBasicHandler {
@FXML
private ImageView searchImg;

@FXML
private ImageView crossImg;

//todo: remove after updating chat by front msg
private int chatsLimit = 20;
private long activeChatId;

public ChatsWindowHandler(){
}
private ObservableList<VBoxMessageCell> chatHistoryBackup;

public ChatsWindowHandler(){}

@FXML
private void onMouseEntered(){
Expand All @@ -85,7 +91,9 @@ private void onMouseEntered(){

@FXML
private void onMouseExited(){
sendMessageImage.setImage(new Image(pathToGreyButton));
if(sendMessageTextArea.getText().isEmpty()){
sendMessageImage.setImage(new Image(pathToGreyButton));
}
}

@Override
Expand All @@ -96,19 +104,25 @@ public void updateEncryWindow(EncryWindow encryWindow) {
initializeDialogArea();
}
enableMenuBar();
FrontMsg a = getUserStateRef().get().inQueue.poll();
if (a != null) {
if (a.code() == FrontMsg.Codes$.MODULE$.newMsgsInChat()) {
FrontMsg.NewMsgsInChat msg = (FrontMsg.NewMsgsInChat) a;
updateDialogArea();
}

private void updateDialogArea(){
FrontMsg frontMsg = getUserStateRef().get().inQueue.poll();
if (frontMsg != null ) {
if (frontMsg.code() == FrontMsg.Codes$.MODULE$.newMsgsInChat()) {
FrontMsg.NewMsgsInChat msg = (FrontMsg.NewMsgsInChat) frontMsg;
ObservableList<VBoxMessageCell> observableChatList = FXCollections.observableArrayList();
msg.msgs().forEach(msgCell -> observableChatList.add(msgCell));
msg.msgs().forEach(msgCell -> chatHistoryBackup.add(msgCell));
messagesListView.scrollTo(1);
messagesListView.setItems(observableChatList);
} else if (a.code() == FrontMsg.Codes$.MODULE$.historyMsgs()) {
FrontMsg.HistoryMsgs msg = (FrontMsg.HistoryMsgs) a;
if (msg.chatId() == activeChatId) {
} else if (frontMsg.code() == FrontMsg.Codes$.MODULE$.historyMsgs()) {
FrontMsg.HistoryMsgs msg = (FrontMsg.HistoryMsgs) frontMsg;
if (msg.chatId() == activeChatId && messagesListView.getItems().size() > 0) {
ObservableList<VBoxMessageCell> observableChatList = FXCollections.observableArrayList();
msg.msgs().forEach(msgCell -> observableChatList.add(msgCell));
msg.msgs().forEach(msgCell -> chatHistoryBackup.add(msgCell));
VBoxMessageCell prevLastCell = messagesListView.getItems().get(0);
messagesListView.getItems().forEach(cell -> observableChatList.add(cell));
messagesListView.setItems(observableChatList);
Expand All @@ -117,7 +131,6 @@ public void updateEncryWindow(EncryWindow encryWindow) {
} else {
System.out.println("Unknown msg");
}

}
}

Expand Down Expand Up @@ -196,18 +209,18 @@ protected void initializeTable() {
@FXML
private ObservableList<VBoxMessageCell> getObservableJMessageList(){
ObservableList<VBoxMessageCell> observableMessageList = FXCollections.observableArrayList();
getUserStateRef().get().messagesListView.getItems().forEach (
message ->
observableMessageList.add(message)
);
forceListRefreshOn();
String previousMsgAuthor = "";
for(VBoxMessageCell messageCell: getUserStateRef().get().messagesListView.getItems() ){
String currentMsgAuthor = messageCell.getElement().getAuthor();
messageCell.getElement().setPreviousSameAuthor(currentMsgAuthor.equals(previousMsgAuthor));
if( currentMsgAuthor.equals(previousMsgAuthor) ){
((VBoxDialogTextMessageCell) messageCell).recreateMessageCell();
}
previousMsgAuthor = currentMsgAuthor;
observableMessageList.add(messageCell);
}
messagesListView.setItems(observableMessageList);
return observableMessageList;

/*
new way of initialization
final String searchingStr = searchMessageTextField.getText().trim();
ObservableList<VBoxMessageCell> observableMessageList = findMessagesByStr(searchingStr);
return observableMessageList;*/
}

@FXML
Expand All @@ -221,7 +234,12 @@ private void showLeftPane(){
messagesListView.setVisible(true);
rightBottomAnchorPane.setVisible(true);
selectChatLabel.setVisible(false);
chatNameLabel.setText(chatsListView.getSelectionModel().getSelectedItem().getChatTitle());
String chatTitleStr = chatsListView.getSelectionModel().getSelectedItem().getChatTitle();
if(chatTitleStr.length() > 30 ){
chatTitleStr = chatTitleStr.substring(0, 27)+"...";
}
chatNameLabel.setText( chatTitleStr );
searchMessageTextField.setText("");
}

public void hideLeftPane(){
Expand All @@ -233,6 +251,7 @@ public void hideLeftPane(){

@FXML
protected void clickItem() {
chatHistoryBackup = FXCollections.observableArrayList();
getUserStateRef().get().setActiveDialog(messagesListView);
if( messagesListView.getItems().size() == 0 ){
showStartMessagingArea();
Expand All @@ -241,9 +260,7 @@ protected void clickItem() {
refreshColors(activeChat);
activeChatId = activeChat.chatIdProperty().get();
BackMsg msg = new BackMsg.SetActiveChat(activeChatId);
initializeDialogArea();
ObservableList<VBoxMessageCell> observableMessageList = FXCollections.observableArrayList();
messagesListView.setItems(observableMessageList);
refreshBasicElements();
try {
getUserStateRef().get().outQueue.put(msg);
} catch (InterruptedException e) {
Expand All @@ -252,19 +269,19 @@ protected void clickItem() {
showLeftPane();
}

private void refreshBasicElements(){
initializeDialogArea();
sendMessageTextArea.setText("");
sendMessageImage.setImage(new Image(pathToGreyButton));
}

private void refreshColors(VBoxChatCell activeChat){
for(VBoxChatCell cell: chatsListView.getItems()){
cell.resetPaneColor();
}
activeChat.updatePaneColor();
}

private void forceListRefreshOn() {
ObservableList<VBoxMessageCell> items = messagesListView.getItems();
messagesListView.getItems().clear();
messagesListView.setItems(items);
}

@FXML
private void searchContactByKeyboard(){
AtomicBoolean keysPressed = KeyboardHandler.handleEnterPressed(searchThroughChatsTextField);
Expand All @@ -278,10 +295,10 @@ public void handle(long now) {
}.start();
}


private void findContact(){
final String searchingStr = searchThroughChatsTextField.getText().trim();
chatsListView.setItems(initTableBySubstr(searchingStr));
notFoundChatLabel.setVisible((chatsListView.getItems().size() == 0 ));
}

private ObservableList<VBoxChatCell> initTableBySubstr(String searchingStr){
Expand All @@ -298,25 +315,23 @@ private ObservableList<VBoxChatCell> initTableBySubstr(String searchingStr){
initChatCell(observableList, chat, chatCellWidth);
}
);
notFoundChatLabel.setVisible((observableList.size() == 0 ));
return observableList;
}

@FXML
public void findContentInDialog(){
final String searchingStr = searchMessageTextField.getText().trim();
// findMessagesByStr(searchingStr);
messagesListView.setItems( getMessagesByStr(searchingStr) );
}

private ObservableList<VBoxMessageCell> findMessagesByStr(String searchingStr){
ObservableList<org.javaFX.model.nodes.VBoxMessageCell> observableMessageList = FXCollections.observableArrayList();
getUserStateRef().get().messagesListView.getItems()
.filtered(message->message.getContentText().contains(searchingStr))
private ObservableList<VBoxMessageCell> getMessagesByStr(String searchingStr){
ObservableList<VBoxMessageCell> observableMessageList = FXCollections.observableArrayList();
chatHistoryBackup.filtered(message->message.getContentText().toLowerCase().contains(searchingStr.toLowerCase()))
.forEach (
message ->
observableMessageList.add(message)
);
forceListRefreshOn();
messagesListView.setItems(observableMessageList);
return observableMessageList;
}

Expand All @@ -333,6 +348,25 @@ public void handle(long now) {
}.start();
}


@FXML
private void onKeyTypedSearchMessage(){
searchMessageTextField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable,
String oldValue, String newValue) {
String searchingStr = searchMessageTextField.getText().trim();
if(searchingStr.isEmpty()){
crossImg.setVisible(false);
}
else {
crossImg.setVisible(true);
}
}
});

}

private void showStartMessagingArea(){
selectChatLabel.setText("There is no messages in this dialogue");
}
Expand All @@ -349,4 +383,22 @@ private void handleSearchImg(){
});
}

@FXML
private void cleanTextField(){
searchMessageTextField.setText("");
messagesListView.setItems( getMessagesByStr("") );
crossImg.setVisible(false);
}


@FXML
public void onSendTextKeyTyped() {
String inputText = sendMessageTextArea.getText();
if(!inputText.isEmpty()){
sendMessageImage.setImage(new Image(pathToBlueButton));
}
else {
sendMessageImage.setImage(new Image(pathToGreyButton));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public abstract class CommunitiesWindowHandler extends DataHandler {

private ScheduledExecutorService service;
private Duration period = Duration.millis(10);
private final Duration period = Duration.millis(10);

public CommunitiesWindowHandler() {
runDelayedInitialization();
Expand Down
Loading