MESSENGER-5410 add toggle to room settings and refactor toggle view

This commit is contained in:
JanNiklas Grabowski
2023-12-22 17:16:35 +01:00
parent 2a875e3846
commit 866e27c1fd
3 changed files with 109 additions and 35 deletions
@@ -75,6 +75,11 @@ enum
ROOM_SETTINGS_ROOM_PROMOTE_SECTION_ROW_SUGGEST
};
enum
{
ROOM_SETTINGS_ROOM_FEDERATION
};
enum
{
ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_ANYONE,
@@ -127,6 +132,7 @@ NSString *const kRoomSettingsAddressCellViewIdentifier = @"kRoomSettingsAddressC
NSString *const kRoomSettingsAdvancedCellViewIdentifier = @"kRoomSettingsAdvancedCellViewIdentifier";
NSString *const kRoomSettingsAdvancedEnableE2eCellViewIdentifier = @"kRoomSettingsAdvancedEnableE2eCellViewIdentifier";
NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSettingsAdvancedE2eEnabledCellViewIdentifier";
NSString *const kRoomSettingsFederationCellViewIdentifier = @"kRoomSettingsFederationCellViewIdentifier";
@interface RoomSettingsViewController () <SingleImagePickerPresenterDelegate, TableViewSectionsDelegate, RoomAccessCoordinatorBridgePresenterDelegate, RoomSuggestionCoordinatorBridgePresenterDelegate>
{
@@ -261,6 +267,7 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
[self.tableView registerClass:TableViewCellWithCheckBoxAndLabel.class forCellReuseIdentifier:[TableViewCellWithCheckBoxAndLabel defaultReuseIdentifier]];
[self.tableView registerClass:MXKTableViewCell.class forCellReuseIdentifier:[MXKTableViewCell defaultReuseIdentifier]];
[self.tableView registerClass:TitleAndRightDetailTableViewCell.class forCellReuseIdentifier:[TitleAndRightDetailTableViewCell defaultReuseIdentifier]];
[self.tableView registerClass:TableViewCellWithLabelSubLabelAndSwitch.class forCellReuseIdentifier:kRoomSettingsFederationCellViewIdentifier];
// Enable self sizing cells
self.tableView.rowHeight = UITableViewAutomaticDimension;
@@ -591,6 +598,10 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
if ( BWIBuildSettings.shared.roomSettingsScreenShowAccessSettingsBW && !mxRoom.isDirect ){
[tmpSections addObject:[self sectionForAccessSwitch]];
}
if ( BWIBuildSettings.shared.isFederationEnabled && !mxRoom.isDirect){
[tmpSections addObject:[self sectionForFederationSwitch]];
}
if (RiotSettings.shared.roomSettingsScreenAllowChangingHistorySettings)
{
@@ -2487,6 +2498,10 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
{
cell = [self cellForAccessSwitch:tableView indexPath:indexPath];
}
else if (row == ROOM_SETTINGS_ROOM_FEDERATION)
{
cell = [self cellForFederationSwitch:tableView indexPath:indexPath];
}
else if (row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ACCESS)
{
TitleAndRightDetailTableViewCell *roomAccessCell = [tableView dequeueReusableCellWithIdentifier:[TitleAndRightDetailTableViewCell defaultReuseIdentifier] forIndexPath:indexPath];
@@ -2933,6 +2948,26 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
return cell;
}
- (TableViewCellWithLabelSubLabelAndSwitch*)getLabelSubLabelAndSwitchCell:(UITableView*)tableView forIndexPath:(NSIndexPath *)indexPath
{
TableViewCellWithLabelSubLabelAndSwitch *cell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsFederationCellViewIdentifier forIndexPath:indexPath];
[cell makeViewControllerWithParent:self toggleText:BWIL10n.createRoomTypeFederated subText:BWIL10n.createRoomTypeFederatedSubtext initalToggleValue:false onValueChanged:^(BOOL newValue) {
/* TODO:
- Trigger Alert
- Change Value
- Reset Toggle
- Update ACLs
- Check Permission
*/
}];
// Force layout before reusing a cell (fix switch displayed outside the screen)
[cell layoutIfNeeded];
return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
@@ -3750,6 +3785,12 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
return sectionAccess;
}
- (Section*) sectionForFederationSwitch {
Section *sectionAccess = [Section sectionWithTag:SECTION_TAG_ACCESS];
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_FEDERATION];
return sectionAccess;
}
- (UITableViewCell*) cellForAccessSwitch:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath {
MXKTableViewCellWithLabelAndSwitch *roomAccessToggleCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
@@ -3779,6 +3820,19 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
return roomAccessToggleCell;
}
- (UITableViewCell*) cellForFederationSwitch:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath {
TableViewCellWithLabelSubLabelAndSwitch *roomAccessToggleCell = [self getLabelSubLabelAndSwitchCell:tableView forIndexPath:indexPath];
MXRoomPowerLevels *powerLevels = [mxRoomState powerLevels];
if ([powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId] != RoomPowerLevelAdmin) {
}
return roomAccessToggleCell;
}
- (UITableViewCell*) cellForNotificationTimesSwitch:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath {
MXKTableViewCellWithLabelAndSwitch *toggleCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];