Skip to content

Commit

Permalink
Add explicit header titles to several screens
Browse files Browse the repository at this point in the history
Some screens used the ugly "plain" table view or used a group table view with no title. Both look awful. This commit updates the cookies, keychain, libraries, and live objects screens to use grouped table views with a descriptive section header, like "5 cookies" or "123 of 456 objects, 30 MB"

Some screens, like live objects and keychain, would display the number of items in the navigation bar title. That has been removed; they now used a fixed title.

Also, rename keyChainItems → keychainItems
  • Loading branch information
NSExceptional committed Nov 27, 2019
1 parent fe36b59 commit 3e12ad9
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//

#import "FLEXGlobalsEntry.h"
#import "FLEXTableViewController.h"

@interface FLEXCookiesTableViewController : UITableViewController <FLEXGlobalsEntry>
@interface FLEXCookiesTableViewController : FLEXTableViewController <FLEXGlobalsEntry>

@end
44 changes: 28 additions & 16 deletions Classes/GlobalStateExplorers/FLEXCookiesTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,37 @@
#import "FLEXUtility.h"

@interface FLEXCookiesTableViewController ()

@property (nonatomic) NSArray<NSHTTPCookie *> *cookies;

@property (nonatomic, readonly) NSArray<NSHTTPCookie *> *cookies;
@property (nonatomic) NSString *headerTitle;
@end

@implementation FLEXCookiesTableViewController

- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];

if (self) {
self.title = @"Cookies";
- (void)viewDidLoad {
[super viewDidLoad];

NSSortDescriptor *nameSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)];
_cookies = [NSHTTPCookieStorage.sharedHTTPCookieStorage.cookies sortedArrayUsingDescriptors:@[nameSortDescriptor]];
}

return self;
NSSortDescriptor *nameSortDescriptor = [[NSSortDescriptor alloc]
initWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)
];
_cookies = [NSHTTPCookieStorage.sharedHTTPCookieStorage.cookies
sortedArrayUsingDescriptors:@[nameSortDescriptor]
];

self.title = @"Cookies";
[self updateHeaderTitle];
}

- (void)updateHeaderTitle {
self.headerTitle = [NSString stringWithFormat:@"%@ cookies", @(self.cookies.count)];
// TODO update header title here when we can search cookies
}

- (NSHTTPCookie *)cookieForRowAtIndexPath:(NSIndexPath *)indexPath {
return self.cookies[indexPath.row];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

#pragma mark - Table View Data Source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.cookies.count;
Expand All @@ -61,13 +65,21 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return self.headerTitle;
}


#pragma mark - Table View Delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSHTTPCookie *cookie = [self cookieForRowAtIndexPath:indexPath];
UIViewController *cookieViewController = (UIViewController *)[FLEXObjectExplorerFactory explorerViewControllerForObject:cookie];

[self.navigationController pushViewController:cookieViewController animated:YES];
}


#pragma mark - FLEXGlobalsEntry

+ (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row {
Expand Down
28 changes: 23 additions & 5 deletions Classes/GlobalStateExplorers/FLEXLibrariesTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @interface FLEXLibrariesTableViewController ()

@property (nonatomic) NSArray<NSString *> *imageNames;
@property (nonatomic) NSArray<NSString *> *filteredImageNames;
@property (nonatomic) NSString *headerTitle;

@property (nonatomic) Class foundClass;

Expand All @@ -37,6 +38,22 @@ - (void)viewDidLoad
[super viewDidLoad];

self.showsSearchBar = YES;
[self updateHeaderTitle];
}

- (void)updateHeaderTitle
{
if (self.foundClass) {
self.headerTitle = @"Looking for this?";
} else if (self.imageNames.count == self.filteredImageNames.count) {
// Unfiltered
self.headerTitle = [NSString stringWithFormat:@"%@ libraries", @(self.imageNames.count)];
} else {
self.headerTitle = [NSString
stringWithFormat:@"%@ of %@ libraries",
@(self.filteredImageNames.count), @(self.imageNames.count)
];
}
}


Expand Down Expand Up @@ -120,17 +137,13 @@ - (void)updateSearchResults:(NSString *)searchText
}

self.foundClass = NSClassFromString(searchText);
[self updateHeaderTitle];
[self.tableView reloadData];
}


#pragma mark - Table View Data Source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.filteredImageNames.count + (self.foundClass ? 1 : 0);
Expand Down Expand Up @@ -162,6 +175,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return self.headerTitle;
}


#pragma mark - Table View Delegate

Expand Down
80 changes: 53 additions & 27 deletions Classes/GlobalStateExplorers/FLEXLiveObjectsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "FLEXInstancesTableViewController.h"
#import "FLEXUtility.h"
#import "FLEXScopeCarousel.h"
#import "FLEXTableView.h"
#import <objc/runtime.h>

static const NSInteger kFLEXLiveObjectsSortAlphabeticallyIndex = 0;
Expand All @@ -23,15 +24,22 @@ @interface FLEXLiveObjectsTableViewController ()
@property (nonatomic) NSDictionary<NSString *, NSNumber *> *instanceSizesForClassNames;
@property (nonatomic, readonly) NSArray<NSString *> *allClassNames;
@property (nonatomic) NSArray<NSString *> *filteredClassNames;
@property (nonatomic) NSString *headerTitle;

@end

@implementation FLEXLiveObjectsTableViewController

- (void)loadView
{
self.tableView = [FLEXTableView flexDefaultTableView];
}

- (void)viewDidLoad
{
[super viewDidLoad];


// self.title = @"Live Objects";
self.showsSearchBar = YES;
self.searchBarDebounceInterval = kFLEXDebounceInstant;
self.showsCarousel = YES;
Expand Down Expand Up @@ -96,35 +104,42 @@ - (void)refreshControlDidRefresh:(id)sender
[self.refreshControl endRefreshing];
}

- (void)updateTitle
- (void)updateHeaderTitle
{
NSString *title = @"Live Objects";

NSUInteger totalCount = 0;
NSUInteger totalSize = 0;
for (NSString *className in self.allClassNames) {
NSUInteger count = [self.instanceCountsForClassNames[className] unsignedIntegerValue];
NSUInteger count = self.instanceCountsForClassNames[className].unsignedIntegerValue;
totalCount += count;
totalSize += count * [self.instanceSizesForClassNames[className] unsignedIntegerValue];
totalSize += count * self.instanceSizesForClassNames[className].unsignedIntegerValue;
}

NSUInteger filteredCount = 0;
NSUInteger filteredSize = 0;
for (NSString *className in self.filteredClassNames) {
NSUInteger count = [self.instanceCountsForClassNames[className] unsignedIntegerValue];
NSUInteger count = self.instanceCountsForClassNames[className].unsignedIntegerValue;
filteredCount += count;
filteredSize += count * [self.instanceSizesForClassNames[className] unsignedIntegerValue];
filteredSize += count * self.instanceSizesForClassNames[className].unsignedIntegerValue;
}

if (filteredCount == totalCount) {
// Unfiltered
title = [title stringByAppendingFormat:@" (%lu, %@)", (unsigned long)totalCount,
[NSByteCountFormatter stringFromByteCount:totalSize countStyle:NSByteCountFormatterCountStyleFile]];
self.headerTitle = [NSString
stringWithFormat:@"%@ objects, %@",
@(totalCount), [NSByteCountFormatter
stringFromByteCount:totalSize
countStyle:NSByteCountFormatterCountStyleFile
]
];
} else {
title = [title stringByAppendingFormat:@" (filtered, %lu, %@)", (unsigned long)filteredCount,
[NSByteCountFormatter stringFromByteCount:filteredSize countStyle:NSByteCountFormatterCountStyleFile]];
self.headerTitle = [NSString
stringWithFormat:@"%@ of %@ objects, %@",
@(filteredCount), @(totalCount), [NSByteCountFormatter
stringFromByteCount:filteredSize
countStyle:NSByteCountFormatterCountStyleFile
]
];
}

self.title = title;
}


Expand All @@ -135,7 +150,10 @@ + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row {
}

+ (UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row {
return [self new];
FLEXLiveObjectsTableViewController *liveObjectsViewController = [self new];
liveObjectsViewController.title = [self globalsEntryTitle:row];

return liveObjectsViewController;
}


Expand Down Expand Up @@ -172,7 +190,7 @@ - (void)updateSearchResults:(NSString *)filter
}];
}

[self updateTitle];
[self updateHeaderTitle];
[self.tableView reloadData];
}

Expand All @@ -189,26 +207,34 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return self.filteredClassNames.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCell *)tableView:(__kindof UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [FLEXUtility defaultTableViewCellLabelFont];
}

UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:[tableView defaultReuseIdentifier]
forIndexPath:indexPath
];

NSString *className = self.filteredClassNames[indexPath.row];
NSNumber *count = self.instanceCountsForClassNames[className];
NSNumber *size = self.instanceSizesForClassNames[className];
unsigned long totalSize = count.unsignedIntegerValue * size.unsignedIntegerValue;
cell.textLabel.text = [NSString stringWithFormat:@"%@ (%ld, %@)", className, (long)[count integerValue],
[NSByteCountFormatter stringFromByteCount:totalSize countStyle:NSByteCountFormatterCountStyleFile]];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [NSString stringWithFormat:@"%@ (%ld, %@)",
className, (long)[count integerValue],
[NSByteCountFormatter
stringFromByteCount:totalSize
countStyle:NSByteCountFormatterCountStyleFile
]
];

return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return self.headerTitle;
}


#pragma mark - Table view delegate

Expand Down
Loading

0 comments on commit 3e12ad9

Please sign in to comment.