-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetasomeEventStore.m
More file actions
98 lines (79 loc) · 2.02 KB
/
MetasomeEventStore.m
File metadata and controls
98 lines (79 loc) · 2.02 KB
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
//
// MetasomeEventStore.m
// Metasome
//
// Created by Omar Metwally on 8/26/13.
// Copyright (c) 2013 Logisome. All rights reserved.
//
#import "MetasomeEventStore.h"
#import "MetasomeEvent.h"
#import "Legend.h"
@implementation MetasomeEventStore
float const EVENT_BAR_WIDTH = 30.0;
+(MetasomeEventStore *)sharedStore
{
static MetasomeEventStore *sharedStore = nil;
if (!sharedStore) {
sharedStore = [[super allocWithZone:nil] init];
}
return sharedStore;
}
+(id)allocWithZone:(NSZone *)zone
{
return [self sharedStore];
}
-(id)init
{
self = [super init];
if (self) {
NSString *path = [self itemArchivePath];
allEvents = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
allEventLabels = [[NSMutableArray alloc] init];
}
if (!allEvents) {
allEvents = [[NSMutableArray alloc] init];
}
return self;
}
-(NSArray *)allEvents
{
return allEvents;
}
-(void)addEvent:(MetasomeEvent *)ev
{
[allEvents addObject:ev];
}
-(void)moveItemAtIndex:(int)from toIndex:(int)to
{
if (from == to) return;
MetasomeEvent *ev = [allEvents objectAtIndex:from];
[allEvents removeObjectAtIndex:from];
[allEvents insertObject:ev atIndex:to];
}
-(void)removeEvent:(MetasomeEvent *)ev
{
[allEvents removeObjectIdenticalTo:ev];
}
-(NSString *)itemArchivePath
{
NSArray *documentdirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [documentdirectories objectAtIndex:0];
return [documentDirectory stringByAppendingPathComponent:@"events.archive"];
}
-(BOOL)saveChanges
{
NSString *path = [self itemArchivePath];
return [NSKeyedArchiver archiveRootObject:allEvents toFile:path];
}
-(void)removeLabelsFromSuperview:(UIView *)v
{
for (UILabel *l in allEventLabels) {
[l removeFromSuperview];
}
//[allEventLabels removeAllObjects];
}
-(NSMutableArray *)allEventLabels
{
return allEventLabels;
}
@end