Advertisement
Guest User

Untitled

a guest
Jul 10th, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2. static NSString *simpleTableIdentifier = @"tweetCell";
  3.  
  4. TweetCell *cell = (TweetCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
  5.  
  6. NSDictionary *tweet = _tweets[indexPath.row];
  7.  
  8. NSString *username = tweet[@"username"];
  9.  
  10. CGFloat tweetHeight = [tweet[@"contentHeight"] floatValue];
  11.  
  12. cell.tweet.frame = ({
  13. CGRect frame = cell.tweet.frame;
  14. frame.size.height = tweetHeight + 2;
  15. frame.origin.y = cell.bounds.size.height / 2 - frame.size.height / 2;
  16. frame;
  17. });
  18.  
  19. cell.tweet.attributedText = tweet[@"attributedText"];
  20.  
  21. cell.imageView.image = [_profilePhotos[username] valueForKey:@"image"];
  22.  
  23. cell.date.text = tweet[@"dateString"];
  24.  
  25. if (tweet[@"media"]) {
  26.  
  27. cell.tweetImage.image = tweet[@"media"];
  28. cell.tweetImage.hidden = NO;
  29.  
  30. } else {
  31.  
  32. cell.tweetImage.image = nil;
  33. cell.tweetImage.hidden = YES;
  34. }
  35.  
  36. NSMutableAttributedString *attributedText = [tweet[@"attributedText"] mutableCopy];
  37.  
  38. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"useDynamicTextSize"]) {
  39.  
  40. UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
  41.  
  42. if (cell.tweet.font.pointSize != font.pointSize) {
  43. cell.tweet.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:font.pointSize];
  44. cell.username.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:font.pointSize];
  45. cell.date.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:font.pointSize];
  46.  
  47. [attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:font.pointSize] range:NSMakeRange(0, attributedText.length)];
  48.  
  49. } else {
  50. [attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:cell.tweet.font.pointSize] range:NSMakeRange(0, attributedText.length)];
  51. }
  52. } else {
  53. [attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:17] range:NSMakeRange(0, attributedText.length)];
  54. }
  55.  
  56. cell.tweet.attributedText = attributedText;
  57.  
  58. cell.username.adjustsFontSizeToFitWidth = YES;
  59.  
  60. NSString *color = [[NSUserDefaults standardUserDefaults] objectForKey:@"color"];
  61. if ([color isEqualToString:@"automatic"]) {
  62. color = ([[UIScreen mainScreen] brightness] <= .5) ? @"black" : @"white";
  63. }
  64. [cell.imageView.layer setMasksToBounds:YES];
  65. [cell.imageView.layer setCornerRadius:5];
  66. [cell.imageView.layer setBorderColor:[[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.55] CGColor]];
  67. [cell.imageView.layer setBorderWidth:0.5];
  68.  
  69. [cell.tweetImage.layer setMasksToBounds:YES];
  70. [cell.tweetImage.layer setCornerRadius:5];
  71. [cell.tweetImage.layer setBorderColor:[[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.55] CGColor]];
  72. [cell.tweetImage.layer setBorderWidth:0.65];
  73.  
  74. // [UIView beginAnimations:nil context:nil];
  75. // [UIView setAnimationDuration:0.25];
  76. // [UIView setAnimationDelegate:self];
  77.  
  78. if ([color isEqualToString: @"white"]) {
  79. cell.tweet.textColor =[UIColor blackColor];
  80. cell.date.textColor = [UIColor blackColor];
  81. cell.username.textColor = [UIColor blackColor];
  82. cell.backgroundColor = [UIColor whiteColor];
  83. cell.tweet.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor blueColor]};
  84.  
  85. [tweet[@"attributedText"] addAttribute:NSForegroundColorAttributeName
  86. value:[UIColor blackColor]
  87. range:NSMakeRange(0, cell.tweet.attributedText.length)];
  88.  
  89. } else /*if ([color isEqualToString: @"black"])*/ {
  90. cell.tweet.textColor = [UIColor whiteColor];
  91. cell.date.textColor = [UIColor whiteColor];
  92. cell.username.textColor = [UIColor whiteColor];
  93. cell.backgroundColor = [UIColor colorWithRed:52/255.0 green:52/255.0 blue:52/255.0 alpha:1];
  94. cell.tweet.linkTextAttributes = @{NSForegroundColorAttributeName: [UIColor colorWithRed:0.66 green:0.82 blue:1 alpha:1]};
  95.  
  96. [tweet[@"attributedText"] addAttribute:NSForegroundColorAttributeName
  97. value:[UIColor whiteColor]
  98. range:NSMakeRange(0, cell.tweet.attributedText.length)];
  99. }
  100.  
  101. // [UIView commitAnimations];
  102.  
  103. if (_retweets[_tweets[indexPath.row][@"id"]]) {
  104. if ([color isEqualToString: @"white"]) {
  105. cell.backgroundColor = [UIColor colorWithRed:0.945 green:0.945 blue:0.945 alpha:1];
  106.  
  107. } else if ([color isEqualToString: @"black"]) {
  108. cell.backgroundColor = [UIColor colorWithRed:0.114 green:0.114 blue:0.114 alpha:1];
  109. }
  110.  
  111. // cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, cell.bounds.size.width);
  112.  
  113. } else {
  114. if ([color isEqualToString: @"white"]) {
  115. [cell setBackgroundColor:[UIColor whiteColor]];
  116. } else if ([color isEqualToString: @"black"]) {
  117. cell.backgroundColor = [UIColor colorWithRed:52/255.0 green:52/255.0 blue:52/255.0 alpha:1];
  118. }
  119.  
  120. // cell.separatorInset = UIEdgeInsetsMake(0, 80, 0, 0);
  121. }
  122.  
  123. cell.tweet.tag = indexPath.row;
  124. cell.tweetImage.userInteractionEnabled = YES;
  125.  
  126. cell.tweet.frame = ({
  127. CGRect frame = cell.tweet.frame;
  128. frame.size.height = tweetHeight + 2;
  129. frame.origin.y = cell.bounds.size.height / 2 - frame.size.height / 2;
  130. if (tweet[@"media"]) {
  131. frame.size.width = 164;
  132. } else {
  133. frame.size.width = 224;
  134. }
  135. frame;
  136. });
  137.  
  138. cell.tweet.delegate = self;
  139.  
  140. UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(retweetTweet:)];
  141. doubleTap.numberOfTapsRequired = 2;
  142. [cell addGestureRecognizer:doubleTap];
  143. [cell.tweet addGestureRecognizer:doubleTap];
  144.  
  145. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showImage:)];
  146. tap.numberOfTapsRequired = 1;
  147. [cell.tweetImage addGestureRecognizer:tap];
  148.  
  149. UITapGestureRecognizer *tapToViewProfile = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewProfile:)];
  150. tap.numberOfTapsRequired = 1;
  151. [cell.imageView setUserInteractionEnabled:YES];
  152. [cell.imageView addGestureRecognizer:tapToViewProfile];
  153.  
  154. return cell;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement