MXKRoomBubbleTableViewCell: Add possiblity to choose between left or right display for timestamp.

This commit is contained in:
SBiOSoftWhare 2022-01-31 17:15:35 +01:00
parent bd4db16e65
commit 26f4aee144
2 changed files with 34 additions and 7 deletions

View file

@ -67,6 +67,17 @@ extern NSString *const kMXKRoomBubbleCellKeyVerificationIncomingRequestDeclinePr
*/
- (void)addTimestampLabelForComponent:(NSUInteger)componentIndex;
/**
Add timestamp label for a component in receiver.
Note: The label added here is automatically removed when [didEndDisplay] is called.
@param componentIndex index of the component in bubble message data
@param displayOnLeft Indicate true to display label on left and false to display on right
*/
- (void)addTimestampLabelForComponent:(NSUInteger)componentIndex
displayOnLeft:(BOOL)displayOnLeft;
/**
Highlight a component in receiver.

View file

@ -36,6 +36,29 @@ NSString *const kMXKRoomBubbleCellKeyVerificationIncomingRequestDeclinePressed =
@implementation MXKRoomBubbleTableViewCell (Riot)
- (void)addTimestampLabelForComponent:(NSUInteger)componentIndex
{
BOOL isFirstDisplayedComponent = (componentIndex == 0);
BOOL isLastMessageMostRecentComponent = NO;
RoomBubbleCellData *roomBubbleCellData;
if ([bubbleData isKindOfClass:RoomBubbleCellData.class])
{
roomBubbleCellData = (RoomBubbleCellData*)bubbleData;
isFirstDisplayedComponent = (componentIndex == roomBubbleCellData.oldestComponentIndex);
isLastMessageMostRecentComponent = roomBubbleCellData.containsLastMessage && (componentIndex == roomBubbleCellData.mostRecentComponentIndex);
}
// Display timestamp on the left for selected component when it cannot overlap other UI elements like user's avatar
BOOL displayLabelOnLeft = roomBubbleCellData.displayTimestampForSelectedComponentOnLeftWhenPossible
&& !isLastMessageMostRecentComponent
&& (!isFirstDisplayedComponent || roomBubbleCellData.shouldHideSenderInformation);
[self addTimestampLabelForComponent:componentIndex displayOnLeft:displayLabelOnLeft];
}
- (void)addTimestampLabelForComponent:(NSUInteger)componentIndex
displayOnLeft:(BOOL)displayLabelOnLeft
{
MXKRoomBubbleComponent *component;
@ -49,7 +72,6 @@ NSString *const kMXKRoomBubbleCellKeyVerificationIncomingRequestDeclinePressed =
if (component && component.date)
{
BOOL isFirstDisplayedComponent = (componentIndex == 0);
BOOL isLastMessageMostRecentComponent = NO;
RoomBubbleCellData *roomBubbleCellData;
@ -57,14 +79,8 @@ NSString *const kMXKRoomBubbleCellKeyVerificationIncomingRequestDeclinePressed =
{
roomBubbleCellData = (RoomBubbleCellData*)bubbleData;
isFirstDisplayedComponent = (componentIndex == roomBubbleCellData.oldestComponentIndex);
isLastMessageMostRecentComponent = roomBubbleCellData.containsLastMessage && (componentIndex == roomBubbleCellData.mostRecentComponentIndex);
}
// Display timestamp on the left for selected component when it cannot overlap other UI elements like user's avatar
BOOL displayLabelOnLeft = roomBubbleCellData.displayTimestampForSelectedComponentOnLeftWhenPossible
&& !isLastMessageMostRecentComponent
&& ( !isFirstDisplayedComponent || roomBubbleCellData.shouldHideSenderInformation);
[self addTimestampLabelForComponentIndex:componentIndex
isFirstDisplayedComponent:isFirstDisplayedComponent
viewTag:componentIndex