Merge branch 'charlesmchen/sortGroupMembers'

This commit is contained in:
Matthew Chen 2018-05-16 17:13:49 -04:00
commit 3cdce13b44
4 changed files with 33 additions and 4 deletions

View file

@ -168,7 +168,14 @@ NS_ASSUME_NONNULL_BEGIN
__weak ShowGroupMembersViewController *weakSelf = self;
ContactsViewHelper *helper = self.contactsViewHelper;
for (NSString *recipientId in [recipientIds sortedArrayUsingSelector:@selector(compare:)]) {
// Sort the group members using contacts manager.
NSArray<NSString *> *sortedRecipientIds =
[recipientIds sortedArrayUsingComparator:^NSComparisonResult(NSString *recipientIdA, NSString *recipientIdB) {
SignalAccount *signalAccountA = [helper.contactsManager signalAccountForRecipientId:recipientIdA];
SignalAccount *signalAccountB = [helper.contactsManager signalAccountForRecipientId:recipientIdB];
return [helper.contactsManager compareSignalAccount:signalAccountA withSignalAccount:signalAccountB];
}];
for (NSString *recipientId in sortedRecipientIds) {
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
ShowGroupMembersViewController *strongSelf = weakSelf;
OWSCAssert(strongSelf);

View file

@ -78,17 +78,14 @@ const CGFloat kContactTableViewCellAvatarTextMargin = 12;
_nameLabel = [UILabel new];
_nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
_nameLabel.font = [UIFont ows_dynamicTypeBodyFont];
[_nameContainerView addSubview:_nameLabel];
_profileNameLabel = [UILabel new];
_profileNameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
_profileNameLabel.font = [UIFont ows_regularFontWithSize:11.f];
_profileNameLabel.textColor = [UIColor grayColor];
[_nameContainerView addSubview:_profileNameLabel];
_subtitle = [UILabel new];
_subtitle.font = [UIFont ows_regularFontWithSize:11.f];
_subtitle.textColor = [UIColor ows_darkGrayColor];
[_nameContainerView addSubview:self.subtitle];
@ -113,10 +110,19 @@ const CGFloat kContactTableViewCellAvatarTextMargin = 12;
[_nameContainerView autoPinLeadingToTrailingEdgeOfView:_avatarView offset:kContactTableViewCellAvatarTextMargin];
[_nameContainerView autoPinTrailingToSuperviewMargin];
[self configureFonts];
// Force layout, since imageView isn't being initally rendered on App Store optimized build.
[self layoutSubviews];
}
- (void)configureFonts
{
self.nameLabel.font = [UIFont ows_dynamicTypeBodyFont];
self.profileNameLabel.font = [UIFont ows_regularFontWithSize:11.f];
self.subtitle.font = [UIFont ows_regularFontWithSize:11.f];
}
- (void)configureWithSignalAccount:(SignalAccount *)signalAccount contactsManager:(OWSContactsManager *)contactsManager
{
[self configureWithRecipientId:signalAccount.recipientId contactsManager:contactsManager];
@ -124,6 +130,12 @@ const CGFloat kContactTableViewCellAvatarTextMargin = 12;
- (void)configureWithRecipientId:(NSString *)recipientId contactsManager:(OWSContactsManager *)contactsManager
{
OWSAssert(recipientId.length > 0);
OWSAssert(contactsManager);
// Update fonts to reflect changes to dynamic type.
[self configureFonts];
self.recipientId = recipientId;
self.contactsManager = contactsManager;
@ -155,6 +167,10 @@ const CGFloat kContactTableViewCellAvatarTextMargin = 12;
- (void)configureWithThread:(TSThread *)thread contactsManager:(OWSContactsManager *)contactsManager
{
OWSAssert(thread);
// Update fonts to reflect changes to dynamic type.
[self configureFonts];
self.contactsManager = contactsManager;
NSString *threadName = thread.name;

View file

@ -70,6 +70,7 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification;
* Used for sorting, respects system contacts name sort order preference.
*/
- (NSString *)comparableNameForSignalAccount:(SignalAccount *)signalAccount;
- (NSComparisonResult)compareSignalAccount:(SignalAccount *)left withSignalAccount:(SignalAccount *)right;
// Generally we prefer the formattedProfileName over the raw profileName so as to
// distinguish a profile name apart from a name pulled from the system's contacts.

View file

@ -757,6 +757,11 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
return image;
}
- (NSComparisonResult)compareSignalAccount:(SignalAccount *)left withSignalAccount:(SignalAccount *)right
{
return self.signalAccountComparator(left, right);
}
- (NSComparisonResult (^)(SignalAccount *left, SignalAccount *right))signalAccountComparator
{
return ^NSComparisonResult(SignalAccount *left, SignalAccount *right) {