mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Merge pull request #433 from vector-im/room_settings_tag_shortcuts
Room Settings - Room tag: replace switches by check boxes
This commit is contained in:
commit
a1d5384cf8
7 changed files with 343 additions and 227 deletions
|
@ -164,8 +164,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 */; };
|
||||
F07ECA4D1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.m in Sources */ = {isa = PBXBuildFile; fileRef = F07ECA4B1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.m */; };
|
||||
F07ECA4E1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.xib in Resources */ = {isa = PBXBuildFile; fileRef = F07ECA4C1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.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 */; };
|
||||
|
@ -466,9 +466,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>"; };
|
||||
F07ECA4A1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TableViewCellWithCheckBoxes.h; path = TableViewCell/TableViewCellWithCheckBoxes.h; sourceTree = "<group>"; };
|
||||
F07ECA4B1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TableViewCellWithCheckBoxes.m; path = TableViewCell/TableViewCellWithCheckBoxes.m; sourceTree = "<group>"; };
|
||||
F07ECA4C1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = TableViewCellWithCheckBoxes.xib; path = TableViewCell/TableViewCellWithCheckBoxes.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>"; };
|
||||
|
@ -660,12 +660,12 @@
|
|||
7179283B1C0384DE00407D96 /* TableViewCell */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F07ECA4A1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.h */,
|
||||
F07ECA4B1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.m */,
|
||||
F07ECA4C1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.xib */,
|
||||
F0B7037B1D22D4AD00B63766 /* TableViewCellWithTickAndLabel.h */,
|
||||
F0B7037C1D22D4AD00B63766 /* TableViewCellWithTickAndLabel.m */,
|
||||
F0B7037D1D22D4AD00B63766 /* TableViewCellWithTickAndLabel.xib */,
|
||||
F072E99E1D217C2C002921AF /* TableViewCellWithSwitches.h */,
|
||||
F072E99F1D217C2C002921AF /* TableViewCellWithSwitches.m */,
|
||||
F072E9A11D217EA0002921AF /* TableViewCellWithSwitches.xib */,
|
||||
F05641781C7C9FD7002276ED /* TableViewCellWithButton.h */,
|
||||
F05641791C7C9FD7002276ED /* TableViewCellWithButton.m */,
|
||||
F056417A1C7C9FD7002276ED /* TableViewCellWithButton.xib */,
|
||||
|
@ -1434,10 +1434,10 @@
|
|||
F0026B521C916E68001D2C04 /* favouriteOff.png in Resources */,
|
||||
32A887221C89B9580037DC17 /* SimpleRoomTitleView.xib in Resources */,
|
||||
F02528FD1C11B6FC00E1FE1B /* selection_untick.png in Resources */,
|
||||
F07ECA4E1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.xib in Resources */,
|
||||
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;
|
||||
};
|
||||
|
@ -1508,7 +1508,6 @@
|
|||
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 */,
|
||||
32A887211C89B9580037DC17 /* SimpleRoomTitleView.m in Sources */,
|
||||
F056417B1C7C9FD7002276ED /* TableViewCellWithButton.m in Sources */,
|
||||
|
@ -1569,6 +1568,7 @@
|
|||
F0C34CB31C16269D00C36F09 /* RoomIncomingTextMsgWithPaginationTitleBubbleCell.m in Sources */,
|
||||
F0D2D9851C197DCB007B8C96 /* RoomIncomingAttachmentWithoutSenderInfoBubbleCell.m in Sources */,
|
||||
71046D5E1C0C639300DCA984 /* RoomTitleView.m in Sources */,
|
||||
F07ECA4D1D2BB0A60060C09F /* TableViewCellWithCheckBoxes.m in Sources */,
|
||||
F02BB04B1CBE2EE70022A025 /* PreviewRoomTitleView.m in Sources */,
|
||||
F0C34B631C15C28300C36F09 /* RoomOutgoingAttachmentWithoutSenderInfoBubbleCell.m in Sources */,
|
||||
F09EE0061C5134BE0078712F /* RoomOutgoingTextMsgWithoutSenderNameBubbleCell.m in Sources */,
|
||||
|
|
|
@ -17,8 +17,9 @@
|
|||
#import <MatrixKit/MatrixKit.h>
|
||||
|
||||
#import "MediaPickerViewController.h"
|
||||
#import "TableViewCellWithCheckBoxes.h"
|
||||
|
||||
@interface RoomSettingsViewController : MXKRoomSettingsViewController<UITextViewDelegate, MediaPickerViewControllerDelegate>
|
||||
@interface RoomSettingsViewController : MXKRoomSettingsViewController<UITextViewDelegate, MediaPickerViewControllerDelegate, TableViewCellWithCheckBoxesDelegate>
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#import "RoomSettingsViewController.h"
|
||||
|
||||
#import "TableViewCellWithLabelAndLargeTextView.h"
|
||||
#import "TableViewCellWithSwitches.h"
|
||||
#import "TableViewCellWithTickAndLabel.h"
|
||||
|
||||
#import "SegmentedViewController.h"
|
||||
|
@ -77,8 +76,9 @@ NSString *const kRoomSettingsHistoryVisibilityKey = @"kRoomSettingsHistoryVisibi
|
|||
// The current table items
|
||||
UITextField* nameTextField;
|
||||
UITextView* topicTextView;
|
||||
UISwitch *favouriteTagSwitch;
|
||||
UISwitch *lowPriorityTagSwitch;
|
||||
|
||||
// The room tag items
|
||||
TableViewCellWithCheckBoxes *roomTagCell;
|
||||
|
||||
// Room Access items
|
||||
TableViewCellWithTickAndLabel *accessInvitedOnlyTickCell;
|
||||
|
@ -148,7 +148,7 @@ NSString *const kRoomSettingsHistoryVisibilityKey = @"kRoomSettingsHistoryVisibi
|
|||
[self.tableView registerClass:MXKTableViewCellWithLabelAndMXKImageView.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndMXKImageView defaultReuseIdentifier]];
|
||||
[self.tableView registerClass:TableViewCellWithLabelAndLargeTextView.class forCellReuseIdentifier:[TableViewCellWithLabelAndLargeTextView defaultReuseIdentifier]];
|
||||
[self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndTextField defaultReuseIdentifier]];
|
||||
[self.tableView registerClass:TableViewCellWithSwitches.class forCellReuseIdentifier:[TableViewCellWithSwitches defaultReuseIdentifier]];
|
||||
[self.tableView registerClass:TableViewCellWithCheckBoxes.class forCellReuseIdentifier:[TableViewCellWithCheckBoxes defaultReuseIdentifier]];
|
||||
[self.tableView registerClass:TableViewCellWithTickAndLabel.class forCellReuseIdentifier:[TableViewCellWithTickAndLabel defaultReuseIdentifier]];
|
||||
|
||||
[self setNavBarButtons];
|
||||
|
@ -1076,22 +1076,18 @@ NSString *const kRoomSettingsHistoryVisibilityKey = @"kRoomSettingsHistoryVisibi
|
|||
}
|
||||
else if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_TAG)
|
||||
{
|
||||
TableViewCellWithSwitches *tagCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithSwitches defaultReuseIdentifier] forIndexPath:indexPath];
|
||||
roomTagCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithCheckBoxes defaultReuseIdentifier] forIndexPath:indexPath];
|
||||
|
||||
tagCell.switchesNumber = 2;
|
||||
roomTagCell.checkboxesNumber = 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;
|
||||
roomTagCell.allowsMultipleSelection = NO;
|
||||
roomTagCell.delegate = self;
|
||||
|
||||
NSArray *labels = roomTagCell.labels;
|
||||
UILabel *label;
|
||||
label = tagCell.labels[0];
|
||||
label = labels[0];
|
||||
label.text = NSLocalizedStringFromTable(@"room_details_favourite_tag", @"Vector", nil);
|
||||
label = tagCell.labels[1];
|
||||
label = labels[1];
|
||||
label.text = NSLocalizedStringFromTable(@"room_details_low_priority_tag", @"Vector", nil);
|
||||
|
||||
if ([updatedItemsDict objectForKey:kRoomSettingsTagKey])
|
||||
|
@ -1099,27 +1095,26 @@ NSString *const kRoomSettingsHistoryVisibilityKey = @"kRoomSettingsHistoryVisibi
|
|||
NSString *roomTag = [updatedItemsDict objectForKey:kRoomSettingsTagKey];
|
||||
if ([roomTag isEqualToString:kMXRoomTagFavourite])
|
||||
{
|
||||
favouriteTagSwitch.on = YES;
|
||||
lowPriorityTagSwitch.on = NO;
|
||||
[roomTagCell setCheckBoxValue:YES atIndex:0];
|
||||
}
|
||||
else if ([roomTag isEqualToString:kMXRoomTagLowPriority])
|
||||
{
|
||||
favouriteTagSwitch.on = NO;
|
||||
lowPriorityTagSwitch.on = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
favouriteTagSwitch.on = NO;
|
||||
lowPriorityTagSwitch.on = NO;
|
||||
[roomTagCell setCheckBoxValue:YES atIndex:1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
favouriteTagSwitch.on = (mxRoom.accountData.tags[kMXRoomTagFavourite] != 0);
|
||||
lowPriorityTagSwitch.on = (mxRoom.accountData.tags[kMXRoomTagLowPriority] != 0);
|
||||
if (mxRoom.accountData.tags[kMXRoomTagFavourite] != nil)
|
||||
{
|
||||
[roomTagCell setCheckBoxValue:YES atIndex:0];
|
||||
}
|
||||
else if (mxRoom.accountData.tags[kMXRoomTagLowPriority] != nil)
|
||||
{
|
||||
[roomTagCell setCheckBoxValue:YES atIndex:1];
|
||||
}
|
||||
}
|
||||
|
||||
cell = tagCell;
|
||||
cell = roomTagCell;
|
||||
}
|
||||
}
|
||||
else if (indexPath.section == ROOM_SETTINGS_ROOM_ACCESS_SECTION_INDEX)
|
||||
|
@ -1669,97 +1664,7 @@ NSString *const kRoomSettingsHistoryVisibilityKey = @"kRoomSettingsHistoryVisibi
|
|||
|
||||
- (void)onSwitchUpdate:(UISwitch*)theSwitch
|
||||
{
|
||||
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 (theSwitch == roomNotifSwitch)
|
||||
{
|
||||
if (roomNotifSwitch.on == mxRoom.isMute)
|
||||
{
|
||||
|
@ -1796,6 +1701,67 @@ NSString *const kRoomSettingsHistoryVisibilityKey = @"kRoomSettingsHistoryVisibi
|
|||
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
||||
}
|
||||
|
||||
#pragma mark - TableViewCellWithCheckBoxesDelegate
|
||||
|
||||
- (void)tableViewCellWithCheckBoxes:(TableViewCellWithCheckBoxes *)tableViewCellWithCheckBoxes didTapOnCheckBoxAtIndex:(NSUInteger)index
|
||||
{
|
||||
if (tableViewCellWithCheckBoxes == roomTagCell)
|
||||
{
|
||||
NSString *tappedRoomTag = (index == 0) ? kMXRoomTagFavourite : kMXRoomTagLowPriority;
|
||||
BOOL isCurrentlySelected = [roomTagCell checkBoxValueAtIndex:index];
|
||||
|
||||
if (isCurrentlySelected)
|
||||
{
|
||||
// The user wants to unselect this tag
|
||||
// Retrieve the current change on room tag (if any)
|
||||
NSString *updatedRoomTag = [updatedItemsDict objectForKey:kRoomSettingsTagKey];
|
||||
|
||||
// Check the actual tag on mxRoom
|
||||
if (mxRoom.accountData.tags[tappedRoomTag])
|
||||
{
|
||||
// The actual tag must be updated, check whether another tag is already set
|
||||
if (!updatedRoomTag)
|
||||
{
|
||||
[updatedItemsDict setObject:@"" forKey:kRoomSettingsTagKey];
|
||||
}
|
||||
}
|
||||
else if (updatedRoomTag && [updatedRoomTag isEqualToString:tappedRoomTag])
|
||||
{
|
||||
// Cancel the updated tag, but take into account the cancellation of another tag when 'tappedRoomTag' was selected.
|
||||
if (mxRoom.accountData.tags.count)
|
||||
{
|
||||
[updatedItemsDict setObject:@"" forKey:kRoomSettingsTagKey];
|
||||
}
|
||||
else
|
||||
{
|
||||
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
|
||||
}
|
||||
}
|
||||
|
||||
// Unselect the tag
|
||||
[roomTagCell setCheckBoxValue:NO atIndex:index];
|
||||
}
|
||||
else
|
||||
{
|
||||
// The user wants to select this room tag
|
||||
// Check the actual tag on mxRoom
|
||||
if (mxRoom.accountData.tags[tappedRoomTag])
|
||||
{
|
||||
[updatedItemsDict removeObjectForKey:kRoomSettingsTagKey];
|
||||
}
|
||||
else
|
||||
{
|
||||
[updatedItemsDict setObject:tappedRoomTag forKey:kRoomSettingsTagKey];
|
||||
}
|
||||
|
||||
// Select the tapped tag
|
||||
[roomTagCell setCheckBoxValue:YES atIndex:index];
|
||||
}
|
||||
|
||||
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
|
91
Vector/Views/TableViewCell/TableViewCellWithCheckBoxes.h
Normal file
91
Vector/Views/TableViewCell/TableViewCellWithCheckBoxes.h
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
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"
|
||||
|
||||
@class TableViewCellWithCheckBoxes;
|
||||
|
||||
/**
|
||||
`TableViewCellWithCheckBoxes` delegate.
|
||||
*/
|
||||
@protocol TableViewCellWithCheckBoxesDelegate <NSObject>
|
||||
|
||||
/**
|
||||
Tells the delegate that the user taps on a check box.
|
||||
|
||||
@param tableViewCellWithCheckBoxes the `TableViewCellWithCheckBoxes` instance.
|
||||
@param index the index of the concerned check box.
|
||||
*/
|
||||
- (void)tableViewCellWithCheckBoxes:(TableViewCellWithCheckBoxes *)tableViewCellWithCheckBoxes didTapOnCheckBoxAtIndex:(NSUInteger)index;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
'TableViewCellWithCheckBoxes' inherits 'MXKTableViewCell' class.
|
||||
It displays several options in a UITableViewCell. Each option has its own check box and its label.
|
||||
All option have the same width and they are horizontally aligned inside the main container.
|
||||
They are vertically centered.
|
||||
*/
|
||||
@interface TableViewCellWithCheckBoxes : MXKTableViewCell
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UIView *mainContainer;
|
||||
|
||||
/**
|
||||
The number of boxes
|
||||
*/
|
||||
@property (nonatomic) NSUInteger checkboxesNumber;
|
||||
|
||||
/**
|
||||
The current array of checkboxes
|
||||
*/
|
||||
@property (nonatomic, readonly) NSArray<UIImageView*> *checkboxes;
|
||||
|
||||
/**
|
||||
The current array of labels
|
||||
*/
|
||||
@property (nonatomic, readonly) NSArray<UILabel*> *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;
|
||||
|
||||
/**
|
||||
The delegate for the cell.
|
||||
*/
|
||||
@property (nonatomic, weak) id<TableViewCellWithCheckBoxesDelegate> delegate;
|
||||
|
||||
/**
|
||||
Default is NO. Controls whether multiple check boxes can be selected simultaneously
|
||||
*/
|
||||
@property (nonatomic) BOOL allowsMultipleSelection;
|
||||
|
||||
/**
|
||||
Select or unselect a check box.
|
||||
If multiple selection is not allowed, this method unselect the current selected box in case of a new selection.
|
||||
|
||||
@param isSelected the new value of the check box.
|
||||
@param index the index of the check box.
|
||||
*/
|
||||
- (void)setCheckBoxValue:(BOOL)isSelected atIndex:(NSUInteger)index;
|
||||
|
||||
/**
|
||||
Get the current state of a check box
|
||||
*/
|
||||
- (BOOL)checkBoxValueAtIndex:(NSUInteger)index;
|
||||
|
||||
@end
|
|
@ -14,23 +14,23 @@
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import "TableViewCellWithSwitches.h"
|
||||
#import "TableViewCellWithCheckBoxes.h"
|
||||
|
||||
// The space between 2 switches
|
||||
#define TABLEVIEWCELLWITHSWITCHES_MARGIN 8
|
||||
// The space between 2 check boxes
|
||||
#define TABLEVIEWCELLWITHCHECKBOXES_MARGIN 8
|
||||
|
||||
@interface TableViewCellWithSwitches ()
|
||||
@interface TableViewCellWithCheckBoxes ()
|
||||
{
|
||||
NSMutableArray *switchArray;
|
||||
NSMutableArray *checkboxesArray;
|
||||
NSMutableArray *labelArray;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation TableViewCellWithSwitches
|
||||
@implementation TableViewCellWithCheckBoxes
|
||||
|
||||
- (void)setSwitchesNumber:(NSUInteger)switchesNumber
|
||||
- (void)setCheckboxesNumber:(NSUInteger)checkboxesNumber
|
||||
{
|
||||
if (_switchesNumber == switchesNumber)
|
||||
if (_checkboxesNumber == checkboxesNumber)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -42,58 +42,58 @@
|
|||
[view removeFromSuperview];
|
||||
}
|
||||
|
||||
_switchesNumber = switchesNumber;
|
||||
_checkboxesNumber = checkboxesNumber;
|
||||
|
||||
if (!switchesNumber)
|
||||
if (!_checkboxesNumber)
|
||||
{
|
||||
// Nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
switchArray = [NSMutableArray arrayWithCapacity:switchesNumber];
|
||||
labelArray = [NSMutableArray arrayWithCapacity:switchesNumber];
|
||||
checkboxesArray = [NSMutableArray arrayWithCapacity:checkboxesNumber];
|
||||
labelArray = [NSMutableArray arrayWithCapacity:checkboxesNumber];
|
||||
|
||||
CGFloat containerWidth = (self.mainContainer.frame.size.width - ((switchesNumber - 1.0) * TABLEVIEWCELLWITHSWITCHES_MARGIN)) / switchesNumber;
|
||||
CGFloat containerWidth = (self.mainContainer.frame.size.width - ((checkboxesNumber - 1.0) * TABLEVIEWCELLWITHCHECKBOXES_MARGIN)) / checkboxesNumber;
|
||||
|
||||
UIView *previousContainer = nil;
|
||||
NSLayoutConstraint *topConstraint, *leftConstraint, *bottomConstraint;
|
||||
NSLayoutConstraint *widthConstraint, *centerYConstraint;
|
||||
NSLayoutConstraint *widthConstraint, *heightConstraint, *centerYConstraint, *centerXConstraint;
|
||||
|
||||
for (NSInteger index = 0; index < switchesNumber; index++)
|
||||
for (NSInteger index = 0; index < checkboxesNumber; 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];
|
||||
UIView *checkboxContainer = [[UIView alloc] initWithFrame:CGRectMake(index * (containerWidth + TABLEVIEWCELLWITHCHECKBOXES_MARGIN), 0, containerWidth, self.mainContainer.frame.size.height)];
|
||||
checkboxContainer.backgroundColor = [UIColor clearColor];
|
||||
[self.mainContainer addSubview:checkboxContainer];
|
||||
|
||||
// Add container constraints
|
||||
switchContainer.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
checkboxContainer.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
if (!previousContainer)
|
||||
{
|
||||
leftConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
|
||||
leftConstraint = [NSLayoutConstraint constraintWithItem:checkboxContainer
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.mainContainer
|
||||
attribute:NSLayoutAttributeLeading
|
||||
multiplier:1
|
||||
constant:0];
|
||||
widthConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
|
||||
widthConstraint = [NSLayoutConstraint constraintWithItem:checkboxContainer
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.mainContainer
|
||||
attribute:NSLayoutAttributeWidth
|
||||
multiplier:(1.0 / switchesNumber)
|
||||
constant:(- ((switchesNumber - 1.0) * TABLEVIEWCELLWITHSWITCHES_MARGIN) / switchesNumber)];
|
||||
multiplier:(1.0 / checkboxesNumber)
|
||||
constant:(- ((checkboxesNumber - 1.0) * TABLEVIEWCELLWITHCHECKBOXES_MARGIN) / checkboxesNumber)];
|
||||
}
|
||||
else
|
||||
{
|
||||
leftConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
|
||||
leftConstraint = [NSLayoutConstraint constraintWithItem:checkboxContainer
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:previousContainer
|
||||
attribute:NSLayoutAttributeTrailing
|
||||
multiplier:1
|
||||
constant:TABLEVIEWCELLWITHSWITCHES_MARGIN];
|
||||
widthConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
|
||||
constant:TABLEVIEWCELLWITHCHECKBOXES_MARGIN];
|
||||
widthConstraint = [NSLayoutConstraint constraintWithItem:checkboxContainer
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:previousContainer
|
||||
|
@ -102,7 +102,7 @@
|
|||
constant:0];
|
||||
}
|
||||
|
||||
topConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
|
||||
topConstraint = [NSLayoutConstraint constraintWithItem:checkboxContainer
|
||||
attribute:NSLayoutAttributeTop
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.mainContainer
|
||||
|
@ -110,7 +110,7 @@
|
|||
multiplier:1
|
||||
constant:0];
|
||||
|
||||
bottomConstraint = [NSLayoutConstraint constraintWithItem:switchContainer
|
||||
bottomConstraint = [NSLayoutConstraint constraintWithItem:checkboxContainer
|
||||
attribute:NSLayoutAttributeBottom
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.mainContainer
|
||||
|
@ -120,40 +120,56 @@
|
|||
|
||||
[NSLayoutConstraint activateConstraints:@[leftConstraint, widthConstraint, topConstraint, bottomConstraint]];
|
||||
|
||||
previousContainer = switchContainer;
|
||||
previousContainer = checkboxContainer;
|
||||
|
||||
// Add Switch and Label
|
||||
UISwitch *theSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 51, 31)];
|
||||
theSwitch.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[switchContainer addSubview:theSwitch];
|
||||
[switchArray addObject:theSwitch];
|
||||
// Add Checkbox and Label
|
||||
UIImageView *checkbox = [[UIImageView alloc] initWithFrame:CGRectMake(14, 11, 22, 22)];
|
||||
checkbox.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[checkboxContainer addSubview:checkbox];
|
||||
|
||||
// Store the new check box unselected by default
|
||||
checkbox.image = [UIImage imageNamed:@"selection_untick"];
|
||||
checkbox.tag = 0;
|
||||
[checkboxesArray addObject:checkbox];
|
||||
|
||||
UILabel *theLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, containerWidth - 60, 31)];
|
||||
theLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[switchContainer addSubview:theLabel];
|
||||
[checkboxContainer addSubview:theLabel];
|
||||
[labelArray addObject:theLabel];
|
||||
|
||||
UIView *checkboxMask = [[UIView alloc] initWithFrame:CGRectMake(7, 4, 36, 36)];
|
||||
checkboxMask.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[checkboxContainer addSubview:checkboxMask];
|
||||
// Listen to check box tap
|
||||
checkboxMask.tag = index;
|
||||
checkboxMask.userInteractionEnabled = YES;
|
||||
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onCheckBoxTap:)];
|
||||
[tapGesture setNumberOfTouchesRequired:1];
|
||||
[tapGesture setNumberOfTapsRequired:1];
|
||||
[tapGesture setDelegate:self];
|
||||
[checkboxMask addGestureRecognizer:tapGesture];
|
||||
|
||||
// Add switch constraints
|
||||
leftConstraint = [NSLayoutConstraint constraintWithItem:theSwitch
|
||||
leftConstraint = [NSLayoutConstraint constraintWithItem:checkbox
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:switchContainer
|
||||
toItem:checkboxContainer
|
||||
attribute:NSLayoutAttributeLeading
|
||||
multiplier:1
|
||||
constant:0];
|
||||
constant:14];
|
||||
|
||||
widthConstraint = [NSLayoutConstraint constraintWithItem:theSwitch
|
||||
widthConstraint = [NSLayoutConstraint constraintWithItem:checkbox
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:nil
|
||||
attribute:NSLayoutAttributeNotAnAttribute
|
||||
multiplier:1
|
||||
constant:51];
|
||||
constant:22];
|
||||
|
||||
centerYConstraint = [NSLayoutConstraint constraintWithItem:theSwitch
|
||||
centerYConstraint = [NSLayoutConstraint constraintWithItem:checkbox
|
||||
attribute:NSLayoutAttributeCenterY
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:switchContainer
|
||||
toItem:checkboxContainer
|
||||
attribute:NSLayoutAttributeCenterY
|
||||
multiplier:1
|
||||
constant:0.0f];
|
||||
|
@ -165,7 +181,7 @@
|
|||
topConstraint = [NSLayoutConstraint constraintWithItem:theLabel
|
||||
attribute:NSLayoutAttributeTop
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:switchContainer
|
||||
toItem:checkboxContainer
|
||||
attribute:NSLayoutAttributeTop
|
||||
multiplier:1
|
||||
constant:0];
|
||||
|
@ -173,7 +189,7 @@
|
|||
leftConstraint = [NSLayoutConstraint constraintWithItem:theLabel
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:theSwitch
|
||||
toItem:checkbox
|
||||
attribute:NSLayoutAttributeTrailing
|
||||
multiplier:1
|
||||
constant:9];
|
||||
|
@ -181,18 +197,53 @@
|
|||
centerYConstraint = [NSLayoutConstraint constraintWithItem:theLabel
|
||||
attribute:NSLayoutAttributeCenterY
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:switchContainer
|
||||
toItem:checkboxContainer
|
||||
attribute:NSLayoutAttributeCenterY
|
||||
multiplier:1
|
||||
constant:0.0f];
|
||||
|
||||
[NSLayoutConstraint activateConstraints:@[topConstraint, leftConstraint, centerYConstraint]];
|
||||
|
||||
// Add check box mask constraints
|
||||
widthConstraint = [NSLayoutConstraint constraintWithItem:checkboxMask
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:nil
|
||||
attribute:NSLayoutAttributeNotAnAttribute
|
||||
multiplier:1
|
||||
constant:36];
|
||||
|
||||
heightConstraint = [NSLayoutConstraint constraintWithItem:checkboxMask
|
||||
attribute:NSLayoutAttributeHeight
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:nil
|
||||
attribute:NSLayoutAttributeNotAnAttribute
|
||||
multiplier:1
|
||||
constant:36];
|
||||
|
||||
centerXConstraint = [NSLayoutConstraint constraintWithItem:checkboxMask
|
||||
attribute:NSLayoutAttributeCenterX
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:checkbox
|
||||
attribute:NSLayoutAttributeCenterX
|
||||
multiplier:1
|
||||
constant:0.0f];
|
||||
|
||||
centerYConstraint = [NSLayoutConstraint constraintWithItem:checkboxMask
|
||||
attribute:NSLayoutAttributeCenterY
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:checkbox
|
||||
attribute:NSLayoutAttributeCenterY
|
||||
multiplier:1
|
||||
constant:0.0f];
|
||||
|
||||
[NSLayoutConstraint activateConstraints:@[widthConstraint, heightConstraint, centerXConstraint, centerYConstraint]];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray*)switches
|
||||
- (NSArray*)checkboxes
|
||||
{
|
||||
return [NSArray arrayWithArray:switchArray];
|
||||
return [NSArray arrayWithArray:checkboxesArray];
|
||||
}
|
||||
|
||||
- (NSArray*)labels
|
||||
|
@ -200,5 +251,62 @@
|
|||
return [NSArray arrayWithArray:labelArray];
|
||||
}
|
||||
|
||||
- (void)setCheckBoxValue:(BOOL)isSelected atIndex:(NSUInteger)index
|
||||
{
|
||||
if (index < checkboxesArray.count)
|
||||
{
|
||||
UIImageView *checkBox = checkboxesArray[index];
|
||||
|
||||
if (isSelected && !checkBox.tag)
|
||||
{
|
||||
checkBox.image = [UIImage imageNamed:@"selection_tick"];
|
||||
checkBox.tag = 1;
|
||||
|
||||
if (!self.allowsMultipleSelection)
|
||||
{
|
||||
// Unselect others check boxes
|
||||
for (NSUInteger k = 0; k < checkboxesArray.count; k++)
|
||||
{
|
||||
if (k != index)
|
||||
{
|
||||
checkBox = checkboxesArray[k];
|
||||
if (checkBox.tag)
|
||||
{
|
||||
checkBox.image = [UIImage imageNamed:@"selection_untick"];
|
||||
checkBox.tag = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (checkBox.tag)
|
||||
{
|
||||
checkBox.image = [UIImage imageNamed:@"selection_untick"];
|
||||
checkBox.tag = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)checkBoxValueAtIndex:(NSUInteger)index
|
||||
{
|
||||
if (index < checkboxesArray.count)
|
||||
{
|
||||
UIImageView *checkBox = checkboxesArray[index];
|
||||
|
||||
return ((BOOL)checkBox.tag);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark - Action
|
||||
|
||||
- (IBAction)onCheckBoxTap:(UITapGestureRecognizer*)sender
|
||||
{
|
||||
if (_delegate)
|
||||
{
|
||||
[_delegate tableViewCellWithCheckBoxes:self didTapOnCheckBoxAtIndex:sender.view.tag];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
<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">
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="20U-7H-xmi" customClass="TableViewCellWithCheckBoxes">
|
||||
<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">
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
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
|
Loading…
Reference in a new issue