From b2ccf294746797a9f37129bd3e063e0d893a7594 Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Wed, 25 Jul 2018 14:54:26 +0200 Subject: [PATCH] Add public room options. Signed-off-by: Ivan Sein --- .../share-settings.imageset/Contents.json | 23 ++ .../share-settings.png | Bin 0 -> 744 bytes .../share-settings@2x.png | Bin 0 -> 1368 bytes .../share-settings@3x.png | Bin 0 -> 2062 bytes VideoCalls/RoomInfoTableViewController.m | 230 +++++++++++++----- 5 files changed, 195 insertions(+), 58 deletions(-) create mode 100644 VideoCalls/Images.xcassets/share-settings.imageset/Contents.json create mode 100644 VideoCalls/Images.xcassets/share-settings.imageset/share-settings.png create mode 100644 VideoCalls/Images.xcassets/share-settings.imageset/share-settings@2x.png create mode 100644 VideoCalls/Images.xcassets/share-settings.imageset/share-settings@3x.png diff --git a/VideoCalls/Images.xcassets/share-settings.imageset/Contents.json b/VideoCalls/Images.xcassets/share-settings.imageset/Contents.json new file mode 100644 index 00000000..e10bf4ef --- /dev/null +++ b/VideoCalls/Images.xcassets/share-settings.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "share-settings.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "share-settings@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "share-settings@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/VideoCalls/Images.xcassets/share-settings.imageset/share-settings.png b/VideoCalls/Images.xcassets/share-settings.imageset/share-settings.png new file mode 100644 index 0000000000000000000000000000000000000000..f44a5f71e0f6d20ca762c0d820c00edea0029041 GIT binary patch literal 744 zcmVP)JyO)>0_ZXuRAjhg$r)vV(wykrymF`^bM*>uvs{S-qT`n`=6x*zp6+a8AON5|O zGMmr;eBkr#y&$57fcCPWNnl8XBU*D!L|R4kg3DFBlS-vN`~k46cmmXovXC{vU$*yJ zYn4c)MrQtcbO&Hr{p}!&fUAmkT0|!@nR`>a33l}R4y3b6_%~zJrLnP*m$d{t(f}f| zQN@!7^QE5fO@P}iuYmOmo>r~ZVl3A8BogUss}-<$$417HawF)Um+?&AJDSJS`d*(E|+TM{VuUB7ps)mQYWm(N4o{OLkYi$-=S^|@{ZJS1O acdcI{KhroV4u|6a0000 literal 0 HcmV?d00001 diff --git a/VideoCalls/Images.xcassets/share-settings.imageset/share-settings@2x.png b/VideoCalls/Images.xcassets/share-settings.imageset/share-settings@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..2a9c6c73ddd9edb5e456c5e39f0870f0c1c2f28e GIT binary patch literal 1368 zcmV-e1*iInP)@~8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H11l37IK~!jg?OAVV8+90d-n*qqHEHWQWq(1`;TK_0SYtak*Qz*> zfpy>q84}p2n&kS=+Nxl8-9WaiYnvunYlNvF6DMVU5Qm~pgtavr(yCCz(GQ~H=0a_n z&ZW)W>jy0)*QC8%t~)>U`F79meV=*Sci^JRaHMawRST zcvweyQV^&<7(8`ZyC9fvO&?sY#0ls#4**V8m@%T|RyBav>vf8v!>1_d1aMcedPF>=13-Vt(HCT&{&>UnOK&7N)0@JDGWh zs-l93uM>%v1_n<4oLTqZYe6G`R{?C&VThUWu_y|%q9_j$Q9poOfztrqPNkCV(P;E$ zK>_^!wu3}C2H@VMXU8`Hzr0~X`SWk^D*M%kb zKs-Kk44{?F1AtARdH#x-yTalAO9uR{h^$|rxw-j4RTY1PIXCwR5xNEjdcQP5D=)H) zs;cPMa)pCN0kta>>ieQN9evQ4r6&M3s&$!}j)cRfE);935NHDMHe)jUbtu$Vk0R0= zh4yW9!H5VE#bJSY01z_|-0qqK05%)Yxxc!)=APPG_xRY@SkfG8`j8c%y1Hf~5$X)+ ztRsS(nY?ay&HAdUUE^1-jN~1Kn2D^%sL$uC6a@QK7~gO#B1yzyMVar3L?ZDbwU)(_ zf8wU5)&^!8&b4L$NdS>_y5z**;PGh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&P<&vgk3(>iCG; z$h0@;3XP48i*4I@TtwCdAnyzgo+x+w*bZ2Mh@k^J^*9RnT%$~i}^?er_g8;g_ zyEDMq0HiZZmf-po3zb1*_&)rU1OM>)%!kpSKLnuZd6FcA2I+GFX#U)5ByvQK zfhm+cTwOia^JGcr3<59=!vy!2YK}OdiHWL}({3g0hyMQFlXu>^DkDNc|9vRJHp}Yx z@kBA9GzcJ_?t7`GrnVepbw1aN(3(oM@0ctuv<3mB(}#XnTU+}&$fxkX4f!vy-m==; z`~-*EAb|eI^f?FvE1?e<-P!g70Lr@c;k-07*qoM6N<$f@GER=Kufz literal 0 HcmV?d00001 diff --git a/VideoCalls/RoomInfoTableViewController.m b/VideoCalls/RoomInfoTableViewController.m index 398fcbc4..0c09878a 100644 --- a/VideoCalls/RoomInfoTableViewController.m +++ b/VideoCalls/RoomInfoTableViewController.m @@ -25,7 +25,8 @@ typedef enum CreationSection { typedef enum PublicSection { kPublicSectionToggle = 0, - kPublicSectionPassword + kPublicSectionPassword, + kPublicSectionSendLink } PublicSection; @interface RoomInfoTableViewController () @@ -35,7 +36,6 @@ typedef enum PublicSection { @property (nonatomic, strong) NSMutableArray *roomParticipants; @property (nonatomic, strong) UITextField *roomNameTextField; @property (nonatomic, strong) UISwitch *publicSwtich; -@property (nonatomic, strong) UITextField *passwordTextField; @end @@ -66,16 +66,6 @@ typedef enum PublicSection { _publicSwtich = [[UISwitch alloc] initWithFrame:CGRectZero]; [_publicSwtich addTarget: self action: @selector(publicValueChanged:) forControlEvents:UIControlEventValueChanged]; - _passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(180, 10, 115, 30)]; - _passwordTextField.textAlignment = NSTextAlignmentRight; - _passwordTextField.placeholder = @"No password"; - _passwordTextField.adjustsFontSizeToFitWidth = YES; - _passwordTextField.textColor = [UIColor blackColor]; - _passwordTextField.secureTextEntry = YES; - - UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)]; - [self.view addGestureRecognizer:tap]; - [self.tableView registerNib:[UINib nibWithNibName:kContactsTableCellNibName bundle:nil] forCellReuseIdentifier:kContactCellIdentifier]; [self.tableView registerNib:[UINib nibWithNibName:kRoomNameTableCellNibName bundle:nil] forCellReuseIdentifier:kRoomNameCellIdentifier]; } @@ -85,12 +75,6 @@ typedef enum PublicSection { [self getRoomParticipants]; } -- (void)dismissKeyboard -{ - [_roomNameTextField resignFirstResponder]; - [_passwordTextField resignFirstResponder]; -} - - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -130,32 +114,122 @@ typedef enum PublicSection { }]; } +- (void)showPasswordOptions +{ + NSString *alertTitle = _room.hasPassword ? @"Set new password:" : @"Set password:"; + UIAlertController *renameDialog = + [UIAlertController alertControllerWithTitle:alertTitle + message:nil + preferredStyle:UIAlertControllerStyleAlert]; + + [renameDialog addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { + textField.placeholder = @"Password"; + textField.secureTextEntry = YES; + }]; + + NSString *actionTitle = _room.hasPassword ? @"Change password" : @"OK"; + UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:actionTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + NSString *password = [[renameDialog textFields][0] text]; + NSString *trimmedPassword = [password stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + [[NCAPIController sharedInstance] setPassword:trimmedPassword toRoom:_room.token withCompletionBlock:^(NSError *error) { + if (!error) { + [self getRoomInfo]; + } else { + NSLog(@"Error setting room password: %@", error.description); + //TODO: Error handling + } + }]; + }]; + [renameDialog addAction:confirmAction]; + + if (_room.hasPassword) { + UIAlertAction *removePasswordAction = [UIAlertAction actionWithTitle:@"Remove password" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { + [[NCAPIController sharedInstance] setPassword:@"" toRoom:_room.token withCompletionBlock:^(NSError *error) { + if (!error) { + [self getRoomInfo]; + } else { + NSLog(@"Error changing room password: %@", error.description); + //TODO: Error handling + } + }]; + }]; + [renameDialog addAction:removePasswordAction]; + } + + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; + [renameDialog addAction:cancelAction]; + + [self presentViewController:renameDialog animated:YES completion:nil]; +} + +- (void)makeRoomPublic +{ + [[NCAPIController sharedInstance] makeRoomPublic:_room.token withCompletionBlock:^(NSError *error) { + if (!error) { + [self shareRoomLink]; + [self getRoomInfo]; + } else { + NSLog(@"Error making public the room: %@", error.description); + //TODO: Error handling + } + _publicSwtich.enabled = YES; + }]; +} + +- (void)makeRoomPrivate +{ + [[NCAPIController sharedInstance] makeRoomPrivate:_room.token withCompletionBlock:^(NSError *error) { + if (!error) { + [self getRoomInfo]; + } else { + NSLog(@"Error making private the room: %@", error.description); + //TODO: Error handling + } + _publicSwtich.enabled = YES; + }]; +} + +- (void)shareRoomLink +{ + NSString *shareMessage = [NSString stringWithFormat:@"Join the conversation at %@/index.php/call/%@", + [[NCAPIController sharedInstance] currentServerUrl], _room.token]; + if (_room.name && ![_room.name isEqualToString:@""]) { + shareMessage = [NSString stringWithFormat:@"Join the conversation%@ at %@/index.php/call/%@", + [NSString stringWithFormat:@" \"%@\"", _room.name], [[NCAPIController sharedInstance] currentServerUrl], _room.token]; + } + NSArray *items = @[shareMessage]; + UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil]; + + NSString *appDisplayName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]; + NSString *emailSubject = [NSString stringWithFormat:@"%@ invitation", appDisplayName]; + [controller setValue:emailSubject forKey:@"subject"]; + + // Presentation on iPads + controller.popoverPresentationController.sourceView = self.tableView; + controller.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:kPublicSectionSendLink inSection:kCreationSectionPublic]]; + + [self presentViewController:controller animated:YES completion:nil]; + + controller.completionWithItemsHandler = ^(NSString *activityType, + BOOL completed, + NSArray *returnedItems, + NSError *error) { + if (error) { + NSLog(@"An Error occured sharing room: %@, %@", error.localizedDescription, error.localizedFailureReason); + } + }; +} + #pragma mark - Public switch - (void)publicValueChanged:(id)sender { - BOOL isPublic = _publicSwtich.on; - _roomName = [_roomNameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; _publicSwtich.enabled = NO; - - [CATransaction begin]; - [CATransaction setCompletionBlock:^{ - _publicSwtich.enabled = YES; - }]; - [self.tableView beginUpdates]; - // Reload room name section - [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone]; - // Show/Hide password row - NSIndexPath *passwordIP = [NSIndexPath indexPathForRow:kPublicSectionPassword inSection:kCreationSectionPublic]; - NSArray *indexArray = [NSArray arrayWithObjects:passwordIP,nil]; - if (isPublic) { - _passwordTextField.text = @""; - [self.tableView insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic]; + if (_publicSwtich.on) { + [self makeRoomPublic]; } else { - [self.tableView deleteRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic]; + [self makeRoomPrivate]; } - [self.tableView endUpdates]; - [CATransaction commit]; } #pragma mark - UITextField delegate @@ -183,7 +257,7 @@ typedef enum PublicSection { { switch (section) { case kCreationSectionPublic: - return (_publicSwtich.on) ? 2 : 1; + return (_publicSwtich.on) ? 3 : 1; break; case kCreationSectionParticipants: @@ -222,7 +296,9 @@ typedef enum PublicSection { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = nil; - static NSString *publicCellIdentifier = @"PublicConversationCellIdentifier"; + static NSString *shareLinkCellIdentifier = @"ShareLinkCellIdentifier"; + static NSString *passwordCellIdentifier = @"PasswordCellIdentifier"; + static NSString *sendLinkCellIdentifier = @"SendLinkCellIdentifier"; switch (indexPath.section) { case kCreationSectionName: @@ -232,17 +308,6 @@ typedef enum PublicSection { cell = [[RoomNameTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kRoomNameCellIdentifier]; } - if (_publicSwtich.on) { - [cell.roomImage setImage:[UIImage imageNamed:@"public-bg"]]; - } else { - [cell.roomImage setImage:[UIImage imageNamed:@"group-bg"]]; - } - cell.roomNameTextField.text = _room.displayName; - _roomNameTextField = cell.roomNameTextField; - _roomNameTextField.delegate = self; - [_roomNameTextField setReturnKeyType:UIReturnKeyDone]; - cell.userInteractionEnabled = YES; - if (_room.type == kNCRoomTypeOneToOneCall) { // Create avatar for every contact [cell.roomImage setImageWithString:_room.name color:nil circular:true]; @@ -252,6 +317,17 @@ typedef enum PublicSection { _roomNameTextField = nil; cell.roomNameTextField.textColor = [UIColor grayColor]; cell.userInteractionEnabled = NO; + } else { + if (_room.type == kNCRoomTypePublicCall) { + [cell.roomImage setImage:[UIImage imageNamed:@"public-bg"]]; + } else { + [cell.roomImage setImage:[UIImage imageNamed:@"group-bg"]]; + } + cell.roomNameTextField.text = _room.displayName; + _roomNameTextField = cell.roomNameTextField; + _roomNameTextField.delegate = self; + [_roomNameTextField setReturnKeyType:UIReturnKeyDone]; + cell.userInteractionEnabled = YES; } cell.roomImage.layer.cornerRadius = 24.0; @@ -266,14 +342,15 @@ typedef enum PublicSection { switch (indexPath.row) { case kPublicSectionToggle: { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:publicCellIdentifier]; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:shareLinkCellIdentifier]; if (!cell) { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:publicCellIdentifier]; + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:shareLinkCellIdentifier]; } cell.textLabel.text = @"Share link"; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.accessoryView = _publicSwtich; + _publicSwtich.on = (_room.type == kNCRoomTypePublicCall) ? YES : NO; [cell.imageView setImage:[UIImage imageNamed:@"public-setting"]]; return cell; @@ -282,16 +359,28 @@ typedef enum PublicSection { case kPublicSectionPassword: { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:publicCellIdentifier]; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:passwordCellIdentifier]; if (!cell) { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:publicCellIdentifier]; + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:passwordCellIdentifier]; } - cell.textLabel.text = @"Password"; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - cell.accessoryView = _passwordTextField; + cell.textLabel.text = (_room.hasPassword) ? @"Change password" : @"Set password"; [cell.imageView setImage:[UIImage imageNamed:@"privacy"]]; + return cell; + } + break; + + case kPublicSectionSendLink: + { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:sendLinkCellIdentifier]; + if (!cell) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sendLinkCellIdentifier]; + } + + cell.textLabel.text = @"Send conversation link"; + [cell.imageView setImage:[UIImage imageNamed:@"share-settings"]]; + return cell; } break; @@ -316,7 +405,6 @@ typedef enum PublicSection { failure:nil]; cell.contactImage.layer.cornerRadius = 24.0; cell.contactImage.layer.masksToBounds = YES; - cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } @@ -326,4 +414,30 @@ typedef enum PublicSection { return cell; } +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + switch (indexPath.section) { + case kCreationSectionName: + break; + case kCreationSectionPublic: + { + switch (indexPath.row) { + case kPublicSectionToggle: + break; + + case kPublicSectionPassword: + [self showPasswordOptions]; + break; + + case kPublicSectionSendLink: + [self shareRoomLink]; + break; + } + } + break; + case kCreationSectionParticipants: + break; + } + [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; +} + @end