Merge branch 'updated-button' into 'main'

Update badge addition

Closes #66

See merge request cse1105/2025-2026/teams/csep-team-76!63
This commit is contained in:
Aysegul Aydinlik 2026-01-16 16:43:39 +01:00
commit ecccebe7c5
2 changed files with 54 additions and 0 deletions

View file

@ -86,6 +86,11 @@ public class FoodpalApplicationCtrl implements LocaleAware {
private List<Recipe> 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();
}
}

View file

@ -82,4 +82,21 @@
<fx:include source="recipe/RecipeDetailView.fxml" fx:id="recipeDetail" />
</center>
<!-- BOTTOM: UPDATED BADGE -->
<bottom>
<HBox alignment="CENTER_RIGHT"
minHeight="40"
prefHeight="40"
maxHeight="40">
<padding>
<Insets bottom="16" left="16" right="16" top="8" />
</padding>
<Label fx:id="updatedBadge"
text="Updated just now"
visible="false"
managed="false"
styleClass="updated-badge"/>
</HBox>
</bottom>
</BorderPane>