added a star for favouriting a recipe and also unfavouriting it
This commit is contained in:
parent
c07bae8d74
commit
7a58153cd6
3 changed files with 59 additions and 5 deletions
|
|
@ -18,6 +18,7 @@ package client;
|
|||
import client.scenes.FoodpalApplicationCtrl;
|
||||
import client.scenes.recipe.IngredientListCtrl;
|
||||
import client.scenes.recipe.RecipeStepListCtrl;
|
||||
import client.utils.ConfigService;
|
||||
import client.utils.LocaleManager;
|
||||
import client.utils.ServerUtils;
|
||||
import client.utils.WebSocketUtils;
|
||||
|
|
@ -27,6 +28,8 @@ import com.google.inject.Scopes;
|
|||
|
||||
import client.scenes.MainCtrl;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class MyModule implements Module {
|
||||
|
||||
@Override
|
||||
|
|
@ -39,5 +42,8 @@ public class MyModule implements Module {
|
|||
binder.bind(LocaleManager.class).in(Scopes.SINGLETON);
|
||||
binder.bind(ServerUtils.class).in(Scopes.SINGLETON);
|
||||
binder.bind(WebSocketUtils.class).in(Scopes.SINGLETON);
|
||||
|
||||
binder.bind(ConfigService.class).toInstance(new ConfigService(Path.of("config.json")));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -9,12 +9,14 @@ import java.util.Locale;
|
|||
import client.exception.UpdateException;
|
||||
import client.scenes.recipe.IngredientListCtrl;
|
||||
import client.scenes.recipe.RecipeStepListCtrl;
|
||||
|
||||
import client.utils.Config;
|
||||
import client.utils.ConfigService;
|
||||
import client.utils.DefaultRecipeFactory;
|
||||
import client.utils.LocaleAware;
|
||||
import client.utils.LocaleManager;
|
||||
import client.utils.ServerUtils;
|
||||
import client.utils.WebSocketUtils;
|
||||
|
||||
import commons.Recipe;
|
||||
|
||||
import commons.ws.Topics;
|
||||
|
|
@ -72,6 +74,13 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
|||
@FXML
|
||||
public Button cloneRecipeButton;
|
||||
|
||||
@FXML
|
||||
private Button favouriteButton;
|
||||
|
||||
private Config config;
|
||||
private final ConfigService configService;
|
||||
|
||||
|
||||
// === CENTER: RECIPE DETAILS ===
|
||||
|
||||
@FXML
|
||||
|
|
@ -89,13 +98,15 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
|||
WebSocketUtils webSocketUtils,
|
||||
LocaleManager localeManager,
|
||||
IngredientListCtrl ingredientListCtrl,
|
||||
RecipeStepListCtrl stepListCtrl
|
||||
RecipeStepListCtrl stepListCtrl,
|
||||
ConfigService configService
|
||||
) {
|
||||
this.server = server;
|
||||
this.webSocketUtils = webSocketUtils;
|
||||
this.localeManager = localeManager;
|
||||
this.ingredientListCtrl = ingredientListCtrl;
|
||||
this.stepListCtrl = stepListCtrl;
|
||||
this.configService = configService;
|
||||
|
||||
initializeWebSocket();
|
||||
}
|
||||
|
|
@ -124,6 +135,7 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
|||
|
||||
@Override
|
||||
public void initializeComponents() {
|
||||
config = configService.getConfig();
|
||||
// TODO Reduce code duplication??
|
||||
// Initialize callback for ingredient list updates
|
||||
this.ingredientListCtrl.setUpdateCallback(newList -> {
|
||||
|
|
@ -162,10 +174,12 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
|||
setText(empty || item == null ? "" : item.getName());
|
||||
}
|
||||
});
|
||||
|
||||
// When your selection changes, update details in the panel
|
||||
recipeList.getSelectionModel().selectedItemProperty().addListener(
|
||||
(obs, oldRecipe, newRecipe) -> showRecipeDetails(newRecipe)
|
||||
(obs, oldRecipe, newRecipe) -> {
|
||||
showRecipeDetails(newRecipe);
|
||||
updateFavouriteButton(newRecipe);
|
||||
}
|
||||
);
|
||||
|
||||
// Double-click to go to detail screen
|
||||
|
|
@ -175,8 +189,8 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
|||
openSelectedRecipe();
|
||||
}
|
||||
});
|
||||
|
||||
refresh();
|
||||
updateFavouriteButton(recipeList.getSelectionModel().getSelectedItem());
|
||||
}
|
||||
|
||||
private void showName(String name) {
|
||||
|
|
@ -357,6 +371,39 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
|||
recipeList.getSelectionModel().select(cloned);
|
||||
}
|
||||
|
||||
private void updateFavouriteButton(Recipe recipe) {
|
||||
if (recipe == null) {
|
||||
favouriteButton.setDisable(true);
|
||||
favouriteButton.setText("☆");
|
||||
return;
|
||||
}
|
||||
|
||||
favouriteButton.setDisable(false);
|
||||
favouriteButton.setText(
|
||||
config.isFavourite(recipe.getId()) ? "★" : "☆"
|
||||
);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void toggleFavourite() {
|
||||
Recipe selected = recipeList.getSelectionModel().getSelectedItem();
|
||||
if (selected == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
long id = selected.getId();
|
||||
|
||||
if (config.isFavourite(id)) {
|
||||
config.removeFavourite(id);
|
||||
} else {
|
||||
config.addFavourite(id);
|
||||
}
|
||||
|
||||
configService.save();
|
||||
updateFavouriteButton(selected);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@
|
|||
<Button fx:id="editRecipeTitleButton" onAction="#editRecipeTitle" text="Edit" />
|
||||
<Button fx:id="removeRecipeButton2" mnemonicParsing="false" onAction="#removeSelectedRecipe" text="Remove Recipe" />
|
||||
<Button fx:id="printRecipeButton" mnemonicParsing="false" onAction="#makePrintable" text="Print Recipe" />
|
||||
<Button fx:id="favouriteButton" onAction="#toggleFavourite" text="☆" />
|
||||
</HBox>
|
||||
|
||||
<!-- Ingredients -->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue