feat: add initial loading screen
This commit is contained in:
parent
4ba39b3cc3
commit
e02ea55179
3 changed files with 82 additions and 13 deletions
|
@ -7,20 +7,27 @@ import fr.insa.clavardator.ui.dialogs.EditUsernameDialogController;
|
||||||
import fr.insa.clavardator.ui.dialogs.SnackbarController;
|
import fr.insa.clavardator.ui.dialogs.SnackbarController;
|
||||||
import fr.insa.clavardator.ui.users.UserListController;
|
import fr.insa.clavardator.ui.users.UserListController;
|
||||||
import fr.insa.clavardator.users.CurrentUser;
|
import fr.insa.clavardator.users.CurrentUser;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public class MainController implements Initializable {
|
public class MainController implements Initializable {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private StackPane root;
|
private StackPane root;
|
||||||
|
@FXML
|
||||||
|
private VBox loadingContainer;
|
||||||
|
@FXML
|
||||||
|
private VBox loginContainer;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ToolbarController toolbarController;
|
private ToolbarController toolbarController;
|
||||||
|
@ -53,9 +60,37 @@ public class MainController implements Initializable {
|
||||||
editUserDialogController.show(root, EditUsernameDialogController.Mode.EDIT);
|
editUserDialogController.show(root, EditUsernameDialogController.Mode.EDIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showChat() {
|
||||||
|
loadingContainer.setVisible(false);
|
||||||
|
loginContainer.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showLogin() {
|
||||||
|
loadingContainer.setVisible(false);
|
||||||
|
loginContainer.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle rb) {
|
public void initialize(URL url, ResourceBundle rb) {
|
||||||
snackbar = new JFXSnackbar(root);
|
snackbar = new JFXSnackbar(root);
|
||||||
|
|
||||||
|
Timer t = new Timer();
|
||||||
|
t.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Platform.runLater(() -> CurrentUser.getInstance().setState(CurrentUser.State.VALID));
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
CurrentUser.getInstance().addObserver(propertyChangeEvent -> {
|
||||||
|
if (propertyChangeEvent.getPropertyName().equals("state")) {
|
||||||
|
if (propertyChangeEvent.getNewValue().equals(CurrentUser.State.VALID))
|
||||||
|
showChat();
|
||||||
|
else
|
||||||
|
showLogin();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
userListController.addRefreshUserListener(() -> System.out.println("refresh event"));
|
userListController.addRefreshUserListener(() -> System.out.println("refresh event"));
|
||||||
userListController.addUserSelectedListener((user) -> chatController.setRemoteUser(user));
|
userListController.addUserSelectedListener((user) -> chatController.setRemoteUser(user));
|
||||||
chatController.addAttachmentListener(() -> System.out.println("attach event"));
|
chatController.addAttachmentListener(() -> System.out.println("attach event"));
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
package fr.insa.clavardator.users;
|
package fr.insa.clavardator.users;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class CurrentUser extends User {
|
public class CurrentUser extends User {
|
||||||
private static CurrentUser instance = null;
|
private static CurrentUser instance = null;
|
||||||
|
|
||||||
|
private State state;
|
||||||
|
|
||||||
private CurrentUser(int uniqueId, String username) {
|
private CurrentUser(int uniqueId, String username) {
|
||||||
super(uniqueId, username);
|
super(uniqueId, username);
|
||||||
|
state = State.UNINITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,4 +32,20 @@ public class CurrentUser extends User {
|
||||||
public static CurrentUser getInstance() {
|
public static CurrentUser getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public State getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setState(State state) {
|
||||||
|
instance.pcs.firePropertyChange("state", this.state, state);
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public enum State {
|
||||||
|
UNINITIALIZED,
|
||||||
|
VALID,
|
||||||
|
INVALID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<!--suppress JavaFxUnresolvedFxIdReference -->
|
<!--suppress JavaFxUnresolvedFxIdReference -->
|
||||||
<?import javafx.scene.layout.HBox?>
|
<?import com.jfoenix.controls.JFXSpinner?>
|
||||||
<?import javafx.scene.layout.StackPane?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.*?>
|
||||||
<StackPane xmlns:fx="http://javafx.com/fxml/1"
|
<StackPane xmlns:fx="http://javafx.com/fxml/1"
|
||||||
xmlns="http://javafx.com/javafx/11.0.1" fx:controller="fr.insa.clavardator.ui.MainController" fx:id="root">
|
xmlns="http://javafx.com/javafx/11.0.1"
|
||||||
|
fx:controller="fr.insa.clavardator.ui.MainController"
|
||||||
|
stylesheets="@styles.css"
|
||||||
|
styleClass="container"
|
||||||
|
fx:id="root">
|
||||||
|
<StackPane fx:id="mainContainer">
|
||||||
<fx:include source="dialogs/editUsernameDialog.fxml" fx:id="editUserDialog"/>
|
<fx:include source="dialogs/editUsernameDialog.fxml" fx:id="editUserDialog"/>
|
||||||
<fx:include source="dialogs/aboutDialog.fxml" fx:id="aboutDialog"/>
|
<fx:include source="dialogs/aboutDialog.fxml" fx:id="aboutDialog"/>
|
||||||
<VBox>
|
<VBox>
|
||||||
|
@ -16,3 +21,11 @@
|
||||||
</HBox>
|
</HBox>
|
||||||
</VBox>
|
</VBox>
|
||||||
</StackPane>
|
</StackPane>
|
||||||
|
<VBox alignment="CENTER" fx:id="loginContainer" styleClass="container" spacing="30">
|
||||||
|
<Label>ERROR</Label>
|
||||||
|
</VBox>
|
||||||
|
<VBox alignment="CENTER" fx:id="loadingContainer" styleClass="container" spacing="30">
|
||||||
|
<Label>Initialisation de Clavardator...</Label>
|
||||||
|
<JFXSpinner/>
|
||||||
|
</VBox>
|
||||||
|
</StackPane>
|
||||||
|
|
Loading…
Reference in a new issue