Feature/1801 ruhezeit einstellungsmenu

This commit is contained in:
Arnfried Griesert
2022-06-02 03:41:21 +00:00
parent 810124110b
commit c20966c2ab
26 changed files with 770 additions and 566 deletions
@@ -114,7 +114,6 @@ NSString *const kRoomSettingsNameKey = @"kRoomSettingsNameKey";
NSString *const kRoomSettingsTopicKey = @"kRoomSettingsTopicKey";
NSString *const kRoomSettingsTagKey = @"kRoomSettingsTagKey";
NSString *const kRoomSettingsMuteNotifKey = @"kRoomSettingsMuteNotifKey";
NSString *const kRoomSettingsWorkTimeNotifKey = @"kRoomSettingsWorkTimeNotifKey";
NSString *const kRoomSettingsDirectChatKey = @"kRoomSettingsDirectChatKey";
NSString *const kRoomSettingsJoinRuleKey = @"kRoomSettingsJoinRuleKey";
NSString *const kRoomSettingsGuestAccessKey = @"kRoomSettingsGuestAccessKey";
@@ -127,6 +126,7 @@ NSString *const kRoomSettingsNewRelatedGroupKey = @"kRoomSettingsNewRelatedGroup
NSString *const kRoomSettingsRemovedRelatedGroupKey = @"kRoomSettingsRemovedRelatedGroupKey";
NSString *const kRoomSettingsEncryptionKey = @"kRoomSettingsEncryptionKey";
NSString *const kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey = @"kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey";
NSString *const kRoomSettingsNotificationTimesKey = @"kRoomSettingsNotificationTimesKey";
NSString *const kRoomSettingsNameCellViewIdentifier = @"kRoomSettingsNameCellViewIdentifier";
NSString *const kRoomSettingsTopicCellViewIdentifier = @"kRoomSettingsTopicCellViewIdentifier";
@@ -490,6 +490,14 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
- (void)updateSections
{
if (@available(iOS 14.0, *)) {
MXSession *session = [AppDelegate theDelegate].mxSessions.firstObject;
if(session) {
RiotSharedSettings *sharedSettings = [[RiotSharedSettings alloc] initWithSession:session];
[sharedSettings fetchNotificationTimes];
}
}
if(mxRoom.isPersonalNotesRoom) {
[self updateSectionsAsPersonalNotes];
return;
@@ -546,7 +554,7 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
{
[sectionMain addRowWithTag:ROOM_SETTINGS_MAIN_SECTION_ROW_DIRECT_CHAT];
}
if (BuildSettings.featureWorkTime)
if (BwiBuildSettings.bwiNotificationTimes)
{
[sectionMain addRowWithTag:ROOM_SETTINGS_MAIN_SECTION_ROW_REST_TIME];
[sectionMain addRowWithTag:ROOM_SETTINGS_MAIN_SECTION_ROW_REST_TIME_INFO];
@@ -2210,6 +2218,26 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
BOOL blacklistUnverifiedDevices = [((NSNumber*)updatedItemsDict[kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey]) boolValue];
[mxRoom.mxSession.crypto setBlacklistUnverifiedDevicesInRoom:mxRoom.roomId blacklist:blacklistUnverifiedDevices];
}
// Notification times toggle
if (updatedItemsDict[kRoomSettingsNotificationTimesKey])
{
if (@available(iOS 14.0, *)) {
bool isON = [[updatedItemsDict[kRoomSettingsNotificationTimesKey] stringValue] isEqualToString:@"ON"];
if(isON) {
[[NotificationTimes shared] enableForRoomWithRoomID:self.roomId];
} else {
[[NotificationTimes shared] disableForRoomWithRoomID:self.roomId];
}
RiotSharedSettings *sharedSetting = [[RiotSharedSettings alloc] initWithSession:self.mainSession];
(void)[sharedSetting storeNotificationTimesWithSuccess:^{} failure:^(NSError *error) {
MXLogWarning(@"[RoomSettingsViewController] Cannot store value for notification times toggle.")
}];
}
[updatedItemsDict removeObjectForKey:kRoomSettingsNotificationTimesKey];
}
}
[self getNavigationItem].rightBarButtonItem.enabled = NO;
@@ -2309,10 +2337,10 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
cell = roomNotifCell;
}
else if( row == ROOM_SETTINGS_MAIN_SECTION_ROW_REST_TIME) {
cell = [self cellForWorkTimeSwitch:tableView indexPath:indexPath];
cell = [self cellForNotificationTimesSwitch:tableView indexPath:indexPath];
}
else if( row == ROOM_SETTINGS_MAIN_SECTION_ROW_REST_TIME_INFO) {
cell = [self cellForWorkTimeInfo:tableView indexPath:indexPath];
cell = [self cellForNotificationTimesInfo:tableView indexPath:indexPath];
}
else if (row == ROOM_SETTINGS_MAIN_SECTION_ROW_DIRECT_CHAT)
{
@@ -4308,35 +4336,34 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
return roomAccessToggleCell;
}
- (UITableViewCell*) cellForWorkTimeSwitch:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath {
MXKTableViewCellWithLabelAndSwitch *workTimeToggleCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
- (UITableViewCell*) cellForNotificationTimesSwitch:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath {
MXKTableViewCellWithLabelAndSwitch *toggleCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
[workTimeToggleCell.mxkSwitch addTarget:self action:@selector(toggleWorkTime:) forControlEvents:UIControlEventValueChanged];
[toggleCell.mxkSwitch addTarget:self action:@selector(toggleNotificationTimes:) forControlEvents:UIControlEventValueChanged];
workTimeToggleCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_main_section_rest_time", @"Vector", nil);
workTimeToggleCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor;
workTimeToggleCell.mxkSwitch.on = [self isWorkTimeSwitchOn];
workTimeToggleCell.mxkSwitch.enabled = [self isWorkTimeSwitchEnabled];
toggleCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_enable_notification_times", @"Vector", nil);
toggleCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor;
toggleCell.mxkSwitch.on = [self isNotificationTimesSwitchOn];
toggleCell.mxkSwitch.enabled = [self isNotificationTimesSwitchEnabled];
return workTimeToggleCell;
return toggleCell;
}
- (UITableViewCell*) cellForWorkTimeInfo:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath {
MXKTableViewCell *workTimeInfoCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCell defaultReuseIdentifier] forIndexPath:indexPath];
if (!workTimeInfoCell)
- (UITableViewCell*) cellForNotificationTimesInfo:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath {
MXKTableViewCell *notificationTimesInfoCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCell defaultReuseIdentifier] forIndexPath:indexPath];
if (!notificationTimesInfoCell)
{
workTimeInfoCell = [[MXKTableViewCell alloc] init];
notificationTimesInfoCell = [[MXKTableViewCell alloc] init];
}
workTimeInfoCell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
workTimeInfoCell.textLabel.font = [UIFont systemFontOfSize:15.0];
workTimeInfoCell.selectionStyle = UITableViewCellSelectionStyleNone;
workTimeInfoCell.userInteractionEnabled = NO;
workTimeInfoCell.textLabel.text = [self textForWorkTimeInfoCell];
workTimeInfoCell.textLabel.adjustsFontSizeToFitWidth = YES;
return workTimeInfoCell;
notificationTimesInfoCell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
notificationTimesInfoCell.textLabel.font = [UIFont systemFontOfSize:15.0];
notificationTimesInfoCell.selectionStyle = UITableViewCellSelectionStyleNone;
notificationTimesInfoCell.userInteractionEnabled = NO;
notificationTimesInfoCell.textLabel.text = NSLocalizedStringFromTable(@"bwi_notification_times_toggle_description", @"Bwi", @"");
notificationTimesInfoCell.textLabel.numberOfLines = 0;
return notificationTimesInfoCell;
}
- (void)toggleDirectoryAccessBW:(UISwitch*)theSwitch
@@ -4366,63 +4393,29 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
}
- (void)toggleWorkTime:(UISwitch*)theSwitch {
NSLog(@"Toggle Worktime");
- (void)toggleNotificationTimes:(UISwitch*)theSwitch {
NSLog(@"Toggle Notification Times");
WorkTimeService *service = [WorkTimeService workTimeService:self.mainSession.myUser.userId];
updatedItemsDict[kRoomSettingsWorkTimeNotifKey] = @(theSwitch.on);
if (theSwitch.on) {
[service activateWorkTimeInRoom:self.roomId];
} else {
[service deactivateWorkTimeInRoom:self.roomId];
if (@available(iOS 14.0, *)) {
updatedItemsDict[kRoomSettingsNotificationTimesKey] = theSwitch.on ? @"ON" : @"OFF";
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
}
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
}
- (NSString*) textForWorkTimeInfoCell {
WorkTimeService *service = [WorkTimeService workTimeService:self.mainSession.myUser.userId];
NSString *text = @"";
if (service.isWorkTimeGlobalyEnabled) {
if ([service.store isWorkTimeRoom:self.roomId] ) {
if ([service.store isWorkTimeInRoomActive:self.roomId]) {
text = [NSString stringWithFormat:@"%@ %@", NSLocalizedStringFromTable(@"room_details_main_section_rest_time_locally_enabled", @"Vector", nil), [service localizedWorkTime]];
} else {
text = NSLocalizedStringFromTable(@"room_details_main_section_rest_time_locally_disabled", @"Vector", nil);
}
} else {
text = [NSString stringWithFormat:@"%@ %@", NSLocalizedStringFromTable(@"room_details_main_section_rest_time_global", @"Vector", nil), [service localizedWorkTime]];
}
- (BOOL) isNotificationTimesSwitchOn {
if (@available(iOS 14.0, *)) {
RiotSharedSettings *sharedSetting = [[RiotSharedSettings alloc] initWithSession:self.mainSession];
[sharedSetting fetchNotificationTimes];
return [[NotificationTimes shared] isEnabledForRoomWithRoomID:self.roomId isDirect:mxRoom.isDirect];
} else {
text = NSLocalizedStringFromTable(@"room_details_main_section_rest_time_global_disabled", @"Vector", nil);
return false;
}
return text;
}
- (BOOL) isWorkTimeSwitchOn {
WorkTimeService *service = [WorkTimeService workTimeService:self.mainSession.myUser.userId];
BOOL isOn = NO;
if (service.isWorkTimeGlobalyEnabled) {
if ([service.store isWorkTimeRoom:self.roomId] ) {
if ([service.store isWorkTimeInRoomActive:self.roomId]) {
isOn = YES;
}
} else {
isOn = !self->mxRoom.isDirect;
}
}
return isOn;
}
- (BOOL) isWorkTimeSwitchEnabled {
WorkTimeService *service = [WorkTimeService workTimeService:self.mainSession.myUser.userId];
return service.isWorkTimeGlobalyEnabled;
- (BOOL) isNotificationTimesSwitchEnabled {
return !mxRoom.isDirect;
}
- (void) updateSectionsAsPersonalNotes {