Update badge addition
This commit is contained in:
parent
780724c14a
commit
b739c78170
2 changed files with 54 additions and 0 deletions
|
|
@ -86,6 +86,11 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
||||||
|
|
||||||
private List<Recipe> allRecipes = new ArrayList<>();
|
private List<Recipe> allRecipes = new ArrayList<>();
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label updatedBadge;
|
||||||
|
|
||||||
|
private javafx.animation.Timeline updatedBadgeTimer;
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FoodpalApplicationCtrl(
|
public FoodpalApplicationCtrl(
|
||||||
|
|
@ -223,6 +228,9 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
||||||
webSocketUtils.subscribe(Topics.RECIPES, (Message msg) -> {
|
webSocketUtils.subscribe(Topics.RECIPES, (Message msg) -> {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
dataService.onMessage(msg);
|
dataService.onMessage(msg);
|
||||||
|
|
||||||
|
showUpdatedBadge();
|
||||||
|
|
||||||
Recipe selectedRecipe = recipeList.getSelectionModel().getSelectedItem();
|
Recipe selectedRecipe = recipeList.getSelectionModel().getSelectedItem();
|
||||||
if (selectedRecipe == null) {
|
if (selectedRecipe == null) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -235,6 +243,7 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
this.recipeDetailController.setCurrentlyViewedRecipe(recipeInList);
|
this.recipeDetailController.setCurrentlyViewedRecipe(recipeInList);
|
||||||
|
|
||||||
}); // runLater as it's on another non-FX thread.
|
}); // runLater as it's on another non-FX thread.
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -290,6 +299,8 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
||||||
|
|
||||||
allRecipes = new ArrayList<>(recipes);
|
allRecipes = new ArrayList<>(recipes);
|
||||||
applyRecipeFilterAndKeepSelection();
|
applyRecipeFilterAndKeepSelection();
|
||||||
|
|
||||||
|
showUpdatedBadge();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printError(String msg) {
|
private void printError(String msg) {
|
||||||
|
|
@ -544,6 +555,32 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
||||||
e.printStackTrace();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,4 +82,21 @@
|
||||||
<fx:include source="recipe/RecipeDetailView.fxml" fx:id="recipeDetail" />
|
<fx:include source="recipe/RecipeDetailView.fxml" fx:id="recipeDetail" />
|
||||||
</center>
|
</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>
|
</BorderPane>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue