Skip to content
This repository was archived by the owner on Mar 9, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/NSBubbleData.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
typedef enum _NSBubbleType
{
BubbleTypeMine = 0,
BubbleTypeSomeoneElse = 1
BubbleTypeSomeoneElse = 1,
BubbleTypeMyStatus = 2,
BubbleTypeSomeoneElsesStatus = 3
} NSBubbleType;

@interface NSBubbleData : NSObject
Expand All @@ -23,6 +25,7 @@ typedef enum _NSBubbleType
@property (readonly, nonatomic, strong) UIView *view;
@property (readonly, nonatomic) UIEdgeInsets insets;
@property (nonatomic, strong) UIImage *avatar;
@property (nonatomic, strong) NSString *screenName;

- (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type;
+ (id)dataWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type;
Expand Down
15 changes: 14 additions & 1 deletion src/NSBubbleData.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ @implementation NSBubbleData
@synthesize view = _view;
@synthesize insets = _insets;
@synthesize avatar = _avatar;
@synthesize screenName = _screenName;

#pragma mark - Lifecycle

Expand All @@ -41,6 +42,7 @@ - (void)dealloc

const UIEdgeInsets textInsetsMine = {5, 10, 11, 17};
const UIEdgeInsets textInsetsSomeone = {5, 15, 11, 10};
const UIEdgeInsets textInsetsStatus = {2, 5, 2, 5};

+ (id)dataWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type
{
Expand All @@ -63,11 +65,22 @@ - (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type
label.font = font;
label.backgroundColor = [UIColor clearColor];

if (type == BubbleTypeMyStatus || type == BubbleTypeSomeoneElsesStatus) {
label.textColor = [UIColor whiteColor];
label.shadowColor = [UIColor grayColor];
label.shadowOffset = CGSizeMake(0, -1.f);
}

#if !__has_feature(objc_arc)
[label autorelease];
#endif

UIEdgeInsets insets = (type == BubbleTypeMine ? textInsetsMine : textInsetsSomeone);
UIEdgeInsets insets;
if (type == BubbleTypeMine || type == BubbleTypeSomeoneElse)
insets = (type == BubbleTypeMine || type == BubbleTypeMyStatus ? textInsetsMine : textInsetsSomeone);
else
insets = textInsetsStatus;

return [self initWithView:label date:date type:type insets:insets];
}

Expand Down
30 changes: 28 additions & 2 deletions src/UIBubbleTableView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,29 @@ - (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
}

NSBubbleData *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1];
return MAX(data.insets.top + data.view.frame.size.height + data.insets.bottom, self.showAvatars ? 52 : 0);

if (indexPath.row > 1) {
NSBubbleData *previousData = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 2];

if ([previousData.screenName isEqualToString:data.screenName]) {
data.screenName = nil;
}
}

CGFloat height;
if (data.type == BubbleTypeMyStatus || data.type == BubbleTypeSomeoneElsesStatus)
height = MAX(data.insets.top + data.view.frame.size.height + data.insets.bottom, 0);
else
height = MAX(data.insets.top + data.view.frame.size.height + data.insets.bottom, self.showAvatars ? 54 : 0);

if (data.screenName)
height += 22.f;

return height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
{
// Now typing
if (indexPath.section >= [self.bubbleSection count])
{
Expand Down Expand Up @@ -222,6 +240,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UIBubbleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
NSBubbleData *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1];

if (indexPath.row > 1) {
NSBubbleData *previousData = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 2];

if ([previousData.screenName isEqualToString:data.screenName]) {
data.screenName = nil;
}
}

if (cell == nil) cell = [[UIBubbleTableViewCell alloc] init];

cell.data = data;
Expand Down
31 changes: 24 additions & 7 deletions src/UIBubbleTableViewCell.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ @interface UIBubbleTableViewCell ()
@property (nonatomic, retain) UIView *customView;
@property (nonatomic, retain) UIImageView *bubbleImage;
@property (nonatomic, retain) UIImageView *avatarImage;
@property (nonatomic, retain) UILabel* screenNameLabel;

- (void) setupInternalData;

Expand Down Expand Up @@ -72,11 +73,11 @@ - (void) setupInternalData
CGFloat width = self.data.view.frame.size.width;
CGFloat height = self.data.view.frame.size.height;

CGFloat x = (type == BubbleTypeSomeoneElse) ? 0 : self.frame.size.width - width - self.data.insets.left - self.data.insets.right;
CGFloat y = 0;
CGFloat x = (type == BubbleTypeSomeoneElse | type == BubbleTypeSomeoneElsesStatus) ? 0 : self.frame.size.width - width - self.data.insets.left - self.data.insets.right;
CGFloat y = (_data.screenName ? 20.f : 0.f);

// Adjusting the x coordinate for avatar
if (self.showAvatar)
if (self.showAvatar && (type == BubbleTypeMine || type == BubbleTypeSomeoneElse))
{
[self.avatarImage removeFromSuperview];
#if !__has_feature(objc_arc)
Expand All @@ -89,7 +90,7 @@ - (void) setupInternalData
self.avatarImage.layer.borderColor = [UIColor colorWithWhite:0.0 alpha:0.2].CGColor;
self.avatarImage.layer.borderWidth = 1.0;

CGFloat avatarX = (type == BubbleTypeSomeoneElse) ? 2 : self.frame.size.width - 52;
CGFloat avatarX = (type == BubbleTypeSomeoneElse | type == BubbleTypeSomeoneElsesStatus) ? 2 : self.frame.size.width - 52;
CGFloat avatarY = self.frame.size.height - 50;

self.avatarImage.frame = CGRectMake(avatarX, avatarY, 50, 50);
Expand All @@ -98,9 +99,23 @@ - (void) setupInternalData
CGFloat delta = self.frame.size.height - (self.data.insets.top + self.data.insets.bottom + self.data.view.frame.size.height);
if (delta > 0) y = delta;

if (type == BubbleTypeSomeoneElse) x += 54;
if (type == BubbleTypeSomeoneElse | type == BubbleTypeSomeoneElsesStatus) x += 54;
if (type == BubbleTypeMine) x -= 54;
}

if (_data.screenName && type == BubbleTypeSomeoneElse) {
[self.screenNameLabel removeFromSuperview];

self.screenNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, self.bounds.size.width, 20.f)];
self.screenNameLabel.text = _data.screenName;
self.screenNameLabel.backgroundColor = [UIColor clearColor];
self.screenNameLabel.font = [UIFont boldSystemFontOfSize:18.f];
self.screenNameLabel.textColor = [UIColor darkGrayColor];
self.screenNameLabel.shadowColor = [UIColor whiteColor];
self.screenNameLabel.shadowOffset = CGSizeMake(0, 1.f);

[self addSubview:self.screenNameLabel];
}

[self.customView removeFromSuperview];
self.customView = self.data.view;
Expand All @@ -112,10 +127,12 @@ - (void) setupInternalData
self.bubbleImage.image = [[UIImage imageNamed:@"bubbleSomeone.png"] stretchableImageWithLeftCapWidth:21 topCapHeight:14];

}
else {
else if (type == BubbleTypeMine) {
self.bubbleImage.image = [[UIImage imageNamed:@"bubbleMine.png"] stretchableImageWithLeftCapWidth:15 topCapHeight:14];
} else {
self.bubbleImage.image = nil;
}

self.bubbleImage.frame = CGRectMake(x, y, width + self.data.insets.left + self.data.insets.right, height + self.data.insets.top + self.data.insets.bottom);
}

Expand Down