Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
Move followedlegislator vote tallies to own method in SFVoteDetailVie…
Browse files Browse the repository at this point in the history
…wController. We can properly refresh if user follows a legislator on a vote table then returns to the votedetailview. Closes #371.
  • Loading branch information
dcloud committed Mar 21, 2014
1 parent 8f1bba1 commit 4ea4676
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions Classes/Controllers/SFVoteDetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ @interface SFVoteDetailViewController () <UITableViewDelegate>
SSLoadingView *_loadingView;
}

- (void)updateFollowedLegislatorVotes;
- (void)navigateToBill;

@end

@implementation SFVoteDetailViewController
Expand Down Expand Up @@ -58,6 +61,8 @@ - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([_voteDetailView.dateLabel.text isEqualToString:@""]) {
[self setVote:_vote];
} else if (self.vote) {
[self updateFollowedLegislatorVotes];
}
}

Expand Down Expand Up @@ -230,21 +235,10 @@ - (void)_fetchVoteData:(NSString *)rollId {
[((SFVoteCountTableDataSource *)_voteCountTableVC.dataProvider)setVote : _vote];
[_voteCountTableVC reloadTableView];

NSArray *allFollowedLegislators = [SFLegislator allObjectsToPersist];
NSIndexSet *indexesOfLegislators = [allFollowedLegislators indexesOfObjectsPassingTest: ^BOOL (id obj, NSUInteger idx, BOOL *stop) {
SFLegislator *legislator = (SFLegislator *)obj;
BOOL inChamber = [legislator.chamber isEqualToString:_vote.chamber];
BOOL didVote = [_vote.voterDict objectForKey:legislator.bioguideId] != nil;
return inChamber && didVote;
}];
_followedLegislatorVC.dataProvider.items = [[allFollowedLegislators objectsAtIndexes:indexesOfLegislators] sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES]]];
_followedLegislatorVC.dataProvider.sections = @[_followedLegislatorVC.dataProvider.items];
[((SFLegislatorVoteTableDataSource *)_followedLegislatorVC.dataProvider)setVote : _vote];

self.title = [_vote.voteType capitalizedString];

[_followedLegislatorVC reloadTableView];
[_voteDetailView.followedVoterLabel setHidden:_followedLegislatorVC.dataProvider.items.count == 0];
[self updateFollowedLegislatorVotes];

if (_vote.billId == nil) {
[_voteDetailView.billButton setHidden:YES];
Expand All @@ -259,6 +253,22 @@ - (void)_fetchVoteData:(NSString *)rollId {
}];
}

- (void)updateFollowedLegislatorVotes {
NSArray *allFollowedLegislators = [SFLegislator allObjectsToPersist];
NSIndexSet *indexesOfLegislators = [allFollowedLegislators indexesOfObjectsPassingTest: ^BOOL (id obj, NSUInteger idx, BOOL *stop) {
SFLegislator *legislator = (SFLegislator *)obj;
BOOL inChamber = [legislator.chamber isEqualToString:_vote.chamber];
BOOL didVote = [_vote.voterDict objectForKey:legislator.bioguideId] != nil;
return inChamber && didVote;
}];
_followedLegislatorVC.dataProvider.items = [[allFollowedLegislators objectsAtIndexes:indexesOfLegislators] sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES]]];
_followedLegislatorVC.dataProvider.sections = @[_followedLegislatorVC.dataProvider.items];
[((SFLegislatorVoteTableDataSource *)_followedLegislatorVC.dataProvider)setVote : _vote];

[_followedLegislatorVC reloadTableView];
[_voteDetailView.followedVoterLabel setHidden:_followedLegislatorVC.dataProvider.items.count == 0];
}

- (void)navigateToBill {
if (_vote.billId) {
if (_vote.bill == nil) {
Expand Down

0 comments on commit 4ea4676

Please sign in to comment.