Adjust attachment view layout

This commit is contained in:
giomfo
2014-11-28 18:36:57 +01:00
parent 3d1f578613
commit b2c55fcfb7
5 changed files with 47 additions and 47 deletions

View File

@@ -63,10 +63,13 @@
<dataDetectorType key="dataDetectorTypes" link="YES"/>
</textView>
<imageView contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="mvK-ez-meg" userLabel="Attachment View" customClass="CustomImageView">
<rect key="frame" x="59" y="18" width="184" height="24"/>
<rect key="frame" x="51" y="18" width="192" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="192" id="Ui5-gH-5Oe"/>
</constraints>
</imageView>
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="play.png" translatesAutoresizingMaskIntoConstraints="NO" id="vF4-rq-4Rn">
<rect key="frame" x="135" y="14" width="32" height="32"/>
<rect key="frame" x="131" y="18" width="32" height="32"/>
<constraints>
<constraint firstAttribute="height" constant="32" id="JvT-k9-GoK"/>
<constraint firstAttribute="width" constant="32" id="sTU-9e-QiN"/>
@@ -103,18 +106,17 @@
<constraint firstItem="Ttt-0P-dQW" firstAttribute="leading" secondItem="egJ-aY-QVW" secondAttribute="trailing" id="6L3-Pz-zbG"/>
<constraint firstItem="ds0-yH-8Uu" firstAttribute="leading" secondItem="iJp-sA-hG6" secondAttribute="leadingMargin" constant="243" id="84m-nV-cXU"/>
<constraint firstItem="ds0-yH-8Uu" firstAttribute="top" secondItem="iJp-sA-hG6" secondAttribute="top" constant="10" id="998-YZ-TJ4"/>
<constraint firstItem="J5R-Mh-3hV" firstAttribute="leading" secondItem="mvK-ez-meg" secondAttribute="leading" constant="-8" id="Cbe-us-CeX"/>
<constraint firstItem="mvK-ez-meg" firstAttribute="top" secondItem="iJp-sA-hG6" secondAttribute="top" constant="18" id="AeJ-P9-ueq"/>
<constraint firstAttribute="bottom" secondItem="Ttt-0P-dQW" secondAttribute="bottom" id="GAU-J5-ciT"/>
<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="mvK-ez-meg" firstAttribute="centerY" secondItem="vF4-rq-4Rn" secondAttribute="centerY" id="ROj-jF-hIQ"/>
<constraint firstAttribute="trailing" secondItem="ds0-yH-8Uu" secondAttribute="trailing" constant="8" id="S8j-em-KNk"/>
<constraint firstItem="mvK-ez-meg" firstAttribute="leading" secondItem="uhu-R0-9NH" secondAttribute="trailing" constant="3" id="SBr-0P-RGD"/>
<constraint firstItem="mvK-ez-meg" firstAttribute="centerX" secondItem="vF4-rq-4Rn" secondAttribute="centerX" id="VwV-of-MSN"/>
<constraint firstItem="J5R-Mh-3hV" firstAttribute="trailing" secondItem="mvK-ez-meg" secondAttribute="trailing" constant="8" id="Zdd-F0-OAU"/>
<constraint firstItem="mvK-ez-meg" firstAttribute="top" secondItem="J5R-Mh-3hV" secondAttribute="top" constant="8" id="d5n-ha-SuV"/>
<constraint firstItem="mvK-ez-meg" firstAttribute="bottom" secondItem="J5R-Mh-3hV" secondAttribute="bottom" constant="-8" id="eaa-XD-uyr"/>
<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 firstAttribute="bottom" secondItem="mvK-ez-meg" secondAttribute="bottom" id="mPQ-LG-kca"/>
<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="10" id="rJt-w3-D8g"/>
@@ -124,12 +126,11 @@
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<connections>
<outlet property="attachViewTopConstraint" destination="AeJ-P9-ueq" id="dWA-2c-S7w"/>
<outlet property="attachViewWidthConstraint" destination="Ui5-gH-5Oe" id="d2f-b0-V0B"/>
<outlet property="attachmentView" destination="mvK-ez-meg" id="Qjc-lo-eJS"/>
<outlet property="attachmentViewBottomAlignmentConstraint" destination="eaa-XD-uyr" id="rfK-uw-FzW"/>
<outlet property="attachmentViewTopAlignmentConstraint" destination="d5n-ha-SuV" id="FaQ-jH-5C4"/>
<outlet property="dateTimeView" destination="ds0-yH-8Uu" id="9X2-Wi-VOS"/>
<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"/>
<outlet property="msgTextViewWidthConstraint" destination="rsq-bW-mGt" id="gt4-3A-412"/>
<outlet property="pictureView" destination="uhu-R0-9NH" id="59O-If-m7H"/>
@@ -154,17 +155,20 @@
<dataDetectorType key="dataDetectorTypes" link="YES"/>
</textView>
<imageView contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="QZT-V8-yqJ" userLabel="Attachment View" customClass="CustomImageView">
<rect key="frame" x="357" y="18" width="184" height="24"/>
<rect key="frame" x="357" y="18" width="192" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="192" id="GvD-tV-Uc3"/>
</constraints>
</imageView>
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="play.png" translatesAutoresizingMaskIntoConstraints="NO" id="0Bl-Sv-Q2H">
<rect key="frame" x="433" y="14" width="32" height="32"/>
<rect key="frame" x="437" y="18" width="32" height="32"/>
<constraints>
<constraint firstAttribute="height" constant="32" id="VbS-GC-vtz"/>
<constraint firstAttribute="width" constant="32" id="faJ-bg-xPV"/>
</constraints>
</imageView>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="Pq8-lB-cZM">
<rect key="frame" x="439" y="20" width="20" height="20"/>
<rect key="frame" x="443" y="24" width="20" height="20"/>
</activityIndicatorView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="default-profile.png" translatesAutoresizingMaskIntoConstraints="NO" id="mks-jh-AiZ" customClass="CustomImageView">
<rect key="frame" x="552" y="5" width="40" height="40"/>
@@ -196,41 +200,39 @@
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="18" id="1Cb-Ec-ljT"/>
<constraint firstAttribute="trailing" secondItem="mks-jh-AiZ" secondAttribute="trailing" constant="8" id="1Fh-Wx-A41"/>
<constraint firstAttribute="bottom" secondItem="Glo-Wx-mP6" secondAttribute="bottom" id="23i-Iz-P2P"/>
<constraint firstItem="7qn-gi-w7s" firstAttribute="leading" secondItem="fNQ-DX-U8F" secondAttribute="trailing" id="AH0-j0-oAW"/>
<constraint firstAttribute="bottom" secondItem="07b-tV-EBC" secondAttribute="bottom" id="B5s-6H-lbt"/>
<constraint firstAttribute="trailingMargin" secondItem="07b-tV-EBC" secondAttribute="trailing" constant="248" id="G9X-vw-Q3y"/>
<constraint firstItem="Glo-Wx-mP6" firstAttribute="leading" secondItem="5tf-BC-9Ed" secondAttribute="leading" constant="8" id="HbL-hO-OE7"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="leading" secondItem="7qn-gi-w7s" secondAttribute="leading" constant="8" id="IVl-I8-Dzq"/>
<constraint firstItem="Glo-Wx-mP6" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="10" id="KAT-n3-5vl"/>
<constraint firstAttribute="bottom" secondItem="7qn-gi-w7s" secondAttribute="bottom" id="KPt-Vo-ntg"/>
<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 firstAttribute="trailingMargin" secondItem="Glo-Wx-mP6" secondAttribute="trailing" constant="243" id="NvS-It-8Cv"/>
<constraint firstItem="mks-jh-AiZ" firstAttribute="leading" secondItem="QZT-V8-yqJ" secondAttribute="trailing" constant="3" id="SRM-ka-P24"/>
<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="8" id="U4f-kJ-Kgb"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="centerX" secondItem="0Bl-Sv-Q2H" secondAttribute="centerX" id="Uvh-A6-5G9"/>
<constraint firstAttribute="bottom" secondItem="QZT-V8-yqJ" secondAttribute="bottom" id="WQQ-5s-XvF"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="centerX" secondItem="Pq8-lB-cZM" secondAttribute="centerX" id="a0M-9u-hMC"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="centerY" secondItem="0Bl-Sv-Q2H" secondAttribute="centerY" id="aUE-Bv-XF2"/>
<constraint firstItem="mks-jh-AiZ" firstAttribute="leading" secondItem="7qn-gi-w7s" secondAttribute="trailing" constant="3" id="cCA-xk-XBe"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="centerY" secondItem="Pq8-lB-cZM" secondAttribute="centerY" id="ej0-OC-3hJ"/>
<constraint firstItem="07b-tV-EBC" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="10" id="fF0-vc-51U"/>
<constraint firstItem="7qn-gi-w7s" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="10" id="owD-KZ-snG"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="bottom" secondItem="7qn-gi-w7s" secondAttribute="bottom" constant="-8" id="q4h-EM-X4Z"/>
<constraint firstItem="QZT-V8-yqJ" firstAttribute="trailing" secondItem="7qn-gi-w7s" secondAttribute="trailing" constant="-8" 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="attachViewTopConstraint" destination="1Cb-Ec-ljT" id="ZmH-1B-rfq"/>
<outlet property="attachViewWidthConstraint" destination="GvD-tV-Uc3" id="Odn-zz-zp7"/>
<outlet property="attachmentView" destination="QZT-V8-yqJ" id="Xrj-e5-Yd9"/>
<outlet property="attachmentViewBottomAlignmentConstraint" destination="q4h-EM-X4Z" id="yFu-TN-JOr"/>
<outlet property="attachmentViewTopAlignmentConstraint" destination="U4f-kJ-Kgb" id="OSr-ds-pmD"/>
<outlet property="dateTimeView" destination="Glo-Wx-mP6" id="12R-NA-lfr"/>
<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"/>
<outlet property="msgTextViewWidthConstraint" destination="a6g-WS-jjN" id="aM9-xQ-hVM"/>
<outlet property="pictureView" destination="mks-jh-AiZ" id="qL1-Kd-oRC"/>

View File

@@ -17,8 +17,8 @@
#import "RoomMessageComponent.h"
#define ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH 200
#define ROOM_MESSAGE_MAX_ATTACHMENTVIEW_WIDTH 192
#define ROOM_MESSAGE_TEXTVIEW_MARGIN 5
#define ROOM_MESSAGE_IMAGE_MARGIN 8
typedef enum : NSUInteger {
// Text type

View File

@@ -205,17 +205,17 @@ static NSAttributedString *messageSeparator = nil;
CGFloat width, height;
width = height = 40;
if (_thumbnailInfo) {
width = [_thumbnailInfo[@"w"] integerValue] + 2 * ROOM_MESSAGE_IMAGE_MARGIN;
height = [_thumbnailInfo[@"h"] integerValue] + 2 * ROOM_MESSAGE_IMAGE_MARGIN;
if (width > ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH || height > ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH) {
width = [_thumbnailInfo[@"w"] integerValue];
height = [_thumbnailInfo[@"h"] integerValue];
if (width > ROOM_MESSAGE_MAX_ATTACHMENTVIEW_WIDTH || height > ROOM_MESSAGE_MAX_ATTACHMENTVIEW_WIDTH) {
if (width > height) {
height = (height * ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH) / width;
height = (height * ROOM_MESSAGE_MAX_ATTACHMENTVIEW_WIDTH) / width;
height = floorf(height / 2) * 2;
width = ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH;
width = ROOM_MESSAGE_MAX_ATTACHMENTVIEW_WIDTH;
} else {
width = (width * ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH) / height;
width = (width * ROOM_MESSAGE_MAX_ATTACHMENTVIEW_WIDTH) / height;
width = floorf(width / 2) * 2;
height = ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH;
height = ROOM_MESSAGE_MAX_ATTACHMENTVIEW_WIDTH;
}
}
}

View File

@@ -26,9 +26,8 @@
@property (weak, nonatomic) IBOutlet UIView *dateTimeView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgTextViewWidthConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgTextViewTopConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *msgTextViewBottomConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *attachmentViewTopAlignmentConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *attachmentViewBottomAlignmentConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *attachViewWidthConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *attachViewTopConstraint;
@end
@interface IncomingMessageTableCell : RoomMessageTableCell

View File

@@ -31,7 +31,7 @@
#define UPLOAD_FILE_SIZE 5000000
#define ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_DEFAULT 10
#define ROOM_MESSAGE_CELL_TEXTVIEW_BOTTOM_CONST_DEFAULT 0
#define ROOM_MESSAGE_CELL_ATTACHMENTVIEW_TOP_CONST_DEFAULT 18
NSString *const kCmdChangeDisplayName = @"/nick";
NSString *const kCmdEmote = @"/me";
@@ -802,8 +802,12 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
RoomMessage* message = [messages objectAtIndex:indexPath.row];
// Consider message content height
rowHeight = message.contentSize.height;
rowHeight += ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_DEFAULT;
rowHeight += ROOM_MESSAGE_CELL_TEXTVIEW_BOTTOM_CONST_DEFAULT;
// Add top margin
if (message.messageType == RoomMessageTypeText) {
rowHeight += ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_DEFAULT;
} else {
rowHeight += ROOM_MESSAGE_CELL_ATTACHMENTVIEW_TOP_CONST_DEFAULT;
}
// We consider the minimun cell height (50) in order to display correctly user's picture
if (rowHeight < 50) {
@@ -844,7 +848,9 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
isIncomingMsg = YES;
}
// Restore initial settings of attachment ImageView
// Restore initial settings
cell.msgTextViewTopConstraint.constant = ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_DEFAULT;
cell.attachViewTopConstraint.constant = ROOM_MESSAGE_CELL_ATTACHMENTVIEW_TOP_CONST_DEFAULT;
cell.attachmentView.imageURL = nil; // Cancel potential attachment loading
cell.attachmentView.hidden = YES;
cell.playIconView.hidden = YES;
@@ -852,8 +858,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
while (cell.attachmentView.gestureRecognizers.count) {
[cell.attachmentView removeGestureRecognizer:cell.attachmentView.gestureRecognizers[0]];
}
cell.attachmentViewTopAlignmentConstraint.constant = 0;
cell.attachmentViewBottomAlignmentConstraint.constant = 0;
// Remove potential dateTime label(s)
if (cell.dateTimeView.constraints.count) {
if ([NSLayoutConstraint respondsToSelector:@selector(deactivateConstraints:)]) {
@@ -878,10 +882,6 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
}
}
// Adjust display
cell.msgTextViewTopConstraint.constant = ROOM_MESSAGE_CELL_TEXTVIEW_TOP_CONST_DEFAULT;
cell.msgTextViewBottomConstraint.constant = ROOM_MESSAGE_CELL_TEXTVIEW_BOTTOM_CONST_DEFAULT;
// Handle user's picture
cell.pictureView.hidden = shouldHideSenderInfo;
if (!shouldHideSenderInfo) {
@@ -916,7 +916,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
}
CGSize contentSize = message.contentSize;
if (message.messageType != RoomMessageTypeText) {
cell.messageTextView.attributedText = nil; // Note: Text view is used as attachment background view
cell.messageTextView.hidden = YES;
cell.attachmentView.hidden = NO;
// Update image view frame in order to center loading wheel (if any)
CGRect frame = cell.attachmentView.frame;
@@ -954,11 +954,10 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
@"info" : message.attachmentInfo};
}
// Adjust constraint constant
cell.msgTextViewWidthConstraint.constant = contentSize.width;
cell.attachmentViewTopAlignmentConstraint.constant = ROOM_MESSAGE_IMAGE_MARGIN;
cell.attachmentViewBottomAlignmentConstraint.constant = -ROOM_MESSAGE_IMAGE_MARGIN;
// Adjust Attachment width constant
cell.attachViewWidthConstraint.constant = contentSize.width;
} else {
cell.messageTextView.hidden = NO;
cell.messageTextView.attributedText = message.attributedTextMessage;
// Adjust textView width constraint
cell.msgTextViewWidthConstraint.constant = contentSize.width;
@@ -1734,7 +1733,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
MXEvent *localEvent = [self addLocalEventForAttachedImage:selectedImage];
// Upload image and its thumbnail
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
NSUInteger thumbnailSize = ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH - 2 * ROOM_MESSAGE_IMAGE_MARGIN;
NSUInteger thumbnailSize = ROOM_MESSAGE_MAX_ATTACHMENTVIEW_WIDTH;
[mxHandler.mxRestClient uploadImage:selectedImage thumbnailSize:thumbnailSize timeout:30 success:^(NSDictionary *imageMessage) {
// Send image
[self postMessage:imageMessage withLocalEvent:localEvent];
@@ -1755,7 +1754,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
if (videoThumbnail) {
// Prepare video thumbnail description
NSUInteger thumbnailSize = ROOM_MESSAGE_MAX_TEXTVIEW_WIDTH - 2 * ROOM_MESSAGE_IMAGE_MARGIN;
NSUInteger thumbnailSize = ROOM_MESSAGE_MAX_ATTACHMENTVIEW_WIDTH;
UIImage *thumbnail = [MediaManager resize:videoThumbnail toFitInSize:CGSizeMake(thumbnailSize, thumbnailSize)];
NSMutableDictionary *thumbnailInfo = [[NSMutableDictionary alloc] init];
[thumbnailInfo setValue:@"image/jpeg" forKey:@"mimetype"];