From 03ac45c673f557d8f6a5840c3372803cacfec76a Mon Sep 17 00:00:00 2001 From: yannick Date: Fri, 20 Nov 2015 14:12:37 +0100 Subject: [PATCH 1/6] Plug the RoomDetailsViewController But -> the update is not yet done -> the ui must be updated. --- Vector.xcodeproj/project.pbxproj | 50 ++-- Vector/Assets/en.lproj/Vector.strings | 4 + .../RoomDetailsViewController.h | 22 ++ .../RoomDetailsViewController.m | 219 ++++++++++++++++++ Vector/ViewController/RoomViewController.m | 19 ++ .../TableViewCellWithLabelAndLargeTextView.h | 35 +++ .../TableViewCellWithLabelAndLargeTextView.m | 40 ++++ ...TableViewCellWithLabelAndLargeTextView.xib | 47 ++++ .../TableViewCellWithLabelAndTextField.h | 24 ++ .../TableViewCellWithLabelAndTextField.m | 33 +++ .../TableViewCellWithLabelAndTextField.xib | 48 ++++ 11 files changed, 525 insertions(+), 16 deletions(-) create mode 100644 Vector/ViewController/RoomDetailsViewController.h create mode 100644 Vector/ViewController/RoomDetailsViewController.m create mode 100644 Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.h create mode 100644 Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.m create mode 100644 Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.xib create mode 100644 Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.h create mode 100644 Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.m create mode 100644 Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.xib diff --git a/Vector.xcodeproj/project.pbxproj b/Vector.xcodeproj/project.pbxproj index 6dc2ea332..622359cc7 100644 --- a/Vector.xcodeproj/project.pbxproj +++ b/Vector.xcodeproj/project.pbxproj @@ -7,6 +7,11 @@ objects = { /* Begin PBXBuildFile section */ + 71E7FE681BFE16F9003457F3 /* RoomDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71E7FE661BFE16F9003457F3 /* RoomDetailsViewController.m */; settings = {ASSET_TAGS = (); }; }; + 71E7FE6D1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 71E7FE6B1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.m */; settings = {ASSET_TAGS = (); }; }; + 71E7FE6E1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.xib in Resources */ = {isa = PBXBuildFile; fileRef = 71E7FE6C1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.xib */; settings = {ASSET_TAGS = (); }; }; + 71E7FE791BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 71E7FE771BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.m */; settings = {ASSET_TAGS = (); }; }; + 71E7FE7A1BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 71E7FE781BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.xib */; settings = {ASSET_TAGS = (); }; }; F001D75E1B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F001D7551B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.m */; }; F001D75F1B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F001D7561B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.xib */; }; F001D7601B8207C000A162C3 /* RoomOutgoingBubbleTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F001D7581B8207C000A162C3 /* RoomOutgoingBubbleTableViewCell.m */; }; @@ -96,6 +101,14 @@ /* Begin PBXFileReference section */ 11865E69C29698A4179E1F3F /* Pods-Vector.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Vector.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Vector/Pods-Vector.debug.xcconfig"; sourceTree = ""; }; 435C7E1A9BC3DE28D526540F /* Pods-Vector.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Vector.release.xcconfig"; path = "Pods/Target Support Files/Pods-Vector/Pods-Vector.release.xcconfig"; sourceTree = ""; }; + 71E7FE651BFE16F9003457F3 /* RoomDetailsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomDetailsViewController.h; sourceTree = ""; }; + 71E7FE661BFE16F9003457F3 /* RoomDetailsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomDetailsViewController.m; sourceTree = ""; }; + 71E7FE6A1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TableViewCellWithLabelAndTextField.h; path = TableViewCell/TableViewCellWithLabelAndTextField.h; sourceTree = ""; }; + 71E7FE6B1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TableViewCellWithLabelAndTextField.m; path = TableViewCell/TableViewCellWithLabelAndTextField.m; sourceTree = ""; }; + 71E7FE6C1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = TableViewCellWithLabelAndTextField.xib; path = TableViewCell/TableViewCellWithLabelAndTextField.xib; sourceTree = ""; }; + 71E7FE761BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TableViewCellWithLabelAndLargeTextView.h; path = TableViewCell/TableViewCellWithLabelAndLargeTextView.h; sourceTree = ""; }; + 71E7FE771BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TableViewCellWithLabelAndLargeTextView.m; path = TableViewCell/TableViewCellWithLabelAndLargeTextView.m; sourceTree = ""; }; + 71E7FE781BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = TableViewCellWithLabelAndLargeTextView.xib; path = TableViewCell/TableViewCellWithLabelAndLargeTextView.xib; sourceTree = ""; }; 9B179239B79688A61A3F465F /* libPods-Vector.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Vector.a"; sourceTree = BUILT_PRODUCTS_DIR; }; F001D7541B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomIncomingBubbleTableViewCell.h; sourceTree = ""; }; F001D7551B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomIncomingBubbleTableViewCell.m; sourceTree = ""; }; @@ -223,6 +236,19 @@ name = Frameworks; sourceTree = ""; }; + 71E7FE691BFE341B003457F3 /* TableViewCell */ = { + isa = PBXGroup; + children = ( + 71E7FE761BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.h */, + 71E7FE771BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.m */, + 71E7FE781BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.xib */, + 71E7FE6A1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.h */, + 71E7FE6B1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.m */, + 71E7FE6C1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.xib */, + ); + name = TableViewCell; + sourceTree = ""; + }; E1451F540F8BC02A7FB7AA31 /* Pods */ = { isa = PBXGroup; children = ( @@ -235,6 +261,7 @@ F001D7521B8207C000A162C3 /* Views */ = { isa = PBXGroup; children = ( + 71E7FE691BFE341B003457F3 /* TableViewCell */, F084DAAA1BB57BD100B4C530 /* Authentication */, F001D7531B8207C000A162C3 /* RoomBubbleList */, F001D75A1B8207C000A162C3 /* RoomInputToolbar */, @@ -422,6 +449,8 @@ F0DD7D871B7B507100C4BE02 /* RoomCreationStep2ViewController.m */, F094AA261B78E42600B1FBBF /* RoomViewController.h */, F094AA271B78E42600B1FBBF /* RoomViewController.m */, + 71E7FE651BFE16F9003457F3 /* RoomDetailsViewController.h */, + 71E7FE661BFE16F9003457F3 /* RoomDetailsViewController.m */, F094AA281B78E42600B1FBBF /* SettingsViewController.h */, F094AA291B78E42600B1FBBF /* SettingsViewController.m */, ); @@ -485,7 +514,6 @@ F094A99F1B78D8F000B1FBBF /* Frameworks */, F094A9A01B78D8F000B1FBBF /* Resources */, 44C35695CFA4F9799C449367 /* Copy Pods Resources */, - CE74DDBF8318D6A2441D715E /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -567,6 +595,7 @@ F00B1BCB1B95CC68001806E3 /* camera_record.png in Resources */, F001D7611B8207C000A162C3 /* RoomOutgoingBubbleTableViewCell.xib in Resources */, F094AA2E1B78E42600B1FBBF /* countryCodes.plist in Resources */, + 71E7FE6E1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.xib in Resources */, F084DAAF1BB57BD100B4C530 /* AuthInputsEmailIdentityBasedView.xib in Resources */, F0E956BF1B834430004C1699 /* share_contact.png in Resources */, F0DD7D7E1B7AAA3C00C4BE02 /* icon_users.png in Resources */, @@ -587,6 +616,7 @@ F0DD7D7F1B7AAA3C00C4BE02 /* icon_users@2x.png in Resources */, F00B1BCA1B95CC68001806E3 /* camera_capture.png in Resources */, F094A9B41B78D8F000B1FBBF /* Main.storyboard in Resources */, + 71E7FE7A1BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.xib in Resources */, F0316E471B7E4C9A00F03620 /* placeholder.png in Resources */, F0DD7D601B7AA8C900C4BE02 /* hide.png in Resources */, F0DD7D741B7AA8C900C4BE02 /* typing.png in Resources */, @@ -649,21 +679,6 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; - CE74DDBF8318D6A2441D715E /* Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Vector/Pods-Vector-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -673,6 +688,9 @@ files = ( F0DD7D821B7B363300C4BE02 /* RoomCreationStep1ViewController.m in Sources */, F094A9AB1B78D8F000B1FBBF /* AppDelegate.m in Sources */, + 71E7FE6D1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.m in Sources */, + 71E7FE791BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.m in Sources */, + 71E7FE681BFE16F9003457F3 /* RoomDetailsViewController.m in Sources */, F094AA2F1B78E42600B1FBBF /* AccountDetailsViewController.m in Sources */, F094AA051B78E3D400B1FBBF /* empty.mm in Sources */, F0A1CD221B9F4BBA00F9C15C /* RoomParticipantsViewController.m in Sources */, diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index 12dcd0928..6033adf49 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -85,6 +85,10 @@ "settings_title_config" = "Configuration"; "settings_clear_cache" = "Clear cache"; +// Room Details +"room_details_room_name" = "Room Name"; +"room_details_topic" = "Topic"; + "notification_settings_global_notification_settings" = "Global Notification Settings"; // Media picker diff --git a/Vector/ViewController/RoomDetailsViewController.h b/Vector/ViewController/RoomDetailsViewController.h new file mode 100644 index 000000000..1bfcbccf6 --- /dev/null +++ b/Vector/ViewController/RoomDetailsViewController.h @@ -0,0 +1,22 @@ +/* + 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 RoomDetailsViewController : MXKRoomDetailsViewController + +@end + diff --git a/Vector/ViewController/RoomDetailsViewController.m b/Vector/ViewController/RoomDetailsViewController.m new file mode 100644 index 000000000..3ad99931a --- /dev/null +++ b/Vector/ViewController/RoomDetailsViewController.m @@ -0,0 +1,219 @@ +/* + 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 "RoomDetailsViewController.h" + +#import "TableViewCellWithLabelAndTextField.h" +#import "TableViewCellWithLabelAndLargeTextView.h" + +#define ROOM_SECTION 0 + +#define ROOM_SECTION_NAME 0 +#define ROOM_SECTION_TOPIC 1 +#define ROOM_SECTION_COUNT 2 + +#define ROOM_TOPIC_CELL_HEIGHT 99 + +@interface RoomDetailsViewController () +{ + // updated user data + NSMutableDictionary *updatedItems; + + UITextView* topicTextView; + UITextField* nameTextField; +} +@end + +@implementation RoomDetailsViewController + + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + CGFloat item = (242.0f / 255.0); + + self.tableView.backgroundColor = [UIColor colorWithRed:item green:item blue:item alpha:item]; + self.tableView.separatorColor = [UIColor clearColor]; +} + +- (NSMutableDictionary*)getUpdatedItems +{ + if (!updatedItems) + { + updatedItems = [[NSMutableDictionary alloc] init]; + } + + return updatedItems; +} +#pragma mark - UITextViewDelegate + +- (void)textViewDidChange:(UITextView *)textView +{ + // avoid nil pointer + NSString* text = (!textView.text) ? textView.text : @""; + + if (topicTextView == textView) + { + [[self getUpdatedItems] setObject:text forKey:@"ROOM_SECTION_TOPIC"]; + } +} + +#pragma mark - field updates + +- (IBAction)onTextFieldUpdate:(UITextField*)textField +{ + // avoid nil pointer + NSString* text = (!textField.text) ? textField.text : @""; + + if (nameTextField == textField) + { + [updatedItems setObject:text forKey:@"ROOM_SECTION_NAME"]; + } +} + +#pragma mark - UITableViewDataSource + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + if (section == ROOM_SECTION) + { + return ROOM_SECTION_COUNT; + } + + return 0; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section +{ + return 33.0f; +} + +- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section +{ + UITableViewHeaderFooterView *header = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectMake(0, 0, 10, 33)]; + + header.backgroundColor = [UIColor redColor]; + + return header; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (indexPath.section == ROOM_SECTION) + { + if (indexPath.row == ROOM_SECTION_TOPIC) + { + return ROOM_TOPIC_CELL_HEIGHT; + } + } + + return [super tableView:tableView heightForRowAtIndexPath:indexPath]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell* cell = nil; + + // general settings + if (indexPath.section == ROOM_SECTION) + { + if (indexPath.row == ROOM_SECTION_TOPIC) + { + TableViewCellWithLabelAndLargeTextView *roomTopicCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithLabelAndLargeTextView defaultReuseIdentifier]]; + + if (!roomTopicCell) + { + roomTopicCell = [[TableViewCellWithLabelAndLargeTextView alloc] init]; + + // define the cell height + CGRect frame = roomTopicCell.frame; + frame.size.height = ROOM_TOPIC_CELL_HEIGHT; + roomTopicCell.frame = frame; + } + + roomTopicCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_topic", @"Vector", nil); + topicTextView = roomTopicCell.mxkTextView; + + if (updatedItems && [updatedItems objectForKey:@"ROOM_SECTION_TOPIC"]) + { + roomTopicCell.mxkTextView.text = (NSString*)[updatedItems objectForKey:@"ROOM_SECTION_TOPIC"]; + } + else + { + roomTopicCell.mxkTextView.text = mxRoomState.topic; + } + + roomTopicCell.mxkTextView.delegate = self; + + // disable the edition if the user cannoy update it + roomTopicCell.mxkTextView.editable = isSuperUser; + roomTopicCell.mxkTextView.textColor = isSuperUser ? [UIColor blackColor] : [UIColor lightGrayColor]; + + cell = roomTopicCell; + } + else if (indexPath.row == ROOM_SECTION_NAME) + { + TableViewCellWithLabelAndTextField *roomNameCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithLabelAndTextField defaultReuseIdentifier]]; + + if (!roomNameCell) + { + roomNameCell = [[TableViewCellWithLabelAndTextField alloc] init]; + } + + roomNameCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_room_name", @"Vector", nil); + roomNameCell.mxkTextField.userInteractionEnabled = YES; + + if (updatedItems && [updatedItems objectForKey:@"ROOM_SECTION_NAME"]) + { + roomNameCell.mxkTextField.text = (NSString*)[updatedItems objectForKey:@"ROOM_SECTION_NAME"]; + } + else + { + roomNameCell.mxkTextField.text = mxRoomState.name; + } + roomNameCell.accessoryType = UITableViewCellAccessoryNone; + + cell = roomNameCell; + nameTextField = roomNameCell.mxkTextField; + + // disable the edition if the user cannoy update it + roomNameCell.editable = isSuperUser; + roomNameCell.mxkTextField.textColor = isSuperUser ? [UIColor blackColor] : [UIColor lightGrayColor]; + + + // Add a "textFieldDidChange" notification method to the text field control. + [roomNameCell.mxkTextField addTarget:self action:@selector(onTextFieldUpdate:) forControlEvents:UIControlEventEditingChanged]; + } + } + + return cell; +} + +- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (self.tableView == aTableView) + { + if ([topicTextView isFirstResponder]) + { + + } + } +} + +@end + + diff --git a/Vector/ViewController/RoomViewController.m b/Vector/ViewController/RoomViewController.m index 8e9767d09..f126aea52 100644 --- a/Vector/ViewController/RoomViewController.m +++ b/Vector/ViewController/RoomViewController.m @@ -23,6 +23,8 @@ #import "RoomParticipantsViewController.h" +#import "RoomDetailsViewController.h" + @interface RoomViewController () { // The constraint used to animate menu list display @@ -386,6 +388,23 @@ [super tableView:tableView didSelectRowAtIndexPath:indexPath]; } +#pragma mark - RoomDetailsViewController management + +- (BOOL)roomTitleViewShouldBeginEditing:(MXKRoomTitleView*)titleView +{ + // instead of opening a text edition + // launch a dedicated viewcontroller. + dispatch_async(dispatch_get_main_queue(), ^{ + RoomDetailsViewController* controller = [RoomDetailsViewController roomDetailsViewController]; + [controller initWithSession:self.roomDataSource.mxSession andRoomId:self.roomDataSource.roomId]; + + [self.navigationController pushViewController:controller animated:YES]; + }); + + // cancel any requested edition + return NO; +} + @end diff --git a/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.h b/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.h new file mode 100644 index 000000000..97a498ac4 --- /dev/null +++ b/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.h @@ -0,0 +1,35 @@ +/* + Copyright 2015 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 "MXKTableViewCell.h" + +@interface TableViewCellWithLabelAndLargeTextView : MXKTableViewCell +{ +@protected + UIView *inputAccessoryView; +} + +@property (strong, nonatomic) IBOutlet UILabel *mxkLabel; +@property (strong, nonatomic) IBOutlet UITextView *mxkTextView; + +/** + The custom accessory view associated with the text field. This view is + actually used to retrieve the keyboard view. Indeed the keyboard view is the superview of + the accessory view when the text field become the first responder. + */ +@property (readonly) UIView *inputAccessoryView; + +@end \ No newline at end of file diff --git a/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.m b/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.m new file mode 100644 index 000000000..31c9f3e7e --- /dev/null +++ b/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.m @@ -0,0 +1,40 @@ +/* + Copyright 2015 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 "TableViewCellWithLabelAndLargeTextView.h" + +@implementation TableViewCellWithLabelAndLargeTextView +@synthesize inputAccessoryView; + +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier +{ + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; + if (self) + { + // Add an accessory view to the text view in order to retrieve keyboard view. + //inputAccessoryView = [[UIView alloc] initWithFrame:CGRectZero]; + //_mxkTextView.inputAccessoryView = inputAccessoryView; + } + + return self; +} + +- (void)dealloc +{ + //inputAccessoryView = nil; +} + +@end diff --git a/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.xib b/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.xib new file mode 100644 index 000000000..2aa0f1aca --- /dev/null +++ b/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.xib @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.h b/Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.h new file mode 100644 index 000000000..6c9ddaf29 --- /dev/null +++ b/Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.h @@ -0,0 +1,24 @@ +/* + Copyright 2015 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 "MXKTableViewCellWithLabelAndTextField.h" + +@interface TableViewCellWithLabelAndTextField : MXKTableViewCellWithLabelAndTextField + +// YES to allow text edition +@property (nonatomic) BOOL editable; + +@end \ No newline at end of file diff --git a/Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.m b/Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.m new file mode 100644 index 000000000..a1c1037d1 --- /dev/null +++ b/Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.m @@ -0,0 +1,33 @@ +/* + Copyright 2015 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 "TableViewCellWithLabelAndTextField.h" + +@implementation TableViewCellWithLabelAndTextField + +#pragma mark - UITextField delegate + +- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField +{ + if (textField == self.mxkTextField) + { + return _editable; + } + + return [super textFieldShouldBeginEditing:textField]; +} + +@end diff --git a/Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.xib b/Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.xib new file mode 100644 index 000000000..f8a90cf7f --- /dev/null +++ b/Vector/Views/TableViewCell/TableViewCellWithLabelAndTextField.xib @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 726efea874bde1936c361d60eb889dd2ca224ede Mon Sep 17 00:00:00 2001 From: yannick Date: Fri, 20 Nov 2015 15:06:48 +0100 Subject: [PATCH 2/6] Add the tableview line separators. --- Vector.xcodeproj/project.pbxproj | 10 ++++ .../RoomDetailsViewController.m | 46 ++++++++++++++++--- .../TableViewCell/TableViewCellSeparator.h | 22 +++++++++ .../TableViewCell/TableViewCellSeparator.m | 21 +++++++++ .../TableViewCell/TableViewCellSeparator.xib | 21 +++++++++ .../TableViewCellWithLabelAndLargeTextView.h | 9 ---- .../TableViewCellWithLabelAndLargeTextView.m | 5 -- 7 files changed, 113 insertions(+), 21 deletions(-) create mode 100644 Vector/Views/TableViewCell/TableViewCellSeparator.h create mode 100644 Vector/Views/TableViewCell/TableViewCellSeparator.m create mode 100644 Vector/Views/TableViewCell/TableViewCellSeparator.xib diff --git a/Vector.xcodeproj/project.pbxproj b/Vector.xcodeproj/project.pbxproj index 622359cc7..eaebe9356 100644 --- a/Vector.xcodeproj/project.pbxproj +++ b/Vector.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 71E7FE6E1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.xib in Resources */ = {isa = PBXBuildFile; fileRef = 71E7FE6C1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.xib */; settings = {ASSET_TAGS = (); }; }; 71E7FE791BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 71E7FE771BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.m */; settings = {ASSET_TAGS = (); }; }; 71E7FE7A1BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 71E7FE781BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.xib */; settings = {ASSET_TAGS = (); }; }; + 71E7FE881BFF59A0003457F3 /* TableViewCellSeparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 71E7FE861BFF59A0003457F3 /* TableViewCellSeparator.m */; settings = {ASSET_TAGS = (); }; }; + 71E7FE891BFF59A0003457F3 /* TableViewCellSeparator.xib in Resources */ = {isa = PBXBuildFile; fileRef = 71E7FE871BFF59A0003457F3 /* TableViewCellSeparator.xib */; settings = {ASSET_TAGS = (); }; }; F001D75E1B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F001D7551B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.m */; }; F001D75F1B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F001D7561B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.xib */; }; F001D7601B8207C000A162C3 /* RoomOutgoingBubbleTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F001D7581B8207C000A162C3 /* RoomOutgoingBubbleTableViewCell.m */; }; @@ -109,6 +111,9 @@ 71E7FE761BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TableViewCellWithLabelAndLargeTextView.h; path = TableViewCell/TableViewCellWithLabelAndLargeTextView.h; sourceTree = ""; }; 71E7FE771BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TableViewCellWithLabelAndLargeTextView.m; path = TableViewCell/TableViewCellWithLabelAndLargeTextView.m; sourceTree = ""; }; 71E7FE781BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = TableViewCellWithLabelAndLargeTextView.xib; path = TableViewCell/TableViewCellWithLabelAndLargeTextView.xib; sourceTree = ""; }; + 71E7FE851BFF59A0003457F3 /* TableViewCellSeparator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TableViewCellSeparator.h; path = TableViewCell/TableViewCellSeparator.h; sourceTree = ""; }; + 71E7FE861BFF59A0003457F3 /* TableViewCellSeparator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TableViewCellSeparator.m; path = TableViewCell/TableViewCellSeparator.m; sourceTree = ""; }; + 71E7FE871BFF59A0003457F3 /* TableViewCellSeparator.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = TableViewCellSeparator.xib; path = TableViewCell/TableViewCellSeparator.xib; sourceTree = ""; }; 9B179239B79688A61A3F465F /* libPods-Vector.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Vector.a"; sourceTree = BUILT_PRODUCTS_DIR; }; F001D7541B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomIncomingBubbleTableViewCell.h; sourceTree = ""; }; F001D7551B8207C000A162C3 /* RoomIncomingBubbleTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomIncomingBubbleTableViewCell.m; sourceTree = ""; }; @@ -239,6 +244,9 @@ 71E7FE691BFE341B003457F3 /* TableViewCell */ = { isa = PBXGroup; children = ( + 71E7FE851BFF59A0003457F3 /* TableViewCellSeparator.h */, + 71E7FE861BFF59A0003457F3 /* TableViewCellSeparator.m */, + 71E7FE871BFF59A0003457F3 /* TableViewCellSeparator.xib */, 71E7FE761BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.h */, 71E7FE771BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.m */, 71E7FE781BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.xib */, @@ -590,6 +598,7 @@ F0DD7D611B7AA8C900C4BE02 /* hide@2x.png in Resources */, F0DD7D751B7AA8C900C4BE02 /* typing@2x.png in Resources */, F0316E3A1B7DF45A00F03620 /* add.png in Resources */, + 71E7FE891BFF59A0003457F3 /* TableViewCellSeparator.xib in Resources */, F0DD7D671B7AA8C900C4BE02 /* members@2x.png in Resources */, F001D7701B83243900A162C3 /* send_other.png in Resources */, F00B1BCB1B95CC68001806E3 /* camera_record.png in Resources */, @@ -689,6 +698,7 @@ F0DD7D821B7B363300C4BE02 /* RoomCreationStep1ViewController.m in Sources */, F094A9AB1B78D8F000B1FBBF /* AppDelegate.m in Sources */, 71E7FE6D1BFE3441003457F3 /* TableViewCellWithLabelAndTextField.m in Sources */, + 71E7FE881BFF59A0003457F3 /* TableViewCellSeparator.m in Sources */, 71E7FE791BFF22C4003457F3 /* TableViewCellWithLabelAndLargeTextView.m in Sources */, 71E7FE681BFE16F9003457F3 /* RoomDetailsViewController.m in Sources */, F094AA2F1B78E42600B1FBBF /* AccountDetailsViewController.m in Sources */, diff --git a/Vector/ViewController/RoomDetailsViewController.m b/Vector/ViewController/RoomDetailsViewController.m index 3ad99931a..3fc97cfcf 100644 --- a/Vector/ViewController/RoomDetailsViewController.m +++ b/Vector/ViewController/RoomDetailsViewController.m @@ -18,6 +18,7 @@ #import "TableViewCellWithLabelAndTextField.h" #import "TableViewCellWithLabelAndLargeTextView.h" +#import "TableViewCellSeparator.h" #define ROOM_SECTION 0 @@ -91,7 +92,8 @@ { if (section == ROOM_SECTION) { - return ROOM_SECTION_COUNT; + // add separators + return ROOM_SECTION_COUNT * 2 + 1; } return 0; @@ -115,10 +117,21 @@ { if (indexPath.section == ROOM_SECTION) { - if (indexPath.row == ROOM_SECTION_TOPIC) - { - return ROOM_TOPIC_CELL_HEIGHT; - } + NSInteger row = indexPath.row; + + // is a separator ? + if ((row % 2) == 0) + { + return 1.0f; + } + + // retrieve row as a ROOM_SECTION_XX index + row = (row - 1) / 2; + + if (row == ROOM_SECTION_TOPIC) + { + return ROOM_TOPIC_CELL_HEIGHT; + } } return [super tableView:tableView heightForRowAtIndexPath:indexPath]; @@ -126,12 +139,31 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + NSInteger row = indexPath.row; UITableViewCell* cell = nil; // general settings if (indexPath.section == ROOM_SECTION) { - if (indexPath.row == ROOM_SECTION_TOPIC) + if ((row % 2) == 0) + { + UITableViewCell* sepCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellSeparator defaultReuseIdentifier]]; + + if (!sepCell) + { + sepCell = [[TableViewCellSeparator alloc] init]; + } + + // the borders are drawn in dark grey + sepCell.contentView.backgroundColor = ((row == 0) || (row == ROOM_SECTION_COUNT * 2)) ? [UIColor darkGrayColor] : [UIColor lightGrayColor]; + + return sepCell; + } + + // retrieve row as a ROOM_SECTION_XX index + row = (row - 1) / 2; + + if (row == ROOM_SECTION_TOPIC) { TableViewCellWithLabelAndLargeTextView *roomTopicCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithLabelAndLargeTextView defaultReuseIdentifier]]; @@ -165,7 +197,7 @@ cell = roomTopicCell; } - else if (indexPath.row == ROOM_SECTION_NAME) + else if (row == ROOM_SECTION_NAME) { TableViewCellWithLabelAndTextField *roomNameCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithLabelAndTextField defaultReuseIdentifier]]; diff --git a/Vector/Views/TableViewCell/TableViewCellSeparator.h b/Vector/Views/TableViewCell/TableViewCellSeparator.h new file mode 100644 index 000000000..cd27da69d --- /dev/null +++ b/Vector/Views/TableViewCell/TableViewCellSeparator.h @@ -0,0 +1,22 @@ +/* + Copyright 2015 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 "MXKTableViewCell.h" + +@interface TableViewCellSeparator : MXKTableViewCell + + +@end \ No newline at end of file diff --git a/Vector/Views/TableViewCell/TableViewCellSeparator.m b/Vector/Views/TableViewCell/TableViewCellSeparator.m new file mode 100644 index 000000000..6ff685117 --- /dev/null +++ b/Vector/Views/TableViewCell/TableViewCellSeparator.m @@ -0,0 +1,21 @@ +/* + Copyright 2015 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 "TableViewCellSeparator.h" + +@implementation TableViewCellSeparator + +@end diff --git a/Vector/Views/TableViewCell/TableViewCellSeparator.xib b/Vector/Views/TableViewCell/TableViewCellSeparator.xib new file mode 100644 index 000000000..153ad7110 --- /dev/null +++ b/Vector/Views/TableViewCell/TableViewCellSeparator.xib @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.h b/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.h index 97a498ac4..851c265a1 100644 --- a/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.h +++ b/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.h @@ -18,18 +18,9 @@ @interface TableViewCellWithLabelAndLargeTextView : MXKTableViewCell { -@protected - UIView *inputAccessoryView; } @property (strong, nonatomic) IBOutlet UILabel *mxkLabel; @property (strong, nonatomic) IBOutlet UITextView *mxkTextView; -/** - The custom accessory view associated with the text field. This view is - actually used to retrieve the keyboard view. Indeed the keyboard view is the superview of - the accessory view when the text field become the first responder. - */ -@property (readonly) UIView *inputAccessoryView; - @end \ No newline at end of file diff --git a/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.m b/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.m index 31c9f3e7e..b16626f6b 100644 --- a/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.m +++ b/Vector/Views/TableViewCell/TableViewCellWithLabelAndLargeTextView.m @@ -17,16 +17,12 @@ #import "TableViewCellWithLabelAndLargeTextView.h" @implementation TableViewCellWithLabelAndLargeTextView -@synthesize inputAccessoryView; - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { - // Add an accessory view to the text view in order to retrieve keyboard view. - //inputAccessoryView = [[UIView alloc] initWithFrame:CGRectZero]; - //_mxkTextView.inputAccessoryView = inputAccessoryView; } return self; @@ -34,7 +30,6 @@ - (void)dealloc { - //inputAccessoryView = nil; } @end From 376c16c2bf3cb48519175f43908885876d0471f2 Mon Sep 17 00:00:00 2001 From: yannick Date: Fri, 20 Nov 2015 15:20:15 +0100 Subject: [PATCH 3/6] Dismiss the keyboard when the text edition is ended. --- .../RoomDetailsViewController.m | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/Vector/ViewController/RoomDetailsViewController.m b/Vector/ViewController/RoomDetailsViewController.m index 3fc97cfcf..4e8e2aa16 100644 --- a/Vector/ViewController/RoomDetailsViewController.m +++ b/Vector/ViewController/RoomDetailsViewController.m @@ -40,7 +40,6 @@ @implementation RoomDetailsViewController - - (void)viewDidLoad { [super viewDidLoad]; @@ -51,6 +50,13 @@ self.tableView.separatorColor = [UIColor clearColor]; } +- (void)viewWillDisappear:(BOOL)animated +{ + [super viewWillDisappear:animated]; + + [self dismissFirstResponder]; +} + - (NSMutableDictionary*)getUpdatedItems { if (!updatedItems) @@ -60,6 +66,21 @@ return updatedItems; } + +- (void)dismissFirstResponder +{ + if ([topicTextView isFirstResponder]) + { + [topicTextView resignFirstResponder]; + } + + if ([nameTextField isFirstResponder]) + { + [nameTextField resignFirstResponder]; + } +} + + #pragma mark - UITextViewDelegate - (void)textViewDidChange:(UITextView *)textView @@ -239,10 +260,15 @@ { if (self.tableView == aTableView) { - if ([topicTextView isFirstResponder]) - { - - } + [self dismissFirstResponder]; + } +} + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView +{ + if (scrollView == self.tableView) + { + [self dismissFirstResponder]; } } From 648a9c2188aa4171befedb906cd1dae0da5be004 Mon Sep 17 00:00:00 2001 From: yannick Date: Fri, 20 Nov 2015 17:07:45 +0100 Subject: [PATCH 4/6] -> use the storyboard to display the roomDetailsViewController. -> the "Back" is removed from the back key in the navbar. --- Vector/Base.lproj/Main.storyboard | 17 ++- .../RoomDetailsViewController.m | 121 +++++++++++++++++- Vector/ViewController/RoomViewController.m | 19 ++- 3 files changed, 143 insertions(+), 14 deletions(-) diff --git a/Vector/Base.lproj/Main.storyboard b/Vector/Base.lproj/Main.storyboard index d3a69b5ce..c20487197 100644 --- a/Vector/Base.lproj/Main.storyboard +++ b/Vector/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -47,6 +47,7 @@ + @@ -255,7 +256,15 @@ - + + + + + + + + + @@ -467,7 +476,7 @@ + - diff --git a/Vector/ViewController/RoomDetailsViewController.m b/Vector/ViewController/RoomDetailsViewController.m index 4e8e2aa16..5f688e3b9 100644 --- a/Vector/ViewController/RoomDetailsViewController.m +++ b/Vector/ViewController/RoomDetailsViewController.m @@ -33,8 +33,12 @@ // updated user data NSMutableDictionary *updatedItems; + // active items UITextView* topicTextView; UITextField* nameTextField; + + // pending http operation + MXHTTPOperation* pendingOperation; } @end @@ -44,6 +48,8 @@ { [super viewDidLoad]; + // TODO use a color panel + // not an hard coded one. CGFloat item = (242.0f / 255.0); self.tableView.backgroundColor = [UIColor colorWithRed:item green:item blue:item alpha:item]; @@ -57,6 +63,21 @@ [self dismissFirstResponder]; } +- (void)destroy +{ + self.navigationItem.rightBarButtonItem.enabled = NO; + + if (pendingOperation) + { + [pendingOperation cancel]; + pendingOperation = nil; + } + + [super destroy]; +} + +#pragma mark - private + - (NSMutableDictionary*)getUpdatedItems { if (!updatedItems) @@ -80,13 +101,26 @@ } } +- (void)showUpdatingSpinner +{ + // TODO : wait that we have the final behaviour + self.view.alpha = 0.5f; + self.view.userInteractionEnabled = NO; +} -#pragma mark - UITextViewDelegate +- (void)hideUpdatingSpinner +{ + // TODO : wait that we have the final behaviour + self.view.alpha = 1.0f; + self.view.userInteractionEnabled = YES; +} + +#pragma mark - actions - (void)textViewDidChange:(UITextView *)textView { // avoid nil pointer - NSString* text = (!textView.text) ? textView.text : @""; + NSString* text = (textView.text) ? textView.text : @""; if (topicTextView == textView) { @@ -94,19 +128,94 @@ } } -#pragma mark - field updates - - (IBAction)onTextFieldUpdate:(UITextField*)textField { // avoid nil pointer - NSString* text = (!textField.text) ? textField.text : @""; + NSString* text = (textField.text) ? textField.text : @""; if (nameTextField == textField) { - [updatedItems setObject:text forKey:@"ROOM_SECTION_NAME"]; + [[self getUpdatedItems] setObject:text forKey:@"ROOM_SECTION_NAME"]; } } +- (IBAction)onDone:(id)sender +{ + // check if there is some update + if (mxRoomState && updatedItems && (updatedItems.count > 0)) + { + // has a new room name + if ([updatedItems objectForKey:@"ROOM_SECTION_NAME"]) + { + NSString* newName = [updatedItems objectForKey:@"ROOM_SECTION_NAME"]; + + if (![newName isEqualToString:mxRoomState.name]) + { + [self showUpdatingSpinner]; + __weak typeof(self) weakSelf = self; + + pendingOperation = [mxRoom setName:newName success:^{ + __strong __typeof(weakSelf)strongSelf = weakSelf; + + strongSelf->pendingOperation = nil; + [strongSelf->updatedItems removeObjectForKey:@"ROOM_SECTION_NAME"]; + [strongSelf onDone:nil]; + + } failure:^(NSError *error) { + __strong __typeof(weakSelf)strongSelf = weakSelf; + + // TODO should stop the saving ? + // continue the saving by now + strongSelf->pendingOperation = nil; + [strongSelf->updatedItems removeObjectForKey:@"ROOM_SECTION_NAME"]; + [strongSelf onDone:nil]; + + NSLog(@"[onDone] Rename room failed: %@", error); + }]; + + return; + } + } + + // has a new room topic + if ([updatedItems objectForKey:@"ROOM_SECTION_TOPIC"]) + { + NSString* newTopic = [updatedItems objectForKey:@"ROOM_SECTION_TOPIC"]; + + if (![newTopic isEqualToString:mxRoomState.topic]) + { + [self showUpdatingSpinner]; + __weak typeof(self) weakSelf = self; + + pendingOperation = [mxRoom setTopic:newTopic success:^{ + __strong __typeof(weakSelf)strongSelf = weakSelf; + + strongSelf->pendingOperation = nil; + [strongSelf->updatedItems removeObjectForKey:@"ROOM_SECTION_TOPIC"]; + [strongSelf onDone:nil]; + + } failure:^(NSError *error) { + __strong __typeof(weakSelf)strongSelf = weakSelf; + + // TODO should stop the saving ? + // continue the saving by now + strongSelf->pendingOperation = nil; + [strongSelf->updatedItems removeObjectForKey:@"ROOM_SECTION_TOPIC"]; + [strongSelf onDone:nil]; + + NSLog(@"[onDone] Rename topic failed: %@", error); + }]; + + return; + } + } + } + + [self hideUpdatingSpinner]; + + [self.navigationController popViewControllerAnimated:YES]; +} + #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section diff --git a/Vector/ViewController/RoomViewController.m b/Vector/ViewController/RoomViewController.m index f126aea52..3eef35eeb 100644 --- a/Vector/ViewController/RoomViewController.m +++ b/Vector/ViewController/RoomViewController.m @@ -303,6 +303,20 @@ participantsViewController.mxRoom = self.roomDataSource.room; } } + else if ([[segue identifier] isEqualToString:@"showRoomDetails"]) + { + if ([pushedViewController isKindOfClass:[RoomDetailsViewController class]]) + { + // Dismiss keyboard + [self dismissKeyboard]; + + RoomDetailsViewController* detailsViewController = (RoomDetailsViewController*)pushedViewController; + [detailsViewController initWithSession:self.roomDataSource.mxSession andRoomId:self.roomDataSource.roomId]; + } + } + + // Hide back button title + self.navigationItem.backBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; } #pragma mark - MXKRoomInputToolbarViewDelegate @@ -395,10 +409,7 @@ // instead of opening a text edition // launch a dedicated viewcontroller. dispatch_async(dispatch_get_main_queue(), ^{ - RoomDetailsViewController* controller = [RoomDetailsViewController roomDetailsViewController]; - [controller initWithSession:self.roomDataSource.mxSession andRoomId:self.roomDataSource.roomId]; - - [self.navigationController pushViewController:controller animated:YES]; + [self performSegueWithIdentifier:@"showRoomDetails" sender:self]; }); // cancel any requested edition From a56171a9d9d0311cc022ec54d61a1f722a5fe4cf Mon Sep 17 00:00:00 2001 From: yannick Date: Fri, 20 Nov 2015 17:42:29 +0100 Subject: [PATCH 5/6] The room settings were not refreshed after debackgrounding the application. --- .../RoomDetailsViewController.m | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Vector/ViewController/RoomDetailsViewController.m b/Vector/ViewController/RoomDetailsViewController.m index 5f688e3b9..aa0f957a3 100644 --- a/Vector/ViewController/RoomDetailsViewController.m +++ b/Vector/ViewController/RoomDetailsViewController.m @@ -56,11 +56,19 @@ self.tableView.separatorColor = [UIColor clearColor]; } +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didMXSessionStateChange:) name:kMXSessionStateDidChangeNotification object:nil]; +} + - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self dismissFirstResponder]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:kMXSessionStateDidChangeNotification object:nil]; } - (void)destroy @@ -139,6 +147,19 @@ } } +- (void)didMXSessionStateChange:(NSNotification *)notif +{ + // Check this is our Matrix session that has changed + if (notif.object == self.session) + { + // refresh when the session sync is done. + if (MXSessionStateRunning == self.session.state) + { + [self.tableView reloadData]; + } + } +} + - (IBAction)onDone:(id)sender { // check if there is some update From cbdd80436f1e54da5326b31a706e6a34a0cd3810 Mon Sep 17 00:00:00 2001 From: yannick Date: Fri, 20 Nov 2015 17:52:16 +0100 Subject: [PATCH 6/6] Add rageshake --- Vector/ViewController/RoomDetailsViewController.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Vector/ViewController/RoomDetailsViewController.m b/Vector/ViewController/RoomDetailsViewController.m index aa0f957a3..41539064d 100644 --- a/Vector/ViewController/RoomDetailsViewController.m +++ b/Vector/ViewController/RoomDetailsViewController.m @@ -20,6 +20,8 @@ #import "TableViewCellWithLabelAndLargeTextView.h" #import "TableViewCellSeparator.h" +#import "RageShakeManager.h" + #define ROOM_SECTION 0 #define ROOM_SECTION_NAME 0 @@ -54,6 +56,9 @@ self.tableView.backgroundColor = [UIColor colorWithRed:item green:item blue:item alpha:item]; self.tableView.separatorColor = [UIColor clearColor]; + + // Setup `RoomDetailsViewController` properties + self.rageShakeManager = [RageShakeManager sharedManager]; } - (void)viewWillAppear:(BOOL)animated