Sort group members.

pull/1/head
Matthew Chen 7 years ago
parent cbc27f1c30
commit 2edabdbba4

@ -168,7 +168,14 @@ NS_ASSUME_NONNULL_BEGIN
__weak ShowGroupMembersViewController *weakSelf = self; __weak ShowGroupMembersViewController *weakSelf = self;
ContactsViewHelper *helper = self.contactsViewHelper; 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:^{ [section addItem:[OWSTableItem itemWithCustomCellBlock:^{
ShowGroupMembersViewController *strongSelf = weakSelf; ShowGroupMembersViewController *strongSelf = weakSelf;
OWSCAssert(strongSelf); OWSCAssert(strongSelf);

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

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

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

Loading…
Cancel
Save