Skip to content

Commit c326e79

Browse files
committed
New way to specify captions
1 parent 2783a0c commit c326e79

File tree

12 files changed

+175
-91
lines changed

12 files changed

+175
-91
lines changed

SPEC.md

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# iHW Project Design Specifications
22

3-
*In order to make the iHW project more coordinated, unified, and better overall, I think that it’s a good idea for us to write up exactly how we are going about creating the two phone apps and web app. If we use this document to communicate our goals and ideas for the project, we can more effectively create a unified experience for the app across platforms. Please add or edit anything you want in any of the sections below, or even add new sections—this is our space to share ideas. Thanks!*
3+
*In order to make the iHW project more coordinated, unified, and better
4+
overall, I think that it’s a good idea for us to write up exactly how we
5+
are going about creating the two phone apps and web app. If we use this
6+
document to communicate our goals and ideas for the project, we can more
7+
effectively create a unified experience for the app across platforms.
8+
Please add or edit anything you want in any of the sections below, or
9+
even add new sections—this is our space to share ideas. Thanks!*
410

511
## Required Features - View
612

@@ -14,21 +20,28 @@
1420

1521
### Schedule View
1622

17-
- Shows one day at a time, with the ability to swipe left and right to see different days.
23+
- Shows one day at a time, with the ability to swipe left and right to
24+
see different days.
1825

1926
- Shows date, day of week, and day number (if applicable).
2027

2128
- Shows a list of periods in the day.
2229

23-
- For each period, shows course name (or "X"), start and end times, and period number (if applicable).
30+
- For each period, shows course name (or "X"), start and end times,
31+
and period number (if applicable).
2432

25-
- For each period, lists the notes the user has added to the period and always has an empty box to add an additional note.
33+
- For each period, lists the notes the user has added to the period
34+
and always has an empty box to add an additional note.
2635

27-
- Ability to show/hide a checkbox for any note or mark it as important (makes it bigger/bolder and moves it to the top) or unimportant (restores font and moves it to the bottom)
36+
- Ability to show/hide a checkbox for any note or mark it as important
37+
(makes it bigger/bolder and moves it to the top) or unimportant
38+
(restores font and moves it to the bottom)
2839

29-
- Shows a countdown timer next to the period title if the period will start soon.
40+
- Shows a countdown timer next to the period title if the period will
41+
start soon.
3042

31-
- Has a button to jump to the current day and a button to choose a date to show.
43+
- Has a button to jump to the current day and a button to choose a
44+
date to show.
3245

3346
### Courses Editor
3447

@@ -42,29 +55,37 @@
4255

4356
- Has text boxes for course name and period.
4457

45-
- Validates the period text box as you type (doesn't let you type anything besides valid period numbers)
58+
- Validates the period text box as you type (doesn't let you type
59+
anything besides valid period numbers)
4660

4761
- Has a drop-down field to choose the term.
4862

49-
- Has a grid of checkboxes with three rows (period before, this period, period after) to select class meetings.
63+
- Has a grid of checkboxes with three rows (period before, this
64+
period, period after) to select class meetings.
5065

5166
- Has buttons to delete this course or save it.
5267

53-
- Rejects courses that do not have a name or at least one class meeting.
68+
- Rejects courses that do not have a name or at least one class
69+
meeting.
5470

5571
## Required Features - Model
5672

5773
- Loads curriculum JSON when user selects a campus during first-run
5874

59-
- Reloads curriculum JSON on app launch every time there's an internet connection available
75+
- Reloads curriculum JSON on app launch every time there's an internet
76+
connection available
6077

6178
- Loads year JSON and cycle 0 on app launch
6279

63-
- Loads cycle JSON files as needed (preloading at least one day before and after the currently selected day)
80+
- Loads cycle JSON files as needed (preloading at least one day before
81+
and after the currently selected day)
6482

65-
- Loads the currently selected day, then preloads day(s) before and after it in the background
83+
- Loads the currently selected day, then preloads day(s) before and
84+
after it in the background
6685

67-
- Saves notes when the user is done editing a note, when a note option is changed, and when the user leaves the day where the notes are written.
86+
- Saves notes when the user is done editing a note, when a note option
87+
is changed, and when the user leaves the day where the notes are
88+
written.
6889

6990
- Saves courses whenever the user leaves the edit course view.
7091

@@ -84,7 +105,8 @@
84105

85106
## Communications / JSON / Saving / etc.
86107

87-
- Schedule JSON: contains all of the data (one year, one campus) that is not specific to any one particular user
108+
- Schedule JSON: contains all of the data (one year, one campus) that
109+
is not specific to any one particular user
88110

89111
- Format:
90112

@@ -101,7 +123,8 @@
101123
“specialDays”: {...} //maps dates to day objects
102124
}
103125

104-
- Year JSON (badly named): contains course information and other general information specific to the user
126+
- Year JSON (badly named): contains course information and other
127+
general information specific to the user
105128

106129
- Format:
107130

@@ -117,22 +140,26 @@
117140

118141
- Week numbers are as follows:
119142

120-
- The partial week between July 1 and the first Sunday after July 1 has week number 0.
143+
- The partial week between July 1 and the first Sunday after
144+
July 1 has week number 0.
121145

122-
- On and after the first Sunday after July 1, the week number is: (number of days since the first Sunday after July 1 / 7)+1.
146+
- On and after the first Sunday after July 1, the week number
147+
is: (number of days since the first Sunday after July 1 /
148+
7)+1.
123149

124150
- Format:
125151

126152
<!-- -->
127153

128154
{
129155
“number”: 1,
130-
“notes”: {...} //maps "date.period" to arrays of notes
156+
“notes”: {...} //maps “<date>.<period>" to arrays of notes
131157
}
132158

133159
- Date Format for JSON: `“M/D/YYYY”` e.g. `“9/16/2012”`
134160

135-
- Time Format for JSON: `“H:M”`  e.g. `“8:0”` or `“14:30”` (use 24 hour time)
161+
- Time Format for JSON: `“H:M”`  e.g. `“8:0”` or `“14:30”` (use 24
162+
hour time)
136163

137164
- Course Format for JSON:
138165

@@ -145,19 +172,23 @@
145172
“meetings”: [1,1,1,1,0]
146173
}
147174

148-
- Note Format for JSON: (IMPORTANT: period is NOT the same as “periodNum” in the Period JSON! periodNum can be any number, but period is the index of the period within the day [-1 for additional notes at the bottom of every day])
175+
- Note Format for JSON: (IMPORTANT: period is NOT the same as
176+
“periodNum” in the Period JSON! “periodNum" can be any number, but
177+
“period" is the INDEX of the period within the day [-1 for
178+
additional notes at the bottom of every day])
149179

150180
<!-- -->
151181

152182
{
153-
text”: “Hello, World!,
154-
isChecked: false,
155-
isImportant: false,
156-
isToDo: false
183+
"text": "Hello, World!",
184+
"isChecked": false,
185+
"isImportant": false,
186+
"isToDo": false
157187
"period": 1
158188
}
159189

160-
- Normal Day (with break) Format for JSON (day number 0 for no day number):
190+
- Normal Day (with break) Format for JSON (day number 0 for no day
191+
number):
161192

162193
<!-- -->
163194

@@ -171,10 +202,14 @@
171202
"periodsBeforeBreak": 2,
172203
"type": "normal",
173204
"date": "9/12/2012",
174-
"hasBreak": true
205+
"hasBreak": true,
206+
"breakIsFree": true,
207+
"caption": "A.P. English Exam today 8:00-10:30",
208+
"captionLink": "http://www.google.com/"
175209
}
176210

177-
- Normal Day (without break) Format for JSON (day number 0 for no day number):
211+
- Normal Day (without break) Format for JSON (day number 0 for no day
212+
number):
178213

179214
<!-- -->
180215

@@ -184,17 +219,22 @@
184219
"numPeriods": 8,
185220
"type": "normal",
186221
"date": "9/12/2012",
187-
"hasBreak": false
222+
"hasBreak": false,
223+
"caption": "A.P. English Exam today 8:00-10:30",
224+
"captionLink": "http://www.google.com/"
188225
}
189226

190-
- Test Day (i.e. Custom Day) Format for JSON:
227+
- Test Day (aka Custom Day) Format for JSON (“tests” refers to an
228+
array of “period” objects):
191229

192230
<!-- -->
193231

194232
{
195233
"date": "10/6/2012",
196234
    "tests": [...],
197-
"type": "test"
235+
"type": "test",
236+
"caption": "A.P. English Exam today 8:00-10:30",
237+
"captionLink": "http://www.google.com/"
198238
}
199239

200240
- Holiday Format for JSON:
@@ -204,10 +244,14 @@
204244
{
205245
"date": "10/22/2012",
206246
"name": "Mid-Semester Break",
207-
"type": "holiday"
247+
"type": "holiday",
248+
"caption": "A.P. English Exam today 8:00-10:30",
249+
"captionLink": "http://www.google.com/"
208250
}
209251

210-
- Period format for JSON: (IMPORTANT: periodNum is NOT the same as “period” in the Note JSON! periodNum can be any number, but period is the index of the period within the day.)
252+
- Period format for JSON: (IMPORTANT: periodNum is NOT the same as
253+
“period” in the Note JSON! periodNum can be any number, but period
254+
is the index of the period within the day.)
211255

212256
<!-- -->
213257

@@ -216,7 +260,8 @@
216260
   "startTime": "8:0",
217261
   "name": "Period Name",
218262
   "date": "11/3/2012",
219-
   "endTime": "14:30"
263+
   "endTime": "14:30”,
264+
“isFreePeriod”: false,
220265
}
221266

222267
- Constants:

iHW-iOS/iHW/iHW/IHWCurriculum.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
@property (strong, nonatomic) NSDictionary *normalDayTemplate;
3737
@property (strong, nonatomic) NSDictionary *normalMondayTemplate;
3838
@property (strong, nonatomic) NSDictionary *specialDayTemplates;
39+
@property (strong, nonatomic) NSDictionary *dayCaptions;
3940
@property (strong) NSMutableDictionary *loadedWeeks;
4041
@property (strong) NSMutableDictionary *loadedDays;
4142
@property (strong, nonatomic) NSMutableDictionary *dayNumbers;

iHW-iOS/iHW/iHW/IHWCurriculum.m

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#import "IHWNote.h"
1919
#import "IHWPeriod.h"
2020

21+
static NSString *curriculumDirectory = @"http://beta.ihwapp.com/curriculum/";
2122
static IHWCurriculum *currentCurriculum;
2223

2324
#pragma mark ****************PRIVATE INSTANCE VARS*****************
@@ -215,7 +216,7 @@ - (BOOL)downloadParseScheduleJSON {
215216
//NSLog(@">downloading schedule JSON");
216217
NSError *error = nil;
217218
NSURLResponse *response = nil;
218-
NSString *urlStr = [NSString stringWithFormat:@"http://beta.ihwapp.com/curriculum/%d%@.hws", self.year, getCampusChar(self.campus)];
219+
NSString *urlStr = [NSString stringWithFormat:@"%@%d%@.hws", curriculumDirectory, self.year, getCampusChar(self.campus)];
219220
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
220221
[(IHWAppDelegate *)[UIApplication sharedApplication].delegate performSelectorOnMainThread:@selector(showNetworkIcon) withObject:nil waitUntilDone:NO];
221222
NSData *scheduleJSON = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
@@ -270,6 +271,14 @@ - (BOOL)parseScheduleJSON:(NSData *)scheduleJSON {
270271
[specialDays setObject:[specialDaysJSON objectForKey:dateStr] forKey:[[IHWDate alloc] initFromString:dateStr]];
271272
}
272273
self.specialDayTemplates = [NSDictionary dictionaryWithDictionary:specialDays];
274+
275+
//Load day captions into curriculum
276+
NSMutableDictionary *captions = [[NSMutableDictionary alloc] init];
277+
NSDictionary *captionsJSON = [scheduleDict objectForKey:@"dayCaptions"];
278+
for (NSString *dateStr in [captionsJSON allKeys]) {
279+
[captions setObject:[captionsJSON objectForKey:dateStr] forKey:[[IHWDate alloc] initFromString:dateStr]];
280+
}
281+
self.dayCaptions = [NSDictionary dictionaryWithDictionary:captions];
273282
return YES;
274283
}
275284

@@ -412,6 +421,15 @@ - (BOOL)loadDay:(IHWDate *)date {
412421
} else if ([type isEqualToString:@"holiday"]) {
413422
day = [[IHWHoliday alloc] initWithJSONDictionary:template];
414423
} else return NO;
424+
425+
//Add caption if necessary
426+
NSDictionary *captionDict = [self.dayCaptions objectForKey:date];
427+
if (captionDict != nil && day.caption == nil) {
428+
day.caption = [captionDict objectForKey:@"text"];
429+
if ([captionDict objectForKey:@"link"] != nil) {
430+
day.captionLink = [captionDict objectForKey:@"link"];
431+
}
432+
}
415433
//[self.loadedDays insertObject:day forKey:date sortedUsingComparator:[IHWDate comparator]];
416434
[self performSelectorOnMainThread:@selector(addLoadedDay:) withObject:day waitUntilDone:YES];
417435
return YES;
@@ -467,12 +485,17 @@ - (NSArray *)allCourseNames {
467485

468486
- (BOOL)addCourse:(IHWCourse *)c {
469487
for (IHWCourse *check in self.courses) {
488+
//Make sure no courses conflict with the new course
470489
if (!termsCompatible(check.term, c.term)) {
490+
//There could be a problem if the terms overlap
471491
if (check.period == c.period) {
492+
//There could be a problem if the periods are the same
472493
for (int i=1; i<=self.campus; i++) {
494+
//There's a problem if the two courses meet on the same day
473495
if ([c meetingOn:i] != MEETING_X_DAY && [check meetingOn:i] != MEETING_X_DAY) return NO;
474496
}
475497
} else {
498+
//Check for double periods
476499
IHWCourse *later;
477500
IHWCourse *earlier;
478501
if (c.period > check.period) {
@@ -483,18 +506,21 @@ - (BOOL)addCourse:(IHWCourse *)c {
483506
earlier = c;
484507
}
485508
if (ABS(c.period-check.period) == 1) {
509+
//Double periods could be a problem when the courses are in consecutive periods
486510
for (int i=1; i<=self.campus; i++) {
487511
if ([earlier meetingOn:i] == MEETING_DOUBLE_AFTER && [later meetingOn:i] != MEETING_X_DAY) return NO;
488512
if ([later meetingOn:i] == MEETING_DOUBLE_BEFORE && [earlier meetingOn:i] != MEETING_X_DAY) return NO;
489513
}
490514
} else if (ABS(c.period-check.period) == 2) {
515+
//Double periods could also be a problem when the courses are two periods apart
491516
for (int i=1; i<=self.campus; i++) {
492517
if ([earlier meetingOn:i] == MEETING_DOUBLE_AFTER && [later meetingOn:i] == MEETING_DOUBLE_BEFORE) return NO;
493518
}
494519
}
495520
}
496521
}
497522
}
523+
//No problems found
498524
[self.courses addObject:c];
499525
[self.loadedDays removeAllObjects];
500526
return YES;
@@ -510,6 +536,8 @@ - (void)removeAllCourses {
510536
[self.loadedDays removeAllObjects];
511537
}
512538

539+
//Unnecessary methods
540+
513541
/*
514542
- (BOOL)replaceCourseWithName:(NSString *)oldName withCourse:(IHWCourse *)c {
515543
IHWCourse *oldCourse = [self courseWithName:oldName];
@@ -546,8 +574,10 @@ - (IHWCourse *)courseMeetingOnDate:(IHWDate *)d period:(int)period {
546574
int dayNum = [[self.dayNumbers objectForKey:d] intValue];
547575
NSArray *terms = [self termsFromDate:d];
548576
if (dayNum == 0) {
577+
//For "No X Periods" days, choose the course that meets the most
549578
IHWCourse *maxMeetings = nil;
550579
int max = 1;
580+
//If the course only meets once per cycle, it doesn't meet on "No X Periods" days
551581
for (IHWCourse *c in self.courses) {
552582
BOOL termFound = NO;
553583
for (NSNumber *term in terms) if ([term intValue] == c.term) {

iHW-iOS/iHW/iHW/IHWDayViewController.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ - (void)loadTableViewCells {
157157

158158
- (void)viewDidAppear:(BOOL)animated {
159159
//NSLog(@"viewDidAppear");
160+
if (self.scrollToIndex != -1) {
161+
[self.periodsTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.scrollToIndex inSection:0] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
162+
self.scrollToIndex = -1;
163+
}
160164
}
161165

162166
- (void)keyboardWillShow:(NSNotification *)notification {
@@ -241,7 +245,7 @@ - (UITableViewCell *)createNewCellForIndex:(int)index {
241245

242246
cell.frame = CGRectMake(0, 0, self.view.bounds.size.width, [view neededHeight]);
243247
view.dayViewController = self;
244-
[view createCountdownViewIfNeeded];
248+
if ([view createCountdownViewIfNeeded]) self.scrollToIndex = index;
245249
[cell.contentView addSubview:view];
246250
return cell;
247251
}

iHW-iOS/iHW/iHW/IHWNormalDay.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@property int periodsAfterBreak;
1919
@property int periodLength;
2020
@property int breakLength;
21+
@property BOOL breakIsFree;
2122
@property (strong, nonatomic) NSDictionary *periodLengths;
2223
@property (strong, nonatomic) NSString *breakName;
2324

@@ -26,6 +27,7 @@
2627
periodsBeforeBreak:(int)pbb
2728
afterBreak:(int)pab
2829
breakLength:(int)blength
30+
breakIsFree:(BOOL)breakIsFree
2931
periodLength:(int)plength;
3032

3133
- (id)initWithDate:(IHWDate *)date

0 commit comments

Comments
 (0)