FLEXCookiesViewController.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // FLEXCookiesViewController.m
  3. // FLEX
  4. //
  5. // Created by Rich Robinson on 19/10/2015.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXCookiesViewController.h"
  9. #import "FLEXObjectExplorerFactory.h"
  10. #import "FLEXMutableListSection.h"
  11. #import "FLEXUtility.h"
  12. @interface FLEXCookiesViewController ()
  13. @property (nonatomic, readonly) FLEXMutableListSection<NSHTTPCookie *> *cookies;
  14. @property (nonatomic) NSString *headerTitle;
  15. @end
  16. @implementation FLEXCookiesViewController
  17. #pragma mark - Overrides
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.title = @"Cookies";
  21. }
  22. - (NSArray<FLEXTableViewSection *> *)makeSections {
  23. NSSortDescriptor *nameSortDescriptor = [[NSSortDescriptor alloc]
  24. initWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)
  25. ];
  26. NSArray *cookies = [NSHTTPCookieStorage.sharedHTTPCookieStorage.cookies
  27. sortedArrayUsingDescriptors:@[nameSortDescriptor]
  28. ];
  29. _cookies = [FLEXMutableListSection list:cookies
  30. cellConfiguration:^(UITableViewCell *cell, NSHTTPCookie *cookie, NSInteger row) {
  31. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  32. cell.textLabel.text = [cookie.name stringByAppendingFormat:@" (%@)", cookie.value];
  33. cell.detailTextLabel.text = [cookie.domain stringByAppendingFormat:@" — %@", cookie.path];
  34. } filterMatcher:^BOOL(NSString *filterText, NSHTTPCookie *cookie) {
  35. return [cookie.name localizedCaseInsensitiveContainsString:filterText] ||
  36. [cookie.value localizedCaseInsensitiveContainsString:filterText] ||
  37. [cookie.domain localizedCaseInsensitiveContainsString:filterText] ||
  38. [cookie.path localizedCaseInsensitiveContainsString:filterText];
  39. }
  40. ];
  41. self.cookies.selectionHandler = ^(UIViewController *host, NSHTTPCookie *cookie) {
  42. [host.navigationController pushViewController:[
  43. FLEXObjectExplorerFactory explorerViewControllerForObject:cookie
  44. ] animated:YES];
  45. };
  46. return @[self.cookies];
  47. }
  48. - (void)reloadData {
  49. self.headerTitle = [NSString stringWithFormat:
  50. @"%@ cookies", @(self.cookies.filteredList.count)
  51. ];
  52. [super reloadData];
  53. }
  54. #pragma mark - FLEXGlobalsEntry
  55. + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row {
  56. return @"🍪 Cookies";
  57. }
  58. + (UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row {
  59. return [self new];
  60. }
  61. @end