iOS web browser with a focus on security and privacy
1/*
2 * Endless
3 * Copyright (c) 2018 joshua stein <jcs@jcs.org>
4 *
5 * See LICENSE file for redistribution terms.
6 */
7
8#import "AppDelegate.h"
9#import "HistoryController.h"
10
11@implementation HistoryController {
12 AppDelegate *appDelegate;
13 WebViewTab *tab;
14 NSArray *history;
15}
16
17- (HistoryController *)initForTab:(WebViewTab *)_tab
18{
19 self = [self init];
20 tab = _tab;
21
22 NSMutableArray *historyCopy = [[tab history] mutableCopy];
23
24 /* we don't need the current page */
25 [historyCopy removeLastObject];
26
27 /* and show in reverse order */
28 history = [[historyCopy reverseObjectEnumerator] allObjects];
29
30 return self;
31}
32
33- (void)viewDidLoad
34{
35 [super viewDidLoad];
36
37 appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
38
39 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", nil) style:UIBarButtonItemStyleDone target:self.navigationController action:@selector(dismissModalViewControllerAnimated:)];
40
41 self.title = NSLocalizedString(@"History", nil);
42
43 if ([[appDelegate webViewController] darkInterface])
44 [[self tableView] setBackgroundColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0]];
45}
46
47- (void)viewWillDisappear:(BOOL)animated
48{
49 [super viewWillDisappear:animated];
50}
51
52#pragma mark - Table view data source
53
54- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
55{
56 return 1;
57}
58
59- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
60{
61 if (section == 0)
62 return [history count];
63 else
64 return 0;
65}
66
67- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
68{
69 return NSLocalizedString(@"History", nil);
70}
71
72- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
73{
74 NSDictionary *hitem = [history objectAtIndex:[indexPath row]];
75
76 if (hitem == nil)
77 return nil;
78
79 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"history"];
80 if (cell == nil)
81 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"history"];
82
83 cell.textLabel.text = [hitem objectForKey:@"title"];
84 cell.detailTextLabel.text = [hitem objectForKey:@"url"];
85
86 [cell setShowsReorderControl:NO];
87
88 if ([[appDelegate webViewController] darkInterface]) {
89 [cell setBackgroundColor:[UIColor clearColor]];
90 [[cell textLabel] setTextColor:[UIColor whiteColor]];
91 [[cell detailTextLabel] setTextColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]];
92 }
93
94 return cell;
95}
96
97- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
98{
99 NSDictionary *hitem = [history objectAtIndex:[indexPath row]];
100
101 if (hitem != nil)
102 [tab loadURL:[NSURL URLWithString:[hitem objectForKey:@"url"]]];
103
104 [self dismissViewControllerAnimated:YES completion:nil];
105}
106
107- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
108{
109 return YES;
110}
111
112- (void)close
113{
114 [self removeFromParentViewController];
115 [[self view] removeFromSuperview];
116}
117
118@end
119