Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/uni_app/lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ class MessageLookup extends MessageLookupByLibrary {
),
"restaurant_period": m4,
"restaurants": MessageLookupByLibrary.simpleMessage("Restaurants"),
"tomorrows_meals": MessageLookupByLibrary.simpleMessage("Tomorrow's Menu"),
"no_menu_tomorrow": MessageLookupByLibrary.simpleMessage(
"Tomorrow's Menu Unavailable",
),
"room": MessageLookupByLibrary.simpleMessage("Room"),
"save": MessageLookupByLibrary.simpleMessage("Save"),
"schedule": MessageLookupByLibrary.simpleMessage("Schedule"),
Expand Down
4 changes: 4 additions & 0 deletions packages/uni_app/lib/generated/intl/messages_pt_PT.dart
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ class MessageLookup extends MessageLookupByLibrary {
),
"restaurant_period": m4,
"restaurants": MessageLookupByLibrary.simpleMessage("Restaurantes"),
"tomorrows_meals": MessageLookupByLibrary.simpleMessage("Menu de Amanhã"),
"no_menu_tomorrow": MessageLookupByLibrary.simpleMessage(
"Menu de Amanhã Indisponível",
),
"room": MessageLookupByLibrary.simpleMessage("Sala"),
"save": MessageLookupByLibrary.simpleMessage("Guardar"),
"schedule": MessageLookupByLibrary.simpleMessage("Aulas"),
Expand Down
20 changes: 20 additions & 0 deletions packages/uni_app/lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/uni_app/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@
"@library": {},
"restaurants": "Restaurants",
"@restaurants": {},
"tomorrows_meals": "Tomorrow's Menu",
"@tomorrows_meals": {},
"no_menu_tomorrow": "Tomorrow's Menu Unavailable",
"@no_menu_tomorrow": {},
"calendar": "Calendar",
"@calendar": {},
"ucs": "UCS",
Expand Down
4 changes: 4 additions & 0 deletions packages/uni_app/lib/l10n/intl_pt_PT.arb
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@
"@library": {},
"restaurants": "Restaurantes",
"@restaurants": {},
"tomorrows_meals": "Menu de Amanhã",
"@tomorrows_meals": {},
"no_menu_tomorrow": "Menu de Amanhã Indisponível",
"@no_menu_tomorrow": {},
"calendar": "Calendário",
"@calendar": {},
"ucs": "UCS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,30 @@ List<RestaurantCard> getRestaurantInformation(
) {
final locale = ref.watch(localeProvider);

final today = parseDateTime(DateTime.now());
final now = DateTime.now();
var today = parseDateTime(now);

final showTomorrow = RestaurantUtils.shouldShowTomorrowMenu(now);
final isSundayNight = RestaurantUtils.isSundayNight(now);

if (showTomorrow) {
final tomorrowIndex = (today.index + 1) % DayOfWeek.values.length;
today = DayOfWeek.values[tomorrowIndex];
}

final restaurantsWidgets =
favoriteRestaurants
.where((element) => element.getMealsOfDay(today).isNotEmpty)
.map((restaurant) {
final menuItems = getMainMenus(today, restaurant, locale);

String? subtitle;
if (showTomorrow) {
subtitle = S.of(context).tomorrows_meals;
} else if (isSundayNight) {
subtitle = S.of(context).no_menu_tomorrow;
}

return RestaurantCard(
name: RestaurantUtils.getRestaurantName(
context,
Expand All @@ -145,6 +162,7 @@ List<RestaurantCard> getRestaurantInformation(
onFavoriteToggle: () => {},
menuItems: menuItems,
showFavoriteButton: false,
subtitle: subtitle,
);
})
.toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import 'package:flutter_riverpod/legacy.dart';
import 'package:uni/model/utils/day_of_week.dart';
import 'package:uni/view/restaurant/widgets/restaurant_utils.dart';

final tabControllerProvider = StateNotifierProvider<TabControllerProvider, int>(
(ref) => TabControllerProvider(),
);

class TabControllerProvider extends StateNotifier<int> {
TabControllerProvider() : super(DateTime.now().weekday - 1);
TabControllerProvider() : super(_getInitialIndex());

static int _getInitialIndex() {
final now = DateTime.now();

int index = now.weekday - 1;

if (RestaurantUtils.shouldShowTomorrowMenu(now)) {
index++;
}

if (index >= DayOfWeek.values.length) {
index = 0;
}

return index;
}

void setTabIndex(int index) {
if (index >= 0 && index < DayOfWeek.values.length) {
Expand Down
15 changes: 15 additions & 0 deletions packages/uni_app/lib/view/restaurant/widgets/restaurant_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ import 'package:uni/model/entities/app_locale.dart';
import 'package:uni_ui/icons.dart';

class RestaurantUtils {
// Hour after which to show tomorrow's menu (except on Sunday)
static const int menuSwitchHour = 21;

/// Determines if tomorrow's menu should be shown based on current time
/// Returns true if it's after menuSwitchHour and not Sunday
static bool shouldShowTomorrowMenu(DateTime now) {
return now.hour >= menuSwitchHour && now.weekday != DateTime.sunday;
}

/// Determines if it's Sunday night after menuSwitchHour
/// (when tomorrow's menu is not available)
static bool isSundayNight(DateTime now) {
return now.hour >= menuSwitchHour && now.weekday == DateTime.sunday;
}

// Method to get a restaurant related UniIcon based on a specific type
static UniIcon getIcon(String? type, {double size = 24, Color? color}) {
switch (type) {
Expand Down
39 changes: 35 additions & 4 deletions packages/uni_ui/lib/cards/restaurant_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RestaurantCard extends StatelessWidget {
required this.onFavoriteToggle,
this.showFavoriteButton = true,
this.onClick,
this.subtitle,
});

final String name;
Expand All @@ -22,6 +23,7 @@ class RestaurantCard extends StatelessWidget {
final VoidCallback onFavoriteToggle;
final bool showFavoriteButton;
final Function()? onClick;
final String? subtitle;

@override
Widget build(BuildContext context) {
Expand All @@ -40,6 +42,7 @@ class RestaurantCard extends StatelessWidget {
isFavorite: isFavorite,
onFavoriteToggle: onFavoriteToggle,
showFavoriteButton: showFavoriteButton,
subtitle: subtitle,
),
Column(children: menuItems),
],
Expand All @@ -57,13 +60,15 @@ class RestaurantCardHeader extends StatelessWidget {
required this.isFavorite,
required this.onFavoriteToggle,
this.showFavoriteButton = true,
this.subtitle,
});

final String name;
final Icon icon;
final bool isFavorite;
final VoidCallback onFavoriteToggle;
final bool showFavoriteButton;
final String? subtitle;

@override
Widget build(BuildContext context) {
Expand All @@ -80,10 +85,36 @@ class RestaurantCardHeader extends StatelessWidget {
flex: 4,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text(
name,
style: Theme.of(context).textTheme.headlineSmall,
overflow: TextOverflow.clip,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
name,
style: Theme.of(context).textTheme.headlineSmall,
overflow: TextOverflow.clip,
),
if (subtitle != null)
Container(
margin: const EdgeInsets.only(top: 4),
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 2,
),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(4),
),
child: Text(
subtitle!,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontWeight: FontWeight.w600,
color:
Theme.of(context).colorScheme.onPrimaryContainer,
),
),
),
],
),
),
),
Expand Down