diff --git a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart index 979759046..c7cc0d20c 100644 --- a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart +++ b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart @@ -1,47 +1,80 @@ +import 'package:intl/intl.dart'; import 'package:uni/controller/networking/network_router.dart'; import 'package:uni/controller/parsers/parser_restaurants.dart'; +import 'package:uni/model/entities/meal.dart'; import 'package:uni/model/entities/restaurant.dart'; +import 'package:uni/model/utils/day_of_week.dart'; import 'package:uni/session/flows/base/session.dart'; +import 'package:up_menus/up_menus.dart'; /// Class for fetching the menu class RestaurantFetcher { - final String spreadSheetUrl = 'https://docs.google.com/spreadsheets/d/' - '1TJauM0HwIf2RauQU2GmhdZZ1ZicFLMHuBkxWwVOw3Q4'; - final String jsonEndpoint = '/gviz/tq?tqx=out:json'; - - // Format: Date(dd/mm/yyyy), Meal("Almoço", "Jantar), Dish("Sopa", "Carne", - // "Peixe", "Dieta", "Vegetariano", "Salada"), Description(String) - final String sheetsColumnRange = 'A:D'; - - // List the Restaurant sheet names in the Google Sheets Document - final List restaurantSheets = ['Cantina']; - - // Generate the Gsheets endpoints list based on a list of sheets - String buildGSheetsEndpoint(String sheet) { - return Uri.encodeFull( - '$spreadSheetUrl$jsonEndpoint&sheet=$sheet&range=$sheetsColumnRange', + Restaurant convertToRestaurant( + Establishment establishment, + Iterable dayMenus, + String period, + ) { + final currentLocale = Intl.getCurrentLocale(); + + final meals = []; + for (final dayMenu in dayMenus) { + for (final dish in dayMenu.dishes) { + // Extract the information about the meal. + meals.add( + Meal( + dish.dishType.namePt, + currentLocale.startsWith('pt') + ? dish.dish.namePt + : dish.dish.nameEn ?? + dish.dish + .namePt, // if there isn't an english name, use the portuguese one. + parseDateTime(dayMenu.day), + dayMenu.day, + ), + ); + } + } + return Restaurant( + establishment.id, + currentLocale.startsWith('pt') + ? establishment.namePt + : establishment.nameEn, + period, + '', + meals: meals, ); } - String getRestaurantGSheetName(Restaurant restaurant) { - return restaurantSheets.firstWhere( - (sheetName) => - restaurant.name.toLowerCase().contains(sheetName.toLowerCase()), - orElse: () => '', - ); - } + Future> fetchSASUPRestaurants() async { + // TODO: change the implementation to accomodate changes for the new UI. + final upMenus = UPMenusApi(); + final establishments = await upMenus.establishments.list(); + final restaurants = []; - Future fetchGSheetsRestaurant( - String url, - String restaurantName, - Session session, { - bool isDinner = false, - }) async { - return getRestaurantFromGSheets( - await NetworkRouter.getWithCookies(url, {}, session), - restaurantName, - isDinner: isDinner, - ); + const periods = [ + {'period': Period.lunch, 'meal': 'lunch'}, + {'period': Period.dinner, 'meal': 'dinner'}, + {'period': Period.snackBar, 'meal': 'snackbar'}, + {'period': Period.breakfast, 'meal': 'breakfast'}, + ]; + + for (final establishment in establishments) { + if (establishment.dayMenu == false) { + continue; + } + + for (final period in periods) { + restaurants.add( + convertToRestaurant( + establishment, + await upMenus.dayMenus + .get(establishment.id, period['period']! as Period), + period['meal']! as String, + ), + ); + } + } + return restaurants; } final List sigarraMenuEndpoints = [ @@ -64,32 +97,8 @@ class RestaurantFetcher { } Future> getRestaurants(Session session) async { - final restaurants = await fetchSigarraRestaurants(session); - - // Check for restaurants without associated meals and attempt to parse them - // from GSheets - final restaurantsWithoutMeals = - restaurants.where((restaurant) => restaurant.meals.isEmpty).toList(); - - for (final restaurant in restaurantsWithoutMeals) { - final sheetName = getRestaurantGSheetName(restaurant); - if (sheetName.isEmpty) { - continue; - } - - final gSheetsRestaurant = await fetchGSheetsRestaurant( - buildGSheetsEndpoint(sheetName), - restaurant.name, - session, - isDinner: restaurant.name.toLowerCase().contains('jantar'), - ); - - restaurants - ..removeWhere( - (restaurant) => restaurant.name == gSheetsRestaurant.name, - ) - ..insert(0, gSheetsRestaurant); - } + final restaurants = + await fetchSASUPRestaurants() + await fetchSigarraRestaurants(session); return restaurants; } diff --git a/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart b/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart index 70c15204f..e7188c932 100644 --- a/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart +++ b/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart @@ -46,6 +46,7 @@ class RestaurantDatabase extends AppDatabase> { return Restaurant( restaurantId, map['name'] as String, + map['period'] as String, map['ref'] as String, meals: meals, ); @@ -70,7 +71,7 @@ class RestaurantDatabase extends AppDatabase> { } }); - return filterPastMeals(restaurants); + return restaurants; } Future> getRestaurantMeals( @@ -129,22 +130,3 @@ class RestaurantDatabase extends AppDatabase> { }); } } - -List filterPastMeals(List restaurants) { - final restaurantsCopy = List.from(restaurants); - // Hide past and next weeks' meals - // (To replicate sigarra's behaviour for the GSheets meals) - final now = DateTime.now().toUtc(); - final today = DateTime.utc(now.year, now.month, now.day); - final nextSunday = today.add(Duration(days: DateTime.sunday - now.weekday)); - - for (final restaurant in restaurantsCopy) { - for (final meals in restaurant.meals.values) { - meals.removeWhere( - (meal) => meal.date.isBefore(today) || meal.date.isAfter(nextSunday), - ); - } - } - - return restaurantsCopy; -} diff --git a/packages/uni_app/lib/controller/parsers/parser_restaurants.dart b/packages/uni_app/lib/controller/parsers/parser_restaurants.dart index a4c543f70..bbe94e3df 100644 --- a/packages/uni_app/lib/controller/parsers/parser_restaurants.dart +++ b/packages/uni_app/lib/controller/parsers/parser_restaurants.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:html/parser.dart'; import 'package:http/http.dart'; import 'package:intl/intl.dart'; @@ -72,52 +70,9 @@ List getRestaurantsFromHtml(Response response) { null, restaurantTuple.item2, restaurantTuple.item1, + '', meals: meals, ); }).toList(); return restaurants; } - -Restaurant getRestaurantFromGSheets( - Response response, - String restaurantName, { - bool isDinner = false, -}) { - // Ignore beginning of response: "/*O_o*/\ngoogle.visualization.Query.setResponse(" - // Ignore the end of the response: ");" - // Check the structure by accessing the link: - // https://docs.google.com/spreadsheets/d/1TJauM0HwIf2RauQU2GmhdZZ1ZicFLMHuBkxWwVOw3Q4/gviz/tq?tqx=out:json&sheet=Cantina%20de%20Engenharia&range=A:D - final jsonString = response.body.substring( - response.body.indexOf('(') + 1, - response.body.lastIndexOf(')'), - ); - final parsedJson = jsonDecode(jsonString) as Map; - - final mealsList = []; - - final format = DateFormat('d/M/y'); - - final table = parsedJson['table'] as Map; - final rows = table['rows'] as List; - - for (final row in rows) { - final cellList = (row as Map)['c'] as List; - if (((cellList[1] as Map)['v'] == 'Almoço' && isDinner) || - ((cellList[1] as Map)['v'] != 'Almoço' && !isDinner)) { - continue; - } - - final meal = Meal( - (cellList[2] as Map)['v'] as String, - (cellList[3] as Map)['v'] as String, - DayOfWeek.values[format - .parseUtc((cellList[0] as Map)['f'] as String) - .weekday - - 1], - format.parseUtc((cellList[0] as Map)['f'] as String), - ); - mealsList.add(meal); - } - - return Restaurant(null, restaurantName, '', meals: mealsList); -} diff --git a/packages/uni_app/lib/generated/intl/messages_en.dart b/packages/uni_app/lib/generated/intl/messages_en.dart index 24826a3e3..29743e6aa 100644 --- a/packages/uni_app/lib/generated/intl/messages_en.dart +++ b/packages/uni_app/lib/generated/intl/messages_en.dart @@ -63,6 +63,7 @@ class MessageLookup extends MessageLookupByLibrary { "banner_info": MessageLookupByLibrary.simpleMessage( "We do now collect anonymous usage statistics in order to improve your experience. You can change it in settings."), "bibliography": MessageLookupByLibrary.simpleMessage("Bibliography"), + "breakfast": MessageLookupByLibrary.simpleMessage("Breakfast"), "bs_description": MessageLookupByLibrary.simpleMessage( "Did you find any bugs in the application?\nDo you have any suggestions for the app?\nTell us so we can improve!"), "bug_description": MessageLookupByLibrary.simpleMessage( @@ -110,6 +111,7 @@ class MessageLookup extends MessageLookupByLibrary { "description": MessageLookupByLibrary.simpleMessage("Description"), "desired_email": MessageLookupByLibrary.simpleMessage( "Email where you want to be contacted"), + "dinner": MessageLookupByLibrary.simpleMessage("Dinner"), "dona_bia": MessageLookupByLibrary.simpleMessage( "D. Beatriz\'s stationery store"), "dona_bia_building": MessageLookupByLibrary.simpleMessage( @@ -167,6 +169,7 @@ class MessageLookup extends MessageLookupByLibrary { "login_with_credentials": MessageLookupByLibrary.simpleMessage("Login with credentials"), "logout": MessageLookupByLibrary.simpleMessage("Log out"), + "lunch": MessageLookupByLibrary.simpleMessage("Lunch"), "menus": MessageLookupByLibrary.simpleMessage("Menus"), "min_value_reference": MessageLookupByLibrary.simpleMessage("Minimum value: 1,00 €"), @@ -272,6 +275,7 @@ class MessageLookup extends MessageLookupByLibrary { "sent_error": MessageLookupByLibrary.simpleMessage( "An error occurred in sending"), "settings": MessageLookupByLibrary.simpleMessage("Settings"), + "snackbar": MessageLookupByLibrary.simpleMessage("Snackbar"), "some_error": MessageLookupByLibrary.simpleMessage("Some error!"), "stcp_stops": MessageLookupByLibrary.simpleMessage("STCP - Upcoming Trips"), diff --git a/packages/uni_app/lib/generated/intl/messages_pt_PT.dart b/packages/uni_app/lib/generated/intl/messages_pt_PT.dart index 502e9f9ec..1aca84f19 100644 --- a/packages/uni_app/lib/generated/intl/messages_pt_PT.dart +++ b/packages/uni_app/lib/generated/intl/messages_pt_PT.dart @@ -63,6 +63,7 @@ class MessageLookup extends MessageLookupByLibrary { "banner_info": MessageLookupByLibrary.simpleMessage( "Agora recolhemos estatísticas de uso anónimas para melhorar a tua experiência. Podes alterá-lo nas definições."), "bibliography": MessageLookupByLibrary.simpleMessage("Bibliografia"), + "breakfast": MessageLookupByLibrary.simpleMessage("Pequeno Almoço"), "bs_description": MessageLookupByLibrary.simpleMessage( "Encontraste algum bug na aplicação?\nTens alguma sugestão para a app?\nConta-nos para que possamos melhorar!"), "bug_description": MessageLookupByLibrary.simpleMessage( @@ -109,6 +110,7 @@ class MessageLookup extends MessageLookupByLibrary { "description": MessageLookupByLibrary.simpleMessage("Descrição"), "desired_email": MessageLookupByLibrary.simpleMessage( "Email em que desejas ser contactado"), + "dinner": MessageLookupByLibrary.simpleMessage("Jantar"), "dona_bia": MessageLookupByLibrary.simpleMessage("Papelaria D. Beatriz"), "dona_bia_building": MessageLookupByLibrary.simpleMessage( @@ -166,6 +168,7 @@ class MessageLookup extends MessageLookupByLibrary { "login_with_credentials": MessageLookupByLibrary.simpleMessage( "Iniciar sessão com credenciais"), "logout": MessageLookupByLibrary.simpleMessage("Terminar sessão"), + "lunch": MessageLookupByLibrary.simpleMessage("Almoço"), "menus": MessageLookupByLibrary.simpleMessage("Ementas"), "min_value_reference": MessageLookupByLibrary.simpleMessage("Valor mínimo: 1,00 €"), @@ -273,6 +276,7 @@ class MessageLookup extends MessageLookupByLibrary { "sent_error": MessageLookupByLibrary.simpleMessage("Ocorreu um erro no envio"), "settings": MessageLookupByLibrary.simpleMessage("Definições"), + "snackbar": MessageLookupByLibrary.simpleMessage("Snackbar"), "some_error": MessageLookupByLibrary.simpleMessage("Algum erro!"), "stcp_stops": MessageLookupByLibrary.simpleMessage("STCP - Próximas Viagens"), diff --git a/packages/uni_app/lib/generated/l10n.dart b/packages/uni_app/lib/generated/l10n.dart index 4201d66c1..ee888da7f 100644 --- a/packages/uni_app/lib/generated/l10n.dart +++ b/packages/uni_app/lib/generated/l10n.dart @@ -260,6 +260,16 @@ class S { ); } + /// `Breakfast` + String get breakfast { + return Intl.message( + 'Breakfast', + name: 'breakfast', + desc: '', + args: [], + ); + } + /// `Did you find any bugs in the application?\nDo you have any suggestions for the app?\nTell us so we can improve!` String get bs_description { return Intl.message( @@ -530,6 +540,16 @@ class S { ); } + /// `Dinner` + String get dinner { + return Intl.message( + 'Dinner', + name: 'dinner', + desc: '', + args: [], + ); + } + /// `D. Beatriz's stationery store` String get dona_bia { return Intl.message( @@ -783,6 +803,16 @@ class S { ); } + /// `Lunch` + String get lunch { + return Intl.message( + 'Lunch', + name: 'lunch', + desc: '', + args: [], + ); + } + /// `Error downloading the file` String get download_error { return Intl.message( @@ -823,6 +853,16 @@ class S { ); } + /// `Snackbar` + String get snackbar { + return Intl.message( + 'Snackbar', + name: 'snackbar', + desc: '', + args: [], + ); + } + /// `Log out` String get logout { return Intl.message( diff --git a/packages/uni_app/lib/generated/model/entities/restaurant.g.dart b/packages/uni_app/lib/generated/model/entities/restaurant.g.dart index 5471eb4f0..11cc0e78c 100644 --- a/packages/uni_app/lib/generated/model/entities/restaurant.g.dart +++ b/packages/uni_app/lib/generated/model/entities/restaurant.g.dart @@ -7,8 +7,9 @@ part of '../../../model/entities/restaurant.dart'; // ************************************************************************** Restaurant _$RestaurantFromJson(Map json) => Restaurant( - json['id'] as int?, + (json['id'] as num?)?.toInt(), json['name'] as String, + json['period'] as String, json['ref'] as String, meals: (json['meals'] as List) .map((e) => Meal.fromJson(e as Map)) @@ -19,6 +20,7 @@ Map _$RestaurantToJson(Restaurant instance) => { 'id': instance.id, 'name': instance.name, + 'period': instance.period, 'ref': instance.reference, 'meals': instance.meals.map((k, e) => MapEntry(_$DayOfWeekEnumMap[k]!, e)), diff --git a/packages/uni_app/lib/l10n/intl_en.arb b/packages/uni_app/lib/l10n/intl_en.arb index 5e3eb22a6..c0cb3ad19 100644 --- a/packages/uni_app/lib/l10n/intl_en.arb +++ b/packages/uni_app/lib/l10n/intl_en.arb @@ -42,6 +42,8 @@ "@balance": {}, "bibliography": "Bibliography", "@bibliography": {}, + "breakfast": "Breakfast", + "@breakfast": {}, "bs_description": "Did you find any bugs in the application?\nDo you have any suggestions for the app?\nTell us so we can improve!", "@bs_description": {}, "bug_description": "Bug found, how to reproduce it, etc.", @@ -96,6 +98,8 @@ "@description": {}, "desired_email": "Email where you want to be contacted", "@desired_email": {}, + "dinner": "Dinner", + "@dinner": {}, "dona_bia": "D. Beatriz's stationery store", "@dona_bia": {}, "dona_bia_building": "Floor -1 of building B (B-142)", @@ -154,6 +158,8 @@ }, "library_occupation": "Library Occupation", "@library_occupation": {}, + "lunch": "Lunch", + "@lunch": {}, "download_error": "Error downloading the file", "@download_error": {}, "loading_terms": "Loading Terms and Conditions...", @@ -162,6 +168,8 @@ "@login": {}, "settings": "Settings", "@settings": {}, + "snackbar": "Snackbar", + "@snackbar": {}, "logout": "Log out", "@logout": {}, "menus": "Menus", @@ -334,4 +342,4 @@ "@wrong_credentials_exception": {}, "internet_status_exception": "Check your internet connection", "@internet_status_exception": {} -} \ No newline at end of file +} diff --git a/packages/uni_app/lib/l10n/intl_pt_PT.arb b/packages/uni_app/lib/l10n/intl_pt_PT.arb index 4212fe69c..50eb23e8b 100644 --- a/packages/uni_app/lib/l10n/intl_pt_PT.arb +++ b/packages/uni_app/lib/l10n/intl_pt_PT.arb @@ -56,6 +56,8 @@ "@buses_text": {}, "bus_information": "Seleciona os autocarros dos quais queres informação:", "@bus_information": {}, + "breakfast": "Pequeno Almoço", + "@breakfast": {}, "cancel": "Cancelar", "@cancel": {}, "change": "Alterar", @@ -98,6 +100,8 @@ "@description": {}, "desired_email": "Email em que desejas ser contactado", "@desired_email": {}, + "dinner": "Jantar", + "@dinner": {}, "dona_bia": "Papelaria D. Beatriz", "@dona_bia": {}, "dona_bia_building": "Piso -1 do edifício B (B-142)", @@ -158,6 +162,8 @@ "@load_error": {}, "library_occupation": "Ocupação da Biblioteca", "@library_occupation": {}, + "lunch": "Almoço", + "@lunch": {}, "download_error": "Erro ao descarregar o ficheiro", "@download_error": {}, "successful_open": "Ficheiro aberto com sucesso", @@ -294,6 +300,8 @@ "@stcp_stops": {}, "student_number": "número de estudante", "@student_number": {}, + "snackbar": "Snackbar", + "@snackbar": {}, "success": "Enviado com sucesso", "@success": {}, "tele_assistance": "Atendimento telefónico", @@ -334,4 +342,4 @@ "@wrong_credentials_exception": {}, "internet_status_exception": "Verifique sua conexão com a internet", "@internet_status_exception": {} -} \ No newline at end of file +} diff --git a/packages/uni_app/lib/model/entities/restaurant.dart b/packages/uni_app/lib/model/entities/restaurant.dart index 74ef474cc..190b6f565 100644 --- a/packages/uni_app/lib/model/entities/restaurant.dart +++ b/packages/uni_app/lib/model/entities/restaurant.dart @@ -7,8 +7,13 @@ part '../../generated/model/entities/restaurant.g.dart'; @JsonSerializable() class Restaurant { - Restaurant(this.id, this.name, this.reference, {required List meals}) - : meals = groupBy(meals, (meal) => meal.dayOfWeek); + Restaurant( + this.id, + this.name, + this.period, + this.reference, { + required List meals, + }) : meals = groupBy(meals, (meal) => meal.dayOfWeek); factory Restaurant.fromMap(Map map, List meals) { final object = Restaurant.fromJson(map); @@ -22,6 +27,8 @@ class Restaurant { final int? id; @JsonKey(name: 'name') final String name; + @JsonKey(name: 'period') + final String period; @JsonKey(name: 'ref') final String reference; // Used only in html parser @JsonKey(includeToJson: true) diff --git a/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart b/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart index f6f9599f7..a422bfba6 100644 --- a/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart +++ b/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart @@ -13,9 +13,11 @@ class RestaurantProvider extends StateProviderNotifier> { Future> loadFromStorage( StateProviders stateProviders, ) async { - final restaurantDb = RestaurantDatabase(); - final restaurants = await restaurantDb.getRestaurants(); - return restaurants; + // TODO: remove this line after PR #1380 (fix: Added meals column to the RESTAURANTS table) is merged + return loadFromRemote(stateProviders); + // final restaurantDb = RestaurantDatabase(); + // final restaurants = await restaurantDb.getRestaurants(); + // return restaurants; } @override @@ -26,6 +28,6 @@ class RestaurantProvider extends StateProviderNotifier> { final db = RestaurantDatabase(); unawaited(db.saveIfPersistentSession(restaurants)); - return filterPastMeals(restaurants); + return restaurants; } } diff --git a/packages/uni_app/lib/model/utils/day_of_week.dart b/packages/uni_app/lib/model/utils/day_of_week.dart index 77f78d9d3..579c4e991 100644 --- a/packages/uni_app/lib/model/utils/day_of_week.dart +++ b/packages/uni_app/lib/model/utils/day_of_week.dart @@ -8,6 +8,28 @@ enum DayOfWeek { sunday } +DayOfWeek parseDateTime(DateTime dateTime) { + final weekDay = dateTime.weekday; + switch (weekDay) { + case DateTime.monday: + return DayOfWeek.monday; + case DateTime.tuesday: + return DayOfWeek.tuesday; + case DateTime.wednesday: + return DayOfWeek.wednesday; + case DateTime.thursday: + return DayOfWeek.thursday; + case DateTime.friday: + return DayOfWeek.friday; + case DateTime.saturday: + return DayOfWeek.saturday; + case DateTime.sunday: + return DayOfWeek.sunday; + default: + throw Exception('Invalid day of week'); + } +} + DayOfWeek? parseDayOfWeek(String str) { final weekDay = str.replaceAll(' ', '').toLowerCase(); if (weekDay == 'segunda-feira') { diff --git a/packages/uni_app/lib/view/home/widgets/restaurant_card.dart b/packages/uni_app/lib/view/home/widgets/restaurant_card.dart index 65007f82d..550ca2f42 100644 --- a/packages/uni_app/lib/view/home/widgets/restaurant_card.dart +++ b/packages/uni_app/lib/view/home/widgets/restaurant_card.dart @@ -41,7 +41,7 @@ class RestaurantCard extends GenericCard { final favoriteRestaurants = restaurants .where( (restaurant) => PreferencesController.getFavoriteRestaurants() - .contains(restaurant.name), + .contains(restaurant.name + restaurant.period), ) .toList(); return generateRestaurants(favoriteRestaurants, context); @@ -117,6 +117,19 @@ class RestaurantCard extends GenericCard { DayOfWeek day, ) { final meals = restaurant.getMealsOfDay(day); + var period = ''; + switch (restaurant.period) { + case 'lunch': + period = S.of(context).lunch; + case 'dinner': + period = S.of(context).dinner; + case 'breakfast': + period = S.of(context).breakfast; + case 'snackbar': + period = S.of(context).snackbar; + default: + period = ''; + } return Column( children: [ Center( @@ -124,7 +137,7 @@ class RestaurantCard extends GenericCard { alignment: Alignment.centerLeft, padding: const EdgeInsets.fromLTRB(10, 15, 5, 10), child: Text( - restaurant.name, + '${restaurant.name} - $period', style: TextStyle( fontSize: 16, color: Theme.of(context).primaryColor, diff --git a/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart b/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart index cd6e7852a..7df81063b 100644 --- a/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart +++ b/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart @@ -24,7 +24,18 @@ class RestaurantPageCard extends GenericCard { @override String getTitle(BuildContext context) { - return restaurant.name; + switch (restaurant.period) { + case 'lunch': + return '${restaurant.name} - ${S.of(context).lunch}'; + case 'dinner': + return '${restaurant.name} - ${S.of(context).dinner}'; + case 'breakfast': + return '${restaurant.name} - ${S.of(context).breakfast}'; + case 'snackbar': + return '${restaurant.name} - ${S.of(context).snackbar}'; + default: + return restaurant.name; + } } @override @@ -52,7 +63,7 @@ class CardFavoriteButtonState extends State { void initState() { super.initState(); isFavorite = PreferencesController.getFavoriteRestaurants() - .contains(widget.restaurant.name); + .contains(widget.restaurant.name + widget.restaurant.period); } @override @@ -62,10 +73,13 @@ class CardFavoriteButtonState extends State { onPressed: () async { final favoriteRestaurants = PreferencesController.getFavoriteRestaurants(); - if (favoriteRestaurants.contains(widget.restaurant.name)) { - favoriteRestaurants.remove(widget.restaurant.name); + if (favoriteRestaurants + .contains(widget.restaurant.name + widget.restaurant.period)) { + favoriteRestaurants + .remove(widget.restaurant.name + widget.restaurant.period); } else { - favoriteRestaurants.add(widget.restaurant.name); + favoriteRestaurants + .add(widget.restaurant.name + widget.restaurant.period); } setState(() { diff --git a/packages/uni_app/lib/view/restaurant/widgets/restaurant_slot.dart b/packages/uni_app/lib/view/restaurant/widgets/restaurant_slot.dart index f819ac36b..a4eee00ce 100644 --- a/packages/uni_app/lib/view/restaurant/widgets/restaurant_slot.dart +++ b/packages/uni_app/lib/view/restaurant/widgets/restaurant_slot.dart @@ -47,9 +47,11 @@ class RestaurantSlotType extends StatelessWidget { 'sopa': 'assets/meal-icons/soup.svg', 'carne': 'assets/meal-icons/chicken.svg', 'peixe': 'assets/meal-icons/fish.svg', + 'pescado': 'assets/meal-icons/fish.svg', 'dieta': 'assets/meal-icons/diet.svg', 'vegetariano': 'assets/meal-icons/vegetarian.svg', 'salada': 'assets/meal-icons/salad.svg', + 'hortícola': 'assets/meal-icons/salad.svg', }; @override diff --git a/packages/uni_app/pubspec.lock b/packages/uni_app/pubspec.lock index e9483f5c4..1f8db98e1 100644 --- a/packages/uni_app/pubspec.lock +++ b/packages/uni_app/pubspec.lock @@ -1519,6 +1519,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.2" + up_menus: + dependency: "direct main" + description: + name: up_menus + sha256: b973555072c6056b757f2740cf7c10fc190ff7f7cd3df3f26c303faf261ce112 + url: "https://pub.dev" + source: hosted + version: "1.0.1" upgrader: dependency: "direct main" description: diff --git a/packages/uni_app/pubspec.yaml b/packages/uni_app/pubspec.yaml index 5e84a6d8b..74ef5cbbd 100644 --- a/packages/uni_app/pubspec.yaml +++ b/packages/uni_app/pubspec.yaml @@ -69,6 +69,7 @@ dependencies: ua_client_hints: ^1.3.1 uni_ui: path: ../uni_ui + up_menus: ^1.0.1 upgrader: ^10.3.0 url_launcher: ^6.2.2 workmanager: ^0.5.2