Compare commits

...

3 Commits

4 changed files with 78 additions and 23 deletions

View File

@ -470,20 +470,44 @@ static void * kJSQMessagesKeyValueObservingContext = &kJSQMessagesKeyValueObserv
JSQCall * call = (JSQCall*)messageItem;
cellIdentifier = self.callCellIndentifier;
JSQCallCollectionViewCell * callCell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
callCell.cellLabel.text = [call text];
if (call.status == kCallMissed)
{
callCell.cellLabel.textColor = [UIColor redColor];
}
BOOL isOutgoing = [self.senderId isEqualToString:call.senderId];
if (isOutgoing)
{
callCell.outgoingCallImageView.image = [call thumbnailImage];
} else {
NSString *text = call.date != nil ? [call text] : call.senderDisplayName;
NSString *allText = call.date != nil ? [text stringByAppendingString:[call dateText]] : text;
const CGFloat fontSize = 14;
UIFont *boldFont = [UIFont fontWithName:@"HelveticaNeue-Medium" size:12.0f];
UIFont *regularFont = [UIFont fontWithName:@"HelveticaNeue-Light" size:12.0f];
UIColor *foregroundColor = [UIColor whiteColor];
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
boldFont, NSFontAttributeName, nil];
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:allText
attributes:attrs];
if([call date]!=nil) {
// Not a group meta message
NSDictionary *subAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
regularFont, NSFontAttributeName, nil];
const NSRange range = NSMakeRange([text length],[[call dateText] length]);
[attributedText setAttributes:subAttrs range:range];
BOOL isOutgoing = [self.senderId isEqualToString:call.senderId];
if (isOutgoing)
{
callCell.outgoingCallImageView.image = [call thumbnailImage];
} else {
callCell.incomingCallImageView.image = [call thumbnailImage];
}
}
else {
// A group meta message
callCell.incomingCallImageView.image = [call thumbnailImage];
}
callCell.cellLabel.attributedText = attributedText;
callCell.cellLabel.lineBreakMode = UILineBreakModeWordWrap;
callCell.cellLabel.numberOfLines = 0; // uses as many lines as it needs
callCell.cellLabel.textColor = [UIColor colorWithRed:32.f/255.f green:144.f/255.f blue:234.f/255.f alpha:1.f];
callCell.layer.shouldRasterize = YES;
callCell.layer.rasterizationScale = [UIScreen mainScreen].scale;
return callCell;

View File

@ -13,9 +13,13 @@ typedef enum : NSUInteger {
kCallOutgoing = 1,
kCallIncoming = 2,
kCallMissed = 3,
kGroupUpdateJoin = 4,
kGroupUpdateLeft = 5,
kGroupUpdate = 6
} CallStatus;
@interface JSQCall : NSObject <JSQMessageData, NSCoding, NSCopying>
/*
@ -45,6 +49,11 @@ typedef enum : NSUInteger {
*/
@property (nonatomic) TSMessageAdapterType messageType;
/*
* User can configure whether a thumbnail is used in the display of this cell or not
*/
@property (nonatomic) BOOL useThumbnail;
#pragma mark - Initialization
@ -54,6 +63,7 @@ typedef enum : NSUInteger {
status:(CallStatus)status;
-(NSString*)text;
-(NSString*)dateText;
-(UIImage*)thumbnailImage;

View File

@ -21,7 +21,6 @@
{
NSParameterAssert(senderId != nil);
NSParameterAssert(senderDisplayName != nil);
NSParameterAssert(date != nil);
self = [super init];
if (self) {
@ -50,30 +49,51 @@
-(NSString*)text
{
NSString *name = _senderDisplayName;
switch (self.status) {
case kCallMissed:
return [NSString stringWithFormat:@"You missed a call from %@.", _senderDisplayName];
return [NSString stringWithFormat:@"Missed call from %@. ", name];
case kCallIncoming:
return [NSString stringWithFormat:@"You received a call from %@.", _senderDisplayName];
return [NSString stringWithFormat:@"You received a call from %@. ", name];
case kCallOutgoing:
return [NSString stringWithFormat:@"You called %@.", _senderDisplayName];
return [NSString stringWithFormat:@"You called %@. ", name];
default:
return nil;
break;
}
}
-(UIImage*)thumbnailImage
-(NSString*)dateText
{
switch (self.status) {
case kCallMissed:
return [UIImage imageNamed:@"call_missed"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterMediumStyle;
dateFormatter.doesRelativeDateFormatting = YES;
return [dateFormatter stringFromDate:_date];
}
-(UIImage*)thumbnailImage {
// This relies on those assets being in the project
if(!_useThumbnail) {
return nil;
}
switch (_status) {
case kCallOutgoing:
return [UIImage imageNamed:@"statCallOutgoing--blue"];
break;
case kCallIncoming:
return [[UIImage imageNamed:@"call_incoming"] jsq_imageMaskedWithColor:[UIColor darkGrayColor]];
case kCallMissed:
return [UIImage imageNamed:@"statCallIncoming--blue"];
break;
case kCallOutgoing:
return [[UIImage imageNamed:@"call_outgoing"] jsq_imageMaskedWithColor:[UIColor darkGrayColor]];
case kGroupUpdate:
return [UIImage imageNamed:@"statRefreshedGroup--blue"];
break;
case kGroupUpdateLeft:
return [UIImage imageNamed:@"statLeftGroup--blue"];
break;
case kGroupUpdateJoin:
return [UIImage imageNamed:@"statJoinedGroup--blue"];
break;
default:
return nil;
@ -81,6 +101,7 @@
}
}
#pragma mark - NSObject
-(BOOL)isEqual:(id)object

View File

@ -9,8 +9,8 @@
#import "JSQMessagesLabel.h"
#define kCallCellHeight 20.0f
#define kCallCellWidth 200.0f
#define kCallCellHeight 40.0f
#define kCallCellWidth 400.0f
@interface JSQCallCollectionViewCell : UICollectionViewCell