FLEXGlobalsTableViewController.m 8.0 KB

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