+ List View Display of attachments.

This commit is contained in:
moritz haarmann 2014-02-24 10:34:51 +01:00
parent 9c957b1688
commit 77b68f4508
3 changed files with 68 additions and 4 deletions

View File

@ -71,4 +71,6 @@ typedef NS_ENUM(NSUInteger, BITFeedbackListViewCellBackgroundStyle) {
+ (CGFloat) heightForRowWithMessage:(BITFeedbackMessage *)message tableViewWidth:(CGFloat)width; + (CGFloat) heightForRowWithMessage:(BITFeedbackMessage *)message tableViewWidth:(CGFloat)width;
- (void)setAttachments:(NSArray *)attachments;
@end @end

View File

@ -29,6 +29,7 @@
#import "BITFeedbackListViewCell.h" #import "BITFeedbackListViewCell.h"
#import "HockeySDKPrivate.h" #import "HockeySDKPrivate.h"
#import "BITFeedbackMessageAttachment.h"
#define BACKGROUNDCOLOR_DEFAULT BIT_RGBCOLOR(245, 245, 245) #define BACKGROUNDCOLOR_DEFAULT BIT_RGBCOLOR(245, 245, 245)
#define BACKGROUNDCOLOR_ALTERNATE BIT_RGBCOLOR(235, 235, 235) #define BACKGROUNDCOLOR_ALTERNATE BIT_RGBCOLOR(235, 235, 235)
@ -54,6 +55,9 @@
#define LABEL_TEXT_Y 25 #define LABEL_TEXT_Y 25
#define ATTACHMENT_SIZE 45
@interface BITFeedbackListViewCell () @interface BITFeedbackListViewCell ()
@property (nonatomic, strong) NSDateFormatter *dateFormatter; @property (nonatomic, strong) NSDateFormatter *dateFormatter;
@ -61,6 +65,8 @@
@property (nonatomic, strong) UILabel *labelTitle; @property (nonatomic, strong) UILabel *labelTitle;
@property (nonatomic, strong) NSMutableArray *attachmentViews;
@end @end
@ -96,6 +102,8 @@
self.labelText.numberOfLines = 0; self.labelText.numberOfLines = 0;
self.labelText.textAlignment = kBITTextLabelAlignmentLeft; self.labelText.textAlignment = kBITTextLabelAlignmentLeft;
self.labelText.dataDetectorTypes = UIDataDetectorTypeAll; self.labelText.dataDetectorTypes = UIDataDetectorTypeAll;
self.attachmentViews = [NSMutableArray new];
} }
return self; return self;
} }
@ -135,6 +143,19 @@
#pragma mark - Layout #pragma mark - Layout
+ (CGFloat) heightForRowWithMessage:(BITFeedbackMessage *)message tableViewWidth:(CGFloat)width { + (CGFloat) heightForRowWithMessage:(BITFeedbackMessage *)message tableViewWidth:(CGFloat)width {
CGFloat baseHeight = [self heightForTextInRowWithMessage:message tableViewWidth:width];
CGFloat attachmentsPerRow = floorf(width / (FRAME_SIDE_BORDER + ATTACHMENT_SIZE));
CGFloat calculatedHeight = baseHeight + (FRAME_TOP_BORDER + ATTACHMENT_SIZE) * ceil(message.attachments.count/attachmentsPerRow);
return ceil(calculatedHeight);
}
+ (CGFloat) heightForTextInRowWithMessage:(BITFeedbackMessage *)message tableViewWidth:(CGFloat)width {
CGFloat calculatedHeight; CGFloat calculatedHeight;
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
@ -143,7 +164,11 @@
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:TEXT_FONTSIZE]} attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:TEXT_FONTSIZE]}
context:nil]; context:nil];
calculatedHeight = calculatedRect.size.height + FRAME_TOP_BORDER + LABEL_TEXT_Y + FRAME_BOTTOM_BORDER; calculatedHeight = calculatedRect.size.height + FRAME_TOP_BORDER + LABEL_TEXT_Y + FRAME_BOTTOM_BORDER;
// added to make space for the images.
} else { } else {
#endif #endif
#pragma clang diagnostic push #pragma clang diagnostic push
@ -151,6 +176,7 @@
calculatedHeight = [message.text sizeWithFont:[UIFont systemFontOfSize:TEXT_FONTSIZE] calculatedHeight = [message.text sizeWithFont:[UIFont systemFontOfSize:TEXT_FONTSIZE]
constrainedToSize:CGSizeMake(width - (2 * FRAME_SIDE_BORDER), CGFLOAT_MAX) constrainedToSize:CGSizeMake(width - (2 * FRAME_SIDE_BORDER), CGFLOAT_MAX)
].height + FRAME_TOP_BORDER + LABEL_TEXT_Y + FRAME_BOTTOM_BORDER; ].height + FRAME_TOP_BORDER + LABEL_TEXT_Y + FRAME_BOTTOM_BORDER;
#pragma clang diagnostic pop #pragma clang diagnostic pop
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
} }
@ -159,6 +185,22 @@
return ceil(calculatedHeight); return ceil(calculatedHeight);
} }
- (void)setAttachments:(NSArray *)attachments {
for (UIView *view in self.attachmentViews){
[view removeFromSuperview];
}
[self.attachmentViews removeAllObjects];
for (BITFeedbackMessageAttachment *attachment in attachments){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
imageView.image = [attachment thumbnailWithSize:CGSizeMake(ATTACHMENT_SIZE, ATTACHMENT_SIZE)];
[self.attachmentViews addObject:imageView];
[self addSubview:imageView];
}
}
- (void)layoutSubviews { - (void)layoutSubviews {
UIView *accessoryViewBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 2, self.frame.size.width * 2, self.frame.size.height - 2)]; UIView *accessoryViewBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 2, self.frame.size.width * 2, self.frame.size.height - 2)];
accessoryViewBackground.autoresizingMask = UIViewAutoresizingFlexibleHeight; accessoryViewBackground.autoresizingMask = UIViewAutoresizingFlexibleHeight;
@ -208,13 +250,32 @@
// text // text
[self.labelText setText:_message.text]; [self.labelText setText:_message.text];
CGSize size = CGSizeMake(self.frame.size.width - (2 * FRAME_SIDE_BORDER), CGSize sizeForTextLabel = CGSizeMake(self.frame.size.width - (2 * FRAME_SIDE_BORDER),
[[self class] heightForRowWithMessage:_message tableViewWidth:self.frame.size.width] - LABEL_TEXT_Y - FRAME_BOTTOM_BORDER); [[self class] heightForTextInRowWithMessage:_message tableViewWidth:self.frame.size.width] - LABEL_TEXT_Y - FRAME_BOTTOM_BORDER);
[self.labelText setFrame:CGRectMake(FRAME_SIDE_BORDER, LABEL_TEXT_Y, size.width, size.height)]; [self.labelText setFrame:CGRectMake(FRAME_SIDE_BORDER, LABEL_TEXT_Y, sizeForTextLabel.width, sizeForTextLabel.height)];
[self addSubview:self.labelText]; [self addSubview:self.labelText];
CGFloat baseOffsetOfText = CGRectGetMaxY(self.labelText.frame);
int i = 0;
CGFloat attachmentsPerRow = ceilf(self.frame.size.width / (FRAME_SIDE_BORDER + ATTACHMENT_SIZE));
for ( UIImageView *imageView in self.attachmentViews){
if ( !_message.userMessage){
imageView.frame = CGRectMake(FRAME_SIDE_BORDER + (FRAME_SIDE_BORDER * ATTACHMENT_SIZE) * i , floor(i/attachmentsPerRow) + baseOffsetOfText , ATTACHMENT_SIZE, ATTACHMENT_SIZE);
} else {
imageView.frame = CGRectMake(self.frame.size.width - FRAME_SIDE_BORDER - ATTACHMENT_SIZE - ((FRAME_SIDE_BORDER * ATTACHMENT_SIZE) * (i) ), floor(i/attachmentsPerRow) + baseOffsetOfText , ATTACHMENT_SIZE, ATTACHMENT_SIZE);
}i++;
}
[super layoutSubviews]; [super layoutSubviews];
} }

View File

@ -628,6 +628,7 @@
cell.message = message; cell.message = message;
cell.labelText.delegate = self; cell.labelText.delegate = self;
cell.labelText.userInteractionEnabled = YES; cell.labelText.userInteractionEnabled = YES;
[cell setAttachments:message.attachments];
if ( if (
[self.manager isPreiOS7Environment] || [self.manager isPreiOS7Environment] ||