mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 15:09:31 +02:00
Room details: display attached images
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6245" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="GsA-m1-kGB">
|
||||
<dependencies>
|
||||
<deployment defaultVersion="1536" identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
|
||||
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
@@ -61,6 +60,12 @@
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<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="30" width="190" height="30"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="190" id="gVc-k2-DHn"/>
|
||||
</constraints>
|
||||
</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="5" width="200" height="20"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
@@ -77,6 +82,9 @@
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottom" secondItem="J5R-Mh-3hV" secondAttribute="bottom" constant="5" id="662-Ze-6ia"/>
|
||||
<constraint firstItem="egJ-aY-QVW" firstAttribute="top" secondItem="iJp-sA-hG6" secondAttribute="top" constant="5" id="N8f-0n-ObR"/>
|
||||
<constraint firstAttribute="bottom" secondItem="mvK-ez-meg" secondAttribute="bottom" constant="10" id="QDe-wv-ghR"/>
|
||||
<constraint firstItem="mvK-ez-meg" firstAttribute="top" secondItem="egJ-aY-QVW" secondAttribute="bottom" constant="5" id="Ymi-fN-lGW"/>
|
||||
<constraint firstItem="mvK-ez-meg" firstAttribute="leading" secondItem="uhu-R0-9NH" secondAttribute="trailing" constant="8" id="ZSk-GW-jSc"/>
|
||||
<constraint firstItem="uhu-R0-9NH" firstAttribute="leading" secondItem="iJp-sA-hG6" secondAttribute="leading" constant="8" id="fNV-Tp-p31"/>
|
||||
<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"/>
|
||||
@@ -86,6 +94,7 @@
|
||||
</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="messageTextView" destination="J5R-Mh-3hV" id="d45-NI-bod"/>
|
||||
<outlet property="pictureView" destination="uhu-R0-9NH" id="59O-If-m7H"/>
|
||||
<outlet property="userNameLabel" destination="egJ-aY-QVW" id="IWg-7t-5Vp"/>
|
||||
@@ -107,6 +116,12 @@
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
|
||||
</textView>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="QZT-V8-yqJ" userLabel="Attachment View">
|
||||
<rect key="frame" x="354" y="10" width="190" height="30"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="190" id="0gc-hU-Jtc"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="default-profile.png" translatesAutoresizingMaskIntoConstraints="NO" id="mks-jh-AiZ">
|
||||
<rect key="frame" x="552" y="5" width="40" height="40"/>
|
||||
<constraints>
|
||||
@@ -132,12 +147,16 @@
|
||||
<constraint firstItem="alD-cg-uMl" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="14" id="M1S-HJ-o3b"/>
|
||||
<constraint firstItem="mks-jh-AiZ" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="5" id="SSl-4u-03L"/>
|
||||
<constraint firstItem="7qn-gi-w7s" firstAttribute="leading" secondItem="alD-cg-uMl" secondAttribute="trailing" constant="5" id="Vde-Q3-e8O"/>
|
||||
<constraint firstItem="mks-jh-AiZ" firstAttribute="leading" secondItem="QZT-V8-yqJ" secondAttribute="trailing" constant="8" id="a1U-Ar-6ln"/>
|
||||
<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="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="10" id="eSd-gt-RQQ"/>
|
||||
<constraint firstAttribute="bottom" secondItem="QZT-V8-yqJ" secondAttribute="bottom" constant="10" id="lEk-gQ-G3T"/>
|
||||
<constraint firstItem="7qn-gi-w7s" firstAttribute="top" secondItem="5tf-BC-9Ed" secondAttribute="top" constant="5" id="owD-KZ-snG"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<connections>
|
||||
<outlet property="attachmentView" destination="QZT-V8-yqJ" id="Xrj-e5-Yd9"/>
|
||||
<outlet property="messageTextView" destination="7qn-gi-w7s" id="0b2-5P-dqR"/>
|
||||
<outlet property="pictureView" destination="mks-jh-AiZ" id="qL1-Kd-oRC"/>
|
||||
<outlet property="unsentLabel" destination="alD-cg-uMl" id="UXm-mh-sux"/>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#import "MediaManager.h"
|
||||
|
||||
@interface CustomTableViewCell () {
|
||||
id mediaLoader;
|
||||
id userPictureLoader;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
|
||||
- (void)setPictureURL:(NSString *)pictureURL {
|
||||
// Cancel media loader in progress (if any)
|
||||
if (mediaLoader) {
|
||||
[MediaManager cancel:mediaLoader];
|
||||
mediaLoader = nil;
|
||||
if (userPictureLoader) {
|
||||
[MediaManager cancel:userPictureLoader];
|
||||
userPictureLoader = nil;
|
||||
}
|
||||
|
||||
_pictureURL = pictureURL;
|
||||
@@ -42,7 +42,7 @@
|
||||
// Consider provided url to update image view
|
||||
if (pictureURL) {
|
||||
// Load picture
|
||||
mediaLoader = [MediaManager loadPicture:pictureURL
|
||||
userPictureLoader = [MediaManager loadPicture:pictureURL
|
||||
success:^(UIImage *image) {
|
||||
_pictureView.image = image;
|
||||
}
|
||||
@@ -52,9 +52,9 @@
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if (mediaLoader) {
|
||||
[MediaManager cancel:mediaLoader];
|
||||
mediaLoader = nil;
|
||||
if (userPictureLoader) {
|
||||
[MediaManager cancel:userPictureLoader];
|
||||
userPictureLoader = nil;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
// Room Message Table View Cell
|
||||
@interface RoomMessageTableCell : CustomTableViewCell
|
||||
@property (weak, nonatomic) IBOutlet UITextView *messageTextView;
|
||||
@property (strong, nonatomic) IBOutlet UIImageView *attachmentView;
|
||||
|
||||
@property (strong, nonatomic) NSString *attachedImageURL;
|
||||
@end
|
||||
|
||||
@interface IncomingMessageTableCell : RoomMessageTableCell
|
||||
|
||||
@@ -15,9 +15,47 @@
|
||||
*/
|
||||
|
||||
#import "RoomMessageTableCell.h"
|
||||
#import "MediaManager.h"
|
||||
|
||||
@interface RoomMessageTableCell () {
|
||||
id attachmentLoader;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation RoomMessageTableCell
|
||||
|
||||
- (void)setAttachedImageURL:(NSString *)attachedImageURL {
|
||||
// Cancel media loader in progress (if any)
|
||||
if (attachmentLoader) {
|
||||
[MediaManager cancel:attachmentLoader];
|
||||
attachmentLoader = nil;
|
||||
}
|
||||
|
||||
_attachedImageURL = attachedImageURL;
|
||||
|
||||
// Reset image view
|
||||
_attachmentView.image = nil;
|
||||
// Consider provided url to update image view
|
||||
if (attachedImageURL) {
|
||||
// Load picture
|
||||
attachmentLoader = [MediaManager loadPicture:attachedImageURL
|
||||
success:^(UIImage *image) {
|
||||
_attachmentView.image = image;
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
NSLog(@"Failed to download attachment (%@): %@", _attachedImageURL, error);
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if (attachmentLoader) {
|
||||
[MediaManager cancel:attachmentLoader];
|
||||
attachmentLoader = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -436,22 +436,32 @@ NSString *const kFailedEventId = @"failedEventId";
|
||||
return 50;
|
||||
}
|
||||
|
||||
// Handle here room thread cells
|
||||
// Compute here height of message cells
|
||||
CGFloat rowHeight;
|
||||
// Get event related to this row
|
||||
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
|
||||
MXEvent *mxEvent = [messages objectAtIndex:indexPath.row];
|
||||
BOOL isIncomingMsg = ([mxEvent.user_id isEqualToString:mxHandler.userId] == NO);
|
||||
CGSize contentSize;
|
||||
|
||||
// Use a TextView template to compute cell height
|
||||
UITextView *dummyTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 200, MAXFLOAT)];
|
||||
dummyTextView.font = [UIFont systemFontOfSize:14];
|
||||
dummyTextView.text = [mxHandler displayTextFor:mxEvent inSubtitleMode:NO];
|
||||
CGSize contentSize = [dummyTextView sizeThatFits:dummyTextView.frame.size];
|
||||
if ([mxHandler isAttachment:mxEvent]) {
|
||||
NSString *msgtype = mxEvent.content[@"msgtype"];
|
||||
if ([msgtype isEqualToString:kMXMessageTypeImage]) {
|
||||
contentSize = CGSizeMake(200, 200);
|
||||
} else {
|
||||
contentSize = CGSizeMake(40, 40);
|
||||
}
|
||||
} else {
|
||||
// Use a TextView template to compute cell height
|
||||
UITextView *dummyTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 200, MAXFLOAT)];
|
||||
dummyTextView.font = [UIFont systemFontOfSize:14];
|
||||
dummyTextView.text = [mxHandler displayTextFor:mxEvent inSubtitleMode:NO];
|
||||
contentSize = [dummyTextView sizeThatFits:dummyTextView.frame.size];
|
||||
}
|
||||
|
||||
// Handle incoming / outgoing layout
|
||||
if (isIncomingMsg) {
|
||||
// By default the user name is displayed above the message
|
||||
// By default the user name is displayed above the message or attachment
|
||||
rowHeight = contentSize.height + ROOM_MESSAGE_CELL_TOP_MARGIN + INCOMING_MESSAGE_CELL_USER_LABEL_HEIGHT + ROOM_MESSAGE_CELL_BOTTOM_MARGIN;
|
||||
|
||||
if (indexPath.row) {
|
||||
@@ -551,15 +561,36 @@ NSString *const kFailedEventId = @"failedEventId";
|
||||
}
|
||||
}
|
||||
|
||||
NSString *displayText = [mxHandler displayTextFor:mxEvent inSubtitleMode:NO];
|
||||
if ([displayText hasPrefix:kMatrixHandlerUnsupportedMessagePrefix]) {
|
||||
cell.messageTextView.textColor = [UIColor redColor];
|
||||
} else if (isIncomingMsg && ([displayText rangeOfString:mxHandler.userDisplayName options:NSCaseInsensitiveSearch].location != NSNotFound || [displayText rangeOfString:mxHandler.userId options:NSCaseInsensitiveSearch].location != NSNotFound)) {
|
||||
cell.messageTextView.textColor = [UIColor blueColor];
|
||||
if ([mxHandler isAttachment:mxEvent]) {
|
||||
cell.attachmentView.hidden = NO;
|
||||
cell.messageTextView.text = nil; // Note: Text view is used to display attachment background
|
||||
|
||||
NSString *msgtype = mxEvent.content[@"msgtype"];
|
||||
if ([msgtype isEqualToString:kMXMessageTypeImage]) {
|
||||
NSString *url = mxEvent.content[@"thumbnail_url"];
|
||||
if (url == nil) {
|
||||
url = mxEvent.content[@"url"];
|
||||
}
|
||||
cell.attachedImageURL = url;
|
||||
} else {
|
||||
cell.attachedImageURL = nil;
|
||||
}
|
||||
} else {
|
||||
cell.messageTextView.textColor = [UIColor blackColor];
|
||||
cell.attachmentView.hidden = YES;
|
||||
// cancel potential attachment loading
|
||||
cell.attachedImageURL = nil;
|
||||
|
||||
NSString *displayText = [mxHandler displayTextFor:mxEvent inSubtitleMode:NO];
|
||||
if ([displayText hasPrefix:kMatrixHandlerUnsupportedMessagePrefix]) {
|
||||
cell.messageTextView.textColor = [UIColor redColor];
|
||||
} else if (isIncomingMsg && ([displayText rangeOfString:mxHandler.userDisplayName options:NSCaseInsensitiveSearch].location != NSNotFound || [displayText rangeOfString:mxHandler.userId options:NSCaseInsensitiveSearch].location != NSNotFound)) {
|
||||
cell.messageTextView.textColor = [UIColor blueColor];
|
||||
} else {
|
||||
cell.messageTextView.textColor = [UIColor blackColor];
|
||||
}
|
||||
cell.messageTextView.text = displayText;
|
||||
}
|
||||
cell.messageTextView.text = displayText;
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user