Room details: display messages timestamp

This commit is contained in:
giomfo
2014-11-13 17:00:05 +01:00
parent ff809c8308
commit 2c4928b7bd
3 changed files with 102 additions and 9 deletions

View File

@@ -39,7 +39,7 @@
<color key="sectionIndexBackgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="sectionIndexTrackingBackgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="IncomingMessageCell" rowHeight="70" id="Lq0-jR-3i5" customClass="IncomingMessageTableCell">
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="IncomingMessageCell" id="Lq0-jR-3i5" customClass="IncomingMessageTableCell">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Lq0-jR-3i5" id="iJp-sA-hG6">
<autoresizingMask key="autoresizingMask"/>
@@ -52,7 +52,7 @@
</constraints>
</imageView>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="J5R-Mh-3hV">
<rect key="frame" x="51" y="20" width="200" height="50"/>
<rect key="frame" x="51" y="20" width="200" height="30"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="rsq-bW-mGt"/>
@@ -62,7 +62,7 @@
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="mvK-ez-meg" userLabel="Attachment View">
<rect key="frame" x="56" y="25" width="190" height="40"/>
<rect key="frame" x="56" y="25" width="190" height="20"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="User name:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="8" translatesAutoresizingMaskIntoConstraints="NO" id="egJ-aY-QVW">
<rect key="frame" x="51" y="3" width="200" height="20"/>
@@ -75,25 +75,52 @@
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ttt-0P-dQW" userLabel="showHideDateTime">
<rect key="frame" x="251" y="0.0" width="349" height="50"/>
<state key="normal">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showHideDateTime:" destination="msb-ol-2LB" eventType="touchUpInside" id="p6W-1a-kI3"/>
</connections>
</button>
<label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Nov 13 14:44" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="8" translatesAutoresizingMaskIntoConstraints="NO" id="yRH-kt-si3" userLabel="DateTimeLabel">
<rect key="frame" x="251" y="25" width="341" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="vdP-aa-23E"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="J5R-Mh-3hV" secondAttribute="bottom" id="662-Ze-6ia"/>
<constraint firstItem="Ttt-0P-dQW" firstAttribute="leading" secondItem="egJ-aY-QVW" secondAttribute="trailing" id="6L3-Pz-zbG"/>
<constraint firstItem="J5R-Mh-3hV" firstAttribute="leading" secondItem="mvK-ez-meg" secondAttribute="leading" constant="-5" id="Cbe-us-CeX"/>
<constraint firstAttribute="bottom" secondItem="Ttt-0P-dQW" secondAttribute="bottom" id="GAU-J5-ciT"/>
<constraint firstItem="yRH-kt-si3" firstAttribute="leading" secondItem="J5R-Mh-3hV" secondAttribute="trailing" id="JMP-AW-CDI"/>
<constraint firstItem="egJ-aY-QVW" firstAttribute="top" secondItem="iJp-sA-hG6" secondAttribute="top" constant="3" id="N8f-0n-ObR"/>
<constraint firstItem="Ttt-0P-dQW" firstAttribute="top" secondItem="iJp-sA-hG6" secondAttribute="top" id="Ptt-qa-Cg4"/>
<constraint firstItem="J5R-Mh-3hV" firstAttribute="trailing" secondItem="mvK-ez-meg" secondAttribute="trailing" constant="5" id="Zdd-F0-OAU"/>
<constraint firstItem="J5R-Mh-3hV" firstAttribute="top" secondItem="mvK-ez-meg" secondAttribute="top" constant="-5" id="d5n-ha-SuV"/>
<constraint firstItem="J5R-Mh-3hV" firstAttribute="bottom" secondItem="mvK-ez-meg" secondAttribute="bottom" constant="5" id="eaa-XD-uyr"/>
<constraint firstItem="yRH-kt-si3" firstAttribute="top" secondItem="iJp-sA-hG6" secondAttribute="top" constant="25" id="epA-UD-55M"/>
<constraint firstItem="uhu-R0-9NH" firstAttribute="leading" secondItem="iJp-sA-hG6" secondAttribute="leading" constant="8" id="fNV-Tp-p31"/>
<constraint firstAttribute="trailing" secondItem="Ttt-0P-dQW" secondAttribute="trailing" id="mJg-Df-CWQ"/>
<constraint firstItem="uhu-R0-9NH" firstAttribute="top" secondItem="iJp-sA-hG6" secondAttribute="top" constant="5" id="mer-CT-cEg"/>
<constraint firstItem="J5R-Mh-3hV" firstAttribute="leading" secondItem="uhu-R0-9NH" secondAttribute="trailing" constant="3" id="qkW-ys-ckn"/>
<constraint firstItem="J5R-Mh-3hV" firstAttribute="top" secondItem="iJp-sA-hG6" secondAttribute="top" constant="20" id="rJt-w3-D8g"/>
<constraint firstAttribute="trailing" secondItem="yRH-kt-si3" secondAttribute="trailing" constant="8" id="vh8-ds-cqA"/>
<constraint firstItem="egJ-aY-QVW" firstAttribute="leading" secondItem="uhu-R0-9NH" secondAttribute="trailing" constant="3" id="wym-In-Raa"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<connections>
<outlet property="attachmentView" destination="mvK-ez-meg" id="Qjc-lo-eJS"/>
<outlet property="dateTimeLabel" destination="yRH-kt-si3" id="udF-ai-dIs"/>
<outlet property="dateTimeLabelTopConstraint" destination="epA-UD-55M" id="QAB-r7-aT6"/>
<outlet property="messageTextView" destination="J5R-Mh-3hV" id="d45-NI-bod"/>
<outlet property="msgTextViewBottomConstraint" destination="662-Ze-6ia" id="wfd-E3-UIV"/>
<outlet property="msgTextViewTopConstraint" destination="rJt-w3-D8g" id="6Um-o1-J08"/>
@@ -141,13 +168,36 @@
<color key="textColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fNQ-DX-U8F" userLabel="showHideDateTime">
<rect key="frame" x="0.0" y="0.0" width="349" height="50"/>
<state key="normal">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showHideDateTime:" destination="msb-ol-2LB" eventType="touchUpInside" id="eOG-oA-DQn"/>
</connections>
</button>
<label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Nov 13 14:44" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="8" translatesAutoresizingMaskIntoConstraints="NO" id="2lD-F0-Haf" userLabel="DateTimeLabel">
<rect key="frame" x="8" y="25" width="341" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="OfQ-rH-7Bi"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="mks-jh-AiZ" secondAttribute="trailing" constant="8" id="1Fh-Wx-A41"/>
<constraint firstItem="2lD-F0-Haf" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="25" id="7Ee-H6-Wsd"/>
<constraint firstItem="7qn-gi-w7s" firstAttribute="leading" secondItem="fNQ-DX-U8F" secondAttribute="trailing" id="AH0-j0-oAW"/>
<constraint firstItem="2lD-F0-Haf" firstAttribute="leading" secondItem="5tf-BC-9Ed" secondAttribute="leading" constant="8" id="CX9-TJ-kJ5"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="leading" secondItem="7qn-gi-w7s" secondAttribute="leading" constant="5" id="IVl-I8-Dzq"/>
<constraint firstAttribute="bottom" secondItem="7qn-gi-w7s" secondAttribute="bottom" id="KPt-Vo-ntg"/>
<constraint firstItem="alD-cg-uMl" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="14" id="M1S-HJ-o3b"/>
<constraint firstItem="fNQ-DX-U8F" firstAttribute="leading" secondItem="5tf-BC-9Ed" secondAttribute="leading" id="MqK-3Z-lp5"/>
<constraint firstAttribute="bottom" secondItem="fNQ-DX-U8F" secondAttribute="bottom" id="NUK-Kq-ITl"/>
<constraint firstItem="mks-jh-AiZ" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="5" id="SSl-4u-03L"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="top" secondItem="7qn-gi-w7s" secondAttribute="top" constant="5" id="U4f-kJ-Kgb"/>
<constraint firstItem="7qn-gi-w7s" firstAttribute="leading" secondItem="alD-cg-uMl" secondAttribute="trailing" constant="5" id="Vde-Q3-e8O"/>
@@ -156,13 +206,17 @@
<constraint firstItem="QZT-V8-yqJ" firstAttribute="centerY" secondItem="Pq8-lB-cZM" secondAttribute="centerY" id="ej0-OC-3hJ"/>
<constraint firstItem="7qn-gi-w7s" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="20" id="owD-KZ-snG"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="bottom" secondItem="7qn-gi-w7s" secondAttribute="bottom" constant="-5" id="q4h-EM-X4Z"/>
<constraint firstItem="7qn-gi-w7s" firstAttribute="leading" secondItem="2lD-F0-Haf" secondAttribute="trailing" id="q5r-bz-qP7"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="trailing" secondItem="7qn-gi-w7s" secondAttribute="trailing" constant="-5" id="tgM-eJ-BEk"/>
<constraint firstItem="fNQ-DX-U8F" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" id="wb3-8X-eQH"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<connections>
<outlet property="activityIndicator" destination="Pq8-lB-cZM" id="YBm-xk-m7t"/>
<outlet property="attachmentView" destination="QZT-V8-yqJ" id="Xrj-e5-Yd9"/>
<outlet property="dateTimeLabel" destination="2lD-F0-Haf" id="8Lb-qZ-9vJ"/>
<outlet property="dateTimeLabelTopConstraint" destination="7Ee-H6-Wsd" id="BFa-Sf-lzF"/>
<outlet property="messageTextView" destination="7qn-gi-w7s" id="0b2-5P-dqR"/>
<outlet property="msgTextViewBottomConstraint" destination="KPt-Vo-ntg" id="5bw-yH-fYK"/>
<outlet property="msgTextViewTopConstraint" destination="owD-KZ-snG" id="oqc-0f-05O"/>

View File

@@ -21,9 +21,11 @@
@interface RoomMessageTableCell : CustomTableViewCell
@property (weak, nonatomic) IBOutlet UITextView *messageTextView;
@property (strong, nonatomic) IBOutlet UIImageView *attachmentView;
@property (weak, nonatomic) IBOutlet UILabel *dateTimeLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgTextViewWidthConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgTextViewTopConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgTextViewBottomConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *dateTimeLabelTopConstraint;
@property (strong, nonatomic) NSString *attachedImageURL;
@end

View File

@@ -28,7 +28,8 @@
#define ROOM_MESSAGE_CELL_MAX_TEXTVIEW_WIDTH 200
#define ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_DEFAULT 10
#define ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_GROUPED_CELL (-5)
#define ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_IN_CHUNK (-5)
#define ROOM_MESSAGE_CELL_TEXTVIEW_EDGE_INSET_TOP_IN_CHUNK ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_IN_CHUNK
#define ROOM_MESSAGE_CELL_TEXTVIEW_BOTTOM_CONST_DEFAULT 0
#define ROOM_MESSAGE_CELL_TEXTVIEW_BOTTOM_CONST_GROUPED_CELL (-5)
@@ -60,6 +61,9 @@ NSString *const kFailedEventId = @"failedEventId";
NSArray *members;
id membersListener;
// Date formatter (nil if dateTimeLabel is hidden)
NSDateFormatter *dateFormatter;
// Cache
NSMutableArray *tmpCachedAttachments;
}
@@ -124,6 +128,10 @@ NSString *const kFailedEventId = @"failedEventId";
[self.actionMenu dismiss:NO];
self.actionMenu = nil;
}
if (dateFormatter) {
dateFormatter = nil;
}
}
- (void)didReceiveMemoryWarning {
@@ -572,7 +580,7 @@ NSString *const kFailedEventId = @"failedEventId";
rowHeight += ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_DEFAULT;
} else {
// Inside chunk the height of the cell is reduced in order to reduce padding between messages
rowHeight += ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_GROUPED_CELL;
rowHeight += ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_IN_CHUNK;
}
// Check whether the message is the last message of the current chunk
@@ -654,10 +662,10 @@ NSString *const kFailedEventId = @"failedEventId";
cell.pictureView.hidden = YES;
// The height of this cell has been reduced in order to reduce padding between messages of the same chunk
// We define here a negative constant for the top space between textView and its superview to display correctly the message text.
cell.msgTextViewTopConstraint.constant = ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_GROUPED_CELL;
// Shift to the top the displayed message to reduce padding between messages of the same chunk
cell.msgTextViewTopConstraint.constant = ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_IN_CHUNK;
// Shift to the top the displayed message to reduce space with the previous messages
UIEdgeInsets edgeInsets = UIEdgeInsetsZero;
edgeInsets.top = ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_GROUPED_CELL;
edgeInsets.top = ROOM_MESSAGE_CELL_TEXTVIEW_EDGE_INSET_TOP_IN_CHUNK;
cell.messageTextView.contentInset = edgeInsets;
// Check whether the next message belongs to the same chunk in order to define bottom space between textView and its superview
@@ -694,7 +702,8 @@ NSString *const kFailedEventId = @"failedEventId";
} else if ([mxEvent.eventId hasPrefix:kFailedEventId]) {
cell.messageTextView.textColor = [UIColor redColor];
outgoingMsgCell.unsentLabel.hidden = NO;
outgoingMsgCell.unsentLabelTopConstraint.constant = cell.msgTextViewTopConstraint.constant + cell.messageTextView.contentInset.top - ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_GROUPED_CELL;
// Align unsent label with the textView
outgoingMsgCell.unsentLabelTopConstraint.constant = cell.msgTextViewTopConstraint.constant + cell.messageTextView.contentInset.top - ROOM_MESSAGE_CELL_TEXTVIEW_EDGE_INSET_TOP_IN_CHUNK;
} else {
cell.messageTextView.textColor = [UIColor blackColor];
}
@@ -741,6 +750,17 @@ NSString *const kFailedEventId = @"failedEventId";
cell.messageTextView.text = displayText;
}
// Handle timestamp display
if (dateFormatter && mxEvent.originServerTs) {
cell.dateTimeLabel.hidden = NO;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:mxEvent.originServerTs/1000];
cell.dateTimeLabel.text = [dateFormatter stringFromDate:date];
// Align dateTime label with the textView
cell.dateTimeLabelTopConstraint.constant = cell.msgTextViewTopConstraint.constant + cell.messageTextView.contentInset.top - ROOM_MESSAGE_CELL_TEXTVIEW_EDGE_INSET_TOP_IN_CHUNK;
} else {
cell.dateTimeLabel.hidden = YES;
}
return cell;
}
@@ -1030,6 +1050,23 @@ NSString *const kFailedEventId = @"failedEventId";
}
}
- (IBAction)showHideDateTime:(id)sender {
if (dateFormatter) {
// dateTime will be hidden
dateFormatter = nil;
} else {
// dateTime will be visible
NSString *dateFormat = @"MMM dd HH:mm";
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:[[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]]];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateFormat:dateFormat];
}
[self.messagesTableView reloadData];
}
#pragma mark - Post messages
- (void)postMessage:(NSDictionary*)msgContent withLocalEventId:(NSString*)localEventId {