Clean up conversation settings screen

This commit is contained in:
Niels Andriesse 2021-02-18 16:49:48 +11:00
parent 067eaf0c3b
commit c4bd4cea6a
5 changed files with 61 additions and 154 deletions

View File

@ -238,6 +238,7 @@
B83F2B88240CB75A000A54AB /* UIImage+Scaling.swift in Sources */ = {isa = PBXBuildFile; fileRef = B83F2B87240CB75A000A54AB /* UIImage+Scaling.swift */; };
B84664F5235022F30083A1CD /* MentionUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84664F4235022F30083A1CD /* MentionUtilities.swift */; };
B849789625D4A2F500D0D0B3 /* LinkPreviewViewV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = B849789525D4A2F500D0D0B3 /* LinkPreviewViewV2.swift */; };
B84A89BC25DE328A0040017D /* ProfilePictureVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84A89BB25DE328A0040017D /* ProfilePictureVC.swift */; };
B85357BF23A1AE0800AAF6CD /* SeedReminderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85357BE23A1AE0800AAF6CD /* SeedReminderView.swift */; };
B85357C323A1BD1200AAF6CD /* SeedVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B85357C223A1BD1200AAF6CD /* SeedVC.swift */; };
B8544E3323D50E4900299F14 /* SNAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8544E3223D50E4900299F14 /* SNAppearance.swift */; };
@ -1297,6 +1298,7 @@
B84664F4235022F30083A1CD /* MentionUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentionUtilities.swift; sourceTree = "<group>"; };
B847570023D568EB00759540 /* SignalServiceKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SignalServiceKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B849789525D4A2F500D0D0B3 /* LinkPreviewViewV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewViewV2.swift; sourceTree = "<group>"; };
B84A89BB25DE328A0040017D /* ProfilePictureVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePictureVC.swift; sourceTree = "<group>"; };
B85357BE23A1AE0800AAF6CD /* SeedReminderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedReminderView.swift; sourceTree = "<group>"; };
B85357C223A1BD1200AAF6CD /* SeedVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedVC.swift; sourceTree = "<group>"; };
B8544E3023D16CA500299F14 /* DeviceUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceUtilities.swift; sourceTree = "<group>"; };
@ -2531,6 +2533,7 @@
340FC8A0204DAC8D007AEB0F /* OWSConversationSettingsViewController.h */,
340FC89A204DAC8D007AEB0F /* OWSConversationSettingsViewController.m */,
340FC899204DAC8D007AEB0F /* OWSConversationSettingsViewDelegate.h */,
B84A89BB25DE328A0040017D /* ProfilePictureVC.swift */,
);
path = Settings;
sourceTree = "<group>";
@ -5029,6 +5032,7 @@
45CD81EF1DC030E7004C9430 /* SyncPushTokensJob.swift in Sources */,
B83524A525C3BA4B0089A44F /* InfoMessageCell.swift in Sources */,
34129B8621EF877A005457A8 /* LinkPreviewView.swift in Sources */,
B84A89BC25DE328A0040017D /* ProfilePictureVC.swift in Sources */,
34386A54207D271D009F5D9C /* NeverClearView.swift in Sources */,
451166C01FD86B98000739BA /* AccountManager.swift in Sources */,
C374EEF425DB31D40073A857 /* VoiceMessageRecordingView.swift in Sources */,

View File

@ -29,29 +29,19 @@
NS_ASSUME_NONNULL_BEGIN
//#define SHOW_COLOR_PICKER
CGFloat kIconViewLength = 24;
const CGFloat kIconViewLength = 24;
@interface OWSConversationSettingsViewController () <
#ifdef SHOW_COLOR_PICKER
ColorPickerDelegate,
#endif
OWSSheetViewControllerDelegate>
@interface OWSConversationSettingsViewController () <OWSSheetViewControllerDelegate>
@property (nonatomic) TSThread *thread;
@property (nonatomic) YapDatabaseConnection *uiDatabaseConnection;
@property (nonatomic, readonly) YapDatabaseConnection *editingDatabaseConnection;
@property (nonatomic) NSArray<NSNumber *> *disappearingMessagesDurations;
@property (nonatomic) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration;
@property (nullable, nonatomic) MediaGallery *mediaGallery;
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
@property (nonatomic, readonly) UIImageView *avatarView;
@property (nonatomic, readonly) UILabel *disappearingMessagesDurationLabel;
#ifdef SHOW_COLOR_PICKER
@property (nonatomic) OWSColorPicker *colorPicker;
#endif
@end
@ -236,11 +226,6 @@ const CGFloat kIconViewLength = 24;
[[OWSDisappearingMessagesConfiguration alloc] initDefaultWithThreadId:self.thread.uniqueId];
}
#ifdef SHOW_COLOR_PICKER
self.colorPicker = [[OWSColorPicker alloc] initWithThread:self.thread];
self.colorPicker.delegate = self;
#endif
[self updateTableContents];
NSString *title;
@ -253,18 +238,6 @@ const CGFloat kIconViewLength = 24;
self.tableView.backgroundColor = UIColor.clearColor;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if (self.showVerificationOnAppear) {
self.showVerificationOnAppear = NO;
if (self.isGroupThread) {
[self showGroupMembersView];
}
}
}
- (void)updateTableContents
{
OWSTableContents *contents = [OWSTableContents new];
@ -279,13 +252,7 @@ const CGFloat kIconViewLength = 24;
OWSTableSection *mainSection = [OWSTableSection new];
mainSection.customHeaderView = [self mainSectionHeader];
if (self.isGroupThread) {
mainSection.customHeaderHeight = @(147.f);
} else {
BOOL isSmallScreen = (UIScreen.mainScreen.bounds.size.height - 568) < 1;
mainSection.customHeaderHeight = isSmallScreen ? @(201.f) : @(208.f);
}
mainSection.customHeaderHeight = @(UITableViewAutomaticDimension);
if ([self.thread isKindOfClass:TSContactThread.class]) {
[mainSection addItem:[OWSTableItem
@ -444,29 +411,6 @@ const CGFloat kIconViewLength = 24;
actionBlock:nil]];
}
}
#ifdef SHOW_COLOR_PICKER
[mainSection
addItem:[OWSTableItem
itemWithCustomCellBlock:^{
OWSConversationSettingsViewController *strongSelf = weakSelf;
OWSCAssertDebug(strongSelf);
ConversationColorName colorName = strongSelf.thread.conversationColorName;
UIColor *currentColor =
[OWSConversationColor conversationColorOrDefaultForColorName:colorName].themeColor;
NSString *title = NSLocalizedString(@"CONVERSATION_SETTINGS_CONVERSATION_COLOR",
@"Label for table cell which leads to picking a new conversation color");
return [strongSelf
cellWithName:title
iconName:@"ic_color_palette"
disclosureIconColor:currentColor
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(
OWSConversationSettingsViewController, @"conversation_color")];
}
actionBlock:^{
[weakSelf showColorPicker];
}]];
#endif
[contents addSection:mainSection];
@ -631,9 +575,6 @@ const CGFloat kIconViewLength = 24;
// Block Conversation section.
if (!isNoteToSelf && [self.thread isKindOfClass:TSContactThread.class]) {
mainSection.footerTitle = NSLocalizedString(
@"BLOCK_USER_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking another user.");
[mainSection addItem:[OWSTableItem
itemWithCustomCellBlock:^{
OWSConversationSettingsViewController *strongSelf = weakSelf;
@ -721,48 +662,18 @@ const CGFloat kIconViewLength = 24;
return cell;
}
static CGRect oldframe;
-(void)showProfilePicture:(UITapGestureRecognizer *)tapGesture
- (void)showProfilePicture:(UITapGestureRecognizer *)tapGesture
{
LKProfilePictureView *profilePictureView = (LKProfilePictureView *)tapGesture.view;
UIImage *image = [profilePictureView getProfilePicture];
if (image == nil) { return; }
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
oldframe = [profilePictureView convertRect:profilePictureView.bounds toView:window];
backgroundView.backgroundColor = [UIColor blackColor];
backgroundView.alpha = 0;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:oldframe];
imageView.image = image;
imageView.tag = 1;
imageView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width / 2;
imageView.layer.masksToBounds = true;
[backgroundView addSubview:imageView];
[window addSubview:backgroundView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)];
[backgroundView addGestureRecognizer: tap];
[UIView animateWithDuration:0.25 animations:^{
imageView.frame = CGRectMake(0,([UIScreen mainScreen].bounds.size.height - oldframe.size.height * [UIScreen mainScreen].bounds.size.width / oldframe.size.width) / 2, [UIScreen mainScreen].bounds.size.width, oldframe.size.height * [UIScreen mainScreen].bounds.size.width / oldframe.size.width);
backgroundView.alpha = 1;
} completion:nil];
NSString *title = (self.threadName != nil && self.threadName.length > 0) ? self.threadName : @"Anonymous";
SNProfilePictureVC *profilePictureVC = [[SNProfilePictureVC alloc] initWithImage:image title:title];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:profilePictureVC];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:navController animated:YES completion:nil];
}
-(void)hideImage:(UITapGestureRecognizer *)tap{
UIView *backgroundView = tap.view;
UIImageView *imageView = (UIImageView *)[tap.view viewWithTag:1];
[UIView animateWithDuration:0.25 animations:^{
imageView.frame = oldframe;
backgroundView.alpha = 0;
} completion:^(BOOL finished) {
[backgroundView removeFromSuperview];
}];
}
- (UIView *)mainSectionHeader
{
UITapGestureRecognizer *profilePictureTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showProfilePicture:)];
@ -866,22 +777,6 @@ static CGRect oldframe;
#pragma mark - Actions
- (void)showShareProfileAlert
{
[self.profileManager presentAddThreadToProfileWhitelist:self.thread
fromViewController:self
success:^{
[self updateTableContents];
}];
}
- (void)showGroupMembersView
{
TSGroupThread *thread = (TSGroupThread *)self.thread;
LKGroupMembersVC *groupMembersVC = [[LKGroupMembersVC alloc] initWithThread:thread];
[self.navigationController pushViewController:groupMembersVC animated:YES];
}
- (void)editGroup
{
LKEditClosedGroupVC *editClosedGroupVC = [[LKEditClosedGroupVC alloc] initWithThreadID:self.thread.uniqueId];
@ -1200,44 +1095,6 @@ static CGRect oldframe;
}
}
#pragma mark - ColorPickerDelegate
#ifdef SHOW_COLOR_PICKER
- (void)showColorPicker
{
OWSSheetViewController *sheetViewController = self.colorPicker.sheetViewController;
sheetViewController.delegate = self;
[self presentViewController:sheetViewController
animated:YES
completion:^() {
OWSLogInfo(@"presented sheet view");
}];
}
- (void)colorPicker:(OWSColorPicker *)colorPicker
didPickConversationColor:(OWSConversationColor *_Nonnull)conversationColor
{
OWSLogDebug(@"picked color: %@", conversationColor.name);
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self.thread updateConversationColorName:conversationColor.name transaction:transaction];
}];
[self.contactsManager.avatarCache removeAllImages];
[self updateTableContents];
[self.conversationSettingsViewDelegate conversationColorWasUpdated];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
ConversationConfigurationSyncOperation *operation =
[[ConversationConfigurationSyncOperation alloc] initWithThread:self.thread];
OWSAssertDebug(operation.isReady);
[operation start];
});
}
#endif
#pragma mark - OWSSheetViewController
- (void)sheetViewControllerRequestedDismiss:(OWSSheetViewController *)sheetViewController

View File

@ -9,7 +9,6 @@ NS_ASSUME_NONNULL_BEGIN
@protocol OWSConversationSettingsViewDelegate <NSObject>
- (void)conversationColorWasUpdated;
- (void)groupWasUpdated:(TSGroupModel *)groupModel;
- (void)conversationSettingsDidRequestConversationSearch:(OWSConversationSettingsViewController *)conversationSettingsViewController;

View File

@ -0,0 +1,48 @@
@objc(SNProfilePictureVC)
final class ProfilePictureVC : BaseVC {
private let image: UIImage
private let snTitle: String
@objc init(image: UIImage, title: String) {
self.image = image
self.snTitle = title
super.init(nibName: nil, bundle: nil)
}
override init(nibName: String?, bundle: Bundle?) {
preconditionFailure("Use init(image:) instead.")
}
required init?(coder: NSCoder) {
preconditionFailure("Use init(coder:) instead.")
}
override func viewDidLoad() {
view.backgroundColor = .clear
setUpGradientBackground()
setUpNavBarStyle()
setNavBarTitle(snTitle)
// Close button
let closeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "X"), style: .plain, target: self, action: #selector(close))
closeButton.tintColor = Colors.text
navigationItem.leftBarButtonItem = closeButton
// Image view
let imageView = UIImageView(image: image)
let size = UIScreen.main.bounds.width - 2 * Values.largeSpacing
imageView.set(.width, to: size)
imageView.set(.height, to: size)
imageView.layer.cornerRadius = size / 2
imageView.layer.masksToBounds = true
view.addSubview(imageView)
imageView.center(in: view)
// Gesture recognizer
let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(close))
swipeGestureRecognizer.direction = .down
view.addGestureRecognizer(swipeGestureRecognizer)
}
@objc private func close() {
presentingViewController?.dismiss(animated: true, completion: nil)
}
}

View File

@ -722,7 +722,6 @@ NSString *const kOWSTableCellIdentifier = @"kOWSTableCellIdentifier";
}
if (section.customHeaderHeight) {
OWSAssertDebug([section.customHeaderHeight floatValue] > 0);
return [section.customHeaderHeight floatValue];
} else if (section.headerTitle.length > 0) {
return UITableViewAutomaticDimension;