From 5b930ee18b5ca33e36ed151fbd8c360a038201da Mon Sep 17 00:00:00 2001 From: Ryan Sickles Date: Thu, 24 Jul 2014 21:51:52 -0400 Subject: [PATCH] Added junction table and in progress with tinder animation --- Memify.xcodeproj/project.pbxproj | 34 ++++ Memify/Card.h | 18 ++ Memify/Card.m | 25 +++ Memify/CardView.h | 18 ++ Memify/CardView.m | 114 +++++++++++++ Memify/FormViewController.h | 3 +- Memify/FormViewController.m | 26 ++- Memify/HomeViewController.h | 11 +- Memify/HomeViewController.m | 271 +++++++++++++++++++++++-------- Memify/HomeViewController.xib | 7 - Memify/ImageView.h | 16 ++ Memify/ImageView.m | 56 +++++++ 12 files changed, 512 insertions(+), 87 deletions(-) create mode 100644 Memify/Card.h create mode 100644 Memify/Card.m create mode 100644 Memify/CardView.h create mode 100644 Memify/CardView.m create mode 100644 Memify/ImageView.h create mode 100644 Memify/ImageView.m diff --git a/Memify.xcodeproj/project.pbxproj b/Memify.xcodeproj/project.pbxproj index e644d7c..aa74866 100644 --- a/Memify.xcodeproj/project.pbxproj +++ b/Memify.xcodeproj/project.pbxproj @@ -40,6 +40,9 @@ 92B9EBAB1971AC680037E036 /* FormViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 92B9EBA91971AC680037E036 /* FormViewController.xib */; }; 92B9EBB01971B81F0037E036 /* DropAnimationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 92B9EBAF1971B81F0037E036 /* DropAnimationController.m */; }; 92BD4D19197F3F3F0047010E /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92BD4D18197F3F3F0047010E /* Social.framework */; }; + 92BD4D1C198010200047010E /* Card.m in Sources */ = {isa = PBXBuildFile; fileRef = 92BD4D1B198010200047010E /* Card.m */; }; + 92BD4D29198011FD0047010E /* ImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 92BD4D28198011FD0047010E /* ImageView.m */; }; + 92BD4D2F198012F50047010E /* CardView.m in Sources */ = {isa = PBXBuildFile; fileRef = 92BD4D2E198012F50047010E /* CardView.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -96,6 +99,12 @@ 92B9EBAE1971B81F0037E036 /* DropAnimationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DropAnimationController.h; sourceTree = ""; }; 92B9EBAF1971B81F0037E036 /* DropAnimationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DropAnimationController.m; sourceTree = ""; }; 92BD4D18197F3F3F0047010E /* Social.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Social.framework; path = System/Library/Frameworks/Social.framework; sourceTree = SDKROOT; }; + 92BD4D1A198010200047010E /* Card.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Card.h; sourceTree = ""; }; + 92BD4D1B198010200047010E /* Card.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Card.m; sourceTree = ""; }; + 92BD4D27198011FD0047010E /* ImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageView.h; sourceTree = ""; }; + 92BD4D28198011FD0047010E /* ImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageView.m; sourceTree = ""; }; + 92BD4D2D198012F50047010E /* CardView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CardView.h; sourceTree = ""; }; + 92BD4D2E198012F50047010E /* CardView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CardView.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -191,6 +200,8 @@ 92B9EBA91971AC680037E036 /* FormViewController.xib */, 927A4E3C1966603E00444506 /* LoginViewController.xib */, 927A4E371966600500444506 /* HomeViewController.xib */, + 92BD4D1F1980116A0047010E /* Card Views */, + 92BD4D1D198010290047010E /* Card Models */, 92B9EBB21971C0AE0037E036 /* Delegates */, 92B9EBB11971C08F0037E036 /* Animation Controllers */, 927A4E1819665F8100444506 /* Images.xcassets */, @@ -248,6 +259,26 @@ name = Delegates; sourceTree = ""; }; + 92BD4D1D198010290047010E /* Card Models */ = { + isa = PBXGroup; + children = ( + 92BD4D1B198010200047010E /* Card.m */, + 92BD4D1A198010200047010E /* Card.h */, + ); + name = "Card Models"; + sourceTree = ""; + }; + 92BD4D1F1980116A0047010E /* Card Views */ = { + isa = PBXGroup; + children = ( + 92BD4D27198011FD0047010E /* ImageView.h */, + 92BD4D28198011FD0047010E /* ImageView.m */, + 92BD4D2D198012F50047010E /* CardView.h */, + 92BD4D2E198012F50047010E /* CardView.m */, + ); + name = "Card Views"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -388,6 +419,9 @@ 927A4E1319665F8100444506 /* main.m in Sources */, 927A4E1719665F8100444506 /* RSAppDelegate.m in Sources */, 92B9EBAA1971AC680037E036 /* FormViewController.m in Sources */, + 92BD4D1C198010200047010E /* Card.m in Sources */, + 92BD4D2F198012F50047010E /* CardView.m in Sources */, + 92BD4D29198011FD0047010E /* ImageView.m in Sources */, 927A4E381966600500444506 /* HomeViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Memify/Card.h b/Memify/Card.h new file mode 100644 index 0000000..379ece1 --- /dev/null +++ b/Memify/Card.h @@ -0,0 +1,18 @@ +// +// Card.h +// Memify +// +// Created by Ryan Sickles on 7/23/14. +// Copyright (c) 2014 sickles.ryan. All rights reserved. +// + +#import + +@interface Card : NSObject + +@property (nonatomic, strong) UIImage *image; +@property (nonatomic, strong) UIImage *senderProPic; +@property (nonatomic, copy) NSString *senderName; + +- (instancetype)initWithName:(NSString *)senderName image:(UIImage *)image image:(UIImage *)senderProPic; +@end diff --git a/Memify/Card.m b/Memify/Card.m new file mode 100644 index 0000000..a2dbb1f --- /dev/null +++ b/Memify/Card.m @@ -0,0 +1,25 @@ +// +// Card.m +// Memify +// +// Created by Ryan Sickles on 7/23/14. +// Copyright (c) 2014 sickles.ryan. All rights reserved. +// + +#import "Card.h" + +@implementation Card + +#pragma mark - Object Lifecycle + +- (instancetype)initWithName:(NSString *)senderName image:(UIImage *)image image:(UIImage *)senderProPic{ + self = [super init]; + if (self) { + _senderName = senderName; + _image = image; + _senderProPic = senderProPic; + } + return self; +} + +@end diff --git a/Memify/CardView.h b/Memify/CardView.h new file mode 100644 index 0000000..de7cab2 --- /dev/null +++ b/Memify/CardView.h @@ -0,0 +1,18 @@ +// +// CardView.h +// Memify +// +// Created by Ryan Sickles on 7/23/14. +// Copyright (c) 2014 sickles.ryan. All rights reserved. +// + +#import +#import + +@class Card; + +@interface CardView : MDCSwipeToChooseView + +@property (nonatomic, strong, readonly) Card *card; +- (instancetype)initWithFrame:(CGRect)frame card:(Card *)card options:(MDCSwipeToChooseViewOptions *)options; +@end diff --git a/Memify/CardView.m b/Memify/CardView.m new file mode 100644 index 0000000..63eb66e --- /dev/null +++ b/Memify/CardView.m @@ -0,0 +1,114 @@ +// +// CardView.m +// Memify +// +// Created by Ryan Sickles on 7/23/14. +// Copyright (c) 2014 sickles.ryan. All rights reserved. +// + +#import "CardView.h" +#import "ImageView.h" +#import "Card.h" + +static const CGFloat ChoosePersonViewImageLabelWidth = 42.f; +@interface CardView () +@property (nonatomic, strong) UIView *informationView; +@property (nonatomic, strong) UILabel *nameLabel; +@property (nonatomic, strong) ImageView *cameraImageLabelView; +@property (nonatomic, strong) ImageView *interestsImageLabelView; +@property (nonatomic, strong) ImageView *friendsImageLabelView; +@end + +@implementation CardView + + +- (instancetype)initWithFrame:(CGRect)frame card:(Card *)card options:(MDCSwipeToChooseViewOptions *)options +{ + self = [super initWithFrame:frame]; + if (self) { + _card = card; + self.imageView.image = _card.image; + NSLog(@"THIS IS THE CARD IMAGE %@",_card); + self.autoresizingMask = UIViewAutoresizingFlexibleHeight | + UIViewAutoresizingFlexibleWidth | + UIViewAutoresizingFlexibleBottomMargin; + self.imageView.autoresizingMask = self.autoresizingMask; + + [self constructInformationView]; + } + return self; +} + +#pragma mark - Internal Methods + +- (void)constructInformationView { + CGFloat bottomHeight = 60.f; + CGRect bottomFrame = CGRectMake(0, + CGRectGetHeight(self.bounds) - bottomHeight, + CGRectGetWidth(self.bounds), + bottomHeight); + _informationView = [[UIView alloc] initWithFrame:bottomFrame]; + _informationView.backgroundColor = [UIColor whiteColor]; + _informationView.clipsToBounds = YES; + _informationView.autoresizingMask = UIViewAutoresizingFlexibleWidth | + UIViewAutoresizingFlexibleTopMargin; + [self addSubview:_informationView]; + + [self constructNameLabel]; + [self constructCameraImageLabelView]; + [self constructInterestsImageLabelView]; + [self constructFriendsImageLabelView]; +} + +- (void)constructNameLabel { + CGFloat leftPadding = 12.f; + CGFloat topPadding = 17.f; + CGRect frame = CGRectMake(leftPadding, + topPadding, + floorf(CGRectGetWidth(_informationView.frame)/2), + CGRectGetHeight(_informationView.frame) - topPadding); + _nameLabel = [[UILabel alloc] initWithFrame:frame]; + _nameLabel.text = [NSString stringWithFormat:@"%@",@"Sender Name"]; + [_informationView addSubview:_nameLabel]; +} + + +- (void)constructCameraImageLabelView { + CGFloat rightPadding = 10.f; + UIImage *image = [UIImage imageNamed:@"camera"]; + _cameraImageLabelView = [self buildImageLabelViewLeftOf:CGRectGetWidth(_informationView.bounds) - rightPadding + image:image + text:@"asdf"]; + [_informationView addSubview:_cameraImageLabelView]; +} + +- (void)constructInterestsImageLabelView { + UIImage *image = [UIImage imageNamed:@"book"]; + _interestsImageLabelView = [self buildImageLabelViewLeftOf:CGRectGetMinX(_cameraImageLabelView.frame) + image:image + text:@"asdf"]; + [_informationView addSubview:_interestsImageLabelView]; +} + +- (void)constructFriendsImageLabelView { + UIImage *image = [UIImage imageNamed:@"group"]; + _friendsImageLabelView = [self buildImageLabelViewLeftOf:CGRectGetMinX(_interestsImageLabelView.frame) + image:image + text:@"asdf"]; + [_informationView addSubview:_friendsImageLabelView]; +} + +- (ImageView *)buildImageLabelViewLeftOf:(CGFloat)x image:(UIImage *)image text:(NSString *)text { + CGRect frame = CGRectMake(x - ChoosePersonViewImageLabelWidth, + 0, + ChoosePersonViewImageLabelWidth, + CGRectGetHeight(_informationView.bounds)); + ImageView *view = [[ImageView alloc] initWithFrame:frame + image:image + text:text]; + view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; + return view; +} + + +@end diff --git a/Memify/FormViewController.h b/Memify/FormViewController.h index d77c6c4..bccb746 100644 --- a/Memify/FormViewController.h +++ b/Memify/FormViewController.h @@ -37,5 +37,6 @@ @property (strong,nonatomic) NSString *userId; @property (strong,nonatomic) NSString *media_reference; @property (strong,nonatomic) NSString *source_type; -@property (strong, nonatomic) IBOutlet NSString *message_text; +@property (strong, nonatomic) NSString *message_text; +@property (strong, nonatomic) NSDictionary *userData; @end diff --git a/Memify/FormViewController.m b/Memify/FormViewController.m index ac48e2e..3bd0f26 100644 --- a/Memify/FormViewController.m +++ b/Memify/FormViewController.m @@ -32,6 +32,8 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (void)viewDidLoad { [super viewDidLoad]; + self.message_text = @"Nothing was entered"; + self.source_type = @"Internet"; [self.taskBar addTarget:self action:@selector(taskBarAction:) forControlEvents:UIControlEventValueChanged]; FBRequest *request = [FBRequest requestForMe]; // Send request to Facebook @@ -273,13 +275,13 @@ -(void)saveImageSelectedtoUser:(UIImage*)image friends:(NSMutableArray *)friends //Picture is sent so remove all recipients! PFObject *card = [PFObject objectWithClassName:@"Cards"]; [card setObject:self.media_reference forKey:@"media_reference"]; + NSLog(@"he"); [card setObject:mediaType forKey:@"media_type"]; + NSLog(@"hi"); [card setObject:self.source_type forKey:@"source_type"]; + NSLog(@"ha"); [card setObject:self.message_text forKey:@"message"]; - //[card setObject:self.active_state forKey:@"active_state"]; add to homeview based on swipe - ////[card setObject:self.flipped forKey:@"flipped"]; add to homeview based on swipe - //[card setObject:[[PFUser currentUser] username] forKey:@"senderName"]; - + NSLog(@"hiii"); [card saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if(error){ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please Try Sending Picture Again" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; @@ -288,9 +290,19 @@ -(void)saveImageSelectedtoUser:(UIImage*)image friends:(NSMutableArray *)friends } else{ self.memeImage = nil; - //save to parse is successful! - //go to back to homepage - + //save Card to parse is successful now add cards to recipients + PFObject *junctionTable = [PFObject objectWithClassName:@"Junction"]; + FBRequest *request = [FBRequest requestForMe]; + [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { + self.userData = (NSDictionary *)result; + for (int arrayIndex=0; arrayIndex<[self.friendsList count]; arrayIndex++) { + [junctionTable setObject:self.userData[@"id"] forKey:@"SenderId"]; + [junctionTable setObject:[self.friendsList objectAtIndex:arrayIndex ] forKey:@"RecipientId"]; + [junctionTable setObject:card.objectId forKey:@"CardId"]; + [junctionTable saveEventually]; + } + + }]; } }]; } diff --git a/Memify/HomeViewController.h b/Memify/HomeViewController.h index 81d3243..1060061 100644 --- a/Memify/HomeViewController.h +++ b/Memify/HomeViewController.h @@ -11,9 +11,10 @@ #import "FormViewController.h" #import "DropAnimationController.h" #import +#import "CardView.h" @class LoginViewController; -@interface HomeViewController : UIViewController +@interface HomeViewController : UIViewController { NSMutableData *_imageData; LoginViewController *login; @@ -24,8 +25,12 @@ @property CGFloat boundsy; @property (nonatomic,strong) UIColor *mainColor; @property (nonatomic,strong) NSString *boldFontName; -@property (strong, nonatomic) IBOutlet UIImageView *cardImage; @property (strong, nonatomic) PFObject *firstImage; @property (strong,nonatomic) NSString *userId; -@property NSInteger *active_state; +@property (strong,nonatomic) NSNumber *active_state; +@property (strong,nonatomic) NSNumber *flipped; +//card properties +@property (nonatomic, strong) Card *currentCard; +@property (nonatomic, strong) CardView *frontCardView; +@property (nonatomic, strong) CardView *backCardView; @end diff --git a/Memify/HomeViewController.m b/Memify/HomeViewController.m index ddfa2b9..f08d496 100644 --- a/Memify/HomeViewController.m +++ b/Memify/HomeViewController.m @@ -10,10 +10,14 @@ #import #import "ADVAnimationController.h" #import +#import "Card.h" +#import +static const CGFloat ChoosePersonButtonHorizontalPadding = 80.f; +static const CGFloat ChoosePersonButtonVerticalPadding = 20.f; @interface HomeViewController () - +@property (nonatomic, strong) NSMutableArray *cards; @property (nonatomic, strong) id animationController; @end @@ -37,51 +41,166 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (void)viewDidLoad { [super viewDidLoad]; - FBRequest *request = [FBRequest requestForMe]; + self.active_state = 0; + self.flipped = 0; + [self createSendButton]; + self.cards = [[NSMutableArray alloc] init]; + [self getCardsFromServer]; + //got cards [self createLogOutButton]; self.view.backgroundColor = [UIColor colorWithRed:239.0/255 green:239.0/255 blue:239.0/255 alpha:1.0f]; - //make a request for data - // Send request to Facebook - [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { - if (!error) { - // result is a dictionary with the user's Facebook data - NSDictionary *userData = (NSDictionary *)result; -// NSString *facebookID = userData[@"id"]; - //add name if neccessary in cool font above image - NSString *name = userData[@"name"]; - float originx = ([UIScreen mainScreen].bounds.size.width/2) - 50; - float originy = ([UIScreen mainScreen].bounds.size.height/2) - 100; - UILabel *userName = [[UILabel alloc]initWithFrame:CGRectMake(originx, originy, 100.0 , 50.0)]; - userName.text = name; -// [self.view addSubview:userName]; - - // Now add the data to the UI elements - // ... - // Download the user's facebook profile picture - _imageData = [[NSMutableData alloc] init]; // the data will be loaded in here - - // URL should point to https://graph.facebook.com/{facebookId}/picture?type=large&return_ssl_resources=1 -// NSURL *pictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookID]]; -// -// NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:pictureURL -// cachePolicy:NSURLRequestUseProtocolCachePolicy -// timeoutInterval:2.0f]; - // Run network request asynchronously -// [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self]; - } - }]; } +- (NSUInteger)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskPortrait; +} +// This is called when a user didn't fully swipe left or right. +- (void)viewDidCancelSwipe:(UIView *)view { + NSLog(@"You couldn't decide on %@.", self.currentCard.senderName); +} + +// This is called then a user swipes the view fully left or right. +- (void)view:(UIView *)view wasChosenWithDirection:(MDCSwipeDirection)direction { + // MDCSwipeToChooseView shows "NOPE" on swipes to the left, + // and "LIKED" on swipes to the right. + if (direction == MDCSwipeDirectionLeft) { + NSLog(@"You noped %@.", self.currentCard.senderName); + } else { + NSLog(@"You liked %@.", self.currentCard.senderName); + } + + // MDCSwipeToChooseView removes the view from the view hierarchy + // after it is swiped (this behavior can be customized via the + // MDCSwipeOptions class). Since the front card view is gone, we + // move the back card to the front, and create a new back card. + self.frontCardView = self.backCardView; + if ((self.backCardView = [self popPersonViewWithFrame:[self backCardViewFrame]])) { + // Fade the back card into view. + self.backCardView.alpha = 0.f; + [self.view insertSubview:self.backCardView belowSubview:self.frontCardView]; + [UIView animateWithDuration:0.5 + delay:0.0 + options:UIViewAnimationOptionCurveEaseInOut + animations:^{ + self.backCardView.alpha = 1.f; + } completion:nil]; + } +} + +#pragma mark - Internal Methods + +- (void)setFrontCardView:(CardView *)frontCardView { + // Keep track of the person currently being chosen. + // Quick and dirty, just for the purposes of this sample app. + _frontCardView = frontCardView; + self.currentCard = frontCardView.card; +} + +- (CardView *)popPersonViewWithFrame:(CGRect)frame { + if ([self.cards count] == 0) { + return nil; + } + // UIView+MDCSwipeToChoose and MDCSwipeToChooseView are heavily customizable. + // Each take an "options" argument. Here, we specify the view controller as + // a delegate, and provide a custom callback that moves the back card view + // based on how far the user has panned the front card view. + MDCSwipeToChooseViewOptions *options = [MDCSwipeToChooseViewOptions new]; + options.delegate = self; + options.threshold = 160.f; + options.onPan = ^(MDCPanState *state){ + CGRect frame = [self backCardViewFrame]; + self.backCardView.frame = CGRectMake(frame.origin.x, + frame.origin.y - (state.thresholdRatio * 10.f), + CGRectGetWidth(frame), + CGRectGetHeight(frame)); + }; + + // Create a personView with the top person in the people array, then pop + // that person off the stack. + CardView *cardView = [[CardView alloc] initWithFrame:frame card:[self.cards objectAtIndex:0] options:options]; + [self.cards removeObjectAtIndex:0]; + return cardView; +} + +#pragma mark View Contruction + +- (CGRect)frontCardViewFrame { + CGFloat horizontalPadding = 20.f; + CGFloat topPadding = 60.f; + CGFloat bottomPadding = 200.f; + return CGRectMake(horizontalPadding, + topPadding, + CGRectGetWidth(self.view.frame) - (horizontalPadding * 2), + CGRectGetHeight(self.view.frame) - bottomPadding); +} + +- (CGRect)backCardViewFrame { + CGRect frontFrame = [self frontCardViewFrame]; + return CGRectMake(frontFrame.origin.x, + frontFrame.origin.y + 10.f, + CGRectGetWidth(frontFrame), + CGRectGetHeight(frontFrame)); +} + +// Create and add the "nope" button. +- (void)constructNopeButton { + UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + UIImage *image = [UIImage imageNamed:@"nope"]; + button.frame = CGRectMake(ChoosePersonButtonHorizontalPadding, + CGRectGetMaxY(self.backCardView.frame) + ChoosePersonButtonVerticalPadding, + image.size.width, + image.size.height); + [button setImage:image forState:UIControlStateNormal]; + [button setTintColor:[UIColor colorWithRed:247.f/255.f + green:91.f/255.f + blue:37.f/255.f + alpha:1.f]]; + [button addTarget:self + action:@selector(nopeFrontCardView) + forControlEvents:UIControlEventTouchUpInside]; + [self.view addSubview:button]; +} + +// Create and add the "like" button. +- (void)constructLikedButton { + UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + UIImage *image = [UIImage imageNamed:@"liked"]; + button.frame = CGRectMake(CGRectGetMaxX(self.view.frame) - image.size.width - ChoosePersonButtonHorizontalPadding, + CGRectGetMaxY(self.backCardView.frame) + ChoosePersonButtonVerticalPadding, + image.size.width, + image.size.height); + [button setImage:image forState:UIControlStateNormal]; + [button setTintColor:[UIColor colorWithRed:29.f/255.f + green:245.f/255.f + blue:106.f/255.f + alpha:1.f]]; + [button addTarget:self + action:@selector(likeFrontCardView) + forControlEvents:UIControlEventTouchUpInside]; + [self.view addSubview:button]; +} + +#pragma mark Control Events + +// Programmatically "nopes" the front card view. +- (void)nopeFrontCardView { + [self.frontCardView mdc_swipe:MDCSwipeDirectionLeft]; +} + +// Programmatically "likes" the front card view. +- (void)likeFrontCardView { + [self.frontCardView mdc_swipe:MDCSwipeDirectionRight]; +} + + --(void)viewWillAppear:(BOOL)animated{ - [super viewWillAppear:animated]; +-(void)getCardsFromServer{ FBRequest *request = [FBRequest requestForMe]; // Send request to Facebook [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (!error) { // result is a dictionary with the user's Facebook data NSDictionary *userData = (NSDictionary *)result; - NSLog(@"%@",userData); self.userId = userData[@"id"]; PFQuery *query = [PFQuery queryWithClassName:@"Cards"]; [query whereKey:@"recipientIds" equalTo:self.userId]; //change whereKey to senderID to see pics sent to self @@ -94,19 +213,14 @@ -(void)viewWillAppear:(BOOL)animated{ //need to view first card then delete it after swiped so always grabbing first card to view if([objects count]>0) { - self.firstImage = [objects objectAtIndex:0]; - PFFile *image = [self.firstImage objectForKey:@"file"]; - NSURL *imageFileUrl = [[NSURL alloc]initWithString:image.url]; - NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl]; - self.cardImage.image = [UIImage imageWithData:imageData]; - // self.messages = objects; - // [self.tableView reloadData]; + self.cards = (NSMutableArray *)objects; + NSLog(@"THIS IS THE OBJECTS ARRAY %@",self.cards); + [self initializeCards]; } else{ //there are no images } - [self createSendButton]; } }]; @@ -118,6 +232,49 @@ -(void)viewWillAppear:(BOOL)animated{ +-(void)cardSwiped +{ + PFObject *card = [PFObject objectWithClassName:@"Cards"]; + [card setObject:self.active_state forKey:@"active_state"]; + [card setObject:self.flipped forKey:@"flipped"]; + [card saveEventually]; +} + + +- (void)initializeCards { + // It would be trivial to download these from a web service + // as needed, but for the purposes of this sample app we'll + // simply store them in memory. + NSMutableArray *cards = [[NSMutableArray alloc]init]; + PFFile *image = [self.cards[0] objectForKey:@"file"]; + NSString *senderName = [self.cards[0] objectForKey:@"senderId"]; + NSURL *imageFileUrl = [[NSURL alloc]initWithString:image.url]; + NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl]; + + Card *first_card = [[Card alloc] initWithName:senderName image:[UIImage imageWithData:imageData] image:[UIImage imageWithData:imageData]]; + [cards addObject:first_card]; + self.cards = cards; + //set up cards + // Display the first ChoosePersonView in front. Users can swipe to indicate + // whether they like or dislike the person displayed. + self.frontCardView = [self popPersonViewWithFrame:[self frontCardViewFrame]]; + NSLog(@"THIS IS THE FIRST PIC %@",self.frontCardView); + [self.view addSubview:self.frontCardView]; + + // Display the second ChoosePersonView in back. This view controller uses + // the MDCSwipeToChooseDelegate protocol methods to update the front and + // back views after each user swipe. + self.backCardView = [self popPersonViewWithFrame:[self backCardViewFrame]]; + [self.view insertSubview:self.backCardView belowSubview:self.frontCardView]; + + // Add buttons to programmatically swipe the view left or right. + // See the `nopeFrontCardView` and `likeFrontCardView` methods. + [self constructNopeButton]; + [self constructLikedButton]; + [self createSendButton]; +} + + -(void)createLogOutButton { //add log out button @@ -144,10 +301,10 @@ -(void)createSendButton memeButton.titleLabel.font = [UIFont fontWithName:self.boldFontName size:20.0f]; [memeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [memeButton setTitleColor:[UIColor colorWithWhite:1.0f alpha:0.5f] forState:UIControlStateHighlighted]; - NSLog(@"%@",self.firstImage); - if(self.firstImage != nil)//has any meme cards in inbox + if([self.cards count] > 0)//has any meme cards in inbox { //display send button below cards + NSLog(@"MORE"); memeButton.frame = CGRectMake(self.boundsx/2-75, self.boundsy-(self.boundsy/4)+50, 150.0, 50.0); } else{ @@ -157,30 +314,6 @@ -(void)createSendButton [self.view addSubview:memeButton]; } -// Called every time a chunk of the data is received -- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { - [_imageData appendData:data]; // Build the image -} - -// Called when the entire profile image is finished downloading -- (void)connectionDidFinishLoading:(NSURLConnection *)connection { - // Set the image in the header imageView should be in top middle - float originx = ([UIScreen mainScreen].bounds.size.width/2) - 50; - float originy = ([UIScreen mainScreen].bounds.size.height/2) - 50; - //get image - UIImage *proPicImage = [UIImage imageWithData:_imageData]; - //make button with image - UIButton *profileButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; - [profileButton setBackgroundImage:proPicImage forState:UIControlStateNormal]; - profileButton.frame = CGRectMake(originx,originy,100,100); - [profileButton addTarget:self action:@selector(friendList:) forControlEvents:UIControlEventTouchUpInside]; - //make image rounded - profileButton.layer.cornerRadius = profileButton.frame.size.height /2; - profileButton.layer.masksToBounds = YES; - profileButton.layer.borderWidth = 0; -// [self.view addSubview:profileButton]; -} - - (IBAction)friendList:(id)sender { NSLog(@"To Friends List!"); } diff --git a/Memify/HomeViewController.xib b/Memify/HomeViewController.xib index dcc9138..0e5a0b2 100644 --- a/Memify/HomeViewController.xib +++ b/Memify/HomeViewController.xib @@ -6,7 +6,6 @@ - @@ -14,12 +13,6 @@ - - - - - - diff --git a/Memify/ImageView.h b/Memify/ImageView.h new file mode 100644 index 0000000..acca80f --- /dev/null +++ b/Memify/ImageView.h @@ -0,0 +1,16 @@ +// +// ImageView.h +// Memify +// +// Created by Ryan Sickles on 7/23/14. +// Copyright (c) 2014 sickles.ryan. All rights reserved. +// + +#import + +@interface ImageView : UIView + + +- (id)initWithFrame:(CGRect)frame image:(UIImage *)image text:(NSString *)text; + +@end diff --git a/Memify/ImageView.m b/Memify/ImageView.m new file mode 100644 index 0000000..a85cd37 --- /dev/null +++ b/Memify/ImageView.m @@ -0,0 +1,56 @@ +// +// ImageView.m +// Memify +// +// Created by Ryan Sickles on 7/23/14. +// Copyright (c) 2014 sickles.ryan. All rights reserved. +// + +#import "ImageView.h" + +@interface ImageView () +@property (nonatomic, strong) UIImageView *imageView; +@property (nonatomic, strong) UILabel *label; +@end + +@implementation ImageView + +- (id)initWithFrame:(CGRect)frame image:(UIImage *)image text:(NSString *)text +{ + self = [super initWithFrame:frame]; + if (self) { + NSLog(@"HJEOLLLOOO"); + [self constructImageView:image]; + [self constructLabel:text]; + } + return self; +} + +#pragma mark - Internal Methods + +- (void)constructImageView:(UIImage *)image { + CGFloat topPadding = 10.f; + CGRect frame = CGRectMake(floorf((CGRectGetWidth(self.bounds) - image.size.width)/2), + topPadding, + image.size.width, + image.size.height); + self.imageView = [[UIImageView alloc] initWithFrame:frame]; + self.imageView.image = image; + [self addSubview:self.imageView]; +} + +- (void)constructLabel:(NSString *)text { + CGFloat height = 18.f; + CGRect frame = CGRectMake(0, + CGRectGetMaxY(self.imageView.frame), + CGRectGetWidth(self.bounds), + height); + self.label = [[UILabel alloc] initWithFrame:frame]; + self.label.text = text; + self.label.textAlignment = NSTextAlignmentCenter; + [self addSubview:self.label]; +} + + + +@end