diff --git a/matrixConsole.xcodeproj/project.pbxproj b/matrixConsole.xcodeproj/project.pbxproj index ea0a053cf..9f06011dc 100644 --- a/matrixConsole.xcodeproj/project.pbxproj +++ b/matrixConsole.xcodeproj/project.pbxproj @@ -17,6 +17,8 @@ 71193D381A6E49F000E59A9E /* MXCPhoneNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = 71193D351A6E49F000E59A9E /* MXCPhoneNumber.m */; }; 71193D3B1A6E50EC00E59A9E /* ContactManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 71193D3A1A6E50EC00E59A9E /* ContactManager.m */; }; 71193D3E1A6E61AD00E59A9E /* SectionedContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 71193D3D1A6E61AD00E59A9E /* SectionedContacts.m */; }; + 7176294C1A77F5D000927125 /* ContactDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7176294B1A77F5D000927125 /* ContactDetailsViewController.m */; }; + 7176294F1A77FED800927125 /* ContactDetailsTableCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7176294E1A77FED800927125 /* ContactDetailsTableCell.m */; }; 71D2E4EC1A49814B000DE015 /* RoomMemberActionsCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 71D2E4EB1A49814B000DE015 /* RoomMemberActionsCell.m */; }; 71DB9DC11A495B6400504A09 /* MemberViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71DB9DC01A495B6400504A09 /* MemberViewController.m */; }; 71E94A771A5C4020009F52E5 /* PieChartView.m in Sources */ = {isa = PBXBuildFile; fileRef = 71E94A761A5C4020009F52E5 /* PieChartView.m */; }; @@ -99,6 +101,10 @@ 71193D3A1A6E50EC00E59A9E /* ContactManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactManager.m; sourceTree = ""; }; 71193D3C1A6E61AD00E59A9E /* SectionedContacts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SectionedContacts.h; sourceTree = ""; }; 71193D3D1A6E61AD00E59A9E /* SectionedContacts.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SectionedContacts.m; sourceTree = ""; }; + 7176294A1A77F5D000927125 /* ContactDetailsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactDetailsViewController.h; sourceTree = ""; }; + 7176294B1A77F5D000927125 /* ContactDetailsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactDetailsViewController.m; sourceTree = ""; }; + 7176294D1A77FED800927125 /* ContactDetailsTableCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactDetailsTableCell.h; sourceTree = ""; }; + 7176294E1A77FED800927125 /* ContactDetailsTableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactDetailsTableCell.m; sourceTree = ""; }; 71D2E4EA1A49814B000DE015 /* RoomMemberActionsCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomMemberActionsCell.h; sourceTree = ""; }; 71D2E4EB1A49814B000DE015 /* RoomMemberActionsCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomMemberActionsCell.m; sourceTree = ""; }; 71DB9DBF1A495B6400504A09 /* MemberViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemberViewController.h; sourceTree = ""; }; @@ -268,6 +274,8 @@ F03EF5E919F171EB00A0EE52 /* ViewController */ = { isa = PBXGroup; children = ( + 7176294A1A77F5D000927125 /* ContactDetailsViewController.h */, + 7176294B1A77F5D000927125 /* ContactDetailsViewController.m */, 71193D271A6E3DC000E59A9E /* ContactsViewController.h */, 71193D281A6E3DC000E59A9E /* ContactsViewController.m */, F03EF5EA19F171EB00A0EE52 /* HomeViewController.h */, @@ -291,6 +299,8 @@ F03EF5FC19F1762000A0EE52 /* View */ = { isa = PBXGroup; children = ( + 7176294D1A77FED800927125 /* ContactDetailsTableCell.h */, + 7176294E1A77FED800927125 /* ContactDetailsTableCell.m */, 71193D2A1A6E433900E59A9E /* ContactTableCell.h */, 71193D2B1A6E433900E59A9E /* ContactTableCell.m */, F05237811A728A0A0079F3E0 /* MXCGrowingTextView.h */, @@ -560,6 +570,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7176294F1A77FED800927125 /* ContactDetailsTableCell.m in Sources */, F04A8AD81A3B3DF4008AC915 /* RoomTitleView.m in Sources */, F07A80DB19DD9DE700B621A1 /* AppDelegate.m in Sources */, F052377C1A7289F00079F3E0 /* APNSHandler.m in Sources */, @@ -594,6 +605,7 @@ F00B5DB91A1B9BCE00EA1C8D /* MXCImageView.m in Sources */, F0D3C30C1A011EF10000D49E /* AppSettings.m in Sources */, F05237831A728A0A0079F3E0 /* MXCGrowingTextView.m in Sources */, + 7176294C1A77F5D000927125 /* ContactDetailsViewController.m in Sources */, F03EF5F719F171EB00A0EE52 /* LoginViewController.m in Sources */, F0D3C30F1A01330F0000D49E /* SettingsTableViewCell.m in Sources */, 71D2E4EC1A49814B000DE015 /* RoomMemberActionsCell.m in Sources */, diff --git a/matrixConsole/Base.lproj/Main.storyboard b/matrixConsole/Base.lproj/Main.storyboard index d3a4108b1..6a429d5ee 100644 --- a/matrixConsole/Base.lproj/Main.storyboard +++ b/matrixConsole/Base.lproj/Main.storyboard @@ -532,7 +532,101 @@ - + + + + + + + + + + + + + + + + + + + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -636,7 +730,7 @@ - + @@ -1489,6 +1583,7 @@ + @@ -1553,6 +1648,7 @@ + diff --git a/matrixConsole/View/ContactDetailsTableCell.h b/matrixConsole/View/ContactDetailsTableCell.h new file mode 100644 index 000000000..8c7daf486 --- /dev/null +++ b/matrixConsole/View/ContactDetailsTableCell.h @@ -0,0 +1,25 @@ +/* + 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 + +@interface ContactDetailsTableCell : UITableViewCell + +@property (strong, nonatomic) IBOutlet UILabel *matrixUserIDLabel; +@property (strong, nonatomic) IBOutlet UIButton *startChatButton; + +@end + diff --git a/matrixConsole/View/ContactDetailsTableCell.m b/matrixConsole/View/ContactDetailsTableCell.m new file mode 100644 index 000000000..d4915fc34 --- /dev/null +++ b/matrixConsole/View/ContactDetailsTableCell.m @@ -0,0 +1,20 @@ +/* + 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 "ContactDetailsTableCell.h" + +@implementation ContactDetailsTableCell +@end \ No newline at end of file diff --git a/matrixConsole/ViewController/ContactDetailsViewController.h b/matrixConsole/ViewController/ContactDetailsViewController.h new file mode 100644 index 000000000..3238bde27 --- /dev/null +++ b/matrixConsole/ViewController/ContactDetailsViewController.h @@ -0,0 +1,25 @@ +/* + 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 + +#import "MXCContact.h" + +@interface ContactDetailsViewController : UITableViewController + +@property (strong, nonatomic) MXCContact* contact; +@end + diff --git a/matrixConsole/ViewController/ContactDetailsViewController.m b/matrixConsole/ViewController/ContactDetailsViewController.m new file mode 100644 index 000000000..af3c15d77 --- /dev/null +++ b/matrixConsole/ViewController/ContactDetailsViewController.m @@ -0,0 +1,130 @@ +/* + 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 "ContactDetailsViewController.h" + +#import "ContactDetailsTableCell.h" + +#import "MatrixSDKHandler.h" + +@interface ContactDetailsViewController () { + NSArray* matrixIDs; +} + +@property (weak, nonatomic) IBOutlet UIButton *memberThumbnailButton; +@property (weak, nonatomic) IBOutlet UITextView *roomMemberMID; + +@end + +@implementation ContactDetailsViewController + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + self.memberThumbnailButton = nil; + self.roomMemberMID = nil; + matrixIDs = nil; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + + // remove the line separator color + self.tableView.separatorColor = [UIColor clearColor]; + self.tableView.rowHeight = 44; + self.tableView.allowsSelection = NO; +} + +- (void)viewWillAppear:(BOOL)animated { + + [super viewWillAppear:animated]; + self.roomMemberMID.text = _contact.displayName; + + // set the thumbnail info + [self.memberThumbnailButton.imageView setContentMode: UIViewContentModeScaleAspectFill]; + [self.memberThumbnailButton.imageView setClipsToBounds:YES]; + + if (_contact.thumbnail) { + self.memberThumbnailButton.imageView.image = _contact.thumbnail; + } + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onThumbnailUpdate:) name:kMXCContactThumbnailUpdateNotification object:nil]; +} + +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + matrixIDs = _contact.matrixIdentifiers; + return matrixIDs.count; +} + +- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + NSInteger row = indexPath.row; + ContactDetailsTableCell* contactDetailsTableCell = (ContactDetailsTableCell*)[aTableView dequeueReusableCellWithIdentifier:@"ContactDetailsTableCell" forIndexPath:indexPath]; + + if (row < matrixIDs.count) { + contactDetailsTableCell.matrixUserIDLabel.text = [matrixIDs objectAtIndex:row]; + } else { + // should never happen + contactDetailsTableCell.matrixUserIDLabel.text = @""; + } + + contactDetailsTableCell.startChatButton.layer.cornerRadius = 5; + contactDetailsTableCell.startChatButton.layer.borderColor = [UIColor blackColor].CGColor; + contactDetailsTableCell.startChatButton.layer.borderWidth = 2; + contactDetailsTableCell.startChatButton.clipsToBounds = YES; + [contactDetailsTableCell.startChatButton addTarget:self action:@selector(startChat:) forControlEvents:UIControlEventTouchUpInside]; + + return contactDetailsTableCell; +} + +- (void)startChat:(UIButton*)sender { + UIView* view = sender; + + // search the parentce cell + while (view && ![view isKindOfClass:[ContactDetailsTableCell class]]) { + view = view.superview; + } + + if ([view isKindOfClass:[ContactDetailsTableCell class]]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [[MatrixSDKHandler sharedHandler] startPrivateOneToOneRoomWith:((ContactDetailsTableCell*)view).matrixUserIDLabel.text]; + }); + } +} + +- (void)onThumbnailUpdate:(NSNotification *)notif { + // sanity check + if ([notif.object isKindOfClass:[NSString class]]) { + NSString* matrixID = notif.object; + + if ([matrixID isEqualToString:self.contact.contactID]) { + if (_contact.thumbnail) { + self.memberThumbnailButton.imageView.image = _contact.thumbnail; + } + } + } +} + +@end diff --git a/matrixConsole/ViewController/ContactsViewController.h b/matrixConsole/ViewController/ContactsViewController.h index fd3c34932..b0e759a8c 100644 --- a/matrixConsole/ViewController/ContactsViewController.h +++ b/matrixConsole/ViewController/ContactsViewController.h @@ -22,7 +22,7 @@ #import "SectionedContacts.h" -@interface ContactsViewController : UIViewController { +@interface ContactsViewController : UIViewController { NSArray* collationTitles; } diff --git a/matrixConsole/ViewController/ContactsViewController.m b/matrixConsole/ViewController/ContactsViewController.m index b4889cb25..b1eb22018 100644 --- a/matrixConsole/ViewController/ContactsViewController.m +++ b/matrixConsole/ViewController/ContactsViewController.m @@ -37,6 +37,9 @@ // settings #import "AppSettings.h" +// +#import "ContactDetailsViewController.h" + NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Please, visit the website http://matrix.org to have more information."; @interface ContactsViewController () { @@ -52,6 +55,9 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl NSMutableDictionary* matrixUserByMatrixID; SectionedContacts* sectionedMatrixContacts; + // tap on thumbnail to display contact info + MXCContact* selectedContact; + // Search UISearchBar *contactsSearchBar; NSMutableArray *filteredContacts; @@ -372,6 +378,29 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl } } + // tap on matrix user thumbnail -> open a detailled sheet + UITapGestureRecognizer* tapGesture = nil; + + // check if it is already defined + // gesture in storyboard does not seem to work properly + // it always triggers a tap event on the first cell + for (UIGestureRecognizer* gesture in cell.thumbnailView.gestureRecognizers) { + + if ([gesture isKindOfClass:[UITapGestureRecognizer class]]) { + tapGesture = (UITapGestureRecognizer*)gesture; + break; + } + } + + // add it if it is not yet defined + if (!tapGesture) { + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onContactThumbnailTap:)]; + [tap setNumberOfTouchesRequired:1]; + [tap setNumberOfTapsRequired:1]; + [tap setDelegate:self]; + [cell.thumbnailView addGestureRecognizer:tap]; + } + cell.contact = contact; return cell; @@ -577,6 +606,40 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl } } +- (IBAction)onContactThumbnailTap:(id)sender { + + if ([sender isKindOfClass:[UITapGestureRecognizer class]]) { + UIView* tappedView = ((UITapGestureRecognizer*)sender).view; + + // search the parentce cell + while (tappedView && ![tappedView isKindOfClass:[ContactTableCell class]]) { + tappedView = tappedView.superview; + } + + // find it ? + if ([tappedView isKindOfClass:[ContactTableCell class]]) { + MXCContact* contact = ((ContactTableCell*)tappedView).contact; + + // open detailled sheet if there + if (contact.matrixIdentifiers.count > 0) { + selectedContact = ((ContactTableCell*)tappedView).contact; + [self performSegueWithIdentifier:@"showContactDetails" sender:self]; + } + } + + } +} + +#pragma mark - Segues + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + if ([segue.identifier isEqualToString:@"showContactDetails"]) { + ContactDetailsViewController *contactDetailsViewController = segue.destinationViewController; + contactDetailsViewController.contact = selectedContact; + selectedContact = nil; + } +} + #pragma mark MFMessageComposeViewControllerDelegate - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {