Просмотр исходного кода

Add explicit header titles to several screens

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
Tanner Bennett лет назад: 6
Родитель
Сommit
3e12ad9887

+ 2 - 1
Classes/GlobalStateExplorers/FLEXCookiesTableViewController.h

@@ -7,7 +7,8 @@
 //
 //
 
 
 #import "FLEXGlobalsEntry.h"
 #import "FLEXGlobalsEntry.h"
+#import "FLEXTableViewController.h"
 
 
-@interface FLEXCookiesTableViewController : UITableViewController <FLEXGlobalsEntry>
+@interface FLEXCookiesTableViewController : FLEXTableViewController <FLEXGlobalsEntry>
 
 
 @end
 @end

+ 28 - 16
Classes/GlobalStateExplorers/FLEXCookiesTableViewController.m

@@ -11,33 +11,37 @@
 #import "FLEXUtility.h"
 #import "FLEXUtility.h"
 
 
 @interface FLEXCookiesTableViewController ()
 @interface FLEXCookiesTableViewController ()
-
-@property (nonatomic) NSArray<NSHTTPCookie *> *cookies;
-
+@property (nonatomic, readonly) NSArray<NSHTTPCookie *> *cookies;
+@property (nonatomic) NSString *headerTitle;
 @end
 @end
 
 
 @implementation FLEXCookiesTableViewController
 @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 {
 - (NSHTTPCookie *)cookieForRowAtIndexPath:(NSIndexPath *)indexPath {
     return self.cookies[indexPath.row];
     return self.cookies[indexPath.row];
 }
 }
 
 
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-    return 1;
-}
+
+#pragma mark - Table View Data Source
 
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     return self.cookies.count;
     return self.cookies.count;
@@ -61,6 +65,13 @@
     return cell;
     return cell;
 }
 }
 
 
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
+    return self.headerTitle;
+}
+
+
+#pragma mark - Table View Delegate
+
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     NSHTTPCookie *cookie = [self cookieForRowAtIndexPath:indexPath];
     NSHTTPCookie *cookie = [self cookieForRowAtIndexPath:indexPath];
     UIViewController *cookieViewController = (UIViewController *)[FLEXObjectExplorerFactory explorerViewControllerForObject:cookie];
     UIViewController *cookieViewController = (UIViewController *)[FLEXObjectExplorerFactory explorerViewControllerForObject:cookie];
@@ -68,6 +79,7 @@
     [self.navigationController pushViewController:cookieViewController animated:YES];
     [self.navigationController pushViewController:cookieViewController animated:YES];
 }
 }
 
 
+
 #pragma mark - FLEXGlobalsEntry
 #pragma mark - FLEXGlobalsEntry
 
 
 + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row {
 + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row {

+ 23 - 5
Classes/GlobalStateExplorers/FLEXLibrariesTableViewController.m

@@ -16,6 +16,7 @@
 
 
 @property (nonatomic) NSArray<NSString *> *imageNames;
 @property (nonatomic) NSArray<NSString *> *imageNames;
 @property (nonatomic) NSArray<NSString *> *filteredImageNames;
 @property (nonatomic) NSArray<NSString *> *filteredImageNames;
+@property (nonatomic) NSString *headerTitle;
 
 
 @property (nonatomic) Class foundClass;
 @property (nonatomic) Class foundClass;
 
 
@@ -37,6 +38,22 @@
     [super viewDidLoad];
     [super viewDidLoad];
     
     
     self.showsSearchBar = YES;
     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)
+        ];
+    }
 }
 }
 
 
 
 
@@ -120,17 +137,13 @@
     }
     }
     
     
     self.foundClass = NSClassFromString(searchText);
     self.foundClass = NSClassFromString(searchText);
+    [self updateHeaderTitle];
     [self.tableView reloadData];
     [self.tableView reloadData];
 }
 }
 
 
 
 
 #pragma mark - Table View Data Source
 #pragma mark - Table View Data Source
 
 
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-{
-    return 1;
-}
-
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
 {
     return self.filteredImageNames.count + (self.foundClass ? 1 : 0);
     return self.filteredImageNames.count + (self.foundClass ? 1 : 0);
@@ -162,6 +175,11 @@
     return cell;
     return cell;
 }
 }
 
 
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
+{
+    return self.headerTitle;
+}
+
 
 
 #pragma mark - Table View Delegate
 #pragma mark - Table View Delegate
 
 

+ 53 - 27
Classes/GlobalStateExplorers/FLEXLiveObjectsTableViewController.m

@@ -11,6 +11,7 @@
 #import "FLEXInstancesTableViewController.h"
 #import "FLEXInstancesTableViewController.h"
 #import "FLEXUtility.h"
 #import "FLEXUtility.h"
 #import "FLEXScopeCarousel.h"
 #import "FLEXScopeCarousel.h"
+#import "FLEXTableView.h"
 #import <objc/runtime.h>
 #import <objc/runtime.h>
 
 
 static const NSInteger kFLEXLiveObjectsSortAlphabeticallyIndex = 0;
 static const NSInteger kFLEXLiveObjectsSortAlphabeticallyIndex = 0;
@@ -23,15 +24,22 @@ static const NSInteger kFLEXLiveObjectsSortBySizeIndex = 2;
 @property (nonatomic) NSDictionary<NSString *, NSNumber *> *instanceSizesForClassNames;
 @property (nonatomic) NSDictionary<NSString *, NSNumber *> *instanceSizesForClassNames;
 @property (nonatomic, readonly) NSArray<NSString *> *allClassNames;
 @property (nonatomic, readonly) NSArray<NSString *> *allClassNames;
 @property (nonatomic) NSArray<NSString *> *filteredClassNames;
 @property (nonatomic) NSArray<NSString *> *filteredClassNames;
+@property (nonatomic) NSString *headerTitle;
 
 
 @end
 @end
 
 
 @implementation FLEXLiveObjectsTableViewController
 @implementation FLEXLiveObjectsTableViewController
 
 
+- (void)loadView
+{
+    self.tableView = [FLEXTableView flexDefaultTableView];
+}
+
 - (void)viewDidLoad
 - (void)viewDidLoad
 {
 {
     [super viewDidLoad];
     [super viewDidLoad];
-    
+
+//    self.title = @"Live Objects";
     self.showsSearchBar = YES;
     self.showsSearchBar = YES;
     self.searchBarDebounceInterval = kFLEXDebounceInstant;
     self.searchBarDebounceInterval = kFLEXDebounceInstant;
     self.showsCarousel = YES;
     self.showsCarousel = YES;
@@ -96,35 +104,42 @@ static const NSInteger kFLEXLiveObjectsSortBySizeIndex = 2;
     [self.refreshControl endRefreshing];
     [self.refreshControl endRefreshing];
 }
 }
 
 
-- (void)updateTitle
+- (void)updateHeaderTitle
 {
 {
-    NSString *title = @"Live Objects";
-    
     NSUInteger totalCount = 0;
     NSUInteger totalCount = 0;
     NSUInteger totalSize = 0;
     NSUInteger totalSize = 0;
     for (NSString *className in self.allClassNames) {
     for (NSString *className in self.allClassNames) {
-        NSUInteger count = [self.instanceCountsForClassNames[className] unsignedIntegerValue];
+        NSUInteger count = self.instanceCountsForClassNames[className].unsignedIntegerValue;
         totalCount += count;
         totalCount += count;
-        totalSize += count * [self.instanceSizesForClassNames[className] unsignedIntegerValue];
+        totalSize += count * self.instanceSizesForClassNames[className].unsignedIntegerValue;
     }
     }
+
     NSUInteger filteredCount = 0;
     NSUInteger filteredCount = 0;
     NSUInteger filteredSize = 0;
     NSUInteger filteredSize = 0;
     for (NSString *className in self.filteredClassNames) {
     for (NSString *className in self.filteredClassNames) {
-        NSUInteger count = [self.instanceCountsForClassNames[className] unsignedIntegerValue];
+        NSUInteger count = self.instanceCountsForClassNames[className].unsignedIntegerValue;
         filteredCount += count;
         filteredCount += count;
-        filteredSize += count * [self.instanceSizesForClassNames[className] unsignedIntegerValue];
+        filteredSize += count * self.instanceSizesForClassNames[className].unsignedIntegerValue;
     }
     }
     
     
     if (filteredCount == totalCount) {
     if (filteredCount == totalCount) {
         // Unfiltered
         // 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 {
     } 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;
 }
 }
 
 
 
 
@@ -135,7 +150,10 @@ static const NSInteger kFLEXLiveObjectsSortBySizeIndex = 2;
 }
 }
 
 
 + (UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row {
 + (UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row {
-    return [self new];
+    FLEXLiveObjectsTableViewController *liveObjectsViewController = [self new];
+    liveObjectsViewController.title = [self globalsEntryTitle:row];
+
+    return liveObjectsViewController;
 }
 }
 
 
 
 
@@ -172,7 +190,7 @@ static const NSInteger kFLEXLiveObjectsSortBySizeIndex = 2;
         }];
         }];
     }
     }
     
     
-    [self updateTitle];
+    [self updateHeaderTitle];
     [self.tableView reloadData];
     [self.tableView reloadData];
 }
 }
 
 
@@ -189,26 +207,34 @@ static const NSInteger kFLEXLiveObjectsSortBySizeIndex = 2;
     return self.filteredClassNames.count;
     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];
     NSString *className = self.filteredClassNames[indexPath.row];
     NSNumber *count = self.instanceCountsForClassNames[className];
     NSNumber *count = self.instanceCountsForClassNames[className];
     NSNumber *size = self.instanceSizesForClassNames[className];
     NSNumber *size = self.instanceSizesForClassNames[className];
     unsigned long totalSize = count.unsignedIntegerValue * size.unsignedIntegerValue;
     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;
     return cell;
 }
 }
 
 
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
+{
+    return self.headerTitle;
+}
+
 
 
 #pragma mark - Table view delegate
 #pragma mark - Table view delegate
 
 

+ 28 - 15
Classes/GlobalStateExplorers/Keychain/FLEXKeychainTableViewController.m

@@ -13,7 +13,8 @@
 
 
 @interface FLEXKeychainTableViewController ()
 @interface FLEXKeychainTableViewController ()
 
 
-@property (nonatomic) NSArray<NSDictionary *> *keyChainItems;
+@property (nonatomic) NSArray<NSDictionary *> *keychainItems;
+@property (nonatomic) NSString *headerTitle;
 
 
 @end
 @end
 
 
@@ -32,15 +33,21 @@
         ],
         ],
     ];
     ];
 
 
-    [self refreshKeychainItems];
+    [self refreshkeychainItems];
+    [self updateHeaderTitle];
 }
 }
 
 
-- (void)refreshKeychainItems
+- (void)refreshkeychainItems
 {
 {
-    self.keyChainItems = [FLEXKeychain allAccounts];
-    self.title = [NSString stringWithFormat:@"🔑 Keychain Items (%lu)", (unsigned long)self.keyChainItems.count];
+    self.keychainItems = [FLEXKeychain allAccounts];
 }
 }
 
 
+- (void)updateHeaderTitle
+{
+    self.headerTitle = [NSString stringWithFormat:@"%@ items", @(self.keychainItems.count)];
+}
+
+
 #pragma mark Buttons
 #pragma mark Buttons
 
 
 - (void)trashPressed
 - (void)trashPressed
@@ -50,7 +57,7 @@
         make.message(@"This will remove all keychain items for this app.\n");
         make.message(@"This will remove all keychain items for this app.\n");
         make.message(@"This action cannot be undone. Are you sure?");
         make.message(@"This action cannot be undone. Are you sure?");
         make.button(@"Yes, clear the keychain").destructiveStyle().handler(^(NSArray *strings) {
         make.button(@"Yes, clear the keychain").destructiveStyle().handler(^(NSArray *strings) {
-            for (id account in self.keyChainItems) {
+            for (id account in self.keychainItems) {
                 FLEXKeychainQuery *query = [FLEXKeychainQuery new];
                 FLEXKeychainQuery *query = [FLEXKeychainQuery new];
                 query.service = account[kFLEXKeychainWhereKey];
                 query.service = account[kFLEXKeychainWhereKey];
                 query.account = account[kFLEXKeychainAccountKey];
                 query.account = account[kFLEXKeychainAccountKey];
@@ -65,7 +72,7 @@
                 }
                 }
             }
             }
 
 
-            [self refreshKeychainItems];
+            [self refreshkeychainItems];
             [self.tableView reloadData];
             [self.tableView reloadData];
         });
         });
         make.button(@"Cancel").cancelStyle();
         make.button(@"Cancel").cancelStyle();
@@ -87,14 +94,13 @@
                 [FLEXAlert showAlert:@"Error" message:error.localizedDescription from:self];
                 [FLEXAlert showAlert:@"Error" message:error.localizedDescription from:self];
             }
             }
 
 
-            [self refreshKeychainItems];
+            [self refreshkeychainItems];
             [self.tableView reloadData];
             [self.tableView reloadData];
         });
         });
     } showFrom:self];
     } showFrom:self];
 }
 }
 
 
 
 
-
 #pragma mark - FLEXGlobalsEntry
 #pragma mark - FLEXGlobalsEntry
 
 
 + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row
 + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row
@@ -102,9 +108,11 @@
     return @"🔑  Keychain";
     return @"🔑  Keychain";
 }
 }
 
 
-+ (UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row
-{
-    return [self new];
++ (UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row {
+    FLEXKeychainTableViewController *viewController = [self new];
+    viewController.title = [self globalsEntryTitle:row];
+
+    return viewController;
 }
 }
 
 
 
 
@@ -112,7 +120,7 @@
 
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
 {
-    return self.keyChainItems.count;
+    return self.keychainItems.count;
 }
 }
 
 
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
@@ -125,18 +133,23 @@
         cell.textLabel.font = [FLEXUtility defaultTableViewCellLabelFont];
         cell.textLabel.font = [FLEXUtility defaultTableViewCellLabelFont];
     }
     }
     
     
-    NSDictionary *item = self.keyChainItems[indexPath.row];
+    NSDictionary *item = self.keychainItems[indexPath.row];
     cell.textLabel.text = item[kFLEXKeychainAccountKey];
     cell.textLabel.text = item[kFLEXKeychainAccountKey];
     
     
     return cell;
     return cell;
 }
 }
 
 
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
+{
+    return self.headerTitle;
+}
+
 
 
 #pragma mark - Table View Delegate
 #pragma mark - Table View Delegate
 
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
 {
-    NSDictionary *item = self.keyChainItems[indexPath.row];
+    NSDictionary *item = self.keychainItems[indexPath.row];
     
     
     FLEXKeychainQuery *query = [FLEXKeychainQuery new];
     FLEXKeychainQuery *query = [FLEXKeychainQuery new];
     query.service = item[kFLEXKeychainWhereKey];
     query.service = item[kFLEXKeychainWhereKey];