Skip to content

Commit 525b223

Browse files
committed
Major: Rename study spaces to buildings because each contain several areas
1 parent 2db33d9 commit 525b223

File tree

3 files changed

+57
-59
lines changed

3 files changed

+57
-59
lines changed

lib/studySpaceList.dart renamed to lib/buildingList.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import 'package:flutter/material.dart';
22
import 'package:mstudy/main.dart';
33

4-
List<StudySpace> studySpaces = [
5-
StudySpace(
4+
List<Building> buildings = [
5+
Building(
66
title: "Art, Architecture, and Engineering Library",
77
id: "duderstadt",
88
openingHours: List.filled(7, const OpeningHours.allDay()),
@@ -13,7 +13,7 @@ List<StudySpace> studySpaces = [
1313
connectedToMLibraryApi: true,
1414
areas: [],
1515
),
16-
StudySpace(
16+
Building(
1717
title: "Hatcher Library",
1818
id: "hatcher",
1919
openingHours: [
@@ -43,7 +43,7 @@ List<StudySpace> studySpaces = [
4343
)
4444
],
4545
),
46-
StudySpace(
46+
Building(
4747
title: "Shapiro Library",
4848
id: "shapiro",
4949
openingHours: [
@@ -62,7 +62,7 @@ List<StudySpace> studySpaces = [
6262
connectedToMLibraryApi: true,
6363
areas: [],
6464
),
65-
StudySpace(
65+
Building(
6666
title: "Fine Arts Library",
6767
id: "fine_arts",
6868
openingHours: [
@@ -80,7 +80,7 @@ List<StudySpace> studySpaces = [
8080
connectedToMLibraryApi: true,
8181
areas: [],
8282
),
83-
StudySpace(
83+
Building(
8484
title: "Taubman Health Sciences Library",
8585
id: "taubman",
8686
openingHours: [
@@ -98,7 +98,7 @@ List<StudySpace> studySpaces = [
9898
connectedToMLibraryApi: true,
9999
areas: [],
100100
),
101-
StudySpace(
101+
Building(
102102
title: "Music Library",
103103
id: "music",
104104
openingHours: [
@@ -116,7 +116,7 @@ List<StudySpace> studySpaces = [
116116
connectedToMLibraryApi: true,
117117
areas: [],
118118
),
119-
StudySpace(
119+
Building(
120120
title: "East Quad",
121121
id: "east_quad",
122122
openingHours: [

lib/studySpacePage.dart renamed to lib/buildingPage.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ class AreasCard extends StatelessWidget {
142142
}
143143
}
144144

145-
class StudySpacePage extends StatelessWidget {
146-
const StudySpacePage({Key? key, required this.studySpace}) : super(key: key);
145+
class BuildingPage extends StatelessWidget {
146+
const BuildingPage({Key? key, required this.building}) : super(key: key);
147147

148-
final StudySpace studySpace;
148+
final Building building;
149149

150150
@override
151151
Widget build(BuildContext context) {
@@ -173,7 +173,7 @@ class StudySpacePage extends StatelessWidget {
173173
mainAxisSize: MainAxisSize.min,
174174
children: [
175175
Text(
176-
studySpace.title,
176+
building.title,
177177
style: Theme.of(context).textTheme.headlineSmall,
178178
textAlign: TextAlign.start,
179179
),
@@ -186,10 +186,10 @@ class StudySpacePage extends StatelessWidget {
186186
onPressed: () async {
187187
if (kDebugMode) {
188188
print(
189-
"Tapped on the address of ${studySpace.title}.");
189+
"Tapped on the address of ${building.title}.");
190190
}
191191
MapsLauncher.launchQuery(
192-
"${studySpace.title}, ${studySpace.address}");
192+
"${building.title}, ${building.address}");
193193
},
194194
icon: const Icon(MaterialIconsSelected.place),
195195
label: const Text("Map")),
@@ -201,9 +201,9 @@ class StudySpacePage extends StatelessWidget {
201201
onPressed: () async {
202202
if (kDebugMode) {
203203
print(
204-
"Tapped on the contact of ${studySpace.title}.");
204+
"Tapped on the contact of ${building.title}.");
205205
}
206-
launch("tel://${studySpace.phoneNumber}");
206+
launch("tel://${building.phoneNumber}");
207207
},
208208
icon: const Icon(MaterialIconsSelected.call),
209209
label: const Text("Call")),
@@ -212,32 +212,32 @@ class StudySpacePage extends StatelessWidget {
212212
SizedBox(
213213
height:
214214
Theme.of(context).textTheme.bodyLarge!.fontSize! / 2),
215-
OpeningHourCard(openingHours: studySpace.openingHours),
215+
OpeningHourCard(openingHours: building.openingHours),
216216
SizedBox(
217217
height:
218218
Theme.of(context).textTheme.headlineSmall!.fontSize! /
219219
2),
220220
Visibility(
221-
visible: studySpace.areas.isNotEmpty,
221+
visible: building.areas.isNotEmpty,
222222
child: Text(
223223
"Areas",
224224
style: Theme.of(context).textTheme.titleLarge,
225225
textAlign: TextAlign.start,
226226
),
227227
),
228228
Visibility(
229-
visible: studySpace.areas.isNotEmpty,
229+
visible: building.areas.isNotEmpty,
230230
child: SizedBox(
231231
height:
232232
Theme.of(context).textTheme.headlineSmall!.fontSize! /
233233
2),
234234
),
235235
Visibility(
236-
visible: studySpace.areas.isNotEmpty,
236+
visible: building.areas.isNotEmpty,
237237
child: AreasCard(
238-
buildingId: studySpace.id, areas: studySpace.areas)),
238+
buildingId: building.id, areas: building.areas)),
239239
Visibility(
240-
visible: studySpace.areas.isNotEmpty,
240+
visible: building.areas.isNotEmpty,
241241
child: SizedBox(
242242
height:
243243
Theme.of(context).textTheme.headlineSmall!.fontSize! /

lib/main.dart

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import 'package:geolocator/geolocator.dart';
77
import 'package:google_fonts/google_fonts.dart';
88
import 'package:json_api/client.dart';
99
import 'package:json_api/routing.dart';
10-
import 'package:mstudy/studySpaceList.dart' as study_space_list;
11-
import 'package:mstudy/studySpacePage.dart';
10+
import 'package:mstudy/buildingList.dart' as building_list;
11+
import 'package:mstudy/buildingPage.dart';
1212
import 'package:shared_preferences/shared_preferences.dart';
1313
import 'package:string_similarity/string_similarity.dart';
1414
import 'package:time_range_picker/time_range_picker.dart'
@@ -20,7 +20,7 @@ import 'utils.dart';
2020
part 'main.freezed.dart';
2121
part 'main.g.dart';
2222

23-
/// Opening hours of a study space
23+
/// Opening hours of a building
2424
///
2525
/// Can be all day, a range from start time to end time, or closed
2626
@freezed
@@ -58,8 +58,8 @@ class AppState with _$AppState {
5858
///
5959
/// An [id] is used to incorporate hours fetched from M Library API.
6060
/// Titles are not stored in the relationships of JSON:API so [id]s
61-
/// are the only way to find and match opening hours to study spaces.
62-
/// Each [HoursType] of a study space has a unique [id].
61+
/// are the only way to find and match opening hours to buildings.
62+
/// Each [HoursType] of a building has a unique [id].
6363
@JsonSerializable(explicitToJson: true)
6464
class OpeningDateAndHours {
6565
late String id;
@@ -81,14 +81,14 @@ class OpeningDateAndHours {
8181
/// Type of [OpeningDateAndHours] specified in JSON:API, e.g. "paragraph--hours_exceptions"
8282
typedef HoursType = String;
8383

84-
/// Title of study spaces
84+
/// Title of buildings
8585
typedef SpaceTitle = String;
8686

87-
/// Unprocessed [OpeningDateAndHours] for each study space, organized by [HoursType]
87+
/// Unprocessed [OpeningDateAndHours] for each building, organized by [HoursType]
8888
typedef FieldOpeningHours
8989
= Map<HoursType, Map<SpaceTitle, List<OpeningDateAndHours>>>;
9090

91-
/// Processed [OpeningDateAndHours] for each study space, listed in decreasing priorities.
91+
/// Processed [OpeningDateAndHours] for each building, listed in decreasing priorities.
9292
/// Priorities cf processFieldOpeningHours.
9393
typedef ProcessedOpeningHours = Map<SpaceTitle, List<OpeningDateAndHours>>;
9494

@@ -170,7 +170,7 @@ class MyApp extends StatelessWidget {
170170
foregroundColor: MaterialStateProperty.resolveWith((_) => blueColor),
171171
)));
172172
return MaterialApp(
173-
title: 'Study spaces',
173+
title: 'Buildings',
174174
theme: theme,
175175
home: const MyHomePage(title: 'Opening Now'),
176176
);
@@ -207,7 +207,7 @@ class Area {
207207

208208
Id getAreaId(Id buildingId, Id areaId) => "${buildingId}_$areaId";
209209

210-
class StudySpace {
210+
class Building {
211211
final String title;
212212
final String id;
213213
List<OpeningHours>
@@ -218,7 +218,7 @@ class StudySpace {
218218
final bool connectedToMLibraryApi;
219219
final List<Area> areas;
220220

221-
StudySpace({
221+
Building({
222222
required this.title,
223223
required this.id,
224224
required this.openingHours,
@@ -253,15 +253,15 @@ class _MyHomePageState extends State<MyHomePage> {
253253
ProcessedOpeningHours openingHours = {};
254254
TimeOfDay filterStartTime = const TimeOfDay(hour: 9, minute: 0);
255255
TimeOfDay filterEndTime = const TimeOfDay(hour: 22, minute: 0);
256-
List<StudySpace> studySpaces = study_space_list.studySpaces;
256+
List<Building> buildings = building_list.buildings;
257257

258258
@override
259259
void initState() {
260260
super.initState();
261261
if (kDebugMode) {
262262
getCurrentPosition().then((position) {
263263
print("Current position is $position");
264-
for (var space in studySpaces) {
264+
for (var space in buildings) {
265265
var distance = Geolocator.distanceBetween(
266266
position.latitude,
267267
position.longitude,
@@ -328,7 +328,7 @@ class _MyHomePageState extends State<MyHomePage> {
328328
});
329329
}
330330

331-
/// Update the opening hours for the next 7 days of all study spaces
331+
/// Update the opening hours for the next 7 days of all buildings
332332
/// connected to the M library API
333333
void updateOpeningHoursForNextSevenDays() {
334334
List<DateTime> nextSevenDays = [];
@@ -338,9 +338,7 @@ class _MyHomePageState extends State<MyHomePage> {
338338
nextDay = nextDay.add(const Duration(days: 1));
339339
}
340340
setState(() {
341-
studySpaces
342-
.where((space) => space.connectedToMLibraryApi)
343-
.forEach((space) {
341+
buildings.where((space) => space.connectedToMLibraryApi).forEach((space) {
344342
for (var day in nextSevenDays) {
345343
var newOpeningHours = getOpeningHours(space.title, day);
346344
if (kDebugMode) {
@@ -356,8 +354,8 @@ class _MyHomePageState extends State<MyHomePage> {
356354
@override
357355
Widget build(BuildContext context) {
358356
var wordBoundary = RegExp(r'\W');
359-
var queryFilteredStudySpaces = queryName.isNotEmpty
360-
? studySpaces
357+
var queryFilteredBuildings = queryName.isNotEmpty
358+
? buildings
361359
.where((space) =>
362360
space.title.toLowerCase().split(wordBoundary).any((word) {
363361
return queryName
@@ -368,18 +366,18 @@ class _MyHomePageState extends State<MyHomePage> {
368366
});
369367
}))
370368
.toList()
371-
: studySpaces;
369+
: buildings;
372370
final openingHoursIndex = getOpeningHoursIndex();
373-
var filteredStudySpaces = appState
371+
var filteredBuildings = appState
374372
.when(
375-
filterResults: () => studySpaces
373+
filterResults: () => buildings
376374
.where((space) => isOpenDuring(
377375
OpeningHours.range(filterStartTime, filterEndTime),
378376
space.openingHours[openingHoursIndex]))
379377
.toList(),
380-
keywordSearch: () => queryFilteredStudySpaces,
381-
filterSearch: () => queryFilteredStudySpaces,
382-
home: () => queryFilteredStudySpaces,
378+
keywordSearch: () => queryFilteredBuildings,
379+
filterSearch: () => queryFilteredBuildings,
380+
home: () => queryFilteredBuildings,
383381
)
384382
.sorted((space1, space2) => space1.openingHours[openingHoursIndex].when(
385383
allDay: () => space2.openingHours[openingHoursIndex].when(
@@ -406,9 +404,9 @@ class _MyHomePageState extends State<MyHomePage> {
406404
),
407405
body: ListView.separated(
408406
padding: const EdgeInsets.all(8),
409-
itemCount: filteredStudySpaces.length,
407+
itemCount: filteredBuildings.length,
410408
itemBuilder: (BuildContext context, int index) {
411-
return showListItem(filteredStudySpaces[index]);
409+
return showListItem(filteredBuildings[index]);
412410
},
413411
separatorBuilder: (context, index) => SizedBox(
414412
height: Theme.of(context).textTheme.bodySmall!.fontSize! / 2,
@@ -630,14 +628,14 @@ class _MyHomePageState extends State<MyHomePage> {
630628
});
631629
}
632630

633-
Widget showListItem(StudySpace studySpace) {
631+
Widget showListItem(Building building) {
634632
var openingHoursIndex = getOpeningHoursIndex();
635633
return GestureDetector(
636634
onTap: () {
637635
Navigator.push(
638636
context,
639637
MaterialPageRoute(
640-
builder: (context) => StudySpacePage(studySpace: studySpace),
638+
builder: (context) => BuildingPage(building: building),
641639
));
642640
},
643641
child: Card(
@@ -649,14 +647,14 @@ class _MyHomePageState extends State<MyHomePage> {
649647
child: Column(
650648
children: [
651649
Text(
652-
studySpace.title,
650+
building.title,
653651
style: Theme.of(context).textTheme.titleLarge,
654652
),
655653
SizedBox(
656654
height: Theme.of(context).textTheme.bodySmall!.fontSize! / 2),
657655
Text(
658656
openingHoursToString(
659-
studySpace.openingHours[openingHoursIndex]),
657+
building.openingHours[openingHoursIndex]),
660658
style: Theme.of(context).textTheme.bodyMedium),
661659
],
662660
mainAxisAlignment: MainAxisAlignment.start,
@@ -672,14 +670,14 @@ class _MyHomePageState extends State<MyHomePage> {
672670
decoration: BoxDecoration(
673671
image: DecorationImage(
674672
fit: BoxFit.fitHeight,
675-
image: AssetImage(
676-
getImageUrl(id: studySpace.id))))))),
673+
image:
674+
AssetImage(getImageUrl(id: building.id))))))),
677675
]),
678676
)),
679677
);
680678
}
681679

682-
/// Get the [OpeningHours] of a study space with a [queryTitle] at a [queryDate].
680+
/// Get the [OpeningHours] of a building with a [queryTitle] at a [queryDate].
683681
OpeningHours? getOpeningHours(String queryTitle, DateTime queryDate) {
684682
// print(openingHours[queryTitle]
685683
// ?.map((hours) => "${hours.startDate} - ${hours.endDate}"));
@@ -723,7 +721,7 @@ class _MyHomePageState extends State<MyHomePage> {
723721
...fallAndWinter.values
724722
];
725723
ProcessedOpeningHours result = {};
726-
studySpaces.where((space) => space.connectedToMLibraryApi).forEach((space) {
724+
buildings.where((space) => space.connectedToMLibraryApi).forEach((space) {
727725
for (var hours in prioritizedHours) {
728726
if (hours[space.title] != null) {
729727
result.putIfAbsent(space.title, () => []).addAll(hours[space.title]!);
@@ -743,7 +741,7 @@ class _MyHomePageState extends State<MyHomePage> {
743741

744742
final client = RoutingClient(uriDesign);
745743

746-
// A Map from fieldHoursOpen.type (eg paragraph__hours_exceptions) to a Map from study space title to its opening hours
744+
// A Map from fieldHoursOpen.type (eg paragraph__hours_exceptions) to a Map from building title to its opening hours
747745
FieldOpeningHours fieldOpeningHours = {};
748746

749747
try {
@@ -757,7 +755,7 @@ class _MyHomePageState extends State<MyHomePage> {
757755

758756
for (var resource in response.collection) {
759757
String title = resource.attributes["title"]! as String;
760-
if (studySpaces
758+
if (buildings
761759
.where((space) => space.connectedToMLibraryApi)
762760
.map((space) => space.title)
763761
.contains(title)) {

0 commit comments

Comments
 (0)