From 8a79dcc214d525d1a59ee95173583976cd774287 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 14 Aug 2016 02:21:31 +0300 Subject: new message cell layout --- Juick.xcodeproj/project.pbxproj | 24 +++-- Juick/Juick-Prefix.pch | 8 +- Juick/LoginViewController.m | 3 - Juick/MessageCell.h | 44 ---------- Juick/MessageCell.m | 190 ---------------------------------------- Juick/MessagesViewController.m | 46 ++-------- Juick/Views/MessageCell.h | 21 +++++ Juick/Views/MessageCell.m | 49 +++++++++++ Juick/Views/MessageCell.xib | 85 ++++++++++++++++++ Podfile | 3 +- Podfile.lock | 72 +++++++-------- 11 files changed, 218 insertions(+), 327 deletions(-) delete mode 100644 Juick/MessageCell.h delete mode 100644 Juick/MessageCell.m create mode 100644 Juick/Views/MessageCell.h create mode 100644 Juick/Views/MessageCell.m create mode 100644 Juick/Views/MessageCell.xib diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index 381779f..f55c8c8 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -44,8 +44,9 @@ 77C67EE81828379700427098 /* ColorScheme.m in Sources */ = {isa = PBXBuildFile; fileRef = 77C67EE71828379700427098 /* ColorScheme.m */; }; 77C67EEA18283C8D00427098 /* buttons.png in Resources */ = {isa = PBXBuildFile; fileRef = 77C67EE918283C8D00427098 /* buttons.png */; }; 77C67EEC18283F2D00427098 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77C67EEB18283F2D00427098 /* QuartzCore.framework */; }; - 77D163C2181F048F00401EF0 /* MessageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 77D163C1181F048F00401EF0 /* MessageCell.m */; }; 77E35A82189A5B5A00B2D216 /* LoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77E35A81189A5B5A00B2D216 /* LoginViewController.m */; }; + 77FFC0191D5FD186003BD81A /* MessageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 77FFC0171D5FD186003BD81A /* MessageCell.m */; }; + 77FFC01A1D5FD186003BD81A /* MessageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 77FFC0181D5FD186003BD81A /* MessageCell.xib */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -112,10 +113,11 @@ 77C67EE71828379700427098 /* ColorScheme.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ColorScheme.m; sourceTree = ""; }; 77C67EE918283C8D00427098 /* buttons.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = buttons.png; sourceTree = ""; }; 77C67EEB18283F2D00427098 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; - 77D163C0181F048F00401EF0 /* MessageCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageCell.h; sourceTree = ""; }; - 77D163C1181F048F00401EF0 /* MessageCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessageCell.m; sourceTree = ""; }; 77E35A80189A5B5A00B2D216 /* LoginViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoginViewController.h; sourceTree = ""; }; 77E35A81189A5B5A00B2D216 /* LoginViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoginViewController.m; sourceTree = ""; }; + 77FFC0161D5FD186003BD81A /* MessageCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MessageCell.h; path = Views/MessageCell.h; sourceTree = ""; }; + 77FFC0171D5FD186003BD81A /* MessageCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MessageCell.m; path = Views/MessageCell.m; sourceTree = ""; }; + 77FFC0181D5FD186003BD81A /* MessageCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = MessageCell.xib; path = Views/MessageCell.xib; sourceTree = ""; }; 8F93DB342C85111DFBC86143 /* Pods-Juick.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Juick.release.xcconfig"; path = "Pods/Target Support Files/Pods-Juick/Pods-Juick.release.xcconfig"; sourceTree = ""; }; D5F79ADD6611E9C3C0D56671 /* Pods-JuickTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JuickTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-JuickTests/Pods-JuickTests.debug.xcconfig"; sourceTree = ""; }; F3C23ADDEF1C47900AA28093 /* Pods-Juick.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Juick.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Juick/Pods-Juick.debug.xcconfig"; sourceTree = ""; }; @@ -203,6 +205,7 @@ 77317BB1181BBE8500D60005 /* Juick */ = { isa = PBXGroup; children = ( + 77FFC0151D5FD13C003BD81A /* Views */, 77B099A1189D516800A84F59 /* UILabel+Utils.h */, 77B099A2189D516800A84F59 /* UILabel+Utils.m */, 77A5BDAF189AEB28000F8D9E /* 0.png */, @@ -220,8 +223,6 @@ 77317BC1181BBE8500D60005 /* MessagesViewController.m */, 77317BC6181BBE8500D60005 /* Images.xcassets */, 77317BB2181BBE8500D60005 /* Supporting Files */, - 77D163C0181F048F00401EF0 /* MessageCell.h */, - 77D163C1181F048F00401EF0 /* MessageCell.m */, 77A09548181F1F25002BDECD /* Message.h */, 77A09549181F1F25002BDECD /* Message.m */, 77C67EE01828288C00427098 /* RevealPanelViewController.h */, @@ -273,6 +274,16 @@ name = "Supporting Files"; sourceTree = ""; }; + 77FFC0151D5FD13C003BD81A /* Views */ = { + isa = PBXGroup; + children = ( + 77FFC0161D5FD186003BD81A /* MessageCell.h */, + 77FFC0171D5FD186003BD81A /* MessageCell.m */, + 77FFC0181D5FD186003BD81A /* MessageCell.xib */, + ); + name = Views; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -362,6 +373,7 @@ 77317BC7181BBE8500D60005 /* Images.xcassets in Resources */, 77C67EEA18283C8D00427098 /* buttons.png in Resources */, 77A5BDB0189AEB28000F8D9E /* 0.png in Resources */, + 77FFC01A1D5FD186003BD81A /* MessageCell.xib in Resources */, 77418CC1182FBABB004111B7 /* iTunesArtwork@2x in Resources */, 77418CBF182FBAB5004111B7 /* iTunesArtwork in Resources */, 77317BB6181BBE8500D60005 /* InfoPlist.strings in Resources */, @@ -479,7 +491,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 77D163C2181F048F00401EF0 /* MessageCell.m in Sources */, 77317BBC181BBE8500D60005 /* AppDelegate.m in Sources */, 77A0954A181F1F25002BDECD /* Message.m in Sources */, 77B09994189D0B9900A84F59 /* UIImage+Utils.m in Sources */, @@ -492,6 +503,7 @@ 77975A1D182B6E9A00410C2B /* NewPostViewController.m in Sources */, 77C67EE81828379700427098 /* ColorScheme.m in Sources */, 77C67EE51828342000427098 /* NSURL+PathParameters.m in Sources */, + 77FFC0191D5FD186003BD81A /* MessageCell.m in Sources */, 77E35A82189A5B5A00B2D216 /* LoginViewController.m in Sources */, 77317BB8181BBE8500D60005 /* main.m in Sources */, ); diff --git a/Juick/Juick-Prefix.pch b/Juick/Juick-Prefix.pch index ad49a41..a0abcee 100644 --- a/Juick/Juick-Prefix.pch +++ b/Juick/Juick-Prefix.pch @@ -15,6 +15,10 @@ #import #import #import - #define MAS_SHORTHAND - #import "Masonry.h" + #import + #import "NSString+HTML.h" + #import "UIImage+Utils.h" + #import "UILabel+Utils.h" + #import "NSDate+TimeAgo.h" + #import "TTTAttributedLabel.h" #endif diff --git a/Juick/LoginViewController.m b/Juick/LoginViewController.m index 38082a3..a803c48 100644 --- a/Juick/LoginViewController.m +++ b/Juick/LoginViewController.m @@ -93,9 +93,6 @@ static NSString *CellIdentifier = @"CellIdentifier"; textField.text = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]; } [cell.contentView addSubview:textField]; - [textField makeConstraints:^(MASConstraintMaker *make) { - make.edges.equalTo(cell.contentView).with.insets(UIEdgeInsetsMake(5, 25, 5, 25)); - }]; return cell; } diff --git a/Juick/MessageCell.h b/Juick/MessageCell.h deleted file mode 100644 index 6140e2d..0000000 --- a/Juick/MessageCell.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// MessageCell.h -// Juick -// -// Created by Vitaly Takmazov on 29.10.13. -// Copyright (c) 2013 com.juick. All rights reserved. -// - -#import -#import -#import "TTTAttributedLabel.h" - -#import "Message.h" - -#import "NSString+HTML.h" -#import "UIImage+Utils.h" -#import "UILabel+Utils.h" - - -#define kLabelHorizontalInsets 20.0f - -@interface MessageCell : UITableViewCell - -@property (strong, nonatomic) IBOutlet Message *message; -@property (strong, nonatomic) IBOutlet UILabel *titleLabel; -@property (strong, nonatomic) IBOutlet UILabel *timestampLabel; -@property (strong, nonatomic) IBOutlet UIImageView *avatar; -@property (strong, nonatomic) IBOutlet UILabel *bodyLabel; -@property (strong, nonatomic) IBOutlet UIImageView *attach; -@property (strong, nonatomic) IBOutlet UILabel *summaryLabel; - -- (void) updateFonts; -- (CGRect) avatarRect; -- (CGRect) timestampRect; -- (CGRect) titleRect; -- (CGRect) bodyRect; -- (CGRect) attachRect; -- (CGRect) summaryRect; - -- (CGFloat) heightForCell; - -- (UITableView *) getTable; - -@end diff --git a/Juick/MessageCell.m b/Juick/MessageCell.m deleted file mode 100644 index 9994e78..0000000 --- a/Juick/MessageCell.m +++ /dev/null @@ -1,190 +0,0 @@ -// -// MessageCell.m -// Juick -// -// Created by Vitaly Takmazov on 29.10.13. -// Copyright (c) 2013 com.juick. All rights reserved. -// - -#import "MessageCell.h" -#import "ColorScheme.h" -#import "NSDate+TimeAgo.h" -#import "UIImage+Utils.h" - -#define kAvatarSizeX 32 -#define kAvatarSizeY 32 -#define kPaddingX 10 -#define kPaddingY 10 - -@implementation MessageCell - -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier -{ - self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; - if (self) { - [self.contentView setBackgroundColor:[UIColor whiteColor]]; - self.avatar = [[UIImageView alloc] initWithFrame:CGRectZero]; - [self.avatar setBackgroundColor:[UIColor clearColor]]; - - self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - [self.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail]; - [self.titleLabel setNumberOfLines:1]; - [self.titleLabel setTextAlignment:NSTextAlignmentLeft]; - [self.titleLabel setTextColor:[ColorScheme linkColor]]; - [self.titleLabel setBackgroundColor:[UIColor clearColor]]; - - self.timestampLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - [self.timestampLabel setLineBreakMode:NSLineBreakByTruncatingTail]; - [self.timestampLabel setNumberOfLines:1]; - [self.timestampLabel setTextAlignment:NSTextAlignmentLeft]; - [self.timestampLabel setTextColor:[UIColor grayColor]]; - [self.timestampLabel setBackgroundColor:[UIColor clearColor]]; - - self.bodyLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - //self.bodyLabel.dataDetectorTypes = NSTextCheckingTypeLink; - //self.bodyLabel.delegate = self; - [self.bodyLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; - [self.bodyLabel setLineBreakMode:NSLineBreakByTruncatingTail]; - [self.bodyLabel setNumberOfLines:0]; - [self.bodyLabel setTextAlignment:NSTextAlignmentLeft]; - [self.bodyLabel setTextColor:[UIColor darkGrayColor]]; - [self.bodyLabel setBackgroundColor:[UIColor clearColor]]; - - - self.summaryLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - [self.summaryLabel setLineBreakMode:NSLineBreakByTruncatingTail]; - [self.summaryLabel setNumberOfLines:1]; - [self.summaryLabel setTextAlignment:NSTextAlignmentLeft]; - [self.summaryLabel setTextColor:[UIColor grayColor]]; - [self.summaryLabel setBackgroundColor:[UIColor clearColor]]; - self.attach = [[UIImageView alloc] initWithFrame:CGRectZero]; - [self.attach setBackgroundColor:[UIColor clearColor]]; - self.attach.contentMode = UIViewContentModeTopLeft; - - [self.contentView addSubview:self.avatar]; - [self.contentView addSubview:self.titleLabel]; - [self.contentView addSubview:self.timestampLabel]; - [self.contentView addSubview:self.bodyLabel]; - [self.contentView addSubview:self.attach]; - [self.contentView addSubview:self.summaryLabel]; - - [self updateFonts]; - } - return self; -} - -- (void)setSelected:(BOOL)selected animated:(BOOL)animated -{ - [super setSelected:selected animated:animated]; - - // Configure the view for the selected state -} - - -- (CGRect) avatarRect { - return CGRectMake(kPaddingX, kPaddingY, kAvatarSizeX, kAvatarSizeY); -} - -- (CGRect) bodyRect { - CGRect bodySize = [UILabel sizeForLabel:self.bodyLabel width:(self.contentView.bounds.size.width - kPaddingX * 2)]; - return CGRectMake(kPaddingX, kPaddingY + kAvatarSizeY + kPaddingY * 2, bodySize.size.width, bodySize.size.height); -} - -- (CGRect) titleRect { - CGRect titleSize = [UILabel sizeForLabel:self.titleLabel width:self.contentView.bounds.size.width - [self avatarRect].size.width - kPaddingX * 2]; - return CGRectMake(kPaddingX + kAvatarSizeX + kPaddingX, kPaddingY, titleSize.size.width, titleSize.size.height); -} - -- (CGRect) timestampRect { - CGRect timeStampSize = [UILabel sizeForLabel:self.timestampLabel width:self.contentView.bounds.size.width - [self avatarRect].size.width - kPaddingX * 2]; - return CGRectMake(kPaddingX + [self avatarRect].size.width + kPaddingX, kPaddingY + [self titleRect].size.height + kPaddingY, timeStampSize.size.width, timeStampSize.size.height); -} - -- (CGRect) summaryRect { - CGRect summarySize = [UILabel sizeForLabel:self.summaryLabel width:(self.contentView.bounds.size.width - 20)]; - float summaryY = 10 + 32 + 10 + [self bodyRect].size.height + 10; - if (self.message.attach != nil) { - summaryY += [self attachRect].size.height + 10; - } - return CGRectMake(10, summaryY , summarySize.size.width, summarySize.size.height); -} - -- (CGRect) attachRect { - return CGRectMake(10, 10 + 32 + 10 + [self bodyRect].size.height + 10, self.attach.image.size.width, self.attach.image.size.height); -} - -- (CGFloat) heightForCell { - CGFloat baseSize = 10 + [self avatarRect].size.height + 20 + [self bodyRect].size.height + 10; - if (self.message.repliesCount > 0) { - baseSize += 10 + [self summaryRect].size.height; - } - if (self.attach.image != nil) { - baseSize += 10 + [self attachRect].size.height + 10; - } - return baseSize; -} - -- (void)layoutSubviews { - [super layoutSubviews]; - self.avatar.frame = [self avatarRect]; - self.titleLabel.frame = [self titleRect]; - self.timestampLabel.frame = [self timestampRect]; - self.bodyLabel.frame = [self bodyRect]; - if (self.message.repliesCount > 0) { - self.summaryLabel.frame = [self summaryRect]; - } - if (self.message.attach != nil) { - self.attach.frame = [self attachRect]; - } -} - - -- (void)updateFonts -{ - if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) { - self.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; - self.bodyLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; - self.timestampLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]; - self.summaryLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]; - } -} - -- (void) setMessage:(Message *)msg { - _message = msg; - [self.avatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/a/%d.png", [msg.userID intValue]]] placeholderImage:[UIImage imageNamed:@"0.png"] options:SDWebImageContinueInBackground]; - self.titleLabel.text = msg.user; - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; - [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; - - self.timestampLabel.text = [[formatter dateFromString:msg.timestamp] timeAgo]; - if (msg.repliesCount > 0) { - if ([msg.repliesBy length] > 0) { - self.summaryLabel.text = [NSString stringWithFormat:@"%@ replies by %@", msg.repliesCount, msg.repliesBy]; - } else { - self.summaryLabel.text = [NSString stringWithFormat:@"%@ replies", msg.repliesCount]; - } - } else { - self.summaryLabel.text = nil; - } - self.bodyLabel.text = [msg.text stringByDecodingHTMLEntities]; - if ([msg.tags count] > 0) { - self.bodyLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@", [msg.tags componentsJoinedByString:@", "], - [msg.text stringByDecodingHTMLEntities]]; - } - [self setNeedsLayout]; -} - -- (UITableView *) getTable { - id view = [self superview]; - while ([view isKindOfClass:[UITableView class]] == NO) { - view = [view superview]; - } - return (UITableView *)view; -} - -- (void) attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url { - [[UIApplication sharedApplication] openURL:url]; -} - -@end diff --git a/Juick/MessagesViewController.m b/Juick/MessagesViewController.m index ff7e556..2cf4267 100644 --- a/Juick/MessagesViewController.m +++ b/Juick/MessagesViewController.m @@ -21,9 +21,6 @@ static NSString *CellIdentifier = @"MessageCell"; -static NSMutableDictionary *heightsCache; - - @interface MessagesViewController (); @@ -84,8 +81,9 @@ static NSMutableDictionary *heightsCache; self.navigationController.navigationBar.tintColor = [ColorScheme navbarBackground]; } - [self.tableView registerClass:[MessageCell class] forCellReuseIdentifier:CellIdentifier]; - heightsCache = [[NSMutableDictionary alloc] init]; + [self.tableView registerNib:[UINib nibWithNibName:@"MessageCell" bundle:nil] forCellReuseIdentifier:CellIdentifier]; + self.tableView.rowHeight = UITableViewAutomaticDimension; + self.tableView.estimatedRowHeight = 500.0f; } - (void) composePressed { @@ -119,12 +117,6 @@ static NSMutableDictionary *heightsCache; } } -- (void)didReceiveMemoryWarning -{ - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - - (void)contentSizeCategoryChanged:(NSNotification *)notification { [self.tableView reloadData]; @@ -139,8 +131,7 @@ static NSMutableDictionary *heightsCache; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; - [cell updateFonts]; + MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; Message *msg = [_messages objectAtIndex:indexPath.row]; [cell setMessage:msg]; if ([msg.attach length] > 0) { @@ -148,12 +139,7 @@ static NSMutableDictionary *heightsCache; [manager downloadWithURL:[NSURL URLWithString:msg.attach] options:SDWebImageContinueInBackground progress:^(NSInteger receivedSize, NSInteger expectedSize) { // <#code#> } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { - [cell.attach setImage:[UIImage imageWithImage:image convertToWidth:300.0f]]; - [heightsCache setObject:[NSNumber numberWithFloat:[cell heightForCell]] forKey:[NSString stringWithFormat:@"%@#%@", msg.MID, msg.RID]]; - [tableView beginUpdates]; - [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; - [tableView endUpdates]; - + [cell.attach setImage:[UIImage imageWithImage:image convertToWidth:300.0f]]; }]; } else { cell.attach.image = nil; @@ -162,28 +148,6 @@ static NSMutableDictionary *heightsCache; return cell; } -- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath -{ - Message *msg = [_messages objectAtIndex:indexPath.row]; - float height = [[heightsCache objectForKey:[NSString stringWithFormat:@"%@#%@", msg.MID, msg.RID]] floatValue]; - if (height > 0) { - return height; - } else { - MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; - [cell updateFonts]; - [cell setMessage:msg]; - return [cell heightForCell]; - } -} - -- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath -{ - /* if (self.dataLoading) { - return [self tableView:tableView heightForRowAtIndexPath:indexPath]; - }*/ - return 500.0f; -} - - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([self.path isEqualToString:[Message threadUrl]]) return; diff --git a/Juick/Views/MessageCell.h b/Juick/Views/MessageCell.h new file mode 100644 index 0000000..c40a12c --- /dev/null +++ b/Juick/Views/MessageCell.h @@ -0,0 +1,21 @@ +// +// MessageCell.h +// Juick +// +// Created by Vitaly Takmazov on 14/08/16. +// Copyright © 2016 com.juick. All rights reserved. +// + +#import +#import "Message.h" + +@interface MessageCell : UITableViewCell + +@property (weak, nonatomic) IBOutlet UILabel *title; +@property (weak, nonatomic) IBOutlet UILabel *timestamp; +@property (weak, nonatomic) IBOutlet UIImageView *avatar; +@property (weak, nonatomic) IBOutlet UILabel *text; +@property (weak, nonatomic) IBOutlet UIImageView *attach; +@property (weak, nonatomic) IBOutlet UILabel *summary; +@property (strong, nonatomic) Message * message; +@end diff --git a/Juick/Views/MessageCell.m b/Juick/Views/MessageCell.m new file mode 100644 index 0000000..8759e63 --- /dev/null +++ b/Juick/Views/MessageCell.m @@ -0,0 +1,49 @@ +// +// MessageCell.m +// Juick +// +// Created by Vitaly Takmazov on 14/08/16. +// Copyright © 2016 com.juick. All rights reserved. +// + +#import "MessageCell.h" + +@implementation MessageCell + +- (void)awakeFromNib { + [super awakeFromNib]; + // Initialization code +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated { + [super setSelected:selected animated:animated]; + + // Configure the view for the selected state +} + +- (void) setMessage:(Message *)msg { + _message = msg; + [self.avatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/a/%d.png", [msg.userID intValue]]] placeholderImage:[UIImage imageNamed:@"0.png"] options:SDWebImageContinueInBackground]; + self.title.text = msg.user; + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; + [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; + + self.timestamp.text = [[formatter dateFromString:msg.timestamp] timeAgo]; + if (msg.repliesCount > 0) { + if ([msg.repliesBy length] > 0) { + self.summary.text = [NSString stringWithFormat:@"%@ replies by %@", msg.repliesCount, msg.repliesBy]; + } else { + self.summary.text = [NSString stringWithFormat:@"%@ replies", msg.repliesCount]; + } + } else { + self.summary.text = nil; + } + self.text.text = [msg.text stringByDecodingHTMLEntities]; + if ([msg.tags count] > 0) { + self.text.text = [[NSString alloc] initWithFormat:@"%@\n%@", [msg.tags componentsJoinedByString:@", "], + [msg.text stringByDecodingHTMLEntities]]; + } +} + +@end diff --git a/Juick/Views/MessageCell.xib b/Juick/Views/MessageCell.xib new file mode 100644 index 0000000..29f37fb --- /dev/null +++ b/Juick/Views/MessageCell.xib @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Podfile b/Podfile index 5a03bd9..54b2939 100644 --- a/Podfile +++ b/Podfile @@ -1,10 +1,9 @@ # Uncomment this line to define a global platform for your project -platform :ios, "6.0" +platform :ios, "9.0" target "Juick" do pod 'MWFeedParser' pod 'TTTAttributedLabel' -pod 'Masonry' pod 'SWRevealViewController' pod 'PDKeychainBindingsController' pod 'RestKit' diff --git a/Podfile.lock b/Podfile.lock index 5ee723b..2d54738 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,55 +1,51 @@ PODS: - - AFNetworking (1.3.4) - - FontAwesome+iOS (0.1.1) + - FontAwesome+iOS (0.1.4) - ISO8601DateFormatterValueTransformer (0.6.1): - RKValueTransformers (~> 1.1.0) - - JVFloatLabeledTextField (0.0.5) - - Masonry (1.0.1) - - MWFeedParser (0.0.1): - - MWFeedParser/Feed (= 0.0.1) - - MWFeedParser/NSDate+InternetDateTime (= 0.0.1) - - MWFeedParser/NSString+HTML (= 0.0.1) - - MWFeedParser/NSString+XMLEntities (= 0.0.1) - - MWFeedParser/Feed (0.0.1) - - MWFeedParser/NSDate+InternetDateTime (0.0.1) - - MWFeedParser/NSString+HTML (0.0.1) - - MWFeedParser/NSString+XMLEntities (0.0.1) - - NSDate+TimeAgo (1.0.2) + - JVFloatLabeledTextField (1.1.1) + - MWFeedParser (1.0.1): + - MWFeedParser/FeedParser (= 1.0.1) + - MWFeedParser/NSDate+InternetDateTime (= 1.0.1) + - MWFeedParser/NSString+HTML (= 1.0.1) + - MWFeedParser/FeedParser (1.0.1): + - MWFeedParser/NSDate+InternetDateTime + - MWFeedParser/NSString+HTML + - MWFeedParser/NSDate+InternetDateTime (1.0.1) + - MWFeedParser/NSString+HTML (1.0.1) + - NSDate+TimeAgo (1.0.6) - PDKeychainBindingsController (0.0.1) - - RestKit (0.26.0): - - RestKit/Core (= 0.26.0) - - RestKit/Core (0.26.0): + - RestKit (0.27.0): + - RestKit/Core (= 0.27.0) + - RestKit/Core (0.27.0): - RestKit/CoreData - RestKit/Network - RestKit/ObjectMapping - - RestKit/CoreData (0.26.0): + - RestKit/CoreData (0.27.0): - RestKit/ObjectMapping - - RestKit/Network (0.26.0): - - AFNetworking (~> 1.3.0) + - RestKit/Network (0.27.0): - RestKit/ObjectMapping - RestKit/Support - SOCKit - - RestKit/ObjectMapping (0.26.0): + - RestKit/ObjectMapping (0.27.0): - ISO8601DateFormatterValueTransformer (~> 0.6.1) - RestKit/Support - RKValueTransformers (~> 1.1.0) - - RestKit/Support (0.26.0): + - RestKit/Support (0.27.0): - TransitionKit (~> 2.2) - RKValueTransformers (1.1.3) - - SDWebImage (3.7.6): - - SDWebImage/Core (= 3.7.6) - - SDWebImage/Core (3.7.6) + - SDWebImage (3.8.1): + - SDWebImage/Core (= 3.8.1) + - SDWebImage/Core (3.8.1) - SIAlertView (1.3) - SOCKit (1.1) - SVPullToRefresh (0.4.1) - - SWRevealViewController (1.0.8) + - SWRevealViewController (2.3.0) - TransitionKit (2.2.1) - - TTTAttributedLabel (1.7.1) + - TTTAttributedLabel (2.0.0) DEPENDENCIES: - FontAwesome+iOS - JVFloatLabeledTextField - - Masonry - MWFeedParser - NSDate+TimeAgo - PDKeychainBindingsController @@ -61,24 +57,22 @@ DEPENDENCIES: - TTTAttributedLabel SPEC CHECKSUMS: - AFNetworking: cf8e418e16f0c9c7e5c3150d019a3c679d015018 - FontAwesome+iOS: 26037dac07b0768df058a1abfd28b10d553db393 + FontAwesome+iOS: 9070b682a9255ca0fdc34bcfb129ad0ba2b73b87 ISO8601DateFormatterValueTransformer: 52da467d6ec899d6aedda8e48280ac92e8ee97e6 - JVFloatLabeledTextField: db6ead6e2f79bb085b4f8df5238c1ff6ce0ab4fb - Masonry: a1a931a0d08870ed8ae415a2ea5ea68ebcac77df - MWFeedParser: fa23be12df3b630c93673fcc20a2af510da63cc1 - NSDate+TimeAgo: 7aa9c53dd3d7c55b5a41c1819a11638344adfbc8 + JVFloatLabeledTextField: 0e5524b097f102036214dd8279edc8ecf08b5e18 + MWFeedParser: 2cf646014c1baf6ad1b08c480b40a08180079247 + NSDate+TimeAgo: 35601c619b2d59290055e4fe76e61d97677a2360 PDKeychainBindingsController: fa8cb3cf99f2ea9240d61066ed0549f34e2cec3c - RestKit: 112fba5bd1f97598aac0db7981863d5fdc0263a2 + RestKit: a0244db34e14ed9cf059fcee2be6733cc162c34a RKValueTransformers: e5ed67e3811229b616fe01bddeeafe3bb337b1b9 - SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9 + SDWebImage: 35f9627a3e44b4f292a8a8ce6a531fa488239b91 SIAlertView: 20c794b55eaf44d888773ea51647cf8907723919 SOCKit: c7376ac262bea9115b8f749358f762522a47d392 SVPullToRefresh: ba2e718695a43253d8bea6852d2960097dc15d8c - SWRevealViewController: 3a2b0d424b1f225d61ea5918416273936b3b6973 + SWRevealViewController: 6d3fd97f70112fd7cef9de14df4260eacce4c63a TransitionKit: 9ceccda4cd0cdc0a05ef85eb235e5a3292c3c250 - TTTAttributedLabel: 97721ce7d11b9fa914a4ab50c4004b1785cc9ff4 + TTTAttributedLabel: 8cffe8e127e4e82ff3af1e5386d4cd0ad000b656 -PODFILE CHECKSUM: aa31fe95a7e0cd985ec4b51499c18fb53c16090d +PODFILE CHECKSUM: 6a733a736f9feef88d560de4dc31c1248592a0a6 COCOAPODS: 1.0.1 -- cgit v1.2.3