feat: shopping list view

This commit is contained in:
Natalia Cholewa 2026-01-22 17:21:40 +01:00
commit 6cfd6ab82c
9 changed files with 107 additions and 0 deletions

View file

@ -33,6 +33,9 @@ import commons.ws.messages.UpdateRecipeMessage;
import jakarta.inject.Inject;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
@ -41,6 +44,7 @@ import javafx.scene.control.ListView;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.ToggleButton;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@ -611,6 +615,15 @@ public class FoodpalApplicationCtrl implements LocaleAware {
updatedBadgeTimer.playFromStart();
}
public void openShoppingListWindow() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("shopping/ShoppingList.fxml"));
Parent root = (Parent)loader.load();
Stage stage = new Stage();
stage.setTitle(this.getLocaleString("menu.shopping.title"));
stage.setScene(new Scene(root));
stage.show();
}
}

View file

@ -0,0 +1,66 @@
package client.scenes.shopping;
import client.service.ShoppingListService;
import client.utils.LocaleAware;
import client.utils.LocaleManager;
import com.google.inject.Inject;
import commons.FormalIngredient;
import javafx.fxml.FXML;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.util.Pair;
import java.util.Optional;
public class ShoppingListCtrl implements LocaleAware {
ShoppingListService shopping;
LocaleManager localeManager;
@FXML
private ListView<Pair<FormalIngredient, Optional<String>>> shoppingListView;
@Inject
public ShoppingListCtrl(
ShoppingListService shopping,
LocaleManager localeManager
) {
this.shopping = shopping;
this.localeManager = localeManager;
}
@Override
public void updateText() {
}
@Override
public LocaleManager getLocaleManager() {
return this.localeManager;
}
public void initializeComponents() {
this.shoppingListView.setCellFactory(l -> new ListCell<>() {
@Override
protected void updateItem(Pair<FormalIngredient, Optional<String>> item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
this.setText("");
return;
}
String display = item.getKey().toString() +
item.getValue().map(recipe -> {
return " (" + recipe + ")";
}).orElse("");
this.setText(display);
}
});
this.shoppingListView.getItems().setAll(
this.shopping.getItems()
);
}
}

View file

@ -70,6 +70,9 @@
<ToggleButton fx:id="favouritesOnlyToggle" text="Favourites" onAction="#toggleFavouritesView" />
</HBox>
<Button fx:id="shoppingListButton"
onAction="#openShoppingListWindow"
text="Shopping List" />
<Button fx:id="manageIngredientsButton"
onAction="#openIngredientsPopup"
text="Ingredients..." />

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.AnchorPane?>
<TitledPane animated="false" collapsible="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" text="Shopping List" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/25">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<ListView fx:id="shoppingListView" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</content>
</TitledPane>

View file

@ -38,6 +38,8 @@ menu.search=Search...
menu.label.selected-langs=Languages
menu.shopping.title=Shopping list
lang.en.display=English
lang.nl.display=Dutch
lang.pl.display=Polish

View file

@ -36,6 +36,8 @@ menu.button.close=Sluiten
menu.label.selected-langs=Talen
menu.shopping.title=Boodschappenlijst
menu.search=Zoeken...
lang.en.display=Engels
lang.nl.display=Nederlands

View file

@ -38,6 +38,8 @@ menu.search=Szukaj...
menu.label.selected-langs=Języki
menu.shopping.title=Lista zakupów
lang.en.display=Inglisz
lang.nl.display=Holenderski
lang.pl.display=Polski

View file

@ -38,6 +38,8 @@ menu.search=o alasa
menu.label.selected-langs=toki wile
menu.shopping.title=ijo wile mani mute
lang.en.display=toki Inli
lang.nl.display=toki Netelan
lang.pl.display=toki Posuka

View file

@ -38,6 +38,8 @@ menu.search=Arama...
menu.label.selected-langs=Diller
menu.shopping.title=Al??veri? listesi
lang.en.display=\u0130ngilizce
lang.nl.display=Hollandaca
lang.pl.display=Leh\u00E7e