forked from sprang/Inkpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWDActivityController.m
More file actions
95 lines (74 loc) · 3.02 KB
/
WDActivityController.m
File metadata and controls
95 lines (74 loc) · 3.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
//
// WDActivityController.m
// Inkpad
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2011-2013 Steve Sprang
//
#import "WDActivity.h"
#import "WDActivityController.h"
#import "WDActivityManager.h"
@implementation WDActivityController
@synthesize table;
@synthesize activityManager;
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (!self) {
return nil;
}
self.title = NSLocalizedString(@"Activity", @"Activity");
return self;
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void) loadView
{
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 374) style:UITableViewStylePlain];
self.view = table;
table.delegate = self;
table.dataSource = activityManager;
table.allowsSelection = NO;
self.preferredContentSize = table.frame.size;
}
- (void) setActivityManager:(WDActivityManager *)am
{
activityManager = am;
table.dataSource = am;
// stop observing any previous activity managers that were set
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(activityAdded:) name:WDActivityAddedNotification object:am];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(activityRemoved:) name:WDActivityRemovedNotification object:am];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(activityProgressChanged:) name:WDActivityProgressChangedNotification object:am];
}
- (void) activityAdded:(NSNotification *)aNotification
{
NSNumber *index = (aNotification.userInfo)[@"index"];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index.integerValue inSection:0];
[table beginUpdates];
[table insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[table endUpdates];
}
- (void) activityRemoved:(NSNotification *)aNotification
{
NSNumber *index = (aNotification.userInfo)[@"index"];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index.integerValue inSection:0];
[table beginUpdates];
[table deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[table endUpdates];
}
- (void) activityProgressChanged:(NSNotification *)aNotification
{
NSNumber *index = (aNotification.userInfo)[@"index"];
WDActivity *activity = (aNotification.userInfo)[@"activity"];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index.integerValue inSection:0];
UITableViewCell *layerCell = (UITableViewCell *) [table cellForRowAtIndexPath:indexPath];
UIProgressView *progress = (UIProgressView *) [layerCell viewWithTag:2];
progress.progress = activity.progress;
}
@end