Skip to content
This repository was archived by the owner on Oct 23, 2019. It is now read-only.

Commit a456df9

Browse files
committed
Save/restore snaps
1 parent 7951f18 commit a456df9

18 files changed

+135
-333
lines changed

.hgignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ build
55
*.pbxuser
66
*.mode1v3
77
*.tmp
8+
*.orig

Classes/Snap.h

-25
This file was deleted.

Classes/Snap.m

-66
This file was deleted.

Classes/SnapsController.h

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
- (void)removeDataAtIndex:(unsigned)theIndex;
2020
- (void)replaceDataAtIndex:(unsigned)theIndex withData:(NSObject*)data;
2121

22+
- (void)loadSnaps;
23+
- (void)saveSnaps;
24+
2225
@property (nonatomic, copy, readwrite) NSMutableArray* snaps;
2326

2427
@end

Classes/SnapsController.m

+17-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#import "SnapsController.h"
1010

11-
1211
@implementation SnapsController
1312

1413
@synthesize snaps;
@@ -17,9 +16,7 @@ - (id)init;
1716
{
1817
if (self = [super init])
1918
{
20-
NSMutableArray* newSnaps = [[NSMutableArray alloc] init];
21-
self.snaps = newSnaps;
22-
[newSnaps release];
19+
self.snaps = [NSMutableArray array];
2320
}
2421

2522
return self;
@@ -40,6 +37,22 @@ - (void)removeDataAtIndex:(unsigned)theIndex;
4037
[snaps removeObjectAtIndex:theIndex];
4138
}
4239

40+
41+
- (void)loadSnaps
42+
{
43+
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
44+
NSArray* savedSnaps = [userDefaults arrayForKey:@"snaps"];
45+
self.snaps = [NSMutableArray arrayWithArray:savedSnaps];
46+
}
47+
48+
49+
- (void)saveSnaps
50+
{
51+
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
52+
[userDefaults setValue:snaps forKey:@"snaps"];
53+
}
54+
55+
4356
- (void)replaceDataAtIndex:(unsigned)theIndex withData:(NSObject*)data;
4457
{
4558
[snaps replaceObjectAtIndex:theIndex withObject:data];

Classes/Song.h

-22
This file was deleted.

Classes/Song.m

-53
This file was deleted.

Classes/WhatJustPlayedAppDelegate.m

+9-34
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#import "WhatJustPlayedAppDelegate.h"
1010
#import "WhatJustPlayedViewController.h"
11-
#import "Snap.h"
12-
#import "Song.h"
1311

1412
#ifdef BROMINE_ENABLED
1513
#import "ScriptRunner.h"
@@ -46,46 +44,23 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
4644
}
4745

4846

49-
- (void)resetApp:(NSDictionary*)data {
47+
- (void)restoreDefaults:(NSDictionary*)ignored {
5048
[viewController setSnaps:[NSArray array]];
51-
[viewController setLookupPattern:[WhatJustPlayedViewController defaultLookupPattern]];
52-
[viewController setTestTime:nil];
49+
viewController.lookupPattern = [WhatJustPlayedViewController defaultLookupPattern];
50+
viewController.testTime = nil;
51+
}
52+
53+
54+
- (void)restartApp:(NSDictionary*)ignored {
55+
[viewController reloadData];
5356
}
5457

5558

5659
- (void)setTestData:(NSDictionary*)data {
5760
NSArray* table = [data objectForKey:@"snaps"];
5861
if (table)
5962
{
60-
NSMutableArray* snaps = [NSMutableArray array];
61-
NSEnumerator* e = [table objectEnumerator];
62-
NSDictionary* dict;
63-
64-
while ((dict = [e nextObject]))
65-
{
66-
NSString* title = [dict objectForKey:@"title"];
67-
NSString* subtitle = [dict objectForKey:@"subtitle"];
68-
NSNumber* needsLookup = [dict objectForKey:@"needsLookup"];
69-
70-
if ([needsLookup boolValue])
71-
{
72-
NSDateFormatter *dateFormat =
73-
[[[NSDateFormatter alloc] init] autorelease];
74-
[dateFormat setDateStyle:NSDateFormatterNoStyle];
75-
[dateFormat setTimeStyle:NSDateFormatterShortStyle];
76-
NSDate* date = [dateFormat dateFromString:subtitle];
77-
78-
Snap* snap = [[Snap alloc] initWithStation:title creationTime:date];
79-
[snaps addObject:snap];
80-
}
81-
else
82-
{
83-
Song* song = [[Song alloc] initWithTitle:title artist:subtitle];
84-
[snaps addObject:song];
85-
}
86-
}
87-
88-
[viewController setSnaps:snaps];
63+
[viewController setSnaps:table];
8964
}
9065

9166
NSString* lookupPattern = [data objectForKey:@"lookupPattern"];

Classes/WhatJustPlayedViewController.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
+ (NSString*) defaultLookupPattern;
2121
- (void)setSnaps:(NSArray*) snaps;
22+
- (void)reloadData;
2223
- (IBAction)lookupButtonPressed:(id)sender;
2324

2425
@property (nonatomic, retain) SnapsController* snapsController;

0 commit comments

Comments
 (0)