summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2013-11-10 15:56:03 +0400
committerGravatar Vitaly Takmazov2013-11-10 16:02:25 +0400
commitb60aec3598a12a5bf07ad490fa87723e308cd58b (patch)
tree412c9b1335102219c411f48bc711be58f63846c0 /Juick
parentc7ac059a7e59ff3da4f88c53bedae29655ae900c (diff)
Images
Diffstat (limited to 'Juick')
-rw-r--r--Juick/AttachPlaceholder.pngbin0 -> 15565 bytes
-rw-r--r--Juick/Message.h1
-rw-r--r--Juick/Message.m2
-rw-r--r--Juick/MessageCell.h8
-rw-r--r--Juick/MessageCell.m38
-rw-r--r--Juick/MessagesViewController.h1
-rw-r--r--Juick/MessagesViewController.m37
-rw-r--r--Juick/UIImage+Helpers.h15
-rw-r--r--Juick/UIImage+Helpers.m24
9 files changed, 50 insertions, 76 deletions
diff --git a/Juick/AttachPlaceholder.png b/Juick/AttachPlaceholder.png
new file mode 100644
index 0000000..94e8c32
--- /dev/null
+++ b/Juick/AttachPlaceholder.png
Binary files 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 <UIKit/UIKit.h>
#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 <UIKit/UIKit.h>
-#import "NSString+HTML.h"
@interface MessagesViewController : UITableViewController<UISplitViewControllerDelegate>
- (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 <SDWebImage/UIImageView+WebCache.h>
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 <UIKit/UIKit.h>
-
-@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