mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-01 05:36:57 +02:00
Merge remote-tracking branch 'origin/develop' into public_rooms_search
Conflicts: Vector/Base.lproj/Main.storyboard Vector/Model/RoomList/RecentsDataSource.m
This commit is contained in:
@@ -16,19 +16,32 @@
|
||||
|
||||
#import "RoomSettingsViewController.h"
|
||||
|
||||
#import <Photos/Photos.h>
|
||||
#import <MediaPlayer/MediaPlayer.h>
|
||||
|
||||
#import "TableViewCellWithLabelAndTextField.h"
|
||||
#import "TableViewCellWithLabelAndLargeTextView.h"
|
||||
#import "TableViewCellWithLabelAndMXKImageView.h"
|
||||
#import "TableViewCellWithLabelAndSwitch.h"
|
||||
|
||||
#import "TableViewCellSeparator.h"
|
||||
|
||||
#import "RageShakeManager.h"
|
||||
|
||||
#import "VectorDesignValues.h"
|
||||
|
||||
#import "AvatarGenerator.h"
|
||||
|
||||
#import "MXRoom+Vector.h"
|
||||
|
||||
#define ROOM_SECTION 0
|
||||
|
||||
#define ROOM_SECTION_NAME 0
|
||||
#define ROOM_SECTION_TOPIC 1
|
||||
#define ROOM_SECTION_COUNT 2
|
||||
#define ROOM_SECTION_PHOTO 0
|
||||
#define ROOM_SECTION_NAME 1
|
||||
#define ROOM_SECTION_TOPIC 2
|
||||
#define ROOM_SECTION_PRIV_PUB 3
|
||||
#define ROOM_SECTION_MUTE_NOTIFICATIONS 4
|
||||
#define ROOM_SECTION_COUNT 5
|
||||
|
||||
#define ROOM_TOPIC_CELL_HEIGHT 99
|
||||
|
||||
@@ -48,6 +61,15 @@
|
||||
UIActivityIndicatorView* updatingSpinner;
|
||||
|
||||
MXKAlert *currentAlert;
|
||||
|
||||
// listen to more events than the mother class
|
||||
id extraEventsListener;
|
||||
|
||||
// picker
|
||||
MediaPickerViewController* mediaPicker;
|
||||
|
||||
// switches
|
||||
UISwitch *roomNotifSwitch;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -93,6 +115,8 @@
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didMXSessionStateChange:) name:kMXSessionStateDidChangeNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didUpdateRules:) name:kMXNotificationCenterDidUpdateRules object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didAccountUserInfoDidChange:) name:kMXKAccountUserInfoDidChangeNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
@@ -101,6 +125,8 @@
|
||||
|
||||
[self dismissFirstResponder];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXSessionStateDidChangeNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXNotificationCenterDidUpdateRules object:nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXKAccountUserInfoDidChangeNotification object:nil];
|
||||
}
|
||||
|
||||
// this method is called when the viewcontroller is displayed inside another one.
|
||||
@@ -150,16 +176,19 @@
|
||||
|
||||
- (void)showUpdatingSpinner
|
||||
{
|
||||
self.tableView.userInteractionEnabled = NO;
|
||||
|
||||
// Add a spinner
|
||||
updatingSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
||||
updatingSpinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin);
|
||||
updatingSpinner.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0];
|
||||
updatingSpinner.hidesWhenStopped = NO;
|
||||
[updatingSpinner startAnimating];
|
||||
updatingSpinner.center = self.view.center;
|
||||
[self.view addSubview:updatingSpinner];
|
||||
if (!updatingSpinner)
|
||||
{
|
||||
self.tableView.userInteractionEnabled = NO;
|
||||
|
||||
// Add a spinner
|
||||
updatingSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
||||
updatingSpinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin);
|
||||
updatingSpinner.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0];
|
||||
updatingSpinner.hidesWhenStopped = NO;
|
||||
[updatingSpinner startAnimating];
|
||||
updatingSpinner.center = self.view.center;
|
||||
[self.view addSubview:updatingSpinner];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)hideUpdatingSpinner
|
||||
@@ -232,10 +261,38 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didUpdateRules:(NSNotification *)notif
|
||||
{
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
- (void)didAccountUserInfoDidChange:(NSNotification *)notif
|
||||
{
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
- (IBAction)onCancel:(id)sender
|
||||
{
|
||||
// warn if there is a pending update ?
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
// if there are some updated fields
|
||||
if (updatedItemsDict && (updatedItemsDict.count > 0))
|
||||
{
|
||||
// ensure that the user understands that the updates will be lost if
|
||||
MXKAlert* alert = [[MXKAlert alloc] initWithTitle:nil message:NSLocalizedStringFromTable(@"room_details_with_updates", @"Vector", nil) style:MXKAlertStyleAlert];
|
||||
|
||||
[alert addActionWithTitle:NSLocalizedStringFromTable(@"cancel", @"Vector", nil) style:MXKAlertActionStyleCancel handler:^(MXKAlert *alert) {
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}];
|
||||
|
||||
[alert addActionWithTitle:NSLocalizedStringFromTable(@"save", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
|
||||
[self onSave:nil];
|
||||
}];
|
||||
|
||||
[alert showInViewController:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onSaveFailed:(NSString*)message withKey:(NSString*)key
|
||||
@@ -274,9 +331,60 @@
|
||||
|
||||
- (IBAction)onSave:(id)sender
|
||||
{
|
||||
[self showUpdatingSpinner];
|
||||
|
||||
// check if there is some update
|
||||
if (mxRoomState && updatedItemsDict && (updatedItemsDict.count > 0))
|
||||
{
|
||||
if ([updatedItemsDict objectForKey:@"ROOM_SECTION_PHOTO"])
|
||||
{
|
||||
// Retrieve the current picture and make sure its orientation is up
|
||||
UIImage *updatedPicture = [MXKTools forceImageOrientationUp:[updatedItemsDict objectForKey:@"ROOM_SECTION_PHOTO"]];
|
||||
|
||||
// Upload picture
|
||||
MXKMediaLoader *uploader = [MXKMediaManager prepareUploaderWithMatrixSession:mxRoom.mxSession initialRange:0 andRange:1.0];
|
||||
|
||||
[uploader uploadData:UIImageJPEGRepresentation(updatedPicture, 0.5) filename:nil mimeType:@"image/jpeg" success:^(NSString *url)
|
||||
{
|
||||
[updatedItemsDict removeObjectForKey:@"ROOM_SECTION_PHOTO"];
|
||||
[updatedItemsDict setObject:url forKey:@"ROOM_SECTION_PHOTO_URL"];
|
||||
|
||||
[self onSave:nil];
|
||||
} failure:^(NSError *error)
|
||||
{
|
||||
NSLog(@"[Vector RoomSettingsViewController] Failed to upload image: %@", error);
|
||||
[updatedItemsDict removeObjectForKey:@"ROOM_SECTION_PHOTO"];
|
||||
[self onSave:nil];
|
||||
}];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ([updatedItemsDict objectForKey:@"ROOM_SECTION_PHOTO_URL"])
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
NSString* photoUrl = [updatedItemsDict objectForKey:@"ROOM_SECTION_PHOTO_URL"];
|
||||
|
||||
[mxRoom setAvatar:photoUrl success:^{
|
||||
|
||||
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
||||
[strongSelf->updatedItemsDict removeObjectForKey:@"ROOM_SECTION_PHOTO_URL"];
|
||||
[strongSelf onSave:nil];
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
|
||||
NSLog(@"[Vector RoomSettingsViewController] Failed to update the room avatar %@", error);
|
||||
|
||||
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
||||
[strongSelf->updatedItemsDict removeObjectForKey:@"ROOM_SECTION_PHOTO_URL"];
|
||||
[strongSelf onSave:nil];
|
||||
|
||||
}];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// has a new room name
|
||||
if ([updatedItemsDict objectForKey:@"ROOM_SECTION_NAME"])
|
||||
{
|
||||
@@ -284,7 +392,6 @@
|
||||
|
||||
if (![newName isEqualToString:mxRoomState.name])
|
||||
{
|
||||
[self showUpdatingSpinner];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
pendingOperation = [mxRoom setName:newName success:^{
|
||||
@@ -319,7 +426,6 @@
|
||||
|
||||
if (![newTopic isEqualToString:mxRoomState.topic])
|
||||
{
|
||||
[self showUpdatingSpinner];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
pendingOperation = [mxRoom setTopic:newTopic success:^{
|
||||
@@ -348,6 +454,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ([updatedItemsDict objectForKey:@"ROOM_SECTION_MUTE_NOTIFICATIONS"])
|
||||
{
|
||||
[mxRoom toggleRoomNotifications:roomNotifSwitch.on];
|
||||
[updatedItemsDict removeObjectForKey:@"ROOM_SECTION_MUTE_NOTIFICATIONS"];
|
||||
[self onSave:nil];
|
||||
}
|
||||
|
||||
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
||||
|
||||
[self hideUpdatingSpinner];
|
||||
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
@@ -430,7 +545,63 @@
|
||||
// retrieve row as a ROOM_SECTION_XX index
|
||||
row = (row - 1) / 2;
|
||||
|
||||
if (row == ROOM_SECTION_TOPIC)
|
||||
if (row == ROOM_SECTION_MUTE_NOTIFICATIONS)
|
||||
{
|
||||
TableViewCellWithLabelAndSwitch *roomNotifCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithLabelAndSwitch defaultReuseIdentifier]];
|
||||
|
||||
if (!roomNotifCell)
|
||||
{
|
||||
roomNotifCell = [[TableViewCellWithLabelAndSwitch alloc] init];
|
||||
[roomNotifCell.mxkSwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
|
||||
roomNotifCell.mxkSwitch.onTintColor = VECTOR_GREEN_COLOR;
|
||||
}
|
||||
|
||||
roomNotifCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_mute_notifs", @"Vector", nil);
|
||||
roomNotifSwitch = roomNotifCell.mxkSwitch;
|
||||
|
||||
if (updatedItemsDict && [updatedItemsDict objectForKey:@"ROOM_SECTION_MUTE_NOTIFICATIONS"])
|
||||
{
|
||||
roomNotifSwitch.on = ((NSNumber*)[updatedItemsDict objectForKey:@"ROOM_SECTION_MUTE_NOTIFICATIONS"]).boolValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
roomNotifSwitch.on = mxRoom.areRoomNotificationsMuted;
|
||||
}
|
||||
|
||||
cell = roomNotifCell;
|
||||
}
|
||||
else if (row == ROOM_SECTION_PHOTO)
|
||||
{
|
||||
TableViewCellWithLabelAndMXKImageView *roomPhotoCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithLabelAndMXKImageView defaultReuseIdentifier]];
|
||||
|
||||
if (!roomPhotoCell)
|
||||
{
|
||||
roomPhotoCell = [[TableViewCellWithLabelAndMXKImageView alloc] init];
|
||||
|
||||
// tap on avatar to update it
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onRoomAvatarTap:)];
|
||||
[roomPhotoCell.mxkImageView addGestureRecognizer:tap];
|
||||
}
|
||||
|
||||
roomPhotoCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_photo", @"Vector", nil);
|
||||
|
||||
if (updatedItemsDict && [updatedItemsDict objectForKey:@"ROOM_SECTION_PHOTO"])
|
||||
{
|
||||
roomPhotoCell.mxkImageView.image = (UIImage*)[updatedItemsDict objectForKey:@"ROOM_SECTION_PHOTO"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[mxRoom setRoomAvatarImageIn:roomPhotoCell.mxkImageView];
|
||||
roomPhotoCell.mxkImageView.alpha = mxRoom.isModerator ? 1.0f : 0.5f;
|
||||
}
|
||||
|
||||
[roomPhotoCell.mxkImageView.layer setCornerRadius:roomPhotoCell.mxkImageView.frame.size.width / 2];
|
||||
roomPhotoCell.mxkImageView.clipsToBounds = YES;
|
||||
roomPhotoCell.userInteractionEnabled = mxRoom.isModerator;
|
||||
|
||||
cell = roomPhotoCell;
|
||||
}
|
||||
else if (row == ROOM_SECTION_TOPIC)
|
||||
{
|
||||
TableViewCellWithLabelAndLargeTextView *roomTopicCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithLabelAndLargeTextView defaultReuseIdentifier]];
|
||||
|
||||
@@ -460,8 +631,8 @@
|
||||
roomTopicCell.mxkTextView.delegate = self;
|
||||
|
||||
// disable the edition if the user cannoy update it
|
||||
roomTopicCell.mxkTextView.editable = isSuperUser;
|
||||
roomTopicCell.mxkTextView.textColor = isSuperUser ? [UIColor blackColor] : [UIColor lightGrayColor];
|
||||
roomTopicCell.mxkTextView.editable = mxRoom.isModerator;
|
||||
roomTopicCell.mxkTextView.textColor = VECTOR_TEXT_GRAY_COLOR;
|
||||
|
||||
cell = roomTopicCell;
|
||||
}
|
||||
@@ -492,13 +663,28 @@
|
||||
nameTextField = roomNameCell.mxkTextField;
|
||||
|
||||
// disable the edition if the user cannoy update it
|
||||
roomNameCell.editable = isSuperUser;
|
||||
roomNameCell.mxkTextField.textColor = isSuperUser ? [UIColor blackColor] : [UIColor lightGrayColor];
|
||||
roomNameCell.editable = mxRoom.isModerator;
|
||||
roomNameCell.mxkTextField.textColor = VECTOR_TEXT_GRAY_COLOR;
|
||||
|
||||
|
||||
// Add a "textFieldDidChange" notification method to the text field control.
|
||||
[roomNameCell.mxkTextField addTarget:self action:@selector(onTextFieldUpdate:) forControlEvents:UIControlEventEditingChanged];
|
||||
}
|
||||
else if (row == ROOM_SECTION_PRIV_PUB)
|
||||
{
|
||||
TableViewCellWithLabelAndTextField *privPublicCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithLabelAndTextField defaultReuseIdentifier]];
|
||||
|
||||
if (!privPublicCell)
|
||||
{
|
||||
privPublicCell = [[TableViewCellWithLabelAndTextField alloc] init];
|
||||
}
|
||||
|
||||
privPublicCell.mxkTextField.userInteractionEnabled = NO;
|
||||
privPublicCell.mxkTextField.text = @"";
|
||||
privPublicCell.mxkLabel.text = mxRoom.state.isPublic ? NSLocalizedStringFromTable(@"room_details_room_is_public", @"Vector", nil) : NSLocalizedStringFromTable(@"room_details_room_is_private", @"Vector", nil);
|
||||
|
||||
cell = privPublicCell;
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
@@ -509,14 +695,124 @@
|
||||
if (self.tableView == aTableView)
|
||||
{
|
||||
[self dismissFirstResponder];
|
||||
|
||||
if (indexPath.section == ROOM_SECTION)
|
||||
{
|
||||
NSUInteger row = indexPath.row;
|
||||
|
||||
// the even views are the line separator
|
||||
if ((row % 2) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// retrieve row as a ROOM_SECTION_XX index
|
||||
row = (row - 1) / 2;
|
||||
|
||||
if (row == ROOM_SECTION_PHOTO)
|
||||
{
|
||||
[self onRoomAvatarTap:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
||||
#pragma mark - MediaPickerViewController Delegate
|
||||
|
||||
- (void)dismissMediaPicker
|
||||
{
|
||||
if (scrollView == self.tableView)
|
||||
if (mediaPicker)
|
||||
{
|
||||
[self dismissFirstResponder];
|
||||
[mediaPicker withdrawViewControllerAnimated:YES completion:nil];
|
||||
mediaPicker = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectImage:(UIImage*)image withURL:(NSURL *)imageURL
|
||||
{
|
||||
[self dismissMediaPicker];
|
||||
|
||||
if (image)
|
||||
{
|
||||
[self getNavigationItem].rightBarButtonItem.enabled = YES;
|
||||
|
||||
NSMutableDictionary* dict = [self getUpdatedItemsDict];
|
||||
[dict setObject:image forKey:@"ROOM_SECTION_PHOTO"];
|
||||
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectVideo:(NSURL*)videoURL isCameraRecording:(BOOL)isCameraRecording
|
||||
{
|
||||
// this method should not be called
|
||||
[self dismissMediaPicker];
|
||||
}
|
||||
|
||||
- (void)mediaPickerController:(MediaPickerViewController *)mediaPickerController didSelectAssets:(NSArray *)assets
|
||||
{
|
||||
if (assets.count > 0)
|
||||
{
|
||||
PHAsset* asset = [assets objectAtIndex:0];
|
||||
PHContentEditingInputRequestOptions *editOptions = [[PHContentEditingInputRequestOptions alloc] init];
|
||||
|
||||
[asset requestContentEditingInputWithOptions:editOptions
|
||||
completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
|
||||
|
||||
if (contentEditingInput.mediaType == PHAssetMediaTypeImage)
|
||||
{
|
||||
// Here the fullSizeImageURL is related to a local file path
|
||||
NSData *data = [NSData dataWithContentsOfURL:contentEditingInput.fullSizeImageURL];
|
||||
UIImage *image = [UIImage imageWithData:data];
|
||||
|
||||
if (image)
|
||||
{
|
||||
[self getNavigationItem].rightBarButtonItem.enabled = YES;
|
||||
|
||||
NSMutableDictionary* dict = [self getUpdatedItemsDict];
|
||||
[dict setObject:image forKey:@"ROOM_SECTION_PHOTO"];
|
||||
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
[self dismissMediaPicker];
|
||||
}
|
||||
|
||||
#pragma mark - actions
|
||||
|
||||
- (void)onRoomAvatarTap:(UITapGestureRecognizer *)recognizer
|
||||
{
|
||||
mediaPicker = [MediaPickerViewController mediaPickerViewController];
|
||||
mediaPicker.mediaTypes = @[(NSString *)kUTTypeImage];
|
||||
mediaPicker.multipleSelections = NO;
|
||||
mediaPicker.selectionButtonCustomLabel = NSLocalizedStringFromTable(@"media_picker_attach", @"Vector", nil);
|
||||
mediaPicker.delegate = self;
|
||||
UINavigationController *navigationController = [UINavigationController new];
|
||||
[navigationController pushViewController:mediaPicker animated:NO];
|
||||
|
||||
[self presentViewController:navigationController animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void)onSwitchUpdate:(UISwitch*)uiSwitch
|
||||
{
|
||||
if (uiSwitch == roomNotifSwitch)
|
||||
{
|
||||
NSMutableDictionary* dict = [self getUpdatedItemsDict];
|
||||
|
||||
if (roomNotifSwitch.on == mxRoom.areRoomNotificationsMuted)
|
||||
{
|
||||
[dict removeObjectForKey:@"ROOM_SECTION_MUTE_NOTIFICATIONS"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[dict setObject:[NSNumber numberWithBool:roomNotifSwitch.on] forKey:@"ROOM_SECTION_MUTE_NOTIFICATIONS"];
|
||||
}
|
||||
|
||||
[self getNavigationItem].rightBarButtonItem.enabled = (dict.count != 0);
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user