Skip to content

Commit

Permalink
Re-organize + group the globals list into sections
Browse files Browse the repository at this point in the history
  • Loading branch information
NSExceptional committed Jul 11, 2019
1 parent c3bb4ff commit 85cc51b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Classes/GlobalStateExplorers/FLEXGlobalsTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Copyright (c) 2014 Flipboard. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "FLEXTableViewController.h"

@protocol FLEXGlobalsTableViewControllerDelegate;

@interface FLEXGlobalsTableViewController : UITableViewController
@interface FLEXGlobalsTableViewController : FLEXTableViewController

@property (nonatomic, weak) id <FLEXGlobalsTableViewControllerDelegate> delegate;

Expand Down
103 changes: 78 additions & 25 deletions Classes/GlobalStateExplorers/FLEXGlobalsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@

static __weak UIWindow *s_applicationWindow = nil;

typedef NS_ENUM(NSUInteger, FLEXGlobalsSection) {
/// NSProcessInfo, Network history, system log,
/// heap, address explorer, libraries, app classes
FLEXGlobalsSectionProcessAndEvents,
/// Browse container, browse bundle, NSBundle.main,
/// NSUserDefaults.standard, UIApplication,
/// app delegate, key window, root VC, cookies
FLEXGlobalsSectionAppShortcuts,
/// UIPasteBoard.general, UIScreen, UIDevice
FLEXGlobalsSectionMisc,
FLEXGlobalsSectionCustom,
FLEXGlobalsSectionCount
};

typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {
FLEXGlobalsRowNetworkHistory,
FLEXGlobalsRowSystemLog,
FLEXGlobalsRowLiveObjects,
FLEXGlobalsRowAddressInspector,
FLEXGlobalsRowFileBrowser,
FLEXGlobalsCookies,
FLEXGlobalsRowCookies,
FLEXGlobalsRowSystemLibraries,
FLEXGlobalsRowAppClasses,
FLEXGlobalsRowAppDelegate,
Expand All @@ -46,13 +60,31 @@ typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {

@interface FLEXGlobalsTableViewController ()

@property (nonatomic, readonly) NSArray<FLEXGlobalsTableViewControllerEntry *> *entries;
@property (nonatomic, readonly) NSArray<NSArray<FLEXGlobalsTableViewControllerEntry *> *> *sections;

@end

@implementation FLEXGlobalsTableViewController

+ (FLEXGlobalsTableViewControllerEntry *)globalsEntryForRow:(FLEXGlobalsRow)row {
+ (NSString *)globalsTitleForSection:(FLEXGlobalsSection)section
{
switch (section) {
case FLEXGlobalsSectionProcessAndEvents:
return @"Process and Events";
case FLEXGlobalsSectionAppShortcuts:
return @"App Shortcuts";
case FLEXGlobalsSectionMisc:
return @"Miscellaneous";
case FLEXGlobalsSectionCustom:
return @"Custom Additions";

default:
@throw NSInternalInconsistencyException;
}
}

+ (FLEXGlobalsTableViewControllerEntry *)globalsEntryForRow:(FLEXGlobalsRow)row
{
switch (row) {
case FLEXGlobalsRowAppClasses:
return [FLEXClassesTableViewController flex_concreteGlobalsEntry];
Expand All @@ -62,7 +94,7 @@ + (FLEXGlobalsTableViewControllerEntry *)globalsEntryForRow:(FLEXGlobalsRow)row
return [FLEXLibrariesTableViewController flex_concreteGlobalsEntry];
case FLEXGlobalsRowLiveObjects:
return [FLEXLiveObjectsTableViewController flex_concreteGlobalsEntry];
case FLEXGlobalsCookies:
case FLEXGlobalsRowCookies:
return [FLEXCookiesTableViewController flex_concreteGlobalsEntry];
case FLEXGlobalsRowFileBrowser:
return [FLEXFileBrowserTableViewController flex_concreteGlobalsEntry];
Expand Down Expand Up @@ -148,24 +180,31 @@ + (FLEXGlobalsTableViewControllerEntry *)globalsEntryForRow:(FLEXGlobalsRow)row
}
}

+ (NSArray<FLEXGlobalsTableViewControllerEntry *> *)defaultGlobalEntries
{
NSMutableArray<FLEXGlobalsTableViewControllerEntry *> *defaultGlobalEntries = [NSMutableArray array];
for (FLEXGlobalsRow defaultRowIndex = 0; defaultRowIndex < FLEXGlobalsRowCount; defaultRowIndex++) {
[defaultGlobalEntries addObject:[self globalsEntryForRow:defaultRowIndex]];
}

return defaultGlobalEntries;
}

- (id)initWithStyle:(UITableViewStyle)style
+ (NSArray<NSArray<FLEXGlobalsTableViewControllerEntry *> *> *)defaultGlobalSections
{
self = [super initWithStyle:style];
if (self) {
self.title = @"💪 FLEX";
_entries = [[[self class] defaultGlobalEntries] arrayByAddingObjectsFromArray:[FLEXManager sharedManager].userGlobalEntries];
}
return self;
return @[
@[ // FLEXGlobalsSectionProcess
[self globalsEntryForRow:FLEXGlobalsRowNetworkHistory],
[self globalsEntryForRow:FLEXGlobalsRowSystemLog],
[self globalsEntryForRow:FLEXGlobalsRowLiveObjects],
[self globalsEntryForRow:FLEXGlobalsRowAddressInspector],
[self globalsEntryForRow:FLEXGlobalsRowSystemLibraries],
[self globalsEntryForRow:FLEXGlobalsRowAppClasses],
],
@[ // FLEXGlobalsSectionAppShortcuts
[self globalsEntryForRow:FLEXGlobalsRowMainBundle],
[self globalsEntryForRow:FLEXGlobalsRowUserDefaults],
[self globalsEntryForRow:FLEXGlobalsRowApplication],
[self globalsEntryForRow:FLEXGlobalsRowAppDelegate],
[self globalsEntryForRow:FLEXGlobalsRowKeyWindow],
[self globalsEntryForRow:FLEXGlobalsRowRootViewController],
[self globalsEntryForRow:FLEXGlobalsRowCookies],
],
@[ // FLEXGlobalsSectionMisc
[self globalsEntryForRow:FLEXGlobalsRowMainScreen],
[self globalsEntryForRow:FLEXGlobalsRowCurrentDevice],
]
];
}

#pragma mark - Public
Expand All @@ -180,7 +219,16 @@ + (void)setApplicationWindow:(UIWindow *)applicationWindow
- (void)viewDidLoad
{
[super viewDidLoad];


self.title = @"💪 FLEX";

// Table view data
_sections = [[self class] defaultGlobalSections];
if ([FLEXManager sharedManager].userGlobalEntries.count) {
_sections = [_sections arrayByAddingObject:[FLEXManager sharedManager].userGlobalEntries];
}

// Done button
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)];
}

Expand All @@ -195,7 +243,7 @@ - (void)donePressed:(id)sender

- (FLEXGlobalsTableViewControllerEntry *)globalEntryAtIndexPath:(NSIndexPath *)indexPath
{
return self.entries[indexPath.row];
return self.sections[indexPath.section][indexPath.row];
}

- (NSString *)titleForRowAtIndexPath:(NSIndexPath *)indexPath
Expand All @@ -209,12 +257,12 @@ - (NSString *)titleForRowAtIndexPath:(NSIndexPath *)indexPath

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
return self.sections.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.entries count];
return self.sections[section].count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Expand All @@ -232,6 +280,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[self class] globalsTitleForSection:section];
}

#pragma mark - Table View Delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down

0 comments on commit 85cc51b

Please sign in to comment.