2012-07-02 15:41:16 -07:00
|
|
|
//
|
2012-07-09 21:13:06 -07:00
|
|
|
// ProfileBadge.m
|
2012-07-02 15:41:16 -07:00
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Roy Yang on 7/2/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2012-07-09 21:13:06 -07:00
|
|
|
#import "ProfileBadge.h"
|
2012-07-02 15:41:16 -07:00
|
|
|
#import "NewsBlurAppDelegate.h"
|
2012-07-03 11:05:19 -07:00
|
|
|
#import "Utilities.h"
|
2012-07-31 00:53:16 -07:00
|
|
|
#import "UIImageView+AFNetworking.h"
|
2012-07-13 14:35:39 -07:00
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2012-07-02 15:41:16 -07:00
|
|
|
|
2012-07-13 14:21:55 -07:00
|
|
|
#define kTopBadgeHeight 125
|
2012-07-31 00:53:16 -07:00
|
|
|
#define kTopBadgeTextXCoordinate 100
|
2012-08-09 16:34:59 -07:00
|
|
|
#define kFollowColor 0x0a6720
|
|
|
|
#define kFollowTextColor 0xffffff
|
|
|
|
#define kFollowingColor 0xcccccc
|
|
|
|
#define kFollowingTextColor 0x333333
|
2012-07-13 14:21:55 -07:00
|
|
|
|
2012-08-08 19:31:33 -07:00
|
|
|
@interface ProfileBadge ()
|
2012-08-09 16:34:59 -07:00
|
|
|
|
|
|
|
@property (readwrite) int moduleWidth;
|
|
|
|
@property (readwrite) BOOL shouldShowStats;
|
2012-08-08 19:31:33 -07:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2012-07-09 21:13:06 -07:00
|
|
|
@implementation ProfileBadge
|
2012-07-02 15:41:16 -07:00
|
|
|
|
2012-08-09 16:34:59 -07:00
|
|
|
@synthesize shouldShowStats;
|
2012-07-02 15:41:16 -07:00
|
|
|
@synthesize appDelegate;
|
|
|
|
@synthesize userAvatar;
|
2012-07-03 17:54:36 -07:00
|
|
|
@synthesize username;
|
2012-07-02 15:41:16 -07:00
|
|
|
@synthesize userLocation;
|
|
|
|
@synthesize userDescription;
|
|
|
|
@synthesize userStats;
|
|
|
|
@synthesize followButton;
|
2012-07-03 17:54:36 -07:00
|
|
|
@synthesize activeProfile;
|
|
|
|
@synthesize activityIndicator;
|
2012-08-08 19:31:33 -07:00
|
|
|
@synthesize moduleWidth;
|
2012-07-02 15:41:16 -07:00
|
|
|
|
|
|
|
|
2012-07-31 00:53:16 -07:00
|
|
|
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
|
|
|
|
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
|
|
userAvatar = nil;
|
|
|
|
username = nil;
|
|
|
|
userLocation = nil;
|
|
|
|
userDescription = nil;
|
|
|
|
userStats = nil;
|
|
|
|
followButton = nil;
|
|
|
|
activeProfile = nil;
|
|
|
|
activityIndicator = nil;
|
2012-07-02 15:41:16 -07:00
|
|
|
}
|
2012-07-31 00:53:16 -07:00
|
|
|
|
2012-07-02 15:41:16 -07:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-07-31 00:53:16 -07:00
|
|
|
|
2012-07-02 15:41:16 -07:00
|
|
|
/*
|
|
|
|
// Only override drawRect: if you perform custom drawing.
|
|
|
|
// An empty implementation adversely affects performance during animation.
|
|
|
|
- (void)drawRect:(CGRect)rect
|
|
|
|
{
|
|
|
|
// Drawing code
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
- (void)layoutSubviews {
|
2012-07-03 17:54:36 -07:00
|
|
|
[super layoutSubviews];
|
2012-07-03 11:05:19 -07:00
|
|
|
}
|
|
|
|
|
2012-08-08 19:31:33 -07:00
|
|
|
- (void)refreshWithProfile:(NSDictionary *)profile showStats:(BOOL)showStats withWidth:(int)newWidth {
|
|
|
|
int width;
|
|
|
|
|
|
|
|
if (newWidth) {
|
|
|
|
width = newWidth;
|
|
|
|
self.moduleWidth = newWidth;
|
|
|
|
} else {
|
|
|
|
width = self.moduleWidth;
|
|
|
|
for (UIView *subview in [self.contentView subviews]) {
|
|
|
|
[subview removeFromSuperview];
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 16:34:59 -07:00
|
|
|
|
2015-12-07 16:09:49 -08:00
|
|
|
self.backgroundColor = UIColorFromRGB(NEWSBLUR_WHITE_COLOR);
|
|
|
|
|
2012-08-09 16:34:59 -07:00
|
|
|
if (showStats) {
|
|
|
|
shouldShowStats = showStats;
|
|
|
|
}
|
2012-07-03 17:54:36 -07:00
|
|
|
self.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
|
|
|
|
self.activeProfile = profile;
|
2012-07-03 11:05:19 -07:00
|
|
|
int yCoordinatePointer = 0;
|
2012-07-31 00:53:16 -07:00
|
|
|
|
2012-07-13 16:02:21 -07:00
|
|
|
// AVATAR
|
|
|
|
NSString *photo_url = [profile objectForKey:@"photo_url"];
|
|
|
|
|
|
|
|
if ([photo_url rangeOfString:@"graph.facebook.com"].location != NSNotFound) {
|
|
|
|
photo_url = [photo_url stringByAppendingFormat:@"?type=large"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([photo_url rangeOfString:@"twimg"].location != NSNotFound) {
|
|
|
|
photo_url = [photo_url stringByReplacingOccurrencesOfString:@"_normal" withString:@""];
|
|
|
|
}
|
|
|
|
|
2012-08-13 22:48:50 -07:00
|
|
|
// UIImage *placeholder = [UIImage imageNamed:@"user_light"];
|
2012-07-31 00:53:16 -07:00
|
|
|
UIImageView *avatar = [[UIImageView alloc] init];
|
|
|
|
avatar.frame = CGRectMake(10, 10, 80, 80);
|
|
|
|
|
|
|
|
[avatar setImageWithURL:[NSURL URLWithString:photo_url]
|
2012-08-13 22:48:50 -07:00
|
|
|
placeholderImage:nil];
|
2012-07-13 16:02:21 -07:00
|
|
|
|
|
|
|
// scale and crop image
|
|
|
|
[avatar setContentMode:UIViewContentModeScaleAspectFill];
|
|
|
|
[avatar setClipsToBounds:YES];
|
2012-07-31 00:53:16 -07:00
|
|
|
[self.contentView addSubview:avatar];
|
2012-07-13 16:02:21 -07:00
|
|
|
|
2012-07-31 00:53:16 -07:00
|
|
|
// username
|
|
|
|
UILabel *user = [[UILabel alloc] initWithFrame:CGRectZero];
|
2015-12-07 16:09:49 -08:00
|
|
|
user.textColor = UIColorFromFixedRGB(NEWSBLUR_LINK_COLOR);
|
2012-07-31 00:53:16 -07:00
|
|
|
user.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
|
|
|
|
user.backgroundColor = [UIColor clearColor];
|
|
|
|
self.username = user;
|
|
|
|
self.username.frame = CGRectMake(kTopBadgeTextXCoordinate, 10, width - kTopBadgeTextXCoordinate - 10, 22);
|
|
|
|
self.username.text = [profile objectForKey:@"username"];
|
|
|
|
[self.contentView addSubview:username];
|
2012-07-13 16:02:21 -07:00
|
|
|
|
|
|
|
// FOLLOW BUTTON
|
2012-08-09 16:34:59 -07:00
|
|
|
UIButton *follow = [UIButton buttonWithType:UIButtonTypeCustom];
|
2012-07-31 00:53:16 -07:00
|
|
|
follow.frame = CGRectMake(10, 96, 80, 24);
|
2012-07-13 16:02:21 -07:00
|
|
|
|
2015-12-07 16:09:49 -08:00
|
|
|
follow.layer.borderColor = UIColorFromRGB(0x808080).CGColor;
|
2012-08-09 16:34:59 -07:00
|
|
|
follow.layer.borderWidth = 0.5f;
|
|
|
|
follow.layer.cornerRadius = 10.0f;
|
|
|
|
|
2015-12-07 16:09:49 -08:00
|
|
|
[follow setTitleColor:UIColorFromFixedRGB(kFollowTextColor) forState:UIControlStateNormal];
|
|
|
|
follow.backgroundColor = UIColorFromFixedRGB(kFollowColor);
|
2012-08-09 16:34:59 -07:00
|
|
|
|
2012-07-28 15:37:03 -07:00
|
|
|
// check follow button status
|
2012-08-09 10:18:15 -07:00
|
|
|
if ([[profile objectForKey:@"yourself"] intValue]) {
|
2012-07-13 16:02:21 -07:00
|
|
|
[follow setTitle:@"You" forState:UIControlStateNormal];
|
|
|
|
follow.enabled = NO;
|
2012-07-28 15:37:03 -07:00
|
|
|
} else if ([[profile objectForKey:@"followed_by_you"] intValue]) {
|
2012-07-13 16:02:21 -07:00
|
|
|
[follow setTitle:@"Following" forState:UIControlStateNormal];
|
2015-12-07 16:09:49 -08:00
|
|
|
follow.backgroundColor = UIColorFromFixedRGB(kFollowingColor);
|
|
|
|
[follow setTitleColor:UIColorFromFixedRGB(kFollowingTextColor) forState:UIControlStateNormal];
|
2012-07-13 16:02:21 -07:00
|
|
|
} else {
|
|
|
|
[follow setTitle:@"Follow" forState:UIControlStateNormal];
|
|
|
|
}
|
|
|
|
|
|
|
|
follow.titleLabel.font = [UIFont systemFontOfSize:12];
|
|
|
|
[follow addTarget:self
|
|
|
|
action:@selector(doFollowButton:)
|
|
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
|
|
self.followButton = follow;
|
2012-07-31 00:53:16 -07:00
|
|
|
[self.contentView addSubview:self.followButton];
|
2012-07-13 16:02:21 -07:00
|
|
|
|
|
|
|
// ACTIVITY INDICATOR
|
|
|
|
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
2012-08-02 00:57:01 -07:00
|
|
|
activityView.frame = CGRectMake(40, 98, 20, 20.0);
|
2012-07-13 16:02:21 -07:00
|
|
|
self.activityIndicator = activityView;
|
2012-08-02 00:57:01 -07:00
|
|
|
|
2012-07-31 00:53:16 -07:00
|
|
|
[self.contentView addSubview:self.activityIndicator];
|
2012-07-13 16:02:21 -07:00
|
|
|
|
2012-07-03 17:54:36 -07:00
|
|
|
yCoordinatePointer = self.username.frame.origin.y + self.username.frame.size.height;
|
2012-07-13 14:21:55 -07:00
|
|
|
|
2012-07-03 17:54:36 -07:00
|
|
|
// BIO
|
2012-07-03 11:05:19 -07:00
|
|
|
if ([profile objectForKey:@"bio"] != [NSNull null]) {
|
|
|
|
UILabel *bio = [[UILabel alloc]
|
2012-07-13 16:02:21 -07:00
|
|
|
initWithFrame:CGRectMake(kTopBadgeTextXCoordinate,
|
2012-07-03 11:05:19 -07:00
|
|
|
yCoordinatePointer,
|
2012-07-31 00:53:16 -07:00
|
|
|
width - kTopBadgeTextXCoordinate - 10,
|
2012-07-13 14:21:55 -07:00
|
|
|
60)];
|
2012-07-03 11:05:19 -07:00
|
|
|
bio.text = [profile objectForKey:@"bio"];
|
2012-07-13 14:21:55 -07:00
|
|
|
bio.textColor = UIColorFromRGB(0x333333);
|
2012-07-03 17:54:36 -07:00
|
|
|
bio.font = [UIFont fontWithName:@"Helvetica" size:12];
|
2013-06-17 11:50:13 -07:00
|
|
|
bio.lineBreakMode = NSLineBreakByTruncatingTail;
|
2012-07-13 14:21:55 -07:00
|
|
|
bio.numberOfLines = 5;
|
|
|
|
bio.backgroundColor = [UIColor clearColor];
|
2012-07-11 18:08:07 -07:00
|
|
|
|
|
|
|
// Calculate the expected size based on the font and linebreak mode of your label
|
2012-07-31 00:53:16 -07:00
|
|
|
CGSize maximumLabelSize = CGSizeMake(width - kTopBadgeTextXCoordinate - 10, 60);
|
2013-09-25 17:43:00 -07:00
|
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
|
|
|
|
paragraphStyle.lineBreakMode = bio.lineBreakMode;
|
2012-07-13 14:21:55 -07:00
|
|
|
CGSize expectedLabelSize = [bio.text
|
2013-09-25 17:43:00 -07:00
|
|
|
boundingRectWithSize:maximumLabelSize
|
2016-10-05 21:03:32 -07:00
|
|
|
options:0
|
2013-09-25 17:43:00 -07:00
|
|
|
attributes:@{NSFontAttributeName: bio.font,
|
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}
|
|
|
|
context:nil].size;
|
2012-07-11 18:08:07 -07:00
|
|
|
CGRect newFrame = bio.frame;
|
|
|
|
newFrame.size.height = expectedLabelSize.height;
|
|
|
|
bio.frame = newFrame;
|
|
|
|
|
2012-07-03 11:05:19 -07:00
|
|
|
self.userDescription = bio;
|
2012-07-31 00:53:16 -07:00
|
|
|
[self.contentView addSubview:self.userDescription];
|
2012-07-13 14:21:55 -07:00
|
|
|
yCoordinatePointer = yCoordinatePointer + self.userDescription.frame.size.height + 6;
|
2012-07-03 11:05:19 -07:00
|
|
|
}
|
|
|
|
|
2012-07-13 14:21:55 -07:00
|
|
|
// LOCATION
|
2012-08-09 10:18:15 -07:00
|
|
|
if ([profile objectForKey:@"location"] != [NSNull null] &&
|
|
|
|
[[profile objectForKey:@"location"] length]) {
|
2012-07-13 14:21:55 -07:00
|
|
|
UILabel *location = [[UILabel alloc]
|
2012-07-15 23:04:26 -07:00
|
|
|
initWithFrame:CGRectMake(kTopBadgeTextXCoordinate + 16,
|
2012-07-13 14:21:55 -07:00
|
|
|
yCoordinatePointer,
|
2012-08-10 18:10:07 -07:00
|
|
|
width - kTopBadgeTextXCoordinate - 10 - 16,
|
2012-07-13 14:21:55 -07:00
|
|
|
20)];
|
|
|
|
location.text = [profile objectForKey:@"location"];
|
|
|
|
location.textColor = UIColorFromRGB(0x666666);
|
|
|
|
location.backgroundColor = [UIColor clearColor];
|
|
|
|
location.font = [UIFont fontWithName:@"Helvetica" size:12];
|
|
|
|
self.userLocation = location;
|
2012-07-31 00:53:16 -07:00
|
|
|
[self.contentView addSubview:self.userLocation];
|
2012-07-13 14:21:55 -07:00
|
|
|
|
2012-07-15 23:04:26 -07:00
|
|
|
UIImage *locationIcon = [UIImage imageNamed:@"7-location-place.png"];
|
2012-07-13 14:21:55 -07:00
|
|
|
UIImageView *locationIconView = [[UIImageView alloc] initWithImage:locationIcon];
|
2015-05-19 10:55:26 -07:00
|
|
|
locationIconView.frame = CGRectMake(kTopBadgeTextXCoordinate,
|
2012-07-13 14:21:55 -07:00
|
|
|
yCoordinatePointer + 2,
|
|
|
|
16,
|
|
|
|
16);
|
2012-07-31 00:53:16 -07:00
|
|
|
[self.contentView addSubview:locationIconView];
|
2012-07-13 14:21:55 -07:00
|
|
|
}
|
|
|
|
|
2012-08-09 16:34:59 -07:00
|
|
|
if (shouldShowStats) {
|
2012-07-31 00:53:16 -07:00
|
|
|
UIView *horizontalBar = [[UIView alloc] initWithFrame:CGRectMake(0, kTopBadgeHeight, width, 1)];
|
2015-12-07 16:09:49 -08:00
|
|
|
horizontalBar.backgroundColor = UIColorFromRGB(0xCBCBCB);
|
2012-07-31 00:53:16 -07:00
|
|
|
[self.contentView addSubview:horizontalBar];
|
|
|
|
|
|
|
|
UIView *leftVerticalBar = [[UIView alloc] initWithFrame:CGRectMake((width/3), kTopBadgeHeight, 1, 55)];
|
2015-12-07 16:09:49 -08:00
|
|
|
leftVerticalBar.backgroundColor = UIColorFromRGB(0xCBCBCB);
|
2012-07-31 00:53:16 -07:00
|
|
|
[self.contentView addSubview:leftVerticalBar];
|
|
|
|
|
|
|
|
UIView *rightVerticalBar = [[UIView alloc] initWithFrame:CGRectMake((width/3) * 2, kTopBadgeHeight, 1, 55)];
|
2015-12-07 16:09:49 -08:00
|
|
|
rightVerticalBar.backgroundColor = UIColorFromRGB(0xCBCBCB);
|
2012-07-31 00:53:16 -07:00
|
|
|
[self.contentView addSubview:rightVerticalBar];
|
|
|
|
|
|
|
|
// Shared
|
|
|
|
UILabel *shared = [[UILabel alloc] initWithFrame:CGRectMake(0, kTopBadgeHeight + 10, (width/3), 20)];
|
|
|
|
NSString *sharedStr = [NSString stringWithFormat:@"%i",
|
|
|
|
[[profile objectForKey:@"shared_stories_count"] intValue]];
|
|
|
|
shared.text = sharedStr;
|
2013-06-17 11:50:13 -07:00
|
|
|
shared.textAlignment = NSTextAlignmentCenter;
|
2012-07-31 00:53:16 -07:00
|
|
|
shared.font = [UIFont boldSystemFontOfSize:20];
|
2015-12-07 16:09:49 -08:00
|
|
|
shared.textColor = UIColorFromRGB(NEWSBLUR_BLACK_COLOR);
|
2012-07-31 00:53:16 -07:00
|
|
|
shared.backgroundColor = [UIColor clearColor];
|
|
|
|
[self.contentView addSubview:shared];
|
|
|
|
|
|
|
|
UILabel *sharedLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, kTopBadgeHeight + 30, (width/3), 20)];
|
|
|
|
NSString *sharedLabelStr = [NSString stringWithFormat:@"Shared Stor%@",
|
|
|
|
[[profile objectForKey:@"shared_stories_count"] intValue] == 1 ? @"y" : @"ies"];
|
|
|
|
sharedLabel.text = sharedLabelStr;
|
2013-06-17 11:50:13 -07:00
|
|
|
sharedLabel.textAlignment = NSTextAlignmentCenter;
|
2012-07-31 00:53:16 -07:00
|
|
|
sharedLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
|
2015-12-07 16:09:49 -08:00
|
|
|
sharedLabel.textColor = UIColorFromRGB(NEWSBLUR_BLACK_COLOR);
|
2012-07-31 00:53:16 -07:00
|
|
|
sharedLabel.backgroundColor = [UIColor clearColor];
|
|
|
|
[self.contentView addSubview:sharedLabel];
|
|
|
|
|
|
|
|
|
|
|
|
// Following
|
|
|
|
UILabel *following = [[UILabel alloc] initWithFrame:CGRectMake((width/3), kTopBadgeHeight + 10, (width/3), 20)];
|
|
|
|
NSString *followingStr = [NSString stringWithFormat:@"%i",
|
|
|
|
[[profile objectForKey:@"following_count"] intValue]];
|
|
|
|
following.text = followingStr;
|
2013-06-17 11:50:13 -07:00
|
|
|
following.textAlignment = NSTextAlignmentCenter;
|
2012-07-31 00:53:16 -07:00
|
|
|
following.font = [UIFont boldSystemFontOfSize:20];
|
2015-12-07 16:09:49 -08:00
|
|
|
following.textColor = UIColorFromRGB(NEWSBLUR_BLACK_COLOR);
|
2012-07-31 00:53:16 -07:00
|
|
|
following.backgroundColor = [UIColor clearColor];
|
|
|
|
[self.contentView addSubview:following];
|
|
|
|
|
|
|
|
UILabel *followingLabel = [[UILabel alloc] initWithFrame:CGRectMake((width/3), kTopBadgeHeight + 30, (width/3), 20)];
|
|
|
|
NSString *followingLabelStr = [NSString stringWithFormat:@"Following"];
|
|
|
|
followingLabel.text = followingLabelStr;
|
2013-06-17 11:50:13 -07:00
|
|
|
followingLabel.textAlignment = NSTextAlignmentCenter;
|
2012-07-31 00:53:16 -07:00
|
|
|
followingLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
|
2015-12-07 16:09:49 -08:00
|
|
|
followingLabel.textColor = UIColorFromRGB(NEWSBLUR_BLACK_COLOR);
|
2012-07-31 00:53:16 -07:00
|
|
|
followingLabel.backgroundColor = [UIColor clearColor];
|
|
|
|
[self.contentView addSubview:followingLabel];
|
|
|
|
|
|
|
|
|
|
|
|
// Followers
|
|
|
|
UILabel *followers = [[UILabel alloc] initWithFrame:CGRectMake((width/3) * 2, kTopBadgeHeight + 10, (width/3), 20)];
|
|
|
|
NSString *followersStr = [NSString stringWithFormat:@"%i",
|
|
|
|
[[profile objectForKey:@"follower_count"] intValue]];
|
|
|
|
followers.text = followersStr;
|
2013-06-17 11:50:13 -07:00
|
|
|
followers.textAlignment = NSTextAlignmentCenter;
|
2012-07-31 00:53:16 -07:00
|
|
|
followers.font = [UIFont boldSystemFontOfSize:20];
|
2015-12-07 16:09:49 -08:00
|
|
|
followers.textColor = UIColorFromRGB(NEWSBLUR_BLACK_COLOR);
|
2012-07-31 00:53:16 -07:00
|
|
|
followers.backgroundColor = [UIColor clearColor];
|
|
|
|
[self.contentView addSubview:followers];
|
|
|
|
|
|
|
|
UILabel *followersLabel = [[UILabel alloc] initWithFrame:CGRectMake((width/3) * 2, kTopBadgeHeight + 30, (width/3), 20)];
|
|
|
|
NSString *followersLabelStr = [NSString stringWithFormat:@"Follower%@",
|
|
|
|
[[profile objectForKey:@"follower_count"] intValue] == 1 ? @"" : @"s"];
|
|
|
|
followersLabel.text = followersLabelStr;
|
2013-06-17 11:50:13 -07:00
|
|
|
followersLabel.textAlignment = NSTextAlignmentCenter;
|
2012-07-31 00:53:16 -07:00
|
|
|
followersLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
|
2015-12-07 16:09:49 -08:00
|
|
|
followersLabel.textColor = UIColorFromRGB(NEWSBLUR_BLACK_COLOR);
|
2012-07-31 00:53:16 -07:00
|
|
|
followersLabel.backgroundColor = [UIColor clearColor];
|
|
|
|
[self.contentView addSubview:followersLabel];
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:21:55 -07:00
|
|
|
|
2012-07-03 17:54:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initProfile {
|
|
|
|
for(UIView *subview in [self subviews]) {
|
|
|
|
[subview removeFromSuperview];
|
|
|
|
|
|
|
|
}
|
2012-07-03 11:05:19 -07:00
|
|
|
}
|
|
|
|
|
2012-07-03 17:54:36 -07:00
|
|
|
- (void)doFollowButton:(id)sender {
|
|
|
|
NSString *urlString;
|
|
|
|
|
|
|
|
[self.activityIndicator startAnimating];
|
|
|
|
|
2012-07-09 21:13:06 -07:00
|
|
|
if ([self.followButton.currentTitle isEqualToString:@"Follow"]) {
|
2013-06-18 21:23:20 -04:00
|
|
|
urlString = [NSString stringWithFormat:@"%@/social/follow",
|
2016-01-21 22:11:37 -08:00
|
|
|
self.appDelegate.url];
|
2012-07-03 17:54:36 -07:00
|
|
|
} else {
|
2013-06-18 21:23:20 -04:00
|
|
|
urlString = [NSString stringWithFormat:@"%@/social/unfollow",
|
2016-01-21 22:11:37 -08:00
|
|
|
self.appDelegate.url];
|
2012-07-03 17:54:36 -07:00
|
|
|
}
|
|
|
|
|
2017-03-28 10:02:34 -07:00
|
|
|
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
2017-03-19 12:09:49 -07:00
|
|
|
[params setObject:[self.activeProfile objectForKey:@"user_id"] forKey:@"user_id"];
|
2012-07-09 21:13:06 -07:00
|
|
|
|
2019-08-22 12:03:39 -07:00
|
|
|
[appDelegate POST:urlString parameters:params success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
2017-03-28 10:02:34 -07:00
|
|
|
if ([self.followButton.currentTitle isEqualToString:@"Follow"]) {
|
|
|
|
[self finishFollowing:responseObject];
|
|
|
|
} else {
|
|
|
|
[self finishUnfollowing:responseObject];
|
|
|
|
}
|
|
|
|
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
|
|
|
[self requestFailed:error];
|
|
|
|
}];
|
2012-07-02 15:41:16 -07:00
|
|
|
}
|
2012-07-03 17:54:36 -07:00
|
|
|
|
2017-03-28 10:02:34 -07:00
|
|
|
- (void)finishFollowing:(NSDictionary *)results {
|
2012-07-03 17:54:36 -07:00
|
|
|
[self.activityIndicator stopAnimating];
|
2012-07-09 21:13:06 -07:00
|
|
|
|
2012-07-03 17:54:36 -07:00
|
|
|
int code = [[results valueForKey:@"code"] intValue];
|
|
|
|
if (code == -1) {
|
|
|
|
NSLog(@"ERROR");
|
|
|
|
return;
|
|
|
|
}
|
2012-07-02 15:41:16 -07:00
|
|
|
|
2012-07-03 17:54:36 -07:00
|
|
|
[self.followButton setTitle:@"Following" forState:UIControlStateNormal];
|
2015-12-07 16:09:49 -08:00
|
|
|
self.followButton.backgroundColor = UIColorFromFixedRGB(kFollowColor);
|
|
|
|
[self.followButton setTitleColor:UIColorFromFixedRGB(kFollowTextColor) forState:UIControlStateNormal];
|
2012-08-03 00:13:56 -07:00
|
|
|
[appDelegate reloadFeedsView:NO];
|
2012-08-08 19:31:33 -07:00
|
|
|
|
|
|
|
NSMutableDictionary *newProfile = [self.activeProfile mutableCopy];
|
|
|
|
NSNumber *count = [newProfile objectForKey:@"follower_count"];
|
|
|
|
int value = [count intValue];
|
|
|
|
count = [NSNumber numberWithInt:value + 1];
|
|
|
|
|
|
|
|
[newProfile setObject:count forKey:@"follower_count"];
|
|
|
|
[newProfile setObject:[NSNumber numberWithInt:1] forKey:@"followed_by_you"];
|
2012-08-10 18:10:07 -07:00
|
|
|
[self refreshWithProfile:newProfile showStats:self.shouldShowStats withWidth:0];
|
2012-07-03 17:54:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-28 10:02:34 -07:00
|
|
|
- (void)finishUnfollowing:(NSDictionary *)results {
|
2012-07-03 17:54:36 -07:00
|
|
|
[self.activityIndicator stopAnimating];
|
2017-03-28 10:02:34 -07:00
|
|
|
|
2012-07-03 17:54:36 -07:00
|
|
|
int code = [[results valueForKey:@"code"] intValue];
|
|
|
|
if (code == -1) {
|
|
|
|
NSLog(@"ERROR");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSLog(@"results %@", results);
|
|
|
|
[self.followButton setTitle:@"Follow" forState:UIControlStateNormal];
|
2015-12-07 16:09:49 -08:00
|
|
|
self.followButton.backgroundColor = UIColorFromFixedRGB(kFollowingColor);
|
|
|
|
[self.followButton setTitleColor:UIColorFromFixedRGB(kFollowingTextColor) forState:UIControlStateNormal];
|
2012-08-09 16:34:59 -07:00
|
|
|
|
2012-08-03 00:13:56 -07:00
|
|
|
[appDelegate reloadFeedsView:NO];
|
2012-08-08 19:31:33 -07:00
|
|
|
|
|
|
|
NSMutableDictionary *newProfile = [self.activeProfile mutableCopy];
|
|
|
|
NSNumber *count = [newProfile objectForKey:@"follower_count"];
|
|
|
|
int value = [count intValue];
|
|
|
|
count = [NSNumber numberWithInt:value - 1];
|
|
|
|
|
|
|
|
[newProfile setObject:count forKey:@"follower_count"];
|
|
|
|
[newProfile setObject:[NSNumber numberWithInt:0] forKey:@"followed_by_you"];
|
2012-08-10 18:10:07 -07:00
|
|
|
[self refreshWithProfile:newProfile showStats:self.shouldShowStats withWidth:0];
|
2012-07-03 17:54:36 -07:00
|
|
|
}
|
|
|
|
|
2017-03-28 10:02:34 -07:00
|
|
|
- (void)requestFailed:(NSError *)error {
|
2012-07-03 17:54:36 -07:00
|
|
|
[self.activityIndicator stopAnimating];
|
|
|
|
NSLog(@"Error: %@", error);
|
2013-03-06 14:29:40 -08:00
|
|
|
[appDelegate informError:error];
|
2012-07-03 17:54:36 -07:00
|
|
|
}
|
2016-10-05 21:03:32 -07:00
|
|
|
@end
|