Chat screen: Update bubble layout

-Define all required cell view classes
-Disable timestamp display (TODO display timestamp for last message, and selected message if any).
This commit is contained in:
giomfo
2015-12-08 10:10:59 +01:00
parent 1ed9058be6
commit 7c6057bfed
29 changed files with 1460 additions and 552 deletions
+1 -142
View File
@@ -30,152 +30,11 @@
if (self)
{
// use the matrix style placeholder
// use the vector style placeholder
self.senderAvatarPlaceholder = [AvatarGenerator generateRoomMemberAvatar:self.senderId displayName:self.senderDisplayName];
}
return self;
}
- (NSAttributedString*)attributedTextMessage
{
if (!attributedTextMessage.length && bubbleComponents.count)
{
if (super.showBubbleDateTime == NO)
{
return super.attributedTextMessage;
}
else
{
// Create attributed string by adding each component timestamp
NSMutableAttributedString *currentAttributedTextMsg;
NSAttributedString *dateTimeAttributedStr;
NSDictionary *attributes;
if ([self.eventFormatter isKindOfClass:[EventFormatter class]])
{
attributes = [(EventFormatter*)self.eventFormatter stringAttributesForEventTimestamp];
}
for (MXKRoomBubbleComponent* component in bubbleComponents)
{
if (!currentAttributedTextMsg)
{
currentAttributedTextMsg = [[NSMutableAttributedString alloc] initWithAttributedString:component.attributedTextMessage];
}
else
{
// Append attributed text
[currentAttributedTextMsg appendAttributedString:[MXKRoomBubbleCellDataWithAppendingMode messageSeparator]];
[currentAttributedTextMsg appendAttributedString:component.attributedTextMessage];
}
// Append component timestamp
NSString *dateTimeStr = [NSString stringWithFormat:@" %@", [self.eventFormatter dateStringFromDate:component.date withTime:YES]];
if (attributes)
{
dateTimeAttributedStr = [[NSAttributedString alloc] initWithString:dateTimeStr attributes:attributes];
}
else
{
dateTimeAttributedStr = [[NSAttributedString alloc] initWithString:dateTimeStr];
}
[currentAttributedTextMsg appendAttributedString:dateTimeAttributedStr];
}
attributedTextMessage = currentAttributedTextMsg;
}
}
return attributedTextMessage;
}
- (void)setShowBubbleDateTime:(BOOL)showBubbleDateTime
{
if (super.showBubbleDateTime != showBubbleDateTime)
{
super.showBubbleDateTime = showBubbleDateTime;
// Attributed string must be rebuilt
self.attributedTextMessage = nil;
}
}
#pragma mark -
- (void)prepareBubbleComponentsPosition
{
if (super.showBubbleDateTime == NO)
{
[super prepareBubbleComponentsPosition];
}
else
{
// We will let super prepare only the first component position by disabling shouldUpdateComponentsPosition flag
BOOL savedShouldUpdateComponentsPosition = shouldUpdateComponentsPosition;
shouldUpdateComponentsPosition = NO;
[super prepareBubbleComponentsPosition];
// Check whether the position of other components need to be refreshed
if (self.attachment || !savedShouldUpdateComponentsPosition || bubbleComponents.count < 2)
{
return;
}
// Compute height of the first text component by considering displayed timestamp
NSAttributedString *dateTimeAttributedStr;
NSDictionary *attributes;
if ([self.eventFormatter isKindOfClass:[EventFormatter class]])
{
attributes = [(EventFormatter*)self.eventFormatter stringAttributesForEventTimestamp];
}
MXKRoomBubbleComponent *component = [bubbleComponents firstObject];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:component.attributedTextMessage];
// Append component timestamp
NSString *dateTimeStr = [NSString stringWithFormat:@" %@", [self.eventFormatter dateStringFromDate:component.date withTime:YES]];
if (attributes)
{
dateTimeAttributedStr = [[NSAttributedString alloc] initWithString:dateTimeStr attributes:attributes];
}
else
{
dateTimeAttributedStr = [[NSAttributedString alloc] initWithString:dateTimeStr];
}
[attributedString appendAttributedString:dateTimeAttributedStr];
CGFloat componentHeight = [self rawTextHeight:attributedString];
// Set position for each other component
CGFloat positionY = component.position.y;
CGFloat cumulatedHeight = 0;
for (NSUInteger index = 1; index < bubbleComponents.count; index++)
{
cumulatedHeight += componentHeight;
positionY += componentHeight;
component = [bubbleComponents objectAtIndex:index];
component.position = CGPointMake(0, positionY);
// Compute height of the current component
[attributedString appendAttributedString:[MXKRoomBubbleCellDataWithAppendingMode messageSeparator]];
[attributedString appendAttributedString:component.attributedTextMessage];
dateTimeStr = [NSString stringWithFormat:@" %@", [self.eventFormatter dateStringFromDate:component.date withTime:YES]];
if (attributes)
{
dateTimeAttributedStr = [[NSAttributedString alloc] initWithString:dateTimeStr attributes:attributes];
}
else
{
dateTimeAttributedStr = [[NSAttributedString alloc] initWithString:dateTimeStr];
}
[attributedString appendAttributedString:dateTimeAttributedStr];
componentHeight = [self rawTextHeight:attributedString] - cumulatedHeight;
}
}
}
@end