diff --git a/src/main/java/ecorp/easy/installer/controllers/MainWindowController.java b/src/main/java/ecorp/easy/installer/controllers/MainWindowController.java index e068bd8462a8591dc5c98f3e5980201e29a3ba2a..0417dc51e59765be27eff8c06fd01079a0fd3c7d 100644 --- a/src/main/java/ecorp/easy/installer/controllers/MainWindowController.java +++ b/src/main/java/ecorp/easy/installer/controllers/MainWindowController.java @@ -21,10 +21,12 @@ import ecorp.easy.installer.controllers.subcontrollers.AbstractSubController; import ecorp.easy.installer.EasyInstaller; import ecorp.easy.installer.models.Device; import ecorp.easy.installer.threads.ThreadFactory; +import ecorp.easy.installer.utils.UiUtils; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; +import javafx.animation.FadeTransition; import javafx.fxml.Initializable; import javafx.application.Platform; @@ -36,9 +38,11 @@ import javafx.scene.control.Label; import javafx.scene.input.MouseEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.scene.Node; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Pane; import javafx.scene.control.Button; +import javafx.util.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** @@ -159,56 +163,45 @@ public class MainWindowController implements Initializable { logger.info("loadSubScene("+currentSubRootId+")"); if(currentSubRootId == null || currentSubRootId.isEmpty()){ - currentSubRootId =loadSubUI("1-beforeYouBegin.fxml"); - titleLabel.setText(i18n.getString("before_mTitle")); + + currentSubRootId =loadSubUI("1-beforeYouBegin.fxml", "before_mTitle").getId(); }else{ switch(currentSubRootId){ case "beforeYouBeginRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("2-connectDevice.fxml"); - this.titleLabel.setText(i18n.getString("connect_mTitle")); + changeView(currentSubRootId, "2-connectDevice.fxml", "connect_mTitle"); break; case "connectDeviceRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("3-enableADB.fxml"); - this.titleLabel.setText(i18n.getString("devMode_mTitle")); + changeView(currentSubRootId, "3-enableADB.fxml", "devMode_mTitle"); break; case "enableDevMode": - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("4-deviceDetected.fxml"); - this.titleLabel.setText(i18n.getString("detect_mTitle")); + changeView(currentSubRootId, "4-deviceDetected.fxml", "detect_mTitle"); disableNextButton(true); break; case "deviceDetectedRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("5-downloadSrc.fxml"); - this.titleLabel.setText(i18n.getString("download_mTitle")); + changeView(currentSubRootId, "5-downloadSrc.fxml", "download_mTitle"); disableNextButton(true); break; case "downloadSceneRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("6-flashScene.fxml"); - this.titleLabel.setText(i18n.getString("installationTitle")); + changeView(currentSubRootId, "6-flashScene.fxml", "installationTitle"); break; case "flashSceneRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId= loadSubUI("7-flashResult.fxml"); + changeView(currentSubRootId, "7-flashResult.fxml", "installationTitle"); break; case "flashResultRoot": - removeNodeFromRoot(currentSubRootId); + final String fxmlFileName; + final String nextViewTitle; if( isFlashed ){ - currentSubRootId=loadSubUI("8-congrats.fxml"); - this.titleLabel.setText(i18n.getString("congrats_mTitle")); + fxmlFileName = "8-congrats.fxml"; + nextViewTitle ="congrats_mTitle"; } else{ - currentSubRootId=loadSubUI("9-feedback.fxml"); - this.titleLabel.setText(i18n.getString("feedback_mTitle")); + fxmlFileName = "9-feedback.fxml"; + nextViewTitle ="feedback_mTitle"; } + changeView(currentSubRootId, fxmlFileName, nextViewTitle); break; case "congratsRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId=loadSubUI("9-feedback.fxml"); - this.titleLabel.setText(i18n.getString("feedback_mTitle")); + changeView(currentSubRootId, "9-feedback.fxml", "feedback_mTitle"); break; case "feedbackRoot": Platform.exit(); @@ -221,9 +214,7 @@ public class MainWindowController implements Initializable { } public void retryToFlash(){ - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("6-flashScene.fxml"); - this.titleLabel.setText(i18n.getString("installationTitle")); + changeView(currentSubRootId, "6-flashScene.fxml", "installationTitle"); } /** @@ -235,15 +226,45 @@ public class MainWindowController implements Initializable { this.device = device; } + /** + * Used to remove currentView's root node from scene + * Required for return to flashScene after accountUI view + * @param rootId + */ + public void removeNodeFromRoot(final String rootId) { + root.getChildren().removeIf( n -> n.getId().equals(rootId)); + } /** - * Remove a node from the root - * @param nodeId fx:id of the node - * @return true if element removed + * Close previous view after a fadeOut, and open new view + * @param previousNodeId + * @param fxmlName + * @param viewTitle */ - public boolean removeNodeFromRoot(String nodeId){ - return root.getChildren().removeIf( n -> n.getId().equals(nodeId)); + public void changeView(final String previousNodeId, final String fxmlName, final String viewTitle){ + Node elementNode = null; + //get current subroot + for(Node node : root.getChildren() ){ + if( node.getId().equals(previousNodeId) ){ + elementNode = node; + break; + } + } + if(elementNode == null) return ; + //apply transition + final FadeTransition fadeOutTransition = UiUtils.buildFadeTransition(elementNode, true); + + fadeOutTransition.setOnFinished(e -> { + removeNodeFromRoot(previousNodeId); + final Node subRoot = loadSubUI(fxmlName, viewTitle); + currentSubRootId= subRoot.getId(); + + subRoot.setOpacity(0.0); + UiUtils.buildFadeTransition(subRoot,false).play(); + }); + fadeOutTransition.play(); } + /** * Load UI from FXML file @@ -267,13 +288,17 @@ public class MainWindowController implements Initializable { /** * Load the subScene from FXML and return the controller * @param fxmlName fxml file name + * @param viewTitle the title for the new View * @return subRoot. */ - public String loadSubUI(String fxmlName){ + public Node loadSubUI(final String fxmlName, final String viewTitle){ + logger.debug("view title: "+viewTitle); + if(viewTitle != null) titleLabel.setText(i18n.getString(viewTitle)); FXMLLoader loader = loadFXML(fxmlName); Pane subRoot = (Pane) loader.getRoot(); root.getChildren().add(0, subRoot); //adding this element as first subNode, let other element like button to still be clickable on small screen - return subRoot.getId(); + + return subRoot; } /** @@ -339,4 +364,5 @@ public class MainWindowController implements Initializable { public Device getDevice() { return device; } + } diff --git a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/EnableADBController.java b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/EnableADBController.java index 44aab4a891b70e0f643867ce204db158bc88f93e..3ed591804bb9fda7d0d390aa16546b6dbd992a18 100644 --- a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/EnableADBController.java +++ b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/EnableADBController.java @@ -16,13 +16,19 @@ */ package ecorp.easy.installer.controllers.subcontrollers; +import ecorp.easy.installer.utils.UiUtils; import java.net.URL; import java.util.ArrayList; import java.util.ResourceBundle; +import javafx.animation.FadeTransition; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; +import javafx.util.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,7 +43,7 @@ public class EnableADBController extends AbstractSubSteppedController { @FXML private Label firstSubStep; @FXML private Label secondSubStep; @FXML private Label thirdSubStep; - + @FXML private HBox instructionsContainer; @FXML private ImageView enableADBImg; private ArrayList