You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.4 KiB

  1. //
  2. // FLEXCookiesTableViewController.m
  3. // FLEX
  4. //
  5. // Created by Rich Robinson on 19/10/2015.
  6. // Copyright © 2015 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXCookiesTableViewController.h"
  9. #import "FLEXObjectExplorerFactory.h"
  10. #import "FLEXUtility.h"
  11. @interface FLEXCookiesTableViewController ()
  12. @property (nonatomic, strong) NSArray<NSHTTPCookie *> *cookies;
  13. @end
  14. @implementation FLEXCookiesTableViewController
  15. - (id)initWithStyle:(UITableViewStyle)style {
  16. self = [super initWithStyle:style];
  17. if (self) {
  18. self.title = @"Cookies";
  19. NSSortDescriptor *nameSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)];
  20. _cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage].cookies sortedArrayUsingDescriptors:@[nameSortDescriptor]];
  21. }
  22. return self;
  23. }
  24. - (NSHTTPCookie *)cookieForRowAtIndexPath:(NSIndexPath *)indexPath {
  25. return self.cookies[indexPath.row];
  26. }
  27. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  28. return 1;
  29. }
  30. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  31. return self.cookies.count;
  32. }
  33. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  34. static NSString *CellIdentifier = @"Cell";
  35. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  36. if (!cell) {
  37. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
  38. cell.textLabel.font = [FLEXUtility defaultTableViewCellLabelFont];
  39. cell.detailTextLabel.font = [FLEXUtility defaultTableViewCellLabelFont];
  40. cell.detailTextLabel.textColor = [UIColor grayColor];
  41. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  42. }
  43. NSHTTPCookie *cookie = [self cookieForRowAtIndexPath:indexPath];
  44. cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)", cookie.name, cookie.value];
  45. cell.detailTextLabel.text = cookie.domain;
  46. return cell;
  47. }
  48. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  49. NSHTTPCookie *cookie = [self cookieForRowAtIndexPath:indexPath];
  50. UIViewController *cookieViewController = (UIViewController *)[FLEXObjectExplorerFactory explorerViewControllerForObject:cookie];
  51. [self.navigationController pushViewController:cookieViewController animated:YES];
  52. }
  53. @end