Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Issue 234-Display projects in filter view on iPad #238

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions View Controllers/FilterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ typedef NS_OPTIONS(NSInteger, FilterViewActiveTypes) {
};

// KVO contexts
static void * kContextsContext = &kContextsContext;
static void * kProjectsContext = &kProjectsContext;
static void * const kUpdatedTasks = (void*)&kUpdatedTasks;

@interface FilterViewController ()

Expand Down Expand Up @@ -112,19 +111,15 @@ - (void)viewDidLoad

[self.taskBag addObserver:self forKeyPath:NSStringFromSelector(@selector(tasks))
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:kContextsContext];
[self.taskBag addObserver:self forKeyPath:NSStringFromSelector(@selector(projects))
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:kProjectsContext];
context:kUpdatedTasks];

// Use ordinary UITableViewCells
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"FilterCell"];
}

- (void)dealloc
{
[self.taskBag removeObserver:self forKeyPath:NSStringFromSelector(@selector(tasks)) context:kContextsContext];
[self.taskBag removeObserver:self forKeyPath:NSStringFromSelector(@selector(projects)) context:kProjectsContext];
[self.taskBag removeObserver:self forKeyPath:NSStringFromSelector(@selector(tasks)) context:kUpdatedTasks];
}

#pragma mark - Custom getters/setters
Expand All @@ -146,7 +141,7 @@ - (BOOL)haveContexts

- (BOOL)haveProjects
{
return (self.projects.count > 0 && (self. activeTypes & FilterViewActiveTypesProjects));
return (self.projects.count > 0 && (self.activeTypes & FilterViewActiveTypesProjects));
}

#pragma mark - Private methods
Expand Down Expand Up @@ -344,15 +339,11 @@ - (void)cancel:(id)sender
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
id<TaskBag> taskBag = object;
if (context == kContextsContext) {
if (context == kUpdatedTasks) {
self.contexts = [[taskBag.tasks valueForKeyPath:@"@distinctUnionOfArrays.contexts"]
sortedArrayUsingSelector:@selector(compare:)];

[self.tableView reloadData];
} else if (context == kProjectsContext) {
self.projects = [[taskBag.tasks valueForKeyPath:@"@distinctUnionOfArrays.projects"]
sortedArrayUsingSelector:@selector(compare:)];

[self.tableView reloadData];
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
Expand Down