From b60aec3598a12a5bf07ad490fa87723e308cd58b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 10 Nov 2013 15:56:03 +0400 Subject: Images --- Juick.xcodeproj/project.pbxproj | 14 ++++++-------- Juick/AttachPlaceholder.png | Bin 0 -> 15565 bytes Juick/Message.h | 1 + Juick/Message.m | 2 ++ Juick/MessageCell.h | 8 +++++++- Juick/MessageCell.m | 38 ++++++++++++++++++++++++++++++++++++-- Juick/MessagesViewController.h | 1 - Juick/MessagesViewController.m | 37 ++++--------------------------------- Juick/UIImage+Helpers.h | 15 --------------- Juick/UIImage+Helpers.m | 24 ------------------------ Podfile | 1 + Podfile.lock | 5 +++++ 12 files changed, 62 insertions(+), 84 deletions(-) create mode 100644 Juick/AttachPlaceholder.png delete mode 100644 Juick/UIImage+Helpers.h delete mode 100644 Juick/UIImage+Helpers.m diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index 5779892..47d1eb3 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 77317BD0181BBE8500D60005 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77317BAF181BBE8500D60005 /* UIKit.framework */; }; 77317BD8181BBE8500D60005 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 77317BD6181BBE8500D60005 /* InfoPlist.strings */; }; 77317BDA181BBE8500D60005 /* JuickTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 77317BD9181BBE8500D60005 /* JuickTests.m */; }; + 77418CBB182F9A78004111B7 /* AttachPlaceholder.png in Resources */ = {isa = PBXBuildFile; fileRef = 77418CBA182F9A78004111B7 /* AttachPlaceholder.png */; }; 77975A1D182B6E9A00410C2B /* NewPostViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77975A1C182B6E9A00410C2B /* NewPostViewController.m */; }; 77975A1F182BDCE900410C2B /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77975A1E182BDCE900410C2B /* SystemConfiguration.framework */; }; 77975A21182BDCF300410C2B /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77975A20182BDCF300410C2B /* MobileCoreServices.framework */; }; @@ -34,7 +35,6 @@ 77C67EEC18283F2D00427098 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77C67EEB18283F2D00427098 /* QuartzCore.framework */; }; 77C67EF21828442C00427098 /* UIImage+Crop.m in Sources */ = {isa = PBXBuildFile; fileRef = 77C67EF11828442C00427098 /* UIImage+Crop.m */; }; 77D163C2181F048F00401EF0 /* MessageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 77D163C1181F048F00401EF0 /* MessageCell.m */; }; - 77DC49E818296EA300A1136A /* UIImage+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 77DC49E718296EA300A1136A /* UIImage+Helpers.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -66,6 +66,7 @@ 77317BD5181BBE8500D60005 /* JuickTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "JuickTests-Info.plist"; sourceTree = ""; }; 77317BD7181BBE8500D60005 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 77317BD9181BBE8500D60005 /* JuickTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JuickTests.m; sourceTree = ""; }; + 77418CBA182F9A78004111B7 /* AttachPlaceholder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = AttachPlaceholder.png; sourceTree = ""; }; 77975A1B182B6E9A00410C2B /* NewPostViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NewPostViewController.h; sourceTree = ""; }; 77975A1C182B6E9A00410C2B /* NewPostViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NewPostViewController.m; sourceTree = ""; }; 77975A1E182BDCE900410C2B /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; @@ -86,8 +87,6 @@ 77C67EF11828442C00427098 /* UIImage+Crop.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Crop.m"; sourceTree = ""; }; 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 = ""; }; - 77DC49E618296EA300A1136A /* UIImage+Helpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Helpers.h"; sourceTree = ""; }; - 77DC49E718296EA300A1136A /* UIImage+Helpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Helpers.m"; sourceTree = ""; }; AD52EBAFFD6B4395B342F246 /* Pods-Juick.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Juick.xcconfig"; path = "Pods/Pods-Juick.xcconfig"; sourceTree = ""; }; E1A04338EB0146778B4503DC /* libPods-Juick.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Juick.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -158,6 +157,7 @@ 77317BB1181BBE8500D60005 /* Juick */ = { isa = PBXGroup; children = ( + 77418CBA182F9A78004111B7 /* AttachPlaceholder.png */, 77C67EE918283C8D00427098 /* buttons.png */, 77C67EE31828342000427098 /* NSURL+PathParameters.h */, 77C67EE41828342000427098 /* NSURL+PathParameters.m */, @@ -179,8 +179,6 @@ 77C67EE71828379700427098 /* ColorsAndButtons.m */, 77C67EF01828442C00427098 /* UIImage+Crop.h */, 77C67EF11828442C00427098 /* UIImage+Crop.m */, - 77DC49E618296EA300A1136A /* UIImage+Helpers.h */, - 77DC49E718296EA300A1136A /* UIImage+Helpers.m */, 77975A1B182B6E9A00410C2B /* NewPostViewController.h */, 77975A1C182B6E9A00410C2B /* NewPostViewController.m */, ); @@ -298,6 +296,7 @@ 77317BC7181BBE8500D60005 /* Images.xcassets in Resources */, 77C67EEA18283C8D00427098 /* buttons.png in Resources */, 77317BB6181BBE8500D60005 /* InfoPlist.strings in Resources */, + 77418CBB182F9A78004111B7 /* AttachPlaceholder.png in Resources */, 77C67EDE182827DB00427098 /* reveal-icon.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -360,7 +359,6 @@ 77C67EE81828379700427098 /* ColorsAndButtons.m in Sources */, 77C67EE51828342000427098 /* NSURL+PathParameters.m in Sources */, 77317BB8181BBE8500D60005 /* main.m in Sources */, - 77DC49E818296EA300A1136A /* UIImage+Helpers.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -487,7 +485,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Juick/Juick-Prefix.pch"; INFOPLIST_FILE = "Juick/Juick-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 6.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; WRAPPER_EXTENSION = app; @@ -507,7 +505,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Juick/Juick-Prefix.pch"; INFOPLIST_FILE = "Juick/Juick-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 6.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; WRAPPER_EXTENSION = app; diff --git a/Juick/AttachPlaceholder.png b/Juick/AttachPlaceholder.png new file mode 100644 index 0000000..94e8c32 Binary files /dev/null and b/Juick/AttachPlaceholder.png differ diff --git a/Juick/Message.h b/Juick/Message.h index 927d9f0..10e9fb3 100644 --- a/Juick/Message.h +++ b/Juick/Message.h @@ -18,6 +18,7 @@ @property(nonatomic, copy) NSString *text; @property(nonatomic, copy) NSArray *tags; @property(nonatomic, copy) NSString *timestamp; +@property(nonatomic, copy) NSString *attach; @property(nonatomic, copy) NSString *repliesBy; @property(nonatomic, copy) NSDecimalNumber *repliesCount; diff --git a/Juick/Message.m b/Juick/Message.m index 7d805b4..1d023c1 100644 --- a/Juick/Message.m +++ b/Juick/Message.m @@ -22,8 +22,10 @@ @"rid" : @"RID", @"tags" : @"tags", @"timestamp" : @"timestamp", + @"photo.small" : @"attach", @"replies" : @"repliesCount", @"repliesby": @"repliesBy" + }]; RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping method:RKRequestMethodAny pathPattern:nil keyPath:nil statusCodes:nil]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; diff --git a/Juick/MessageCell.h b/Juick/MessageCell.h index 342aecc..c1298af 100644 --- a/Juick/MessageCell.h +++ b/Juick/MessageCell.h @@ -9,6 +9,10 @@ #import #import "TTTAttributedLabel.h" +#import "Message.h" + +#import "NSString+HTML.h" + #define kLabelHorizontalInsets 20.0f @@ -18,8 +22,10 @@ @property (strong, nonatomic) IBOutlet UILabel *timestampLabel; @property (strong, nonatomic) IBOutlet UIImageView *avatar; @property (strong, nonatomic) IBOutlet TTTAttributedLabel *bodyLabel; +@property (strong, nonatomic) IBOutlet UIImageView *attach; @property (strong, nonatomic) IBOutlet UILabel *summaryLabel; -- (void)updateFonts; +- (void) updateFonts; +- (void) bind:(Message *)msg; @end diff --git a/Juick/MessageCell.m b/Juick/MessageCell.m index cf2e134..ad3a849 100644 --- a/Juick/MessageCell.m +++ b/Juick/MessageCell.m @@ -22,6 +22,8 @@ { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { + [self setBackgroundColor:[UIColor whiteColor]]; + self.selectionStyle = UITableViewCellSelectionStyleNone; self.avatar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; [self.avatar setBackgroundColor:[UIColor clearColor]]; @@ -31,7 +33,7 @@ [self.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail]; [self.titleLabel setNumberOfLines:1]; [self.titleLabel setTextAlignment:NSTextAlignmentLeft]; - [self.titleLabel setTextColor:[UIColor blackColor]]; + [self.titleLabel setTextColor:[ColorsAndButtons linkColor]]; [self.titleLabel setBackgroundColor:[UIColor clearColor]]; self.timestampLabel = [[UILabel alloc] initWithFrame:CGRectZero]; @@ -61,11 +63,15 @@ [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 = UIViewContentModeScaleAspectFit; [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]; @@ -110,14 +116,20 @@ make.leading.equalTo(self.contentView.leading).with.offset(padding.left); make.top.equalTo(self.timestampLabel.bottom).with.offset(padding.top); make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.bottom.equalTo(self.attach.top).with.offset(-padding.bottom); + }]; + + [self.attach makeConstraints:^(MASConstraintMaker *make) { + make.leading.equalTo(self.contentView.leading).with.offset(padding.left); make.bottom.equalTo(self.summaryLabel.top).with.offset(-padding.bottom); + make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.top.equalTo(self.bodyLabel.bottom).with.offset(padding.top); }]; [self.summaryLabel makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.contentView.leading).with.offset(padding.left); make.bottom.equalTo(self.contentView.bottom).with.offset(-padding.bottom); make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); - }]; @@ -136,6 +148,28 @@ } } +- (void) bind:(Message *)msg { + [self.avatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://i.juick.com/as/%@.png", msg.userID]]]; + + self.titleLabel.text = msg.user; + self.timestampLabel.text = msg.timestamp; + if (msg.repliesCount > 0) { + self.summaryLabel.text = [NSString stringWithFormat:@"%@ replies by %@", msg.repliesCount, msg.repliesBy]; + } 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]]; + } + if ([msg.attach length] > 0) { + [self.attach setImageWithURL:[NSURL URLWithString:msg.attach]]; + } else { + self.attach.image = nil; + } +} + - (void) attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url { [[UIApplication sharedApplication] openURL:url]; } diff --git a/Juick/MessagesViewController.h b/Juick/MessagesViewController.h index e3391db..3e6af7e 100644 --- a/Juick/MessagesViewController.h +++ b/Juick/MessagesViewController.h @@ -7,7 +7,6 @@ // #import -#import "NSString+HTML.h" @interface MessagesViewController : UITableViewController - (void)loadFromURL:(NSURL *)messagesURL withTitle:(NSString *)title; diff --git a/Juick/MessagesViewController.m b/Juick/MessagesViewController.m index 2e27d43..372345a 100644 --- a/Juick/MessagesViewController.m +++ b/Juick/MessagesViewController.m @@ -18,7 +18,7 @@ #import "NSURL+PathParameters.h" -#import "UIImage+Helpers.h" +#import static NSString *CellIdentifier = @"MessageCell"; @@ -158,23 +158,7 @@ static NSString *CellIdentifier = @"MessageCell"; MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; [cell updateFonts]; Message *msg = [_messages objectAtIndex:indexPath.row]; - [UIImage loadFromURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://i.juick.com/as/%@.png", msg.userID]] callback:^(UIImage *image) { - [cell.avatar setImage:image]; - }]; - cell.titleLabel.text = msg.user; - cell.titleLabel.textColor = [ColorsAndButtons linkColor]; - cell.timestampLabel.text = msg.timestamp; - if (msg.repliesCount > 0) { - cell.summaryLabel.text = [NSString stringWithFormat:@"%@ replies by %@", msg.repliesCount, msg.repliesBy]; - } else { - cell.summaryLabel.text = nil; - } - cell.bodyLabel.text = [msg.text stringByDecodingHTMLEntities]; - if ([msg.tags count] > 0) { - cell.bodyLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@", [msg.tags componentsJoinedByString:@", "], - [msg.text stringByDecodingHTMLEntities]]; - } - [cell setBackgroundColor:[UIColor whiteColor]]; + [cell bind:msg]; [cell setNeedsUpdateConstraints]; return cell; } @@ -188,22 +172,9 @@ static NSString *CellIdentifier = @"MessageCell"; [cell updateFonts]; Message *msg = [_messages objectAtIndex:indexPath.row]; - [UIImage loadFromURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://i.juick.com/as/%@.png", msg.userID]] callback:^(UIImage *image) { - [cell.avatar setImage:image]; - }]; - cell.titleLabel.text = msg.user; - cell.timestampLabel.text = msg.timestamp; - if (msg.repliesCount > 0) { - cell.summaryLabel.text = [NSString stringWithFormat:@"%@ replies by %@", msg.repliesCount, msg.repliesBy]; - } else { - cell.summaryLabel.text = nil; - } - cell.bodyLabel.text = [msg.text stringByDecodingHTMLEntities]; - if ([msg.tags count] > 0) { - cell.bodyLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@", [msg.tags componentsJoinedByString:@", "], - [msg.text stringByDecodingHTMLEntities]]; - } + [cell bind:msg]; + cell.bodyLabel.preferredMaxLayoutWidth = tableView.bounds.size.width - (kLabelHorizontalInsets * 2.0f); [cell setNeedsUpdateConstraints]; diff --git a/Juick/UIImage+Helpers.h b/Juick/UIImage+Helpers.h deleted file mode 100644 index d30ad7b..0000000 --- a/Juick/UIImage+Helpers.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// UIImage+Helpers.h -// Juick -// -// Created by Vitaly Takmazov on 05.11.13. -// Copyright (c) 2013 com.juick. All rights reserved. -// - -#import - -@interface UIImage (Helpers) - -+ (void) loadFromURL: (NSURL*) url callback:(void (^)(UIImage *image))callback; - -@end diff --git a/Juick/UIImage+Helpers.m b/Juick/UIImage+Helpers.m deleted file mode 100644 index a4ae8e4..0000000 --- a/Juick/UIImage+Helpers.m +++ /dev/null @@ -1,24 +0,0 @@ -// -// UIImage+Helpers.m -// Juick -// -// Created by Vitaly Takmazov on 05.11.13. -// Copyright (c) 2013 com.juick. All rights reserved. -// - -#import "UIImage+Helpers.h" - -@implementation UIImage (Helpers) - -+ (void) loadFromURL: (NSURL*) url callback:(void (^)(UIImage *image))callback { - dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); - dispatch_async(queue, ^{ - NSData * imageData = [NSData dataWithContentsOfURL:url]; - dispatch_async(dispatch_get_main_queue(), ^{ - UIImage *image = [UIImage imageWithData:imageData]; - callback(image); - }); - }); -} - -@end diff --git a/Podfile b/Podfile index a089837..edb4893 100644 --- a/Podfile +++ b/Podfile @@ -8,6 +8,7 @@ pod 'Masonry' pod 'SWRevealViewController' pod 'PDKeychainBindingsController' pod 'RestKit' +pod 'SDWebImage' end target "JuickTests" do diff --git a/Podfile.lock b/Podfile.lock index 7c09c02..65d4b0a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -32,6 +32,9 @@ PODS: - RestKit/Support (0.21.0): - TransitionKit (= 1.1.1) - RKValueTransformers (1.0.0) + - SDWebImage (3.5): + - SDWebImage/Core + - SDWebImage/Core (3.5) - SOCKit (1.1) - SWRevealViewController (1.0.8) - TransitionKit (1.1.1) @@ -42,6 +45,7 @@ DEPENDENCIES: - MWFeedParser - PDKeychainBindingsController - RestKit + - SDWebImage - SWRevealViewController - TTTAttributedLabel @@ -53,6 +57,7 @@ SPEC CHECKSUMS: PDKeychainBindingsController: 463c207f8726e4aaec1ec20fd1876082ee86cb0a RestKit: c11a30e7bc73513d9d2c2695672aba7697d24181 RKValueTransformers: 01dc043fd853f6e40459b2e732dff545298a0f91 + SDWebImage: f1a72472f8a2d54445f1fedafe2090593d9caf7f SOCKit: 2f3bc4d07910de12dcc202815e07db68a3802581 SWRevealViewController: 5688d9d017e228c9edd92db359f670d8c47ab8e6 TransitionKit: d0e3344aac92991395d4c2e72d9c5a8ceeb12910 -- cgit v1.2.3