Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *simpleTableIdentifier = @"tweetCell";
- TweetCell *cell = (TweetCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
- NSDictionary *tweet = _tweets[indexPath.row];
- NSString *username = tweet[@"username"];
- CGFloat tweetHeight = [tweet[@"contentHeight"] floatValue];
- cell.tweet.frame = ({
- CGRect frame = cell.tweet.frame;
- frame.size.height = tweetHeight + 2;
- frame.origin.y = cell.bounds.size.height / 2 - frame.size.height / 2;
- frame;
- });
- cell.tweet.attributedText = tweet[@"attributedText"];
- cell.imageView.image = [_profilePhotos[username] valueForKey:@"image"];
- cell.date.text = tweet[@"dateString"];
- if (tweet[@"media"]) {
- cell.tweetImage.image = tweet[@"media"];
- cell.tweetImage.hidden = NO;
- } else {
- cell.tweetImage.image = nil;
- cell.tweetImage.hidden = YES;
- }
- NSMutableAttributedString *attributedText = [tweet[@"attributedText"] mutableCopy];
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"useDynamicTextSize"]) {
- UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
- if (cell.tweet.font.pointSize != font.pointSize) {
- cell.tweet.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:font.pointSize];
- cell.username.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:font.pointSize];
- cell.date.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:font.pointSize];
- [attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:font.pointSize] range:NSMakeRange(0, attributedText.length)];
- } else {
- [attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:cell.tweet.font.pointSize] range:NSMakeRange(0, attributedText.length)];
- }
- } else {
- [attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:17] range:NSMakeRange(0, attributedText.length)];
- }
- cell.tweet.attributedText = attributedText;
- cell.username.adjustsFontSizeToFitWidth = YES;
- NSString *color = [[NSUserDefaults standardUserDefaults] objectForKey:@"color"];
- if ([color isEqualToString:@"automatic"]) {
- color = ([[UIScreen mainScreen] brightness] <= .5) ? @"black" : @"white";
- }
- [cell.imageView.layer setMasksToBounds:YES];
- [cell.imageView.layer setCornerRadius:5];
- [cell.imageView.layer setBorderColor:[[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.55] CGColor]];
- [cell.imageView.layer setBorderWidth:0.5];
- [cell.tweetImage.layer setMasksToBounds:YES];
- [cell.tweetImage.layer setCornerRadius:5];
- [cell.tweetImage.layer setBorderColor:[[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.55] CGColor]];
- [cell.tweetImage.layer setBorderWidth:0.65];
- // [UIView beginAnimations:nil context:nil];
- // [UIView setAnimationDuration:0.25];
- // [UIView setAnimationDelegate:self];
- if ([color isEqualToString: @"white"]) {
- cell.tweet.textColor =[UIColor blackColor];
- cell.date.textColor = [UIColor blackColor];
- cell.username.textColor = [UIColor blackColor];
- cell.backgroundColor = [UIColor whiteColor];
- cell.tweet.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor blueColor]};
- [tweet[@"attributedText"] addAttribute:NSForegroundColorAttributeName
- value:[UIColor blackColor]
- range:NSMakeRange(0, cell.tweet.attributedText.length)];
- } else /*if ([color isEqualToString: @"black"])*/ {
- cell.tweet.textColor = [UIColor whiteColor];
- cell.date.textColor = [UIColor whiteColor];
- cell.username.textColor = [UIColor whiteColor];
- cell.backgroundColor = [UIColor colorWithRed:52/255.0 green:52/255.0 blue:52/255.0 alpha:1];
- cell.tweet.linkTextAttributes = @{NSForegroundColorAttributeName: [UIColor colorWithRed:0.66 green:0.82 blue:1 alpha:1]};
- [tweet[@"attributedText"] addAttribute:NSForegroundColorAttributeName
- value:[UIColor whiteColor]
- range:NSMakeRange(0, cell.tweet.attributedText.length)];
- }
- // [UIView commitAnimations];
- if (_retweets[_tweets[indexPath.row][@"id"]]) {
- if ([color isEqualToString: @"white"]) {
- cell.backgroundColor = [UIColor colorWithRed:0.945 green:0.945 blue:0.945 alpha:1];
- } else if ([color isEqualToString: @"black"]) {
- cell.backgroundColor = [UIColor colorWithRed:0.114 green:0.114 blue:0.114 alpha:1];
- }
- // cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, cell.bounds.size.width);
- } else {
- if ([color isEqualToString: @"white"]) {
- [cell setBackgroundColor:[UIColor whiteColor]];
- } else if ([color isEqualToString: @"black"]) {
- cell.backgroundColor = [UIColor colorWithRed:52/255.0 green:52/255.0 blue:52/255.0 alpha:1];
- }
- // cell.separatorInset = UIEdgeInsetsMake(0, 80, 0, 0);
- }
- cell.tweet.tag = indexPath.row;
- cell.tweetImage.userInteractionEnabled = YES;
- cell.tweet.frame = ({
- CGRect frame = cell.tweet.frame;
- frame.size.height = tweetHeight + 2;
- frame.origin.y = cell.bounds.size.height / 2 - frame.size.height / 2;
- if (tweet[@"media"]) {
- frame.size.width = 164;
- } else {
- frame.size.width = 224;
- }
- frame;
- });
- cell.tweet.delegate = self;
- UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(retweetTweet:)];
- doubleTap.numberOfTapsRequired = 2;
- [cell addGestureRecognizer:doubleTap];
- [cell.tweet addGestureRecognizer:doubleTap];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showImage:)];
- tap.numberOfTapsRequired = 1;
- [cell.tweetImage addGestureRecognizer:tap];
- UITapGestureRecognizer *tapToViewProfile = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewProfile:)];
- tap.numberOfTapsRequired = 1;
- [cell.imageView setUserInteractionEnabled:YES];
- [cell.imageView addGestureRecognizer:tapToViewProfile];
- return cell;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement