diff --git a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java index 93ec852..d276137 100644 --- a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java +++ b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java @@ -86,6 +86,11 @@ public class FoodpalApplicationCtrl implements LocaleAware { private List allRecipes = new ArrayList<>(); + @FXML + private Label updatedBadge; + + private javafx.animation.Timeline updatedBadgeTimer; + @Inject public FoodpalApplicationCtrl( @@ -223,6 +228,9 @@ public class FoodpalApplicationCtrl implements LocaleAware { webSocketUtils.subscribe(Topics.RECIPES, (Message msg) -> { Platform.runLater(() -> { dataService.onMessage(msg); + + showUpdatedBadge(); + Recipe selectedRecipe = recipeList.getSelectionModel().getSelectedItem(); if (selectedRecipe == null) { return; @@ -235,6 +243,7 @@ public class FoodpalApplicationCtrl implements LocaleAware { .orElse(null); this.recipeDetailController.setCurrentlyViewedRecipe(recipeInList); + }); // runLater as it's on another non-FX thread. }); }); @@ -290,6 +299,8 @@ public class FoodpalApplicationCtrl implements LocaleAware { allRecipes = new ArrayList<>(recipes); applyRecipeFilterAndKeepSelection(); + + showUpdatedBadge(); } private void printError(String msg) { @@ -544,6 +555,32 @@ public class FoodpalApplicationCtrl implements LocaleAware { e.printStackTrace(); } } + private static final double UPDATED_VISIBLE_SECONDS = 3.0; + + public void showUpdatedBadge() { + if (updatedBadge == null) { + return; + } + + updatedBadge.setManaged(true); + updatedBadge.setVisible(true); + + if (updatedBadgeTimer != null) { + updatedBadgeTimer.stop(); + } + + updatedBadgeTimer = new javafx.animation.Timeline( + new javafx.animation.KeyFrame( + javafx.util.Duration.seconds(UPDATED_VISIBLE_SECONDS), + e -> { + updatedBadge.setVisible(false); + updatedBadge.setManaged(false); + } + ) + ); + + updatedBadgeTimer.playFromStart(); + } } diff --git a/client/src/main/resources/client/scenes/FoodpalApplication.fxml b/client/src/main/resources/client/scenes/FoodpalApplication.fxml index a6b0b49..c777543 100644 --- a/client/src/main/resources/client/scenes/FoodpalApplication.fxml +++ b/client/src/main/resources/client/scenes/FoodpalApplication.fxml @@ -82,4 +82,21 @@ + + + + + + + + +