mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-16 06:28:27 +02:00
Room details display member's picture
This commit is contained in:
@@ -11,12 +11,15 @@
|
||||
F01628C119E29C660071C473 /* default-profile.png in Resources */ = {isa = PBXBuildFile; fileRef = F01628BC19E29C660071C473 /* default-profile.png */; };
|
||||
F01628C319E29C660071C473 /* logo.png in Resources */ = {isa = PBXBuildFile; fileRef = F01628BE19E29C660071C473 /* logo.png */; };
|
||||
F024098219E7D177006E741B /* tab_recents@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F024098119E7D177006E741B /* tab_recents@2x.png */; };
|
||||
F02D707319F1CE4A007B47D3 /* CustomTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F02D707219F1CE4A007B47D3 /* CustomTableViewCell.m */; };
|
||||
F03EF5F619F171EB00A0EE52 /* HomeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F03EF5EB19F171EB00A0EE52 /* HomeViewController.m */; };
|
||||
F03EF5F719F171EB00A0EE52 /* LoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F03EF5ED19F171EB00A0EE52 /* LoginViewController.m */; };
|
||||
F03EF5F819F171EB00A0EE52 /* MasterTabBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = F03EF5EF19F171EB00A0EE52 /* MasterTabBarController.m */; };
|
||||
F03EF5F919F171EB00A0EE52 /* RecentsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F03EF5F119F171EB00A0EE52 /* RecentsViewController.m */; };
|
||||
F03EF5FA19F171EB00A0EE52 /* RoomViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F03EF5F319F171EB00A0EE52 /* RoomViewController.m */; };
|
||||
F03EF5FB19F171EB00A0EE52 /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F03EF5F519F171EB00A0EE52 /* SettingsViewController.m */; };
|
||||
F03EF5FF19F1762000A0EE52 /* RoomMessageTableCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F03EF5FE19F1762000A0EE52 /* RoomMessageTableCell.m */; };
|
||||
F03EF60219F19E7C00A0EE52 /* MediaManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F03EF60119F19E7C00A0EE52 /* MediaManager.m */; };
|
||||
F05B955F19DEED8A008761B0 /* MatrixHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = F05B955E19DEED8A008761B0 /* MatrixHandler.m */; };
|
||||
F07A80D819DD9DE700B621A1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F07A80D719DD9DE700B621A1 /* main.m */; };
|
||||
F07A80DB19DD9DE700B621A1 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F07A80DA19DD9DE700B621A1 /* AppDelegate.m */; };
|
||||
@@ -46,6 +49,8 @@
|
||||
F01628BC19E29C660071C473 /* default-profile.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "default-profile.png"; sourceTree = "<group>"; };
|
||||
F01628BE19E29C660071C473 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = "<group>"; };
|
||||
F024098119E7D177006E741B /* tab_recents@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_recents@2x.png"; sourceTree = "<group>"; };
|
||||
F02D707119F1CE4A007B47D3 /* CustomTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomTableViewCell.h; sourceTree = "<group>"; };
|
||||
F02D707219F1CE4A007B47D3 /* CustomTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomTableViewCell.m; sourceTree = "<group>"; };
|
||||
F03EF5EA19F171EB00A0EE52 /* HomeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HomeViewController.h; sourceTree = "<group>"; };
|
||||
F03EF5EB19F171EB00A0EE52 /* HomeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HomeViewController.m; sourceTree = "<group>"; };
|
||||
F03EF5EC19F171EB00A0EE52 /* LoginViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoginViewController.h; sourceTree = "<group>"; };
|
||||
@@ -58,6 +63,10 @@
|
||||
F03EF5F319F171EB00A0EE52 /* RoomViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomViewController.m; sourceTree = "<group>"; };
|
||||
F03EF5F419F171EB00A0EE52 /* SettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsViewController.h; sourceTree = "<group>"; };
|
||||
F03EF5F519F171EB00A0EE52 /* SettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingsViewController.m; sourceTree = "<group>"; };
|
||||
F03EF5FD19F1762000A0EE52 /* RoomMessageTableCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomMessageTableCell.h; sourceTree = "<group>"; };
|
||||
F03EF5FE19F1762000A0EE52 /* RoomMessageTableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomMessageTableCell.m; sourceTree = "<group>"; };
|
||||
F03EF60019F19E7C00A0EE52 /* MediaManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaManager.h; sourceTree = "<group>"; };
|
||||
F03EF60119F19E7C00A0EE52 /* MediaManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MediaManager.m; sourceTree = "<group>"; };
|
||||
F05B955D19DEED8A008761B0 /* MatrixHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MatrixHandler.h; sourceTree = "<group>"; };
|
||||
F05B955E19DEED8A008761B0 /* MatrixHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MatrixHandler.m; sourceTree = "<group>"; };
|
||||
F07A80D219DD9DE700B621A1 /* syMessaging.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = syMessaging.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -144,6 +153,17 @@
|
||||
path = ViewController;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F03EF5FC19F1762000A0EE52 /* View */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F02D707119F1CE4A007B47D3 /* CustomTableViewCell.h */,
|
||||
F02D707219F1CE4A007B47D3 /* CustomTableViewCell.m */,
|
||||
F03EF5FD19F1762000A0EE52 /* RoomMessageTableCell.h */,
|
||||
F03EF5FE19F1762000A0EE52 /* RoomMessageTableCell.m */,
|
||||
);
|
||||
path = View;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F07A80C919DD9DE700B621A1 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -167,11 +187,14 @@
|
||||
F07A80D419DD9DE700B621A1 /* syMessaging */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F03EF5FC19F1762000A0EE52 /* View */,
|
||||
F03EF5E919F171EB00A0EE52 /* ViewController */,
|
||||
F07A80D919DD9DE700B621A1 /* AppDelegate.h */,
|
||||
F07A80DA19DD9DE700B621A1 /* AppDelegate.m */,
|
||||
F05B955D19DEED8A008761B0 /* MatrixHandler.h */,
|
||||
F05B955E19DEED8A008761B0 /* MatrixHandler.m */,
|
||||
F03EF60019F19E7C00A0EE52 /* MediaManager.h */,
|
||||
F03EF60119F19E7C00A0EE52 /* MediaManager.m */,
|
||||
F07A80E219DD9DE700B621A1 /* Main.storyboard */,
|
||||
F07A80E519DD9DE700B621A1 /* Images.xcassets */,
|
||||
F07A80E719DD9DE700B621A1 /* LaunchScreen.xib */,
|
||||
@@ -349,12 +372,15 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
F07A80DB19DD9DE700B621A1 /* AppDelegate.m in Sources */,
|
||||
F03EF5FF19F1762000A0EE52 /* RoomMessageTableCell.m in Sources */,
|
||||
F02D707319F1CE4A007B47D3 /* CustomTableViewCell.m in Sources */,
|
||||
F07A80D819DD9DE700B621A1 /* main.m in Sources */,
|
||||
F05B955F19DEED8A008761B0 /* MatrixHandler.m in Sources */,
|
||||
F03EF5FB19F171EB00A0EE52 /* SettingsViewController.m in Sources */,
|
||||
F03EF5FA19F171EB00A0EE52 /* RoomViewController.m in Sources */,
|
||||
F03EF5F819F171EB00A0EE52 /* MasterTabBarController.m in Sources */,
|
||||
F03EF5F619F171EB00A0EE52 /* HomeViewController.m in Sources */,
|
||||
F03EF60219F19E7C00A0EE52 /* MediaManager.m in Sources */,
|
||||
F03EF5F919F171EB00A0EE52 /* RecentsViewController.m in Sources */,
|
||||
F03EF5F719F171EB00A0EE52 /* LoginViewController.m in Sources */,
|
||||
);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#import "AppDelegate.h"
|
||||
#import "RoomViewController.h"
|
||||
#import "MatrixHandler.h"
|
||||
#import "MediaManager.h"
|
||||
|
||||
@interface AppDelegate () <UISplitViewControllerDelegate>
|
||||
|
||||
@@ -80,6 +81,9 @@
|
||||
#pragma mark -
|
||||
|
||||
- (void)logout {
|
||||
// Clear cache
|
||||
[MediaManager clearCache];
|
||||
// Logout Matrix
|
||||
[[MatrixHandler sharedHandler] logout];
|
||||
[self.masterTabBarController showLoginScreen];
|
||||
// By default the "Home" tab is focussed
|
||||
|
||||
@@ -37,12 +37,12 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="556"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<prototypes>
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="IncomingMessageCell" rowHeight="70" id="Lq0-jR-3i5" customClass="IncomingMessageCell">
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="IncomingMessageCell" rowHeight="70" 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"/>
|
||||
<subviews>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="default-profile.png" translatesAutoresizingMaskIntoConstraints="NO" id="uhu-R0-9NH">
|
||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="default-profile.png" translatesAutoresizingMaskIntoConstraints="NO" id="uhu-R0-9NH">
|
||||
<rect key="frame" x="8" y="5" width="40" height="40"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="40" id="SqY-kA-9u5"/>
|
||||
@@ -87,11 +87,11 @@
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<connections>
|
||||
<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"/>
|
||||
<outlet property="userPicture" destination="uhu-R0-9NH" id="b7D-KD-aga"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="OutgoingMessageCell" id="eVZ-HH-LWn" customClass="OutgoingMessageCell">
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="OutgoingMessageCell" id="eVZ-HH-LWn" customClass="OutgoingMessageTableCell">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="eVZ-HH-LWn" id="5tf-BC-9Ed">
|
||||
@@ -107,7 +107,7 @@
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
|
||||
</textView>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="default-profile.png" translatesAutoresizingMaskIntoConstraints="NO" id="mks-jh-AiZ">
|
||||
<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>
|
||||
<constraint firstAttribute="height" constant="40" id="sGR-sG-6fA"/>
|
||||
@@ -139,8 +139,8 @@
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<connections>
|
||||
<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"/>
|
||||
<outlet property="userPicture" destination="mks-jh-AiZ" id="bxN-GB-VOx"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
|
||||
30
syMessaging/syMessaging/MediaManager.h
Normal file
30
syMessaging/syMessaging/MediaManager.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright 2014 OpenMarket Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface MediaManager : NSObject
|
||||
|
||||
+ (id)sharedInstance;
|
||||
|
||||
+ (NSString*)cachePictureWithData:(NSData*)imageData forURL:(NSString *)pictureURL;
|
||||
|
||||
+ (UIImage*)loadCachePicture:(NSString*)pictureURL;
|
||||
|
||||
+ (void)clearCache;
|
||||
|
||||
@end
|
||||
104
syMessaging/syMessaging/MediaManager.m
Normal file
104
syMessaging/syMessaging/MediaManager.m
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Copyright 2014 OpenMarket Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import "MediaManager.h"
|
||||
|
||||
static NSString* pictureCachePath = nil;
|
||||
static NSString *pictureDir = @"picturecache";
|
||||
|
||||
static MediaManager *sharedMediaManager = nil;
|
||||
|
||||
@implementation MediaManager
|
||||
|
||||
+ (id)sharedInstance {
|
||||
@synchronized(self) {
|
||||
if(sharedMediaManager == nil)
|
||||
sharedMediaManager = [[self alloc] init];
|
||||
}
|
||||
return sharedMediaManager;
|
||||
}
|
||||
|
||||
#pragma mark - Cache handling
|
||||
|
||||
+ (NSString*)cachePictureWithData:(NSData*)imageData forURL:(NSString *)pictureURL {
|
||||
NSString* filename = [MediaManager getCacheFileNameFor:pictureURL];
|
||||
|
||||
if ([imageData writeToFile:filename atomically:YES]) {
|
||||
return filename;
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
+ (UIImage*)loadCachePicture:(NSString*)pictureURL {
|
||||
UIImage* res = nil;
|
||||
NSString* filename = [MediaManager getCacheFileNameFor:pictureURL];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:filename]) {
|
||||
NSData* imageContent = [NSData dataWithContentsOfFile:filename options:(NSDataReadingMappedAlways | NSDataReadingUncached) error:nil];
|
||||
if (imageContent) {
|
||||
res = [[UIImage alloc] initWithData:imageContent];
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
+ (NSString*)getCachePath {
|
||||
NSString *mediaCachePath = nil;
|
||||
|
||||
if (!pictureCachePath) {
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
NSString *cacheRoot = [paths objectAtIndex:0];
|
||||
|
||||
pictureCachePath = [cacheRoot stringByAppendingPathComponent:pictureDir];
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:pictureCachePath]) {
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:pictureCachePath withIntermediateDirectories:NO attributes:nil error:nil];
|
||||
}
|
||||
}
|
||||
mediaCachePath = pictureCachePath;
|
||||
|
||||
return mediaCachePath;
|
||||
}
|
||||
|
||||
+ (NSString*)getCacheFileNameFor:(NSString*)pictureURL {
|
||||
NSString* baseFileName = [[MediaManager getCachePath] stringByAppendingPathComponent:@"ima"];
|
||||
return [NSString stringWithFormat:@"%@%d.jpg", baseFileName, pictureURL.hash];
|
||||
}
|
||||
|
||||
+ (void)clearCache {
|
||||
NSError *error = nil;
|
||||
|
||||
if (!pictureCachePath) {
|
||||
// compute the path
|
||||
pictureCachePath = [MediaManager getCachePath];
|
||||
}
|
||||
|
||||
if (pictureCachePath) {
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:pictureCachePath error:&error]) {
|
||||
NSLog(@"Fails to delete picture cache dir : %@", error);
|
||||
} else {
|
||||
NSLog(@"Picture cache : deleted !");
|
||||
}
|
||||
} else {
|
||||
NSLog(@"Picture cache does not exist");
|
||||
}
|
||||
|
||||
pictureCachePath = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
26
syMessaging/syMessaging/View/CustomTableViewCell.h
Normal file
26
syMessaging/syMessaging/View/CustomTableViewCell.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 2014 OpenMarket Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
// Customize UITableViewCell in order to handle Table cell with UIImageView based on remote url
|
||||
@interface CustomTableViewCell : UITableViewCell <NSURLConnectionDataDelegate>
|
||||
@property (weak, nonatomic) IBOutlet UIImageView *pictureView;
|
||||
|
||||
@property (strong, nonatomic) NSString *placeholder;
|
||||
@property (strong, nonatomic) NSString *pictureURL;
|
||||
@end
|
||||
|
||||
97
syMessaging/syMessaging/View/CustomTableViewCell.m
Normal file
97
syMessaging/syMessaging/View/CustomTableViewCell.m
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
Copyright 2014 OpenMarket Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import "CustomTableViewCell.h"
|
||||
#import "MediaManager.h"
|
||||
|
||||
@interface CustomTableViewCell () {
|
||||
NSMutableData *downloadData;
|
||||
NSURLConnection *downloadConnection;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation CustomTableViewCell
|
||||
|
||||
- (void)setPictureURL:(NSString *)pictureURL {
|
||||
// Cancel current request (if any)
|
||||
[downloadConnection cancel];
|
||||
downloadConnection = nil;
|
||||
downloadData = nil;
|
||||
|
||||
_pictureURL = pictureURL;
|
||||
|
||||
// Update user picture
|
||||
_pictureView.image = nil;
|
||||
if (pictureURL) {
|
||||
// Check cache
|
||||
_pictureView.image = [MediaManager loadCachePicture:pictureURL];
|
||||
|
||||
if (!_pictureView.image) {
|
||||
if (_placeholder) {
|
||||
// Set picture placeholder
|
||||
_pictureView.image = [UIImage imageNamed:_placeholder];
|
||||
}
|
||||
|
||||
// Download picture
|
||||
NSURL *url = [NSURL URLWithString:pictureURL];
|
||||
downloadData = [[NSMutableData alloc] init];
|
||||
downloadConnection = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:url] delegate:self];
|
||||
}
|
||||
} else {
|
||||
if (_placeholder) {
|
||||
// Set picture placeholder
|
||||
_pictureView.image = [UIImage imageNamed:_placeholder];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
downloadData = nil;
|
||||
downloadConnection = nil;
|
||||
}
|
||||
|
||||
#pragma mark - NSURLConnectionDelegate
|
||||
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
|
||||
{
|
||||
NSLog(@"ERROR: picture download failed: %@", error);
|
||||
}
|
||||
|
||||
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
|
||||
{
|
||||
// Append data
|
||||
[downloadData appendData:data];
|
||||
}
|
||||
|
||||
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
|
||||
{
|
||||
// Set the downloaded image
|
||||
_pictureView.image = [UIImage imageWithData:downloadData];
|
||||
if (_pictureView.image) {
|
||||
// Cache the downloaded data
|
||||
[MediaManager cachePictureWithData:downloadData forURL:_pictureURL];
|
||||
} else {
|
||||
if (_placeholder) {
|
||||
// Set picture placeholder
|
||||
_pictureView.image = [UIImage imageNamed:_placeholder];
|
||||
}
|
||||
}
|
||||
|
||||
downloadData = nil;
|
||||
downloadConnection = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
32
syMessaging/syMessaging/View/RoomMessageTableCell.h
Normal file
32
syMessaging/syMessaging/View/RoomMessageTableCell.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright 2014 OpenMarket Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "CustomTableViewCell.h"
|
||||
|
||||
// Room Message Table View Cell
|
||||
@interface RoomMessageTableCell : CustomTableViewCell
|
||||
@property (weak, nonatomic) IBOutlet UITextView *messageTextView;
|
||||
@end
|
||||
|
||||
@interface IncomingMessageTableCell : RoomMessageTableCell
|
||||
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
|
||||
@end
|
||||
|
||||
@interface OutgoingMessageTableCell : RoomMessageTableCell
|
||||
@property (weak, nonatomic) IBOutlet UILabel *unsentLabel;
|
||||
@end
|
||||
|
||||
29
syMessaging/syMessaging/View/RoomMessageTableCell.m
Normal file
29
syMessaging/syMessaging/View/RoomMessageTableCell.m
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright 2014 OpenMarket Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import "RoomMessageTableCell.h"
|
||||
|
||||
|
||||
@implementation RoomMessageTableCell
|
||||
@end
|
||||
|
||||
|
||||
@implementation IncomingMessageTableCell
|
||||
@end
|
||||
|
||||
|
||||
@implementation OutgoingMessageTableCell
|
||||
@end
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#import "RoomViewController.h"
|
||||
#import "RoomMessageTableCell.h"
|
||||
|
||||
#import "MatrixHandler.h"
|
||||
#import "AppDelegate.h"
|
||||
@@ -26,26 +27,6 @@
|
||||
NSString *const kLocalEchoEventIdPrefix = @"localEcho-";
|
||||
NSString *const kFailedEventId = @"failedEventId";
|
||||
|
||||
// Table view cell
|
||||
@interface RoomMessageCell : UITableViewCell
|
||||
@property (weak, nonatomic) IBOutlet UIImageView *userPicture;
|
||||
@property (weak, nonatomic) IBOutlet UITextView *messageTextView;
|
||||
@end
|
||||
@implementation RoomMessageCell
|
||||
@end
|
||||
|
||||
@interface IncomingMessageCell : RoomMessageCell
|
||||
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
|
||||
@end
|
||||
@implementation IncomingMessageCell
|
||||
@end
|
||||
|
||||
@interface OutgoingMessageCell : RoomMessageCell
|
||||
@property (weak, nonatomic) IBOutlet UILabel *unsentLabel;
|
||||
@end
|
||||
@implementation OutgoingMessageCell
|
||||
@end
|
||||
|
||||
|
||||
@interface RoomViewController ()
|
||||
{
|
||||
@@ -437,7 +418,7 @@ NSString *const kFailedEventId = @"failedEventId";
|
||||
}
|
||||
|
||||
// Handle here room thread cells
|
||||
RoomMessageCell *cell;
|
||||
RoomMessageTableCell *cell;
|
||||
MXEvent *mxEvent = [messages objectAtIndex:indexPath.row];
|
||||
BOOL isIncomingMsg = NO;
|
||||
|
||||
@@ -456,20 +437,25 @@ NSString *const kFailedEventId = @"failedEventId";
|
||||
}
|
||||
|
||||
// Hide user picture if the previous message is from the same user
|
||||
cell.userPicture.hidden = NO;
|
||||
cell.pictureView.hidden = NO;
|
||||
if (indexPath.row) {
|
||||
MXEvent *previousMxEvent = [messages objectAtIndex:indexPath.row - 1];
|
||||
if ([previousMxEvent.user_id isEqualToString:mxEvent.user_id]) {
|
||||
cell.userPicture.hidden = YES;
|
||||
cell.pictureView.hidden = YES;
|
||||
}
|
||||
}
|
||||
// Set url for visible picture
|
||||
if (!cell.pictureView.hidden) {
|
||||
cell.placeholder = @"default-profile";
|
||||
cell.pictureURL = [mxRoomData getMember:mxEvent.user_id].avatar_url;
|
||||
}
|
||||
|
||||
// Update incoming/outgoing message layout
|
||||
if (isIncomingMsg) {
|
||||
// Hide userName in incoming message if the previous message is from the same user
|
||||
IncomingMessageCell* incomingMsgCell = (IncomingMessageCell*)cell;
|
||||
IncomingMessageTableCell* incomingMsgCell = (IncomingMessageTableCell*)cell;
|
||||
CGRect frame = incomingMsgCell.userNameLabel.frame;
|
||||
if (cell.userPicture.hidden) {
|
||||
if (cell.pictureView.hidden) {
|
||||
incomingMsgCell.userNameLabel.text = nil;
|
||||
frame.size.height = 0;
|
||||
incomingMsgCell.userNameLabel.hidden = YES;
|
||||
@@ -482,7 +468,7 @@ NSString *const kFailedEventId = @"failedEventId";
|
||||
incomingMsgCell.userNameLabel.frame = frame;
|
||||
} else {
|
||||
// Hide unsent label by default
|
||||
UILabel *unsentLabel = ((OutgoingMessageCell*)cell).unsentLabel;
|
||||
UILabel *unsentLabel = ((OutgoingMessageTableCell*)cell).unsentLabel;
|
||||
unsentLabel.hidden = YES;
|
||||
|
||||
// Set the right text color for outgoing messages
|
||||
|
||||
Reference in New Issue
Block a user