Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3241 - Make filter list URL configurable in devbuilds #30

Closed
wants to merge 20 commits into from

Conversation

dedecej
Copy link
Contributor

@dedecej dedecej commented Mar 14, 2016

Related to Issue 3241.

@@ -804,6 +845,36 @@
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AdblockPlusSafariTests/Pods-AdblockPlusSafariTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
83C19D903DD1D9F927CBD253 /* Copy Pods Resources */ = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, how I interpret this is, XCode got upgraded in the mean time and there are some pods related changes happening because of that? Could we put these in a separate commit? No need for an issue, just something like: "Noissue - XCode project file updates" would do. Then I can merge that one first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh? I might understand what you asking but I am afraid that I am not able to split this commit to two standalone working parts. I can move xcode project file to different commit, and append this commit to this pull request. In that case you would have to pull both commits to be able to build it properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would suffice, ideally it'd be a separate pull request.

@fhd
Copy link
Contributor

fhd commented Apr 15, 2016

@dedecej Did you notice my comment here?

@"easylist+exceptionrules_content_blocker.json"
};

for (NSString *defaultFilterListName in defaultFilterListsFileNames) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided, that it would be more convenient to map filter lists by names rather then urls (which can be changed).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of doc lines explaining the migration transformation would be handy


@implementation AdblockPlus (Extension)

- (NSURL *__nullable)activeFilterListsURL
{
NSString *fileName;
NSString *filename;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the rename, isn't fileName how we normally capitalise this in the code base? Assuming Apple's coding style doesn't cover this case, I suggest we stay consistent with the rest of the project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, I probably forgot about it.

@fhd
Copy link
Contributor

fhd commented Jun 30, 2016

Alright, starting on this one. Had a quick look and left some superficial comments. Will take a closer look tomorrow.

@fhd fhd self-assigned this Jun 30, 2016
@dedecej dedecej force-pushed the issue-3241 branch 2 times, most recently from 337d821 to 797b501 Compare July 11, 2016 13:26
@dedecej
Copy link
Contributor Author

dedecej commented Jul 11, 2016

@fhd: Rebased and updated.

Copy link
Contributor

@pavel-zdenek pavel-zdenek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only bigger issue is the hardcoded tableviewdatasource index shifting magic. And maybe the asserts.

@@ -64,7 +66,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
{
if ([keyPath isEqualToString:NSStringFromSelector(@selector(enabled))]) {
self.blockingEnablingSwitch.on = self.adblockPlus.enabled;
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)] withRowAnimation:UITableViewRowAnimationNone];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An unfortunate binding of momentary design to hardcoded numbers. Someone will forget to update this when/if the design changes around. Like when a new section is inserted between. If such inserted section is NOT to be disabled on ABP toggle, then Range will be a wrong tool altogether. Any idea of how to make this programmatically safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do something, but unfortunately I cannot do more. It is possible to append any information to section in designer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this is basically Massive View Controller inception, so wrapping the index arithmetic away in a separate class would be good. The pluses and minuses should not be scattered across the controller. But this is already 50% better than the original hardcode, so let's do the other 50% when there is another UI requirement.


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [super tableView:tableView numberOfRowsInSection:section] + (section == 0 ? 1 : 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded design again. section == 0 should be at least a declared constant "which section needs the section offseting magic".

cell.textLabel.enabled = enabled;
return cell;
} else {
return [super tableView:tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row - 1 inSection:0]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using correctedIndexPath here?

@property (nonatomic, strong, nullable) NSString *version;

@property (nonatomic) BOOL userTriggered;
@property (nonatomic) BOOL downloaded;
@property (nonatomic) BOOL updating;
@property (nonatomic) BOOL lastUpdateFailed;
@property (nonatomic) NSUInteger taskIdentifier;
@property (nonatomic) NSUInteger updatingGroupId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a clueless novice to the ABP code, i would like to have one line explanation of what is this number for. Task identifier would be nice to have explained too.

return self;
}

- (NSDictionary *)dictionary
{
NSAssert(self.fileName, @"Filename must be set!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert will do nothing on release run. Is this really just a debug sanity check? Are the asserts always true on release? If not, what will the function produce?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not happen. FilterList is create only from special dictionary, and that dictionary is not accessed from outside.

}
}

if (!fileName) {
fileName = @"empty.json";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be declared constant. It is used in multiple places.

@pavel-zdenek
Copy link
Contributor

@fhd LGTM

@dedecej dedecej force-pushed the issue-3241 branch 2 times, most recently from 7ac44ee to 9339f46 Compare October 21, 2016 08:24
Copy link
Contributor

@fhd fhd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally managed to take a closer look. Looks good, some minor comments.


for (NSString *defaultFilterListName in defaultFilterListsFileNames) {
NSString *defaultFilterListFileName = defaultFilterListsFileNames[defaultFilterListName];
for (NSString *filterListName in filterListsVersion1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How I see it, filterListName actually contains the filter list URL - so how about filterListUrl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

for (NSString *filterListName in filterListsVersion1) {
NSDictionary *filterList = filterListsVersion1[filterListName];
if ([filterList[@"filename"] isEqualToString:defaultFilterListFileName]) {
NSMutableDictionary *modifiedFilterList = [filterList mutableCopy];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why copy filterList and then modify it? Looks to me as if it would be cleaner and less code if we create a fresh object. Or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I need to copy all properties from old filter list

_filterLists = filterListsVersion2;

} else {
// No filter lists was loaded, use default filter lists
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't need an empty block just for this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

{
if (section == AdblockPlusControllerSectionDefault) {
return [super tableView:tableView numberOfRowsInSection:section] + 1;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Another else after return, see above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

NSDate *lastUpdate = [self.adblockPlus.filterLists[self.adblockPlus.activeFilterListName] lastUpdate];
if (lastUpdate) {
return [NSString stringWithFormat:defaultTitle, [self.dateFormatter stringFromDate:lastUpdate]];
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Another else after return, see above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

NSString *url = [NSUserDefaults.standardUserDefaults stringForKey:customFilterListKey];
if ([url length] == 0) {
return customFilterListUrl;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Another else after return, see above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


- (NSAttributedString *)footerTitleForFilterList:(FilterList *)filterList
{
if (filterList) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block has a few else after return - I think the code can be simplified a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

{
if (!self.defaultFilterListEnabled && [self.filterLists[CustomFilterListName] downloaded]) {
return CustomFilterListName;
} else if (self.acceptableAdsEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We typically avoid else after return - it's redundant. But I wouldn't insist. Same goes for the other occurrences I pointed out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == AdblockPlusControllerSectionDefault && indexPath.row > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block has a few else after return - I think the code can be simplified a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


updated = updated || (!lastUpdate && currentLastUpdate) || (currentLastUpdate && [currentLastUpdate compare:lastUpdate] == NSOrderedDescending);
updated = updated || (!lastUpdate && !!currentLastUpdate) || (!!currentLastUpdate && [currentLastUpdate compare:lastUpdate] == NSOrderedDescending);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add the !! here? I don't think it changes the behaviour of this expression.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@fhd
Copy link
Contributor

fhd commented Oct 28, 2016

LGTM, I'll merge this.

@fhd
Copy link
Contributor

fhd commented Oct 28, 2016

Merged, thanks! d468b47

@fhd fhd closed this Oct 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants