-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLHiPhotoRoll.m
115 lines (95 loc) · 2.38 KB
/
LHiPhotoRoll.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// LHiPhotoRoll.m
// LastHistory
//
// Created by Frederik Seiffert on 10.11.09.
// Copyright 2009 Frederik Seiffert. All rights reserved.
//
#import "LHiPhotoRoll.h"
#import "LHiPhotoLibrary.h"
// Example Roll:
/*
<dict>
<key>RollID</key>
<integer>11</integer>
<key>RollName</key>
<string>My Roll</string>
<key>RollDateAsTimerInterval</key>
<real>-86024549.000000</real>
<key>KeyPhotoKey</key>
<string>2</string>
<key>KeyList</key>
<array>
<string>4</string>
<string>7</string>
<string>8</string>
<string>9</string>
<string>123</string>
<string>122</string>
<string>12</string>
<string>13</string>
<string>14</string>
<string>15</string>
<string>16</string>
<string>17</string>
<string>18</string>
<string>19</string>
<string>20</string>
<string>2</string>
</array>
<key>PhotoCount</key>
<integer>16</integer>
</dict>
*/
@implementation LHiPhotoRoll
@synthesize library=_library;
@synthesize name=_name;
@synthesize timestamp=_timestamp;
- (id)initWithDictionary:(NSDictionary *)rollDict forLibrary:(LHiPhotoLibrary *)library
{
self = [super init];
if (self != nil) {
_library = library;
_name = [rollDict objectForKey:@"RollName"];
_timestamp = [NSDate dateWithTimeIntervalSinceReferenceDate:[[rollDict objectForKey:@"RollDateAsTimerInterval"] floatValue]];
_keyPhotoKey = [rollDict objectForKey:@"KeyPhotoKey"];
_photoKeys = [rollDict objectForKey:@"KeyList"];
}
return self;
}
- (LHiPhotoPhoto *)keyPhoto
{
return [self.library imageForKey:_keyPhotoKey inRoll:self];
}
- (NSArray *)photos
{
if (!_photos)
{
NSMutableArray *photos = [NSMutableArray arrayWithCapacity:_photoKeys.count];
for (NSString *key in _photoKeys)
{
LHiPhotoPhoto *photo = [self.library imageForKey:key inRoll:self];
if (photo)
[photos addObject:photo];
}
_photos = [photos copy];
}
return _photos;
}
- (NSDate *)eventStart
{
if (_photoKeys.count == 0)
return nil;
LHiPhotoPhoto *firstPhoto = [self.library imageForKey:[_photoKeys objectAtIndex:0] inRoll:self];
return firstPhoto.timestamp;
}
- (NSDate *)eventEnd
{
if (_photoKeys.count == 0)
return nil;
LHiPhotoPhoto *lastPhoto = [self.library imageForKey:[_photoKeys lastObject] inRoll:self];
return lastPhoto.timestamp;
}
- (NSInteger)eventStartTime {return LH_EVENT_TIME_UNDEFINED;}
- (NSInteger)eventEndTime {return LH_EVENT_TIME_UNDEFINED;}
@end