Last active
December 25, 2015 17:29
-
-
Save gregtemp/7014015 to your computer and use it in GitHub Desktop.
current proj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// C4WorkSpace.m | |
// TumblrGetPostsTest1 | |
// | |
// Created by Gregory Debicki on 2013-10-16. | |
// | |
#import "C4Workspace.h" | |
#import "TMAPIClient.h" | |
@implementation C4WorkSpace { | |
NSMutableArray *myArray; | |
C4ScrollView *viewer; | |
NSInteger newSize; | |
C4Shape *lpb; | |
} | |
-(void)setup { | |
// Options: 75, 100, 250, 400, 500 | |
newSize = 75; | |
viewer = [C4ScrollView scrollView:CGRectMake(20, 30, newSize, self.canvas.height - 50)]; | |
viewer.contentSize = CGSizeMake(newSize, 0); | |
viewer.showsHorizontalScrollIndicator = NO; | |
viewer.showsVerticalScrollIndicator = NO; | |
[self.canvas addSubview:viewer]; | |
[TMAPIClient sharedInstance].OAuthConsumerKey = @"sNUjbu3uXKvSleBLBlOTfD3wysGV8inthwujz7d3xsQNO0MBRJ"; | |
[TMAPIClient sharedInstance].OAuthConsumerSecret = @"WXcwOPoN1SaaRfwjF48zUIw8GoM6maNRTRE0oaVVpR4YSEkdYO"; | |
[TMAPIClient sharedInstance].OAuthToken = @"yffc905h8cUpyHsfVwGJoAXWMwwV2aSUmrtaukSHYc4YAWYKwV"; | |
[TMAPIClient sharedInstance].OAuthTokenSecret = @"Oj9LOa9fkxcE1vVF0P4wo78ai8xXQc4aghjmlhAVRyjw2aXdgY"; | |
[[TMAPIClient sharedInstance] posts:@"alonglistofthings.tumblr.com" type:@"photo" parameters:@{@"limit" : @10} | |
callback:^(id response, NSError *error) { | |
if (error) | |
NSLog(@"Error"); | |
else { | |
myArray = response[@"posts"]; | |
C4Log(@"%@", response[@"posts"]); | |
[self getSmallSizeAt:CGPointMake(0, 0)]; | |
} | |
}]; | |
} | |
-(void) getSmallSizeAt: (CGPoint)startPoint { | |
CGPoint originPoint = startPoint; | |
for (int i = 0; i < 10; i++) { | |
NSString *imgUrl = [self getSmallUrlAtIndex:i]; | |
C4Image *img = [C4Image imageWithURL:imgUrl]; | |
img.origin = originPoint; | |
originPoint.y += img.height + 10; | |
viewer.contentSize = CGSizeMake(0, originPoint.y); | |
[viewer addImage:img]; | |
} | |
lpb = [self loadMorePicsButton:originPoint]; | |
viewer.contentSize = CGSizeMake(0, originPoint.y + 75 + 10); | |
[viewer addShape:lpb]; | |
} | |
-(C4Shape *) loadMorePicsButton: (CGPoint)originPoint { | |
C4Shape *picsBut = [C4Shape ellipse:CGRectMake(0, 0, 30, 30)]; | |
[self listenFor:@"touchesEnded" fromObject:picsBut andRunMethod:@"loadMorePics"]; | |
picsBut.origin = originPoint; | |
picsBut.center = CGPointMake(viewer.width/2, picsBut.center.y); | |
picsBut.animationDuration = 0.5f; | |
picsBut.animationOptions = REPEAT | AUTOREVERSE; | |
picsBut.fillColor = [UIColor whiteColor]; | |
return picsBut; | |
} | |
-(void) loadMorePics { | |
[[TMAPIClient sharedInstance] posts:@"alonglistofthings.tumblr.com" type:@"photo" parameters:@{@"offset": @10, @"limit" : @10} | |
callback:^(id response, NSError *error) { | |
if (error) | |
NSLog(@"Error"); | |
else { | |
myArray = response[@"posts"]; | |
[viewer removeObject:lpb]; | |
[self getSmallSizeAt:CGPointMake(0, lpb.origin.y)]; | |
} | |
}]; | |
} | |
// | |
// Going to need something like this but "getPlayerAtIndex" to display | |
// which player is doing what. I could use a caption on the image, or | |
// a tag or something. That way I don't have to keep track of who is | |
// uploading what. | |
// | |
-(NSString *) getSmallUrlAtIndex: (NSInteger)index { | |
NSNumber *newSizeNumber = [NSNumber numberWithInt:newSize]; | |
BOOL rightWidth = NO; | |
NSInteger i = 0; | |
NSString *imgUrl = nil; | |
while (!rightWidth) { | |
NSNumber *imgWidth = [[[[[[myArray valueForKey:@"photos"] | |
valueForKey:@"alt_sizes"] | |
objectAtIndex:index] | |
valueForKey:@"width"] | |
objectAtIndex:0] | |
objectAtIndex:i]; | |
if ([imgWidth isEqualToNumber:newSizeNumber]){ | |
imgUrl = [[[[[[myArray valueForKey:@"photos"] | |
valueForKey:@"alt_sizes"] | |
objectAtIndex:index] | |
valueForKey:@"url"] | |
objectAtIndex:0] | |
objectAtIndex:i]; | |
rightWidth = YES; | |
C4Log(@"imgUrl :%@", imgUrl); | |
} | |
else { | |
i++; | |
} | |
} | |
return imgUrl; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment