FLEXGlobalsTableViewController.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //
  2. // FLEXGlobalsTableViewController.m
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 2014-05-03.
  6. // Copyright (c) 2014 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXGlobalsTableViewController.h"
  9. #import "FLEXUtility.h"
  10. #import "FLEXLibrariesTableViewController.h"
  11. #import "FLEXClassesTableViewController.h"
  12. #import "FLEXObjectExplorerViewController.h"
  13. #import "FLEXObjectExplorerFactory.h"
  14. #import "FLEXLiveObjectsTableViewController.h"
  15. #import "FLEXFileBrowserTableViewController.h"
  16. typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {
  17. FLEXGlobalsRowAppClasses,
  18. FLEXGlobalsRowSystemLibraries,
  19. FLEXGlobalsRowLiveObjects,
  20. FLEXGlobalsRowAppDelegate,
  21. FLEXGlobalsRowRootViewController,
  22. FLEXGlobalsRowUserDefaults,
  23. FLEXGlobalsRowApplication,
  24. FLEXGlobalsRowKeyWindow,
  25. FLEXGlobalsRowMainScreen,
  26. FLEXGlobalsRowCurrentDevice,
  27. FLEXGlobalsRowFileBrowser
  28. };
  29. @interface FLEXGlobalsTableViewController ()
  30. @property (nonatomic, strong) NSArray *rows;
  31. @end
  32. @implementation FLEXGlobalsTableViewController
  33. - (id)initWithStyle:(UITableViewStyle)style
  34. {
  35. self = [super initWithStyle:style];
  36. if (self) {
  37. self.title = @"🌎 Global State";
  38. }
  39. return self;
  40. }
  41. - (void)viewDidLoad
  42. {
  43. [super viewDidLoad];
  44. self.rows = @[@(FLEXGlobalsRowLiveObjects),
  45. @(FLEXGlobalsRowFileBrowser),
  46. @(FLEXGlobalsRowSystemLibraries),
  47. @(FLEXGlobalsRowAppClasses),
  48. @(FLEXGlobalsRowAppDelegate),
  49. @(FLEXGlobalsRowRootViewController),
  50. @(FLEXGlobalsRowUserDefaults),
  51. @(FLEXGlobalsRowApplication),
  52. @(FLEXGlobalsRowKeyWindow),
  53. @(FLEXGlobalsRowMainScreen),
  54. @(FLEXGlobalsRowCurrentDevice)];
  55. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)];
  56. }
  57. - (void)donePressed:(id)sender
  58. {
  59. [self.delegate globalsViewControllerDidFinish:self];
  60. }
  61. #pragma mark - Table Data Helpers
  62. - (FLEXGlobalsRow)rowTypeAtIndexPath:(NSIndexPath *)indexPath
  63. {
  64. return [[self.rows objectAtIndex:indexPath.row] unsignedIntegerValue];
  65. }
  66. - (NSString *)titleForRowType:(FLEXGlobalsRow)rowType
  67. {
  68. NSString *title = nil;
  69. switch (rowType) {
  70. case FLEXGlobalsRowAppClasses:
  71. title = [NSString stringWithFormat:@"📕 %@ Classes", [FLEXUtility applicationName]];
  72. break;
  73. case FLEXGlobalsRowSystemLibraries:
  74. title = @"📚 System Libraries";
  75. break;
  76. case FLEXGlobalsRowLiveObjects:
  77. title = @"💩 Heap Objects";
  78. break;
  79. case FLEXGlobalsRowAppDelegate:
  80. title = [NSString stringWithFormat:@"👉 %@", [[[UIApplication sharedApplication] delegate] class]];
  81. break;
  82. case FLEXGlobalsRowRootViewController:
  83. title = [NSString stringWithFormat:@"🌴 %@", [[self.applicationWindow rootViewController] class]];
  84. break;
  85. case FLEXGlobalsRowUserDefaults:
  86. title = @"🚶 +[NSUserDefaults standardUserDefaults]";
  87. break;
  88. case FLEXGlobalsRowApplication:
  89. title = @"💾 +[UIApplication sharedApplication]";
  90. break;
  91. case FLEXGlobalsRowKeyWindow:
  92. title = @"🔑 -[UIApplication keyWindow]";
  93. break;
  94. case FLEXGlobalsRowMainScreen:
  95. title = @"💻 +[UIScreen mainScreen]";
  96. break;
  97. case FLEXGlobalsRowCurrentDevice:
  98. title = @"📱 +[UIDevice currentDevice]";
  99. break;
  100. case FLEXGlobalsRowFileBrowser:
  101. title = @"📁 File Browser";
  102. break;
  103. }
  104. return title;
  105. }
  106. - (UIViewController *)drillDownViewControllerForRowType:(FLEXGlobalsRow)rowType
  107. {
  108. UIViewController *viewController = nil;
  109. switch (rowType) {
  110. case FLEXGlobalsRowAppClasses: {
  111. FLEXClassesTableViewController *classesViewController = [[FLEXClassesTableViewController alloc] init];
  112. classesViewController.binaryImageName = [FLEXUtility applicationImageName];
  113. viewController = classesViewController;
  114. } break;
  115. case FLEXGlobalsRowSystemLibraries: {
  116. FLEXLibrariesTableViewController *librariesViewController = [[FLEXLibrariesTableViewController alloc] init];
  117. librariesViewController.title = [self titleForRowType:FLEXGlobalsRowSystemLibraries];
  118. viewController = librariesViewController;
  119. } break;
  120. case FLEXGlobalsRowLiveObjects: {
  121. viewController = [[FLEXLiveObjectsTableViewController alloc] init];
  122. } break;
  123. case FLEXGlobalsRowAppDelegate: {
  124. id <UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
  125. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:appDelegate];
  126. } break;
  127. case FLEXGlobalsRowRootViewController: {
  128. UIViewController *rootViewController = [self.applicationWindow rootViewController];
  129. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:rootViewController];
  130. } break;
  131. case FLEXGlobalsRowUserDefaults: {
  132. NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
  133. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:standardUserDefaults];
  134. } break;
  135. case FLEXGlobalsRowApplication: {
  136. UIApplication *sharedApplication = [UIApplication sharedApplication];
  137. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:sharedApplication];
  138. } break;
  139. case FLEXGlobalsRowKeyWindow: {
  140. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:self.applicationWindow];
  141. } break;
  142. case FLEXGlobalsRowMainScreen: {
  143. UIScreen *mainScreen = [UIScreen mainScreen];
  144. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:mainScreen];
  145. } break;
  146. case FLEXGlobalsRowCurrentDevice: {
  147. UIDevice *currentDevice = [UIDevice currentDevice];
  148. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:currentDevice];
  149. } break;
  150. case FLEXGlobalsRowFileBrowser: {
  151. viewController = [[FLEXFileBrowserTableViewController alloc] init];
  152. }
  153. }
  154. return viewController;
  155. }
  156. #pragma mark - Table View Data Source
  157. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  158. {
  159. return 1;
  160. }
  161. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  162. {
  163. return [self.rows count];
  164. }
  165. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  166. {
  167. static NSString *CellIdentifier = @"Cell";
  168. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  169. if (!cell) {
  170. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  171. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  172. cell.textLabel.font = [FLEXUtility defaultTableViewCellLabelFont];
  173. }
  174. FLEXGlobalsRow rowType = [self rowTypeAtIndexPath:indexPath];
  175. cell.textLabel.text = [self titleForRowType:rowType];
  176. return cell;
  177. }
  178. #pragma mark - Table View Delegate
  179. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  180. {
  181. FLEXGlobalsRow rowType = [self rowTypeAtIndexPath:indexPath];
  182. UIViewController *drillDownViewController = [self drillDownViewControllerForRowType:rowType];
  183. [self.navigationController pushViewController:drillDownViewController animated:YES];
  184. }
  185. @end