FLEXGlobalsTableViewController.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. - (BOOL)prefersStatusBarHidden
  42. {
  43. return YES;
  44. }
  45. - (void)viewDidLoad
  46. {
  47. [super viewDidLoad];
  48. self.rows = @[@(FLEXGlobalsRowLiveObjects),
  49. @(FLEXGlobalsRowFileBrowser),
  50. @(FLEXGlobalsRowSystemLibraries),
  51. @(FLEXGlobalsRowAppClasses),
  52. @(FLEXGlobalsRowAppDelegate),
  53. @(FLEXGlobalsRowRootViewController),
  54. @(FLEXGlobalsRowUserDefaults),
  55. @(FLEXGlobalsRowApplication),
  56. @(FLEXGlobalsRowKeyWindow),
  57. @(FLEXGlobalsRowMainScreen),
  58. @(FLEXGlobalsRowCurrentDevice)];
  59. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)];
  60. }
  61. - (void)donePressed:(id)sender
  62. {
  63. [self.delegate globalsViewControllerDidFinish:self];
  64. }
  65. #pragma mark - Table Data Helpers
  66. - (FLEXGlobalsRow)rowTypeAtIndexPath:(NSIndexPath *)indexPath
  67. {
  68. return [[self.rows objectAtIndex:indexPath.row] unsignedIntegerValue];
  69. }
  70. - (NSString *)titleForRowType:(FLEXGlobalsRow)rowType
  71. {
  72. NSString *title = nil;
  73. switch (rowType) {
  74. case FLEXGlobalsRowAppClasses:
  75. title = [NSString stringWithFormat:@"📕 %@ Classes", [FLEXUtility applicationName]];
  76. break;
  77. case FLEXGlobalsRowSystemLibraries:
  78. title = @"📚 System Libraries";
  79. break;
  80. case FLEXGlobalsRowLiveObjects:
  81. title = @"💩 Heap Objects";
  82. break;
  83. case FLEXGlobalsRowAppDelegate:
  84. title = [NSString stringWithFormat:@"👉 %@", [[[UIApplication sharedApplication] delegate] class]];
  85. break;
  86. case FLEXGlobalsRowRootViewController:
  87. title = [NSString stringWithFormat:@"🌴 %@", [[self.applicationWindow rootViewController] class]];
  88. break;
  89. case FLEXGlobalsRowUserDefaults:
  90. title = @"🚶 +[NSUserDefaults standardUserDefaults]";
  91. break;
  92. case FLEXGlobalsRowApplication:
  93. title = @"💾 +[UIApplication sharedApplication]";
  94. break;
  95. case FLEXGlobalsRowKeyWindow:
  96. title = @"🔑 -[UIApplication keyWindow]";
  97. break;
  98. case FLEXGlobalsRowMainScreen:
  99. title = @"💻 +[UIScreen mainScreen]";
  100. break;
  101. case FLEXGlobalsRowCurrentDevice:
  102. title = @"📱 +[UIDevice currentDevice]";
  103. break;
  104. case FLEXGlobalsRowFileBrowser:
  105. title = @"📁 File Browser";
  106. break;
  107. }
  108. return title;
  109. }
  110. - (UIViewController *)drillDownViewControllerForRowType:(FLEXGlobalsRow)rowType
  111. {
  112. UIViewController *viewController = nil;
  113. switch (rowType) {
  114. case FLEXGlobalsRowAppClasses: {
  115. FLEXClassesTableViewController *classesViewController = [[FLEXClassesTableViewController alloc] init];
  116. classesViewController.binaryImageName = [FLEXUtility applicationImageName];
  117. viewController = classesViewController;
  118. } break;
  119. case FLEXGlobalsRowSystemLibraries: {
  120. FLEXLibrariesTableViewController *librariesViewController = [[FLEXLibrariesTableViewController alloc] init];
  121. librariesViewController.title = [self titleForRowType:FLEXGlobalsRowSystemLibraries];
  122. viewController = librariesViewController;
  123. } break;
  124. case FLEXGlobalsRowLiveObjects: {
  125. viewController = [[FLEXLiveObjectsTableViewController alloc] init];
  126. } break;
  127. case FLEXGlobalsRowAppDelegate: {
  128. id <UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
  129. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:appDelegate];
  130. } break;
  131. case FLEXGlobalsRowRootViewController: {
  132. UIViewController *rootViewController = [self.applicationWindow rootViewController];
  133. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:rootViewController];
  134. } break;
  135. case FLEXGlobalsRowUserDefaults: {
  136. NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
  137. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:standardUserDefaults];
  138. } break;
  139. case FLEXGlobalsRowApplication: {
  140. UIApplication *sharedApplication = [UIApplication sharedApplication];
  141. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:sharedApplication];
  142. } break;
  143. case FLEXGlobalsRowKeyWindow: {
  144. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:self.applicationWindow];
  145. } break;
  146. case FLEXGlobalsRowMainScreen: {
  147. UIScreen *mainScreen = [UIScreen mainScreen];
  148. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:mainScreen];
  149. } break;
  150. case FLEXGlobalsRowCurrentDevice: {
  151. UIDevice *currentDevice = [UIDevice currentDevice];
  152. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:currentDevice];
  153. } break;
  154. case FLEXGlobalsRowFileBrowser: {
  155. viewController = [[FLEXFileBrowserTableViewController alloc] init];
  156. }
  157. }
  158. return viewController;
  159. }
  160. #pragma mark - Table View Data Source
  161. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  162. {
  163. return 1;
  164. }
  165. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  166. {
  167. return [self.rows count];
  168. }
  169. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  170. {
  171. static NSString *CellIdentifier = @"Cell";
  172. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  173. if (!cell) {
  174. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  175. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  176. cell.textLabel.font = [FLEXUtility defaultTableViewCellLabelFont];
  177. }
  178. FLEXGlobalsRow rowType = [self rowTypeAtIndexPath:indexPath];
  179. cell.textLabel.text = [self titleForRowType:rowType];
  180. return cell;
  181. }
  182. #pragma mark - Table View Delegate
  183. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  184. {
  185. FLEXGlobalsRow rowType = [self rowTypeAtIndexPath:indexPath];
  186. UIViewController *drillDownViewController = [self drillDownViewControllerForRowType:rowType];
  187. [self.navigationController pushViewController:drillDownViewController animated:YES];
  188. }
  189. @end