Merge pull request #409 from vector-im/218

Bug Fix - Room Settings: Add favourite/low prio toggle in room settings
This commit is contained in:
giomfo 2016-06-28 17:41:44 +02:00 committed by GitHub
commit 3b6853f039
6 changed files with 627 additions and 159 deletions

View file

@ -170,6 +170,8 @@
F05641941C7DF9DE002276ED /* error@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = F05641911C7DF9DE002276ED /* error@3x.png */; };
F05895001B8B7E6600B73E85 /* RoomBubbleCellData.m in Sources */ = {isa = PBXBuildFile; fileRef = F05894FF1B8B7E6600B73E85 /* RoomBubbleCellData.m */; };
F067F2BC1CF6F0EA00F35EE8 /* third_party_licenses.html in Resources */ = {isa = PBXBuildFile; fileRef = F067F2BB1CF6F0EA00F35EE8 /* third_party_licenses.html */; };
F072E9A01D217C2C002921AF /* TableViewCellWithSwitches.m in Sources */ = {isa = PBXBuildFile; fileRef = F072E99F1D217C2C002921AF /* TableViewCellWithSwitches.m */; };
F072E9A21D217EA0002921AF /* TableViewCellWithSwitches.xib in Resources */ = {isa = PBXBuildFile; fileRef = F072E9A11D217EA0002921AF /* TableViewCellWithSwitches.xib */; };
F08BE09E1B87025B00C480FB /* EventFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = F08BE09D1B87025B00C480FB /* EventFormatter.m */; };
F08BE0A21B87064000C480FB /* RoomDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = F08BE0A11B87064000C480FB /* RoomDataSource.m */; };
F094A9A81B78D8F000B1FBBF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F094A9A71B78D8F000B1FBBF /* main.m */; };
@ -477,6 +479,9 @@
F05894FE1B8B7E6600B73E85 /* RoomBubbleCellData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomBubbleCellData.h; sourceTree = "<group>"; };
F05894FF1B8B7E6600B73E85 /* RoomBubbleCellData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomBubbleCellData.m; sourceTree = "<group>"; };
F067F2BB1CF6F0EA00F35EE8 /* third_party_licenses.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = third_party_licenses.html; sourceTree = "<group>"; };
F072E99E1D217C2C002921AF /* TableViewCellWithSwitches.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TableViewCellWithSwitches.h; path = TableViewCell/TableViewCellWithSwitches.h; sourceTree = "<group>"; };
F072E99F1D217C2C002921AF /* TableViewCellWithSwitches.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TableViewCellWithSwitches.m; path = TableViewCell/TableViewCellWithSwitches.m; sourceTree = "<group>"; };
F072E9A11D217EA0002921AF /* TableViewCellWithSwitches.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = TableViewCellWithSwitches.xib; path = TableViewCell/TableViewCellWithSwitches.xib; sourceTree = "<group>"; };
F08BE09C1B87025B00C480FB /* EventFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventFormatter.h; sourceTree = "<group>"; };
F08BE09D1B87025B00C480FB /* EventFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EventFormatter.m; sourceTree = "<group>"; };
F08BE0A01B87064000C480FB /* RoomDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomDataSource.h; sourceTree = "<group>"; };
@ -665,6 +670,9 @@
7179283B1C0384DE00407D96 /* TableViewCell */ = {
isa = PBXGroup;
children = (
F072E99E1D217C2C002921AF /* TableViewCellWithSwitches.h */,
F072E99F1D217C2C002921AF /* TableViewCellWithSwitches.m */,
F072E9A11D217EA0002921AF /* TableViewCellWithSwitches.xib */,
F05641781C7C9FD7002276ED /* TableViewCellWithButton.h */,
F05641791C7C9FD7002276ED /* TableViewCellWithButton.m */,
F056417A1C7C9FD7002276ED /* TableViewCellWithButton.xib */,
@ -1447,6 +1455,7 @@
F0026B5C1C916E68001D2C04 /* notificationsOff@2x.png in Resources */,
F0CC4DC11C4E26FA003BBE45 /* MediaAlbumTableCell.xib in Resources */,
F02528DD1C11B6FC00E1FE1B /* camera_switch@2x.png in Resources */,
F072E9A21D217EA0002921AF /* TableViewCellWithSwitches.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1517,6 +1526,7 @@
F094A9AB1B78D8F000B1FBBF /* AppDelegate.m in Sources */,
32C52BF61CBE4B0A00863B33 /* RoomEmailInvitation.m in Sources */,
F047DBB91C576F6600952DA2 /* AuthInputsView.m in Sources */,
F072E9A01D217C2C002921AF /* TableViewCellWithSwitches.m in Sources */,
323A520B1C3183CC00010773 /* UIViewController+VectorSearch.m in Sources */,
717928491C03852C00407D96 /* TableViewCellWithLabelAndTextField.m in Sources */,
32A887211C89B9580037DC17 /* SimpleRoomTitleView.m in Sources */,

View file

@ -93,7 +93,7 @@
// Room recents
"room_recents_directory" = "DIRECTORY";
"room_recents_favourites" = "FAVORITES";
"room_recents_favourites" = "FAVOURITES";
"room_recents_conversations" = "ROOMS";
"room_recents_low_priority" = "LOW PRIORITY";
"room_recents_invites" = "INVITES";
@ -245,6 +245,8 @@
"room_details_photo" = "Room Photo";
"room_details_room_name" = "Room Name";
"room_details_topic" = "Topic";
"room_details_favourite_tag" = "Favourite";
"room_details_low_priority_tag" = "Low priority";
"room_details_people" = "Members";
"room_details_settings" = "Settings";
"room_details_fail_to_update_avatar" = "Fail to update the room photo";

View file

@ -19,6 +19,7 @@
#import "TableViewCellWithLabelAndTextField.h"
#import "TableViewCellWithLabelAndLargeTextView.h"
#import "TableViewCellWithLabelAndSwitch.h"
#import "TableViewCellWithSwitches.h"
#import "SegmentedViewController.h"
@ -38,7 +39,7 @@
#define ROOM_SETTINGS_MAIN_SECTION_ROW_PHOTO 0
#define ROOM_SETTINGS_MAIN_SECTION_ROW_NAME 1
#define ROOM_SETTINGS_MAIN_SECTION_ROW_TOPIC 2
#define ROOM_SETTINGS_MAIN_SECTION_ROW_PRIV_PUB 3
#define ROOM_SETTINGS_MAIN_SECTION_ROW_TAG 3
#define ROOM_SETTINGS_MAIN_SECTION_ROW_MUTE_NOTIFICATIONS 4
#define ROOM_SETTINGS_MAIN_SECTION_ROW_COUNT 5
@ -48,6 +49,7 @@ NSString *const kRoomSettingsAvatarKey = @"kRoomSettingsAvatarKey";
NSString *const kRoomSettingsAvatarURLKey = @"kRoomSettingsAvatarURLKey";
NSString *const kRoomSettingsNameKey = @"kRoomSettingsNameKey";
NSString *const kRoomSettingsTopicKey = @"kRoomSettingsTopicKey";
NSString *const kRoomSettingsTagKey = @"kRoomSettingsTagKey";
NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
@interface RoomSettingsViewController ()
@ -58,6 +60,8 @@ NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
// The current table items
UITextField* nameTextField;
UITextView* topicTextView;
UISwitch *favouriteTagSwitch;
UISwitch *lowPriorityTagSwitch;
// The potential image loader
MXKMediaLoader *uploader;
@ -112,6 +116,8 @@ NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
updatedItemsDict = [[NSMutableDictionary alloc] init];
[self.tableView registerClass:TableViewCellWithSwitches.class forCellReuseIdentifier:[TableViewCellWithSwitches defaultReuseIdentifier]];
[self setNavBarButtons];
}
@ -452,179 +458,216 @@ NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
- (IBAction)onSave:(id)sender
{
[self startActivityIndicator];
// check if there is some updates related to room state
if (mxRoomState && updatedItemsDict.count)
if (updatedItemsDict.count)
{
[self startActivityIndicator];
__weak typeof(self) weakSelf = self;
if ([updatedItemsDict objectForKey:kRoomSettingsAvatarKey])
// check if there is some updates related to room state
if (mxRoomState)
{
// Retrieve the current picture and make sure its orientation is up
UIImage *updatedPicture = [MXKTools forceImageOrientationUp:[updatedItemsDict objectForKey:kRoomSettingsAvatarKey]];
if ([updatedItemsDict objectForKey:kRoomSettingsAvatarKey])
{
// Retrieve the current picture and make sure its orientation is up
UIImage *updatedPicture = [MXKTools forceImageOrientationUp:[updatedItemsDict objectForKey:kRoomSettingsAvatarKey]];
// Upload picture
uploader = [MXKMediaManager prepareUploaderWithMatrixSession:mxRoom.mxSession initialRange:0 andRange:1.0];
[uploader uploadData:UIImageJPEGRepresentation(updatedPicture, 0.5) filename:nil mimeType:@"image/jpeg" success:^(NSString *url) {
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->uploader = nil;
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsAvatarKey];
[strongSelf->updatedItemsDict setObject:url forKey:kRoomSettingsAvatarURLKey];
[strongSelf onSave:nil];
}
} failure:^(NSError *error) {
NSLog(@"[RoomSettingsViewController] Image upload failed");
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->uploader = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_avatar", @"Vector", nil) withKey:kRoomSettingsAvatarKey];
});
}
}];
return;
}
// Upload picture
uploader = [MXKMediaManager prepareUploaderWithMatrixSession:mxRoom.mxSession initialRange:0 andRange:1.0];
if ([updatedItemsDict objectForKey:kRoomSettingsAvatarURLKey])
{
NSString* photoUrl = [updatedItemsDict objectForKey:kRoomSettingsAvatarURLKey];
pendingOperation = [mxRoom setAvatar:photoUrl success:^{
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsAvatarURLKey];
[strongSelf onSave:nil];
}
} failure:^(NSError *error) {
NSLog(@"[RoomSettingsViewController] Failed to update the room avatar");
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_avatar", @"Vector", nil) withKey:kRoomSettingsAvatarURLKey];
});
}
}];
return;
}
[uploader uploadData:UIImageJPEGRepresentation(updatedPicture, 0.5) filename:nil mimeType:@"image/jpeg" success:^(NSString *url) {
// has a new room name
if ([updatedItemsDict objectForKey:kRoomSettingsNameKey])
{
NSString* newName = [updatedItemsDict objectForKey:kRoomSettingsNameKey];
pendingOperation = [mxRoom setName:newName success:^{
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsNameKey];
[strongSelf onSave:nil];
}
} failure:^(NSError *error) {
NSLog(@"[RoomSettingsViewController] Rename room failed");
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_room_name", @"Vector", nil) withKey:kRoomSettingsNameKey];
});
}
}];
return;
}
// has a new room topic
if ([updatedItemsDict objectForKey:kRoomSettingsTopicKey])
{
NSString* newTopic = [updatedItemsDict objectForKey:kRoomSettingsTopicKey];
pendingOperation = [mxRoom setTopic:newTopic success:^{
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsTopicKey];
[strongSelf onSave:nil];
}
} failure:^(NSError *error) {
NSLog(@"[RoomSettingsViewController] Rename topic failed");
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_topic", @"Vector", nil) withKey:kRoomSettingsTopicKey];
});
}
}];
return;
}
}
// Update here other room settings
if ([updatedItemsDict objectForKey:kRoomSettingsTagKey])
{
NSString *roomTag = [updatedItemsDict objectForKey:kRoomSettingsTagKey];
if (!roomTag.length)
{
roomTag = nil;
}
[mxRoom setRoomTag:roomTag completion:^{
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->uploader = nil;
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsAvatarKey];
[strongSelf->updatedItemsDict setObject:url forKey:kRoomSettingsAvatarURLKey];
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
[strongSelf onSave:nil];
}
} failure:^(NSError *error) {
NSLog(@"[RoomSettingsViewController] Image upload failed");
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->uploader = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_avatar", @"Vector", nil) withKey:kRoomSettingsAvatarKey];
});
}
}];
return;
}
if ([updatedItemsDict objectForKey:kRoomSettingsAvatarURLKey])
{
NSString* photoUrl = [updatedItemsDict objectForKey:kRoomSettingsAvatarURLKey];
pendingOperation = [mxRoom setAvatar:photoUrl success:^{
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsAvatarURLKey];
[strongSelf onSave:nil];
}
} failure:^(NSError *error) {
NSLog(@"[RoomSettingsViewController] Failed to update the room avatar");
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_avatar", @"Vector", nil) withKey:kRoomSettingsAvatarURLKey];
});
}
}];
return;
}
// has a new room name
if ([updatedItemsDict objectForKey:kRoomSettingsNameKey])
if ([updatedItemsDict objectForKey:kRoomSettingsMuteNotifKey])
{
NSString* newName = [updatedItemsDict objectForKey:kRoomSettingsNameKey];
pendingOperation = [mxRoom setName:newName success:^{
[mxRoom setMute:roomNotifSwitch.on completion:^{
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsNameKey];
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsMuteNotifKey];
[strongSelf onSave:nil];
}
} failure:^(NSError *error) {
NSLog(@"[RoomSettingsViewController] Rename room failed");
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_room_name", @"Vector", nil) withKey:kRoomSettingsNameKey];
});
}
}];
return;
}
// has a new room topic
if ([updatedItemsDict objectForKey:kRoomSettingsTopicKey])
{
NSString* newTopic = [updatedItemsDict objectForKey:kRoomSettingsTopicKey];
pendingOperation = [mxRoom setTopic:newTopic success:^{
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
[strongSelf->updatedItemsDict removeObjectForKey:kRoomSettingsTopicKey];
[strongSelf onSave:nil];
}
} failure:^(NSError *error) {
NSLog(@"[RoomSettingsViewController] Rename topic failed");
if (weakSelf)
{
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf->pendingOperation = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf onSaveFailed:NSLocalizedStringFromTable(@"room_details_fail_to_update_topic", @"Vector", nil) withKey:kRoomSettingsTopicKey];
});
}
}];
return;
}
}
if ([updatedItemsDict objectForKey:kRoomSettingsMuteNotifKey])
{
[mxRoom setMute:roomNotifSwitch.on completion:nil];
[updatedItemsDict removeObjectForKey:kRoomSettingsMuteNotifKey];
[self onSave:nil];
}
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
[self getNavigationItem].rightBarButtonItem.enabled = NO;
[self stopActivityIndicator];
@ -687,7 +730,7 @@ NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
roomNotifCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_mute_notifs", @"Vector", nil);
roomNotifSwitch = roomNotifCell.mxkSwitch;
if (updatedItemsDict && [updatedItemsDict objectForKey:kRoomSettingsMuteNotifKey])
if ([updatedItemsDict objectForKey:kRoomSettingsMuteNotifKey])
{
roomNotifSwitch.on = ((NSNumber*)[updatedItemsDict objectForKey:kRoomSettingsMuteNotifKey]).boolValue;
}
@ -722,7 +765,7 @@ NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
roomPhotoCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_photo", @"Vector", nil);
if (updatedItemsDict && [updatedItemsDict objectForKey:kRoomSettingsAvatarKey])
if ([updatedItemsDict objectForKey:kRoomSettingsAvatarKey])
{
roomPhotoCell.mxkImageView.image = (UIImage*)[updatedItemsDict objectForKey:kRoomSettingsAvatarKey];
}
@ -754,7 +797,7 @@ NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
topicTextView = roomTopicCell.mxkTextView;
if (updatedItemsDict && [updatedItemsDict objectForKey:kRoomSettingsTopicKey])
if ([updatedItemsDict objectForKey:kRoomSettingsTopicKey])
{
topicTextView.text = (NSString*)[updatedItemsDict objectForKey:kRoomSettingsTopicKey];
}
@ -791,7 +834,7 @@ NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
nameTextField.userInteractionEnabled = YES;
nameTextField.tintColor = kVectorColorGreen;
if (updatedItemsDict && [updatedItemsDict objectForKey:kRoomSettingsNameKey])
if ([updatedItemsDict objectForKey:kRoomSettingsNameKey])
{
nameTextField.text = (NSString*)[updatedItemsDict objectForKey:kRoomSettingsNameKey];
}
@ -809,21 +852,52 @@ NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
cell = roomNameCell;
}
else if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_PRIV_PUB)
else if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_TAG)
{
TableViewCellWithLabelAndTextField *privPublicCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithLabelAndTextField defaultReuseIdentifier]];
TableViewCellWithSwitches *tagCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithSwitches defaultReuseIdentifier] forIndexPath:indexPath];
if (!privPublicCell)
tagCell.switchesNumber = 2;
favouriteTagSwitch = tagCell.switches[0];
[favouriteTagSwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
favouriteTagSwitch.onTintColor = kVectorColorGreen;
lowPriorityTagSwitch = tagCell.switches[1];
[lowPriorityTagSwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
lowPriorityTagSwitch.onTintColor = kVectorColorGreen;
UILabel *label;
label = tagCell.labels[0];
label.text = NSLocalizedStringFromTable(@"room_details_favourite_tag", @"Vector", nil);
label = tagCell.labels[1];
label.text = NSLocalizedStringFromTable(@"room_details_low_priority_tag", @"Vector", nil);
if ([updatedItemsDict objectForKey:kRoomSettingsTagKey])
{
privPublicCell = [[TableViewCellWithLabelAndTextField alloc] init];
NSString *roomTag = [updatedItemsDict objectForKey:kRoomSettingsTagKey];
if ([roomTag isEqualToString:kMXRoomTagFavourite])
{
favouriteTagSwitch.on = YES;
lowPriorityTagSwitch.on = NO;
}
else if ([roomTag isEqualToString:kMXRoomTagLowPriority])
{
favouriteTagSwitch.on = NO;
lowPriorityTagSwitch.on = YES;
}
else
{
favouriteTagSwitch.on = NO;
lowPriorityTagSwitch.on = NO;
}
}
else
{
favouriteTagSwitch.on = mxRoom.accountData.tags[kMXRoomTagFavourite];
lowPriorityTagSwitch.on = mxRoom.accountData.tags[kMXRoomTagLowPriority];
}
privPublicCell.mxkTextField.userInteractionEnabled = NO;
privPublicCell.mxkTextField.text = @"";
// FIXME: Do we want to display that the join rule of this room is public?
privPublicCell.mxkLabel.text = mxRoom.state.isJoinRulePublic ? NSLocalizedStringFromTable(@"room_details_room_is_public", @"Vector", nil) : NSLocalizedStringFromTable(@"room_details_room_is_private", @"Vector", nil);
cell = privPublicCell;
cell = tagCell;
}
}
@ -890,9 +964,99 @@ NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
[self presentViewController:navigationController animated:YES completion:nil];
}
- (void)onSwitchUpdate:(UISwitch*)uiSwitch
- (void)onSwitchUpdate:(UISwitch*)theSwitch
{
if (uiSwitch == roomNotifSwitch)
if (theSwitch == favouriteTagSwitch)
{
if (favouriteTagSwitch.on)
{
// Check the actual tag on mxRoom
if (mxRoom.accountData.tags[kMXRoomTagFavourite])
{
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
}
else
{
[updatedItemsDict setObject:kMXRoomTagFavourite forKey:kRoomSettingsTagKey];
}
// Force off the low priority toggle
lowPriorityTagSwitch.on = NO;
}
else
{
// Retrieve the current change on room tag (if any)
NSString *updatedRoomTag = [updatedItemsDict objectForKey:kRoomSettingsTagKey];
// Check the actual tag on mxRoom
if (mxRoom.accountData.tags[kMXRoomTagFavourite])
{
// The actual tag must be updated, check whether another tag is already set
if (!updatedRoomTag)
{
[updatedItemsDict setObject:@"" forKey:kRoomSettingsTagKey];
}
}
else if (updatedRoomTag && [updatedRoomTag isEqualToString:kMXRoomTagFavourite])
{
// Cancel the updated tag, but take into account the cancellation of the another tag (low priority) when favourite was selected
if (mxRoom.accountData.tags[kMXRoomTagLowPriority])
{
[updatedItemsDict setObject:@"" forKey:kRoomSettingsTagKey];
}
else
{
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
}
}
}
}
else if (theSwitch == lowPriorityTagSwitch)
{
if (lowPriorityTagSwitch.on)
{
// Check the actual tag on mxRoom
if (mxRoom.accountData.tags[kMXRoomTagLowPriority])
{
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
}
else
{
[updatedItemsDict setObject:kMXRoomTagLowPriority forKey:kRoomSettingsTagKey];
}
// Force off the favourite toggle
favouriteTagSwitch.on = NO;
}
else
{
// Retrieve the current change on room tag (if any)
NSString *updatedRoomTag = [updatedItemsDict objectForKey:kRoomSettingsTagKey];
// Check the actual tag on mxRoom
if (mxRoom.accountData.tags[kMXRoomTagLowPriority])
{
// The actual tag must be updated, check whether another tag is already set
if (!updatedRoomTag)
{
[updatedItemsDict setObject:@"" forKey:kRoomSettingsTagKey];
}
}
else if (updatedRoomTag && [updatedRoomTag isEqualToString:kMXRoomTagLowPriority])
{
// Cancel the updated tag, but take into account the cancellation of the another tag (favourite) when low priority was selected
if (mxRoom.accountData.tags[kMXRoomTagFavourite])
{
[updatedItemsDict setObject:@"" forKey:kRoomSettingsTagKey];
}
else
{
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
}
}
}
}
else if (theSwitch == roomNotifSwitch)
{
if (roomNotifSwitch.on == mxRoom.isMute)
{
@ -902,9 +1066,9 @@ NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
{
[updatedItemsDict setObject:[NSNumber numberWithBool:roomNotifSwitch.on] forKey:kRoomSettingsMuteNotifKey];
}
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
}
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
}
@end

View file

@ -0,0 +1,50 @@
/*
Copyright 2016 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"
/**
'TableViewCellWithSwitches' inherits 'MXKTableViewCell' class.
It displays several switches in a UITableViewCell. Each switch has its own label.
All switches have the same width and they are horizontally aligned inside the main container.
They are vertically centered.
*/
@interface TableViewCellWithSwitches : MXKTableViewCell
@property (weak, nonatomic) IBOutlet UIView *mainContainer;
/**
The number of switches
*/
@property (nonatomic) NSUInteger switchesNumber;
/**
The current array of switches
*/
@property (nonatomic, readonly) NSArray *switches;
/**
The current array of labels
*/
@property (nonatomic, readonly) NSArray *labels;
/**
Leading/Trailing constraints define here spacing to nearest neighbor (no relative to margin)
*/
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *mainContainerLeadingConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *mainContainerTrailingConstraint;
@end

View file

@ -0,0 +1,204 @@
/*
Copyright 2016 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 "TableViewCellWithSwitches.h"
// The space between 2 switches
#define TABLEVIEWCELLWITHSWITCHES_MARGIN 8
@interface TableViewCellWithSwitches ()
{
NSMutableArray *switchArray;
NSMutableArray *labelArray;
}
@end
@implementation TableViewCellWithSwitches
- (void)setSwitchesNumber:(NSUInteger)switchesNumber
{
if (_switchesNumber == switchesNumber)
{
return;
}
// Remove existing items
NSArray *subviews = self.mainContainer.subviews;
for (UIView *view in subviews)
{
[view removeFromSuperview];
}
_switchesNumber = switchesNumber;
if (!switchesNumber)
{
// Nothing to do
return;
}
switchArray = [NSMutableArray arrayWithCapacity:switchesNumber];
labelArray = [NSMutableArray arrayWithCapacity:switchesNumber];
CGFloat containerWidth = (self.mainContainer.frame.size.width - ((switchesNumber - 1.0) * TABLEVIEWCELLWITHSWITCHES_MARGIN)) / switchesNumber;
UIView *previousContainer = nil;
NSLayoutConstraint *topConstraint, *leftConstraint, *bottomConstraint;
NSLayoutConstraint *widthConstraint, *centerYConstraint;
for (NSInteger index = 0; index < switchesNumber; index++)
{
UIView *switchContainer = [[UIView alloc] initWithFrame:CGRectMake(index * (containerWidth + TABLEVIEWCELLWITHSWITCHES_MARGIN), 0, containerWidth, self.mainContainer.frame.size.height)];
switchContainer.backgroundColor = [UIColor clearColor];
[self.mainContainer addSubview:switchContainer];
// Add container constraints
switchContainer.translatesAutoresizingMaskIntoConstraints = NO;
if (!previousContainer)
{
leftConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.mainContainer
attribute:NSLayoutAttributeLeading
multiplier:1
constant:0];
widthConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self.mainContainer
attribute:NSLayoutAttributeWidth
multiplier:(1.0 / switchesNumber)
constant:(- ((switchesNumber - 1.0) * TABLEVIEWCELLWITHSWITCHES_MARGIN) / switchesNumber)];
}
else
{
leftConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:previousContainer
attribute:NSLayoutAttributeTrailing
multiplier:1
constant:TABLEVIEWCELLWITHSWITCHES_MARGIN];
widthConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:previousContainer
attribute:NSLayoutAttributeWidth
multiplier:1
constant:0];
}
topConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.mainContainer
attribute:NSLayoutAttributeTop
multiplier:1
constant:0];
bottomConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.mainContainer
attribute:NSLayoutAttributeBottom
multiplier:1
constant:0];
[NSLayoutConstraint activateConstraints:@[leftConstraint, widthConstraint, topConstraint, bottomConstraint]];
previousContainer = switchContainer;
// Add Switch and Label
UISwitch *theSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 51, 31)];
theSwitch.translatesAutoresizingMaskIntoConstraints = NO;
[switchContainer addSubview:theSwitch];
[switchArray addObject:theSwitch];
UILabel *theLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, containerWidth - 60, 31)];
theLabel.translatesAutoresizingMaskIntoConstraints = NO;
[switchContainer addSubview:theLabel];
[labelArray addObject:theLabel];
// Add switch constraints
leftConstraint = [NSLayoutConstraint constraintWithItem:theSwitch
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:switchContainer
attribute:NSLayoutAttributeLeading
multiplier:1
constant:0];
widthConstraint = [NSLayoutConstraint constraintWithItem:theSwitch
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:51];
centerYConstraint = [NSLayoutConstraint constraintWithItem:theSwitch
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:switchContainer
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:0.0f];
[NSLayoutConstraint activateConstraints:@[leftConstraint, widthConstraint, centerYConstraint]];
// Add Label constraints
topConstraint = [NSLayoutConstraint constraintWithItem:theLabel
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:switchContainer
attribute:NSLayoutAttributeTop
multiplier:1
constant:0];
leftConstraint = [NSLayoutConstraint constraintWithItem:theLabel
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:theSwitch
attribute:NSLayoutAttributeTrailing
multiplier:1
constant:9];
centerYConstraint = [NSLayoutConstraint constraintWithItem:theLabel
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:switchContainer
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:0.0f];
[NSLayoutConstraint activateConstraints:@[topConstraint, leftConstraint, centerYConstraint]];
}
}
- (NSArray*)switches
{
return [NSArray arrayWithArray:switchArray];
}
- (NSArray*)labels
{
return [NSArray arrayWithArray:labelArray];
}
@end

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="20U-7H-xmi" customClass="TableViewCellWithSwitches">
<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="20U-7H-xmi" id="cFw-g7-Cgn">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hGF-Ge-C0t">
<rect key="frame" x="15" y="6" width="570" height="31"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="31" id="JHe-A2-qQn"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstItem="hGF-Ge-C0t" firstAttribute="leading" secondItem="cFw-g7-Cgn" secondAttribute="leading" constant="15" id="hl1-17-xPW"/>
<constraint firstItem="hGF-Ge-C0t" firstAttribute="centerY" secondItem="cFw-g7-Cgn" secondAttribute="centerY" id="lvp-ia-Agx"/>
<constraint firstAttribute="trailing" secondItem="hGF-Ge-C0t" secondAttribute="trailing" constant="15" id="njm-cy-8WD"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="mainContainer" destination="hGF-Ge-C0t" id="ozw-BB-s9o"/>
<outlet property="mainContainerLeadingConstraint" destination="hl1-17-xPW" id="PMX-A4-OXZ"/>
<outlet property="mainContainerTrailingConstraint" destination="njm-cy-8WD" id="T1O-tz-J6b"/>
</connections>
</tableViewCell>
</objects>
</document>