diff --git a/kitchenowl/lib/l10n/app_de.arb b/kitchenowl/lib/l10n/app_de.arb index 542ff7b3..216fbc3b 100644 --- a/kitchenowl/lib/l10n/app_de.arb +++ b/kitchenowl/lib/l10n/app_de.arb @@ -341,6 +341,8 @@ "@themeLight": {}, "@themeMode": {}, "@themeSystem": {}, + "@today": {}, + "@tomorrow": {}, "@total": {}, "@totalTime": {}, "@tutorialItemDescription1": {}, @@ -624,6 +626,8 @@ "themeLight": "Hell", "themeMode": "Farbschema", "themeSystem": "System", + "today": "Heute", + "tomorrow": "Morgen", "total": "Gesamt", "totalTime": "Gesamtzeit", "tutorialItemDescription1": "Bei der Suche nach Artikeln kannst du mit einer Menge anfangen, die dann als Beschreibung hinzugefügt wird.", diff --git a/kitchenowl/lib/l10n/app_en.arb b/kitchenowl/lib/l10n/app_en.arb index cfcf0fb9..4f5dda02 100644 --- a/kitchenowl/lib/l10n/app_en.arb +++ b/kitchenowl/lib/l10n/app_en.arb @@ -343,6 +343,8 @@ "@themeLight": {}, "@themeMode": {}, "@themeSystem": {}, + "@today": {}, + "@tomorrow": {}, "@total": {}, "@totalTime": {}, "@tutorialItemDescription1": {}, @@ -626,6 +628,8 @@ "themeLight": "Light", "themeMode": "Theme", "themeSystem": "System", + "today": "Today", + "tomorrow": "Tomorrow", "total": "Total", "totalTime": "Total time", "tutorialItemDescription1": "When searching for items, you can add an amount at the start of your query, and it will be added as a description.", diff --git a/kitchenowl/lib/l10n/app_es.arb b/kitchenowl/lib/l10n/app_es.arb index de517a15..fd240acd 100644 --- a/kitchenowl/lib/l10n/app_es.arb +++ b/kitchenowl/lib/l10n/app_es.arb @@ -341,6 +341,8 @@ "@themeLight": {}, "@themeMode": {}, "@themeSystem": {}, + "@today": {}, + "@tomorrow": {}, "@total": {}, "@totalTime": {}, "@tutorialItemDescription1": {}, @@ -624,6 +626,8 @@ "themeLight": "Claro", "themeMode": "Tema", "themeSystem": "Sistema", + "today": "Hoy", + "tomorrow": "Mañana", "total": "Total", "totalTime": "Tiempo total", "tutorialItemDescription1": "Al buscar artículos, puede añadir una cantidad al principio de la consulta, y se añadirá como descripción.", diff --git a/kitchenowl/lib/pages/household_page/planner.dart b/kitchenowl/lib/pages/household_page/planner.dart index 83f10dea..9a007e43 100644 --- a/kitchenowl/lib/pages/household_page/planner.dart +++ b/kitchenowl/lib/pages/household_page/planner.dart @@ -17,6 +17,31 @@ import 'package:kitchenowl/widgets/recipe_card.dart'; import 'package:responsive_builder/responsive_builder.dart'; import 'package:tuple/tuple.dart'; +int db_weekday(int shift) { + // subtract 1 because DateTime.weekday goes from 1 to 7. Kitchenowl-db from 0 to 6 + return DateTime.now().add(Duration(days: shift)).weekday - 1; +} + +String formatDateAsWeekday(DateTime date, BuildContext context, + {String default_format = 'EEEE'}) { + DateTime today = DateTime.now(); + DateTime tomorrow = today.add(Duration(days: 1)); + + // Check if the date is today or tomorrow + if (date.year == today.year && + date.month == today.month && + date.day == today.day) { + return AppLocalizations.of(context)!.today; + } else if (date.year == tomorrow.year && + date.month == tomorrow.month && + date.day == tomorrow.day) { + return AppLocalizations.of(context)!.tomorrow; + } else { + // Return the weekday name + return DateFormat(default_format).format(date); + } +} + class PlannerPage extends StatefulWidget { const PlannerPage({super.key}); @@ -43,16 +68,6 @@ class _PlannerPageState extends State { final cubit = BlocProvider.of(context); final household = BlocProvider.of(context).state.household; - final weekdayMapping = { - 0: DateTime.monday, - 1: DateTime.tuesday, - 2: DateTime.wednesday, - 3: DateTime.thursday, - 4: DateTime.friday, - 5: DateTime.saturday, - 6: DateTime.sunday, - }; - return SafeArea( child: Scrollbar( child: RefreshIndicator( @@ -172,8 +187,9 @@ class _PlannerPageState extends State { ), ), ), - for (int day = 0; day < 7; day++) - for (final plan in state.getPlannedOfDay(day)) + for (int i = 0; i < 7; i++) + for (final plan + in state.getPlannedOfDay(db_weekday(i))) KitchenOwlFractionallySizedBox( widthFactor: (1 / DynamicStyling.itemCrossAxisCount( @@ -188,12 +204,14 @@ class _PlannerPageState extends State { crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - if (plan == state.getPlannedOfDay(day)[0]) + if (plan == + state.getPlannedOfDay( + db_weekday(i))[0]) Padding( padding: const EdgeInsets.only(top: 5), child: Text( - '${DateFormat.E().dateSymbols.STANDALONEWEEKDAYS[weekdayMapping[day]! % 7]}:', + '${formatDateAsWeekday(DateTime.now().add(Duration(days: i)), context, default_format: 'E')}', style: Theme.of(context) .textTheme .bodyLarge, @@ -211,7 +229,7 @@ class _PlannerPageState extends State { onPressed: () { cubit.remove( plan.recipe, - day, + db_weekday(i), ); }, onLongPressed: () => _openRecipePage( @@ -394,28 +412,17 @@ class _PlannerPageState extends State { PlannerCubit cubit, Recipe recipe, ) async { - final weekdayMapping = { - 0: DateTime.monday, - 1: DateTime.tuesday, - 2: DateTime.wednesday, - 3: DateTime.thursday, - 4: DateTime.friday, - 5: DateTime.saturday, - 6: DateTime.sunday, - }; int? day = await showDialog( context: context, builder: (context) => SelectDialog( title: AppLocalizations.of(context)!.addRecipeToPlannerShort, cancelText: AppLocalizations.of(context)!.cancel, - options: weekdayMapping.entries - .map( - (e) => SelectDialogOption( - e.key, - DateFormat.E().dateSymbols.STANDALONEWEEKDAYS[e.value % 7], - ), - ) - .toList(), + options: List.generate(7, (index) { + return SelectDialogOption( + db_weekday(index), + formatDateAsWeekday( + DateTime.now().add(Duration(days: index)), context)); + }), ), ); if (day != null) { diff --git a/kitchenowl/lib/pages/recipe_page.dart b/kitchenowl/lib/pages/recipe_page.dart index f7a9dfcb..a5b7408d 100644 --- a/kitchenowl/lib/pages/recipe_page.dart +++ b/kitchenowl/lib/pages/recipe_page.dart @@ -19,6 +19,31 @@ import 'package:responsive_builder/responsive_builder.dart'; import 'package:sliver_tools/sliver_tools.dart'; import 'package:tuple/tuple.dart'; +int db_weekday(int shift) { + // subtract 1 because DateTime.weekday goes from 1 to 7. Kitchenowl-db from 0 to 6 + return DateTime.now().add(Duration(days: shift)).weekday - 1; +} + +String formatDateAsWeekday(DateTime date, BuildContext context, + {String default_format = 'EEEE'}) { + DateTime today = DateTime.now(); + DateTime tomorrow = today.add(Duration(days: 1)); + + // Check if the date is today or tomorrow + if (date.year == today.year && + date.month == today.month && + date.day == today.day) { + return AppLocalizations.of(context)!.today; + } else if (date.year == tomorrow.year && + date.month == tomorrow.month && + date.day == tomorrow.day) { + return AppLocalizations.of(context)!.tomorrow; + } else { + // Return the weekday name + return DateFormat(default_format).format(date); + } +} + class RecipePage extends StatefulWidget { final Household? household; final Recipe recipe; @@ -339,15 +364,6 @@ class _RecipePageState extends State { LoadingElevatedButton( child: const Icon(Icons.calendar_month_rounded), onPressed: () async { - final weekdayMapping = { - 0: DateTime.monday, - 1: DateTime.tuesday, - 2: DateTime.wednesday, - 3: DateTime.thursday, - 4: DateTime.friday, - 5: DateTime.saturday, - 6: DateTime.sunday, - }; int? day = await showDialog( context: context, builder: (context) => SelectDialog( @@ -355,17 +371,14 @@ class _RecipePageState extends State { .addRecipeToPlannerShort, cancelText: AppLocalizations.of(context)!.cancel, - options: weekdayMapping.entries - .map( - (e) => SelectDialogOption( - e.key, - DateFormat.E() - .dateSymbols - .STANDALONEWEEKDAYS[ - e.value % 7], - ), - ) - .toList(), + options: List.generate(7, (index) { + return SelectDialogOption( + db_weekday(index), + formatDateAsWeekday( + DateTime.now() + .add(Duration(days: index)), + context)); + }), ), ); if (day != null) {