Skip to content

Commit

Permalink
Improve the people invite screens
Browse files Browse the repository at this point in the history
 #904.

Enable contacts section shrinking when the 2 sections are displayed.
  • Loading branch information
giomfo committed Jan 13, 2017
1 parent 464d103 commit e50bb34
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 6 deletions.
95 changes: 90 additions & 5 deletions Vector/ViewController/ContactsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#import "AppDelegate.h"

#define CONTACTS_TABLEVC_LOCALCONTACTS_BIT 0x01
#define CONTACTS_TABLEVC_KNOWNCONTACTS_BIT 0x02

@interface ContactsTableViewController ()
{
// Search processing
Expand All @@ -39,8 +42,12 @@ @interface ContactsTableViewController ()
// This dictionary tells for each display name whether it appears several times.
NSMutableDictionary <NSString*,NSNumber*> *isMultiUseNameByDisplayName;

// Report all the contacts by matrix id
// Report all the contacts by matrix id.
NSMutableDictionary <NSString*, MXKContact*> *contactsByMatrixId;

// Shrinked sections.
BOOL enableSectionShrinking;
NSInteger shrinkedSectionsBitMask;
}

@end
Expand Down Expand Up @@ -86,6 +93,9 @@ - (void)finalizeInit
contactsByMatrixId = [NSMutableDictionary dictionary];

_forceMatrixIdInDisplayName = NO;

enableSectionShrinking = NO;
shrinkedSectionsBitMask = 0;
}

- (void)viewDidLoad
Expand Down Expand Up @@ -219,6 +229,9 @@ - (void)searchWithPattern:(NSString *)searchText forceReset:(BOOL)forceRefresh
{
searchProcessingLocalContacts = nil;
searchProcessingMatrixContacts = nil;

// Disclose the sections
shrinkedSectionsBitMask = 0;
}
else if (forceRefresh || !searchProcessingText.length || [searchText hasPrefix:searchProcessingText] == NO)
{
Expand All @@ -227,6 +240,9 @@ - (void)searchWithPattern:(NSString *)searchText forceReset:(BOOL)forceRefresh

// Retrieve all known matrix users
searchProcessingMatrixContacts = [self unfilteredMatrixContactsArray];

// Disclose the sections
shrinkedSectionsBitMask = 0;
}

// List all the filtered local Matrix-enabled contacts by their matrix id to remove a contact
Expand Down Expand Up @@ -473,6 +489,14 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
}
}

// Enable the section shrinking only when all the contacts sections are displayed.
enableSectionShrinking = (filteredLocalContactsSection != -1 && filteredMatrixContactsSection != -1);
if (enableSectionShrinking == NO)
{
// Disclose the section
shrinkedSectionsBitMask = 0;
}

return count;
}

Expand All @@ -484,11 +508,11 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
{
count = 1;
}
else if (section == filteredLocalContactsSection)
else if (section == filteredLocalContactsSection && !(shrinkedSectionsBitMask & CONTACTS_TABLEVC_LOCALCONTACTS_BIT))
{
count = filteredLocalContacts.count;
}
else if (section == filteredMatrixContactsSection)
else if (section == filteredMatrixContactsSection && !(shrinkedSectionsBitMask & CONTACTS_TABLEVC_KNOWNCONTACTS_BIT))
{
count = filteredMatrixContacts.count;
}
Expand Down Expand Up @@ -598,6 +622,8 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger

if (section == filteredLocalContactsSection || section == filteredMatrixContactsSection)
{
NSInteger sectionBit = -1;

sectionHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 30)];
sectionHeader.backgroundColor = kVectorColorLightGrey;

Expand All @@ -609,17 +635,51 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
UILabel *headerLabel = [[UILabel alloc] initWithFrame:frame];
headerLabel.font = [UIFont boldSystemFontOfSize:15.0];
headerLabel.backgroundColor = [UIColor clearColor];
[sectionHeader addSubview:headerLabel];

if (section == filteredLocalContactsSection)
{
headerLabel.text = NSLocalizedStringFromTable(@"contacts_address_book_section", @"Vector", nil);
sectionBit = CONTACTS_TABLEVC_LOCALCONTACTS_BIT;
}
else if (section == filteredMatrixContactsSection)
else //if (section == filteredMatrixContactsSection)
{
headerLabel.text = NSLocalizedStringFromTable(@"contacts_matrix_users_section", @"Vector", nil);
sectionBit = CONTACTS_TABLEVC_KNOWNCONTACTS_BIT;
}

[sectionHeader addSubview:headerLabel];
if (enableSectionShrinking)
{
// Add shrink button
UIButton *shrinkButton = [UIButton buttonWithType:UIButtonTypeCustom];
frame = sectionHeader.frame;
frame.origin.x = frame.origin.y = 0;
shrinkButton.frame = frame;
shrinkButton.backgroundColor = [UIColor clearColor];
[shrinkButton addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
shrinkButton.tag = sectionBit;
[sectionHeader addSubview:shrinkButton];
sectionHeader.userInteractionEnabled = YES;

// Add shrink icon
UIImage *chevron;
if (shrinkedSectionsBitMask & sectionBit)
{
chevron = [UIImage imageNamed:@"disclosure_icon"];
}
else
{
chevron = [UIImage imageNamed:@"shrink_icon"];
}
UIImageView *chevronView = [[UIImageView alloc] initWithImage:chevron];
chevronView.contentMode = UIViewContentModeCenter;
frame = chevronView.frame;
frame.origin.x = sectionHeader.frame.size.width - frame.size.width - 16;
frame.origin.y = (sectionHeader.frame.size.height - frame.size.height) / 2;
chevronView.frame = frame;
[sectionHeader addSubview:chevronView];
chevronView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
}
}
return sectionHeader;
}
Expand Down Expand Up @@ -699,4 +759,29 @@ - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
[self withdrawViewControllerAnimated:YES completion:nil];
}

#pragma mark - Action

- (IBAction)onButtonPressed:(id)sender
{
if ([sender isKindOfClass:[UIButton class]])
{
UIButton *shrinkButton = (UIButton*)sender;
NSInteger selectedSectionBit = shrinkButton.tag;

if (shrinkedSectionsBitMask & selectedSectionBit)
{
// Disclose the section
shrinkedSectionsBitMask &= ~selectedSectionBit;
}
else
{
// Shrink this section
shrinkedSectionsBitMask |= selectedSectionBit;
}

// Refresh
[self refreshTableView];
}
}

@end
2 changes: 1 addition & 1 deletion Vector/ViewController/HomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ - (void)checkAndShowBackgroundImage
}
else if (self.selectedViewController == peopleSearchViewController)
{
self.backgroundImageView.hidden = (([peopleSearchViewController.tableView numberOfRowsInSection:0] != 0) || (self.keyboardHeight == 0));
self.backgroundImageView.hidden = (([peopleSearchViewController.tableView numberOfSections] != 0) || (self.keyboardHeight == 0));
}
else if (self.selectedViewController == filesSearchViewController)
{
Expand Down

0 comments on commit e50bb34

Please sign in to comment.