Skip to content

Commit

Permalink
Show Opening Hours for Cafeterias (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkoerber authored Oct 13, 2023
1 parent e4482b0 commit 39857ff
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 42 deletions.
18 changes: 18 additions & 0 deletions lib/base/helpers/info_row.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:flutter/material.dart';

class InfoRow extends StatelessWidget {
const InfoRow({super.key, required this.title, required this.info});

final String title;
final String info;

@override
Widget build(BuildContext context) {
return Row(children: [
Expanded(
child:
Text(title, style: const TextStyle(fontWeight: FontWeight.w500))),
Expanded(child: Text(info))
]);
}
}
45 changes: 33 additions & 12 deletions lib/base/localization/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"contactSupport":"Support kontaktieren",
"cafeteria":"Mensa",
"cafeterias":"Mensen",
"noMealPlanFound":"Kein Speiseplan gefunden",
"latestNews":"Neueste Nachrichten",
"scheduledLectureDates":"Termine",
"@scheduledLectureDates":{
Expand Down Expand Up @@ -189,7 +188,6 @@
"rooms":"Räume",
"roomDetails":"Raumdetails",
"building":"Gebäude",
"departures":"Abfahrten",
"nfreeRooms":"{count, plural, =0{Keine freien Räume} =1{1 freier Raum} other{{count} freie Räume}}",
"@nfreeRooms":{
"description":"How many free rooms there are",
Expand All @@ -203,15 +201,15 @@
"noRoomsFound":"Keine Räume gefunden",
"noMealPlanFound":"Kein Essensplan gefunden",
"noEntriesFoundSearch":"Keine {searchCategory} gefunden",
"@noEntriesFoundSearch":{
"description":"Title of Search Category",
"placeholders":{
"searchCategory":{
"type":"String",
"example":"Grades"
}
}
},
"@noEntriesFoundSearch":{
"description":"Title of Search Category",
"placeholders":{
"searchCategory":{
"type":"String",
"example":"Grades"
}
}
},
"enterQueryStart":"Stelle eine Suchanfrage",
"personalLectures":"Persönliche Vorlesungen",
"persons":"Personen",
Expand All @@ -228,5 +226,28 @@
"requestCancelled":"Anfrage abgebrochen",
"pleaseReport":"Bitte melden Sie dies als Fehler \nper E-Mail oder auf GitHub",
"connectionTimeout":"Zeitüberschreitung",
"unknownError":"Unbekannter Fehler"
"unknownError":"Unbekannter Fehler",
"monday":"Montag",
"tuesday":"Dienstag",
"wednesday":"Mittwoch",
"thursday":"Donnerstag",
"friday":"Freitag",
"weekend":"Wochenende",
"openingHours":"Öffnungszeiten",
"openToday":"Heute offen von {start} - {end}",
"@openToday":{
"description":"Opening Times",
"placeholders":{
"start":{
"type":"String",
"example":"11:00"
},
"end":{
"type":"String",
"example":"14:00"
}
}
},
"closed":"Geschlossen",
"closedToday":"Heute geschlossen"
}
45 changes: 33 additions & 12 deletions lib/base/localization/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"contactSupport":"Contact Support",
"cafeteria":"Cafeteria",
"cafeterias":"Cafeterias",
"noMealPlanFound":"no meal plan found",
"latestNews":"Latest News",
"scheduledLectureDates":"Dates",
"@scheduledLectureDates":{
Expand Down Expand Up @@ -189,7 +188,6 @@
"rooms":"Rooms",
"roomDetails":"Room Details",
"building":"Building",
"departures":"Departures",
"nfreeRooms":"{count, plural, =0{no free rooms} =1{1 free room} other{{count} free rooms}}",
"@nfreeRooms":{
"description":"How many free rooms there are",
Expand All @@ -203,15 +201,15 @@
"noRoomsFound":"No Rooms Found",
"noMealPlanFound":"No Meal Plan Found",
"noEntriesFoundSearch":"No {searchCategory} Found",
"@noEntriesFoundSearch":{
"description":"Title of Search Category",
"placeholders":{
"searchCategory":{
"type":"String",
"example":"Grades"
}
}
},
"@noEntriesFoundSearch":{
"description":"Title of Search Category",
"placeholders":{
"searchCategory":{
"type":"String",
"example":"Grades"
}
}
},
"enterQueryStart":"Enter a Query to Start",
"personalLectures":"Personal Lectures",
"persons":"Persons",
Expand All @@ -228,5 +226,28 @@
"requestCancelled":"Request Cancelled",
"pleaseReport":"Please report this is as a bug \nvia Email or on GitHub",
"connectionTimeout":"Connection Timeout",
"unknownError":"Unknown Error"
"unknownError":"Unknown Error",
"monday":"Monday",
"tuesday":"Tuesday",
"wednesday":"Wednesday",
"thursday":"Thursday",
"friday":"Friday",
"weekend":"Weekend",
"openingHours":"Opening Hours",
"openToday":"Open today from {start} - {end}",
"@openToday":{
"description":"Opening Times",
"placeholders":{
"start":{
"type":"String",
"example":"11:00"
},
"end":{
"type":"String",
"example":"14:00"
}
}
},
"closed":"Closed",
"closedToday":"Closed Today"
}
22 changes: 7 additions & 15 deletions lib/homeComponent/contactComponent/views/tuition_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:campus_flutter/base/helpers/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/helpers/icon_text.dart';
import 'package:campus_flutter/base/helpers/info_row.dart';
import 'package:campus_flutter/profileComponent/model/tuition.dart';
import 'package:campus_flutter/providers_get_it.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -43,13 +44,13 @@ class TuitionView extends ConsumerWidget {
?.copyWith(fontWeight: FontWeight.w500),
),
const Padding(padding: EdgeInsets.symmetric(vertical: 5.0)),
_infoRow(
context.localizations.tuitionDueDate,
DateFormat.yMd(context.localizations.localeName)
InfoRow(
title: context.localizations.tuitionDueDate,
info: DateFormat.yMd(context.localizations.localeName)
.format(snapshot.data!.deadline)),
_infoRow(
context.localizations.tuitionOpenAmount,
NumberFormat.currency(locale: "de_DE", symbol: '€')
InfoRow(
title: context.localizations.tuitionOpenAmount,
info: NumberFormat.currency(locale: "de_DE", symbol: '€')
.format(snapshot.data!.amount))
]),
actions: [
Expand Down Expand Up @@ -94,13 +95,4 @@ class TuitionView extends ConsumerWidget {
?.copyWith(color: Colors.red)));
}
}

Widget _infoRow(String title, String info) {
return Row(children: [
Expanded(
child:
Text(title, style: const TextStyle(fontWeight: FontWeight.w500))),
Expanded(child: Text(info))
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class TimeStrategy implements WidgetRecommenderStrategy {
}

// The menu is not interesting anymore after the cafeteria has closed.
if (14 <= currentDate.hour) {
/*if (14 <= currentDate.hour) {
priority = 0;
break;
}
}*/

// The menu might be interesting before the opening hours.
if (currentDate.hour < 14 && 6 < currentDate.hour) {
Expand Down
24 changes: 23 additions & 1 deletion lib/placesComponent/model/cafeterias/cafeteria.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:campus_flutter/placesComponent/model/cafeterias/opening_hours.dart';
import 'package:campus_flutter/searchComponent/model/comparison_token.dart';
import 'package:campus_flutter/searchComponent/protocols/searchable.dart';
import 'package:json_annotation/json_annotation.dart';
Expand Down Expand Up @@ -40,11 +41,31 @@ class Cafeteria extends Searchable {
@JsonKey(name: "queue_status")
final String? queueStatusApi;
Queue? queue;
@JsonKey(name: "open_hours")
final OpeningHours? openingHours;

String? get title {
return name;
}

(bool, OpeningHour?) get openingHoursToday {
final today = DateTime.now();
switch (today.weekday) {
case 1:
return (true, openingHours?.mon);
case 2:
return (true, openingHours?.tue);
case 3:
return (true, openingHours?.wed);
case 4:
return (true, openingHours?.thu);
case 5:
return (true, openingHours?.fri);
default:
return (false, null);
}
}

@override
@JsonKey(includeFromJson: false, includeToJson: false)
List<ComparisonToken> get comparisonTokens => [
Expand All @@ -61,7 +82,8 @@ class Cafeteria extends Searchable {
required this.name,
required this.id,
required this.queueStatusApi,
required this.queue});
required this.queue,
this.openingHours});

factory Cafeteria.fromJson(Map<String, dynamic> json) =>
_$CafeteriaFromJson(json);
Expand Down
4 changes: 4 additions & 0 deletions lib/placesComponent/model/cafeterias/cafeteria.g.dart

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

32 changes: 32 additions & 0 deletions lib/placesComponent/model/cafeterias/opening_hours.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:json_annotation/json_annotation.dart';

part 'opening_hours.g.dart';

@JsonSerializable()
class OpeningHours {
final OpeningHour? mon;
final OpeningHour? tue;
final OpeningHour? wed;
final OpeningHour? thu;
final OpeningHour? fri;

OpeningHours({this.mon, this.tue, this.wed, this.thu, this.fri});

factory OpeningHours.fromJson(Map<String, dynamic> json) =>
_$OpeningHoursFromJson(json);

Map<String, dynamic> toJson() => _$OpeningHoursToJson(this);
}

@JsonSerializable()
class OpeningHour {
final String start;
final String end;

OpeningHour({required this.start, required this.end});

factory OpeningHour.fromJson(Map<String, dynamic> json) =>
_$OpeningHourFromJson(json);

Map<String, dynamic> toJson() => _$OpeningHourToJson(this);
}
45 changes: 45 additions & 0 deletions lib/placesComponent/model/cafeterias/opening_hours.g.dart

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

Loading

0 comments on commit 39857ff

Please sign in to comment.