Skip to content

Commit 34eaf71

Browse files
committed
Add connectedToMLibraryApi flag
1 parent a1b55a1 commit 34eaf71

File tree

1 file changed

+50
-25
lines changed

1 file changed

+50
-25
lines changed

lib/main.dart

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class StudySpace {
192192
final BuildingPosition buildingPosition;
193193
final String address;
194194
final PhoneNumber phoneNumber;
195+
final bool connectedToMLibraryApi;
195196

196197
StudySpace({
197198
required this.title,
@@ -200,6 +201,7 @@ class StudySpace {
200201
required this.buildingPosition,
201202
required this.address,
202203
required this.phoneNumber,
204+
required this.connectedToMLibraryApi,
203205
});
204206
}
205207

@@ -230,6 +232,7 @@ class _MyHomePageState extends State<MyHomePage> {
230232
buildingPosition:
231233
BuildingPosition(latitude: 42.291165, longitude: -83.715716),
232234
phoneNumber: PhoneNumber("734", "647", "5747"),
235+
connectedToMLibraryApi: true,
233236
),
234237
StudySpace(
235238
title: "Hatcher Library",
@@ -243,6 +246,7 @@ class _MyHomePageState extends State<MyHomePage> {
243246
latitude: 42.276334,
244247
longitude: -83.737981), // Uses Hatcher Library South
245248
phoneNumber: PhoneNumber("734", "764", "0401"),
249+
connectedToMLibraryApi: true,
246250
),
247251
StudySpace(
248252
title: "Shapiro Library",
@@ -252,6 +256,7 @@ class _MyHomePageState extends State<MyHomePage> {
252256
buildingPosition:
253257
BuildingPosition(latitude: 42.275615, longitude: -83.737183),
254258
phoneNumber: PhoneNumber("734", "764", "7490"),
259+
connectedToMLibraryApi: true,
255260
),
256261
StudySpace(
257262
title: "Fine Arts Library",
@@ -264,19 +269,21 @@ class _MyHomePageState extends State<MyHomePage> {
264269
buildingPosition:
265270
BuildingPosition(latitude: 42.274944, longitude: -83.738995),
266271
phoneNumber: PhoneNumber("734", "764", "5405"),
272+
connectedToMLibraryApi: true,
267273
),
268274
StudySpace(
269-
title: "Asia Library",
270-
openingHours: [
271-
const OpeningHours.range(
272-
TimeOfDay(hour: 8, minute: 0), TimeOfDay(hour: 19, minute: 0))
273-
],
274-
pictureUrl: "assets/asia.webp",
275-
address:
276-
"913 S. University Ave", // located on 4th floor of Hatcher North
277-
buildingPosition:
278-
BuildingPosition(latitude: 42.276334, longitude: -83.737981),
279-
phoneNumber: PhoneNumber("734", "764", "0406")),
275+
title: "Asia Library",
276+
openingHours: [
277+
const OpeningHours.range(
278+
TimeOfDay(hour: 8, minute: 0), TimeOfDay(hour: 19, minute: 0))
279+
],
280+
pictureUrl: "assets/asia.webp",
281+
address: "913 S. University Ave", // located on 4th floor of Hatcher North
282+
buildingPosition:
283+
BuildingPosition(latitude: 42.276334, longitude: -83.737981),
284+
phoneNumber: PhoneNumber("734", "764", "0406"),
285+
connectedToMLibraryApi: true,
286+
),
280287
StudySpace(
281288
title: "Taubman Health Sciences Library",
282289
openingHours: [
@@ -288,18 +295,21 @@ class _MyHomePageState extends State<MyHomePage> {
288295
buildingPosition:
289296
BuildingPosition(latitude: 42.283548, longitude: -83.734451),
290297
phoneNumber: PhoneNumber("734", "764", "1210"),
298+
connectedToMLibraryApi: true,
291299
),
292300
StudySpace(
293-
title: "Music Library",
294-
openingHours: [
295-
const OpeningHours.range(
296-
TimeOfDay(hour: 9, minute: 0), TimeOfDay(hour: 17, minute: 0))
297-
],
298-
pictureUrl: "assets/music.webp",
299-
address: "1100 Baits Dr",
300-
buildingPosition:
301-
BuildingPosition(latitude: 42.290373, longitude: -83.721006),
302-
phoneNumber: PhoneNumber("734", "764", "2512"))
301+
title: "Music Library",
302+
openingHours: [
303+
const OpeningHours.range(
304+
TimeOfDay(hour: 9, minute: 0), TimeOfDay(hour: 17, minute: 0))
305+
],
306+
pictureUrl: "assets/music.webp",
307+
address: "1100 Baits Dr",
308+
buildingPosition:
309+
BuildingPosition(latitude: 42.290373, longitude: -83.721006),
310+
phoneNumber: PhoneNumber("734", "764", "2512"),
311+
connectedToMLibraryApi: true,
312+
)
303313
];
304314

305315
@override
@@ -308,6 +318,15 @@ class _MyHomePageState extends State<MyHomePage> {
308318
if (kDebugMode) {
309319
getCurrentPosition().then((position) {
310320
print("Current position is $position");
321+
for (var space in studySpaces) {
322+
var distance = Geolocator.distanceBetween(
323+
position.latitude,
324+
position.longitude,
325+
space.buildingPosition.latitude,
326+
space.buildingPosition.longitude);
327+
print(
328+
"Distance from current position to ${space.title} is ${distance}m.");
329+
}
311330
});
312331
}
313332
SharedPreferences.getInstance().then((prefs) {
@@ -367,6 +386,7 @@ class _MyHomePageState extends State<MyHomePage> {
367386
}
368387

369388
/// Update the opening hours for the next 7 days of all study spaces
389+
/// connected to the M library API
370390
void updateOpeningHoursForNextSevenDays() {
371391
List<DateTime> nextSevenDays = [];
372392
var nextDay = DateTime.now();
@@ -375,7 +395,9 @@ class _MyHomePageState extends State<MyHomePage> {
375395
nextDay = nextDay.add(const Duration(days: 1));
376396
}
377397
setState(() {
378-
studySpaces = studySpaces.map((space) {
398+
studySpaces = studySpaces
399+
.where((space) => space.connectedToMLibraryApi)
400+
.map((space) {
379401
space.openingHours.clear();
380402
for (var day in nextSevenDays) {
381403
var newOpeningHours = getOpeningHours(space.title, day);
@@ -755,13 +777,13 @@ class _MyHomePageState extends State<MyHomePage> {
755777
...fallAndWinter.values
756778
];
757779
ProcessedOpeningHours result = {};
758-
for (var space in studySpaces) {
780+
studySpaces.where((space) => space.connectedToMLibraryApi).forEach((space) {
759781
for (var hours in prioritizedHours) {
760782
if (hours[space.title] != null) {
761783
result.putIfAbsent(space.title, () => []).addAll(hours[space.title]!);
762784
}
763785
}
764-
}
786+
});
765787
return result;
766788
}
767789

@@ -789,7 +811,10 @@ class _MyHomePageState extends State<MyHomePage> {
789811

790812
for (var resource in response.collection) {
791813
String title = resource.attributes["title"]! as String;
792-
if (studySpaces.map((space) => space.title).contains(title)) {
814+
if (studySpaces
815+
.where((space) => space.connectedToMLibraryApi)
816+
.map((space) => space.title)
817+
.contains(title)) {
793818
resource.relationships["field_hours_open"]?.forEach((fieldHoursOpen) {
794819
var emptyOpeningHoursWithId = OpeningDateAndHours(
795820
id: fieldHoursOpen.id,

0 commit comments

Comments
 (0)