iOS web browser with a focus on security and privacy
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

RuleEditorController: make rows RuleEditorRow objects, not just strings

+104 -58
+26 -21
Endless/HTTPSEverywhereRuleController.m
··· 1 1 /* 2 2 * Endless 3 - * Copyright (c) 2014-2015 joshua stein <jcs@jcs.org> 3 + * Copyright (c) 2014-2017 joshua stein <jcs@jcs.org> 4 4 * 5 5 * See LICENSE file for redistribution terms. 6 6 */ ··· 17 17 18 18 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self.navigationController action:@selector(dismissModalViewControllerAnimated:)]; 19 19 20 - self.sortedRuleNames = [[NSMutableArray alloc] initWithCapacity:[[HTTPSEverywhere rules] count]]; 20 + self.sortedRuleRows = [[NSMutableArray alloc] initWithCapacity:[[HTTPSEverywhere rules] count]]; 21 + self.inUseRuleRows = [[NSMutableArray alloc] init]; 21 22 22 - if ([[self.appDelegate webViewController] curWebViewTab] != nil) { 23 - self.inUseRuleNames = [[NSMutableArray alloc] initWithArray:[[[[[self.appDelegate webViewController] curWebViewTab] applicableHTTPSEverywhereRules] allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]]; 23 + NSDictionary *inUse = nil; 24 + if ([[self.appDelegate webViewController] curWebViewTab] != nil) 25 + inUse = [[[self.appDelegate webViewController] curWebViewTab] applicableHTTPSEverywhereRules]; 26 + 27 + for (NSString *k in [[[HTTPSEverywhere rules] allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]) { 28 + RuleEditorRow *row = [[RuleEditorRow alloc] init]; 29 + row.key = k; 30 + row.textLabel = k; 31 + 32 + if (inUse && [inUse objectForKey:k]) 33 + [self.inUseRuleRows addObject:row]; 34 + else 35 + [self.sortedRuleRows addObject:row]; 24 36 } 25 - else { 26 - self.inUseRuleNames = [[NSMutableArray alloc] init]; 27 - } 28 - 29 - for (NSString *k in [[HTTPSEverywhere rules] allKeys]) { 30 - if (![self.inUseRuleNames containsObject:k]) 31 - [self.sortedRuleNames addObject:k]; 32 - } 33 - 34 - self.sortedRuleNames = [NSMutableArray arrayWithArray:[self.sortedRuleNames sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]]; 35 - self.searchResult = [NSMutableArray arrayWithCapacity:[self.sortedRuleNames count]]; 37 + 38 + self.inUseRuleRows = [NSMutableArray arrayWithArray:self.inUseRuleRows]; 39 + self.sortedRuleRows = [NSMutableArray arrayWithArray:self.sortedRuleRows]; 36 40 37 41 self.title = @"HTTPS Everywhere Rules"; 38 42 39 43 return self; 40 44 } 41 45 42 - - (NSString *)ruleDisabledReason:(NSString *)rule 46 + 47 + - (NSString *)ruleDisabledReason:(RuleEditorRow *)row 43 48 { 44 - return [[HTTPSEverywhere disabledRules] objectForKey:rule]; 49 + return [[HTTPSEverywhere disabledRules] objectForKey:[row key]]; 45 50 } 46 51 47 - - (void)disableRuleByName:(NSString *)rule withReason:(NSString *)reason 52 + - (void)disableRuleForRow:(RuleEditorRow *)row withReason:(NSString *)reason 48 53 { 49 - [HTTPSEverywhere disableRuleByName:rule withReason:reason]; 54 + [HTTPSEverywhere disableRuleByName:[row key] withReason:reason]; 50 55 } 51 56 52 - - (void)enableRuleByName:(NSString *)rule 57 + - (void)enableRuleForRow:(RuleEditorRow *)row 53 58 { 54 - [HTTPSEverywhere enableRuleByName:rule]; 59 + [HTTPSEverywhere enableRuleByName:[row key]]; 55 60 } 56 61 57 62 @end
+8 -7
Endless/RuleEditorController.h
··· 1 1 /* 2 2 * Endless 3 - * Copyright (c) 2014-2015 joshua stein <jcs@jcs.org> 3 + * Copyright (c) 2014-2017 joshua stein <jcs@jcs.org> 4 4 * 5 5 * See LICENSE file for redistribution terms. 6 6 */ 7 7 8 8 #import <UIKit/UIKit.h> 9 9 #import "AppDelegate.h" 10 + #import "RuleEditorRow.h" 10 11 11 12 @interface RuleEditorController : UITableViewController <UISearchBarDelegate, UISearchDisplayDelegate, UITableViewDelegate> 12 13 13 14 @property AppDelegate *appDelegate; 14 - @property NSMutableArray *sortedRuleNames; 15 - @property NSMutableArray *inUseRuleNames; 15 + @property NSMutableArray<RuleEditorRow *> *sortedRuleRows; 16 + @property NSMutableArray<RuleEditorRow *> *inUseRuleRows; 16 17 17 18 @property UISearchBar *searchBar; 18 - @property NSMutableArray *searchResult; 19 + @property NSMutableArray<RuleEditorRow *> *searchResult; 19 20 20 - - (NSString *)ruleDisabledReason:(NSString *)rule; 21 - - (void)disableRuleByName:(NSString *)rule withReason:(NSString *)reason; 22 - - (void)enableRuleByName:(NSString *)rule; 21 + - (NSString *)ruleDisabledReason:(RuleEditorRow *)row; 22 + - (void)disableRuleForRow:(RuleEditorRow *)row withReason:(NSString *)reason; 23 + - (void)enableRuleForRow:(RuleEditorRow *)row; 23 24 24 25 @end
+42 -30
Endless/RuleEditorController.m
··· 1 1 /* 2 2 * Endless 3 - * Copyright (c) 2014-2015 joshua stein <jcs@jcs.org> 3 + * Copyright (c) 2014-2017 joshua stein <jcs@jcs.org> 4 4 * 5 5 * See LICENSE file for redistribution terms. 6 6 */ ··· 17 17 18 18 self.appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 19 19 20 - self.sortedRuleNames = [[NSMutableArray alloc] init]; 21 - self.inUseRuleNames = [[NSMutableArray alloc] init]; 20 + self.sortedRuleRows = [[NSMutableArray alloc] init]; 21 + self.inUseRuleRows = [[NSMutableArray alloc] init]; 22 22 23 23 self.searchResult = [[NSMutableArray alloc] init]; 24 24 ··· 38 38 [[self tableView] setTableHeaderView:self.searchBar]; 39 39 } 40 40 41 - - (void)didReceiveMemoryWarning 42 - { 43 - [super didReceiveMemoryWarning]; 44 - // Dispose of any resources that can be recreated. 45 - } 46 - 47 41 #pragma mark - Table view data source 48 42 49 43 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView ··· 62 56 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 63 57 { 64 58 if (section == 0) 65 - return [self.inUseRuleNames count]; 59 + return [self.inUseRuleRows count]; 66 60 else if (tableView == self.searchDisplayController.searchResultsTableView) 67 61 return [self.searchResult count]; 68 62 else 69 - return [self.sortedRuleNames count]; 63 + return [self.sortedRuleRows count]; 70 64 } 71 65 72 66 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath ··· 78 72 /* TODO: once we have a per-rule view page, enable this */ 79 73 //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 80 74 81 - cell.textLabel.text = [self ruleForTableView:tableView atIndexPath:indexPath]; 75 + RuleEditorRow *row = [self ruleForTableView:tableView atIndexPath:indexPath]; 76 + 77 + cell.textLabel.text = [row textLabel]; 82 78 83 - NSString *disabled = [self ruleDisabledReason:cell.textLabel.text]; 79 + NSString *disabled = [self ruleDisabledReason:row]; 84 80 if (disabled == nil) { 85 81 cell.textLabel.textColor = [UIColor darkTextColor]; 86 - cell.detailTextLabel.text = nil; 82 + cell.detailTextLabel.text = [row detailTextLabel]; 87 83 } 88 84 else { 89 85 cell.textLabel.textColor = [UIColor redColor]; 90 - cell.detailTextLabel.text = [NSString stringWithFormat:@"Disabled: %@", disabled]; 86 + if ([row detailTextLabel] == nil || [[row detailTextLabel] isEqualToString:@""]) 87 + cell.detailTextLabel.text = [NSString stringWithFormat:@"Disabled: %@", disabled]; 88 + else 89 + cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ (Disabled: %@)", [row detailTextLabel], disabled]; 91 90 cell.detailTextLabel.textColor = [UIColor redColor]; 92 91 } 93 92 ··· 107 106 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 108 107 { 109 108 if (editingStyle == UITableViewCellEditingStyleDelete) { 110 - NSString *row = [self ruleForTableView:tableView atIndexPath:indexPath]; 109 + RuleEditorRow *row = [self ruleForTableView:tableView atIndexPath:indexPath]; 111 110 112 111 if ([self ruleDisabledReason:row] == nil) 113 - [self disableRuleByName:row withReason:@"User disabled"]; 112 + [self disableRuleForRow:row withReason:@"User disabled"]; 114 113 else 115 - [self enableRuleByName:row]; 114 + [self enableRuleForRow:row]; 116 115 } 117 116 118 117 [tableView reloadData]; ··· 127 126 { 128 127 [self.searchResult removeAllObjects]; 129 128 130 - for (NSString *ruleName in self.sortedRuleNames) { 131 - NSRange range = [ruleName rangeOfString:searchString options:NSCaseInsensitiveSearch]; 129 + for (RuleEditorRow *row in self.sortedRuleRows) { 130 + if ([row textLabel] != nil) { 131 + NSRange range = [[row textLabel] rangeOfString:searchString options:NSCaseInsensitiveSearch]; 132 + 133 + if (range.length > 0) { 134 + [self.searchResult addObject:row]; 135 + continue; 136 + } 137 + } 138 + if ([row detailTextLabel] != nil) { 139 + NSRange range = [[row detailTextLabel] rangeOfString:searchString options:NSCaseInsensitiveSearch]; 132 140 133 - if (range.length > 0) 134 - [self.searchResult addObject:ruleName]; 141 + if (range.length > 0) { 142 + [self.searchResult addObject:row]; 143 + continue; 144 + } 145 + } 135 146 } 136 147 137 148 return YES; 138 149 } 139 150 140 - -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { 141 - NSString *row = [self ruleForTableView:tableView atIndexPath:indexPath]; 151 + - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(nonnull NSIndexPath *)indexPath 152 + { 153 + RuleEditorRow *row = [self ruleForTableView:tableView atIndexPath:indexPath]; 142 154 143 155 if ([self ruleDisabledReason:row] == nil) 144 156 return @"Disable"; ··· 146 158 return @"Enable"; 147 159 } 148 160 149 - - (NSString *)ruleForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath 161 + - (RuleEditorRow *)ruleForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath 150 162 { 151 163 NSMutableArray *group; 152 164 153 165 if ([indexPath section] == 0) 154 - group = [self inUseRuleNames]; 166 + group = [self inUseRuleRows]; 155 167 else if (tableView == self.searchDisplayController.searchResultsTableView) 156 168 group = [self searchResult]; 157 169 else 158 - group = [self sortedRuleNames]; 170 + group = [self sortedRuleRows]; 159 171 160 172 if (group && [group count] > [indexPath row]) 161 173 return [group objectAtIndex:indexPath.row]; ··· 163 175 return nil; 164 176 } 165 177 166 - - (NSString *)ruleDisabledReason:(NSString *)rule 178 + - (NSString *)ruleDisabledReason:(RuleEditorRow *)row 167 179 { 168 180 return nil; 169 181 } 170 182 171 - - (void)disableRuleByName:(NSString *)rule withReason:(NSString *)reason 183 + - (void)disableRuleForRow:(RuleEditorRow *)row withReason:(NSString *)reason 172 184 { 173 185 abort(); 174 186 } 175 187 176 - - (void)enableRuleByName:(NSString *)rule 188 + - (void)enableRuleForRow:(RuleEditorRow *)row 177 189 { 178 190 abort(); 179 191 }
+16
Endless/RuleEditorRow.h
··· 1 + /* 2 + * Endless 3 + * Copyright (c) 2017 joshua stein <jcs@jcs.org> 4 + * 5 + * See LICENSE file for redistribution terms. 6 + */ 7 + 8 + #import <Foundation/Foundation.h> 9 + 10 + @interface RuleEditorRow : NSObject 11 + 12 + @property NSString *textLabel; 13 + @property NSString *detailTextLabel; 14 + @property NSString *key; 15 + 16 + @end
+12
Endless/RuleEditorRow.m
··· 1 + /* 2 + * Endless 3 + * Copyright (c) 2017 joshua stein <jcs@jcs.org> 4 + * 5 + * See LICENSE file for redistribution terms. 6 + */ 7 + 8 + #import "RuleEditorRow.h" 9 + 10 + @implementation RuleEditorRow 11 + 12 + @end