forked from rdougan/RDActivityViewController
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRDActivityViewController.m
77 lines (58 loc) · 2.17 KB
/
RDActivityViewController.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
//
// RDActivityViewController.m
// APOD
//
// Created by Robert Dougan on 11/5/12.
// Copyright (c) 2012 Robert Dougan. All rights reserved.
//
#import "RDActivityViewController.h"
@interface RDActivityViewController () {
NSMutableDictionary *_itemsMapping;
int _maximumNumberOfItems;
}
@end
@implementation RDActivityViewController
@synthesize delegate = _delegate;
- (id)initWithDelegate:(id)delegate {
return [self initWithDelegate:delegate maximumNumberOfItems:10];
}
- (id)initWithDelegate:(id)delegate maximumNumberOfItems:(int)maximumNumberOfItems {
_delegate = delegate;
_maximumNumberOfItems = maximumNumberOfItems;
NSMutableArray *items = [[NSMutableArray alloc] init];
int i;
for (i = 0; i < maximumNumberOfItems; i++) {
[items addObject:self];
}
self = [self initWithActivityItems:items applicationActivities:nil];
if (self) {
_itemsMapping = [[NSMutableDictionary alloc] init];
}
return self;
}
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
// Get the items if not already received
NSMutableDictionary *activity = [_itemsMapping objectForKey:activityType];
NSArray *items;
if (!activity) {
items = [_delegate performSelector:@selector(activityViewController:itemsForActivityType:) withObject:self withObject:activityType];
activity = [[NSMutableDictionary alloc] initWithObjectsAndKeys:items, @"items", [NSNumber numberWithInt:0], @"index", nil];
[_itemsMapping setObject:activity forKey:activityType];
} else {
items = [activity objectForKey:@"items"];
}
// Get the item
int index = [[activity objectForKey:@"index"] integerValue];
id item = nil;
if (index < [items count]) {
item = [items objectAtIndex:index];
}
// Increase the index, and reset
index = (index + 1) % _maximumNumberOfItems;
[activity setObject:[NSNumber numberWithInt:index] forKey:@"index"];
return item;
}
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return @"";
}
@end