diff --git a/client/src/main/java/client/MyModule.java b/client/src/main/java/client/MyModule.java
index 21da1dc..68ef84f 100644
--- a/client/src/main/java/client/MyModule.java
+++ b/client/src/main/java/client/MyModule.java
@@ -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")));
+
}
}
\ No newline at end of file
diff --git a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java
index 4079723..0baff95 100644
--- a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java
+++ b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java
@@ -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);
+ }
+
+
}
diff --git a/client/src/main/resources/client/scenes/FoodpalApplication.fxml b/client/src/main/resources/client/scenes/FoodpalApplication.fxml
index 27b5bc2..21f79fa 100644
--- a/client/src/main/resources/client/scenes/FoodpalApplication.fxml
+++ b/client/src/main/resources/client/scenes/FoodpalApplication.fxml
@@ -113,6 +113,7 @@
+