Skip to content

Commit 998f0c4

Browse files
Michael BeattieAlfredo Uribe
authored andcommitted
[#67863352] cleaned up menu code formating
1 parent 911f88a commit 998f0c4

6 files changed

Lines changed: 128 additions & 111 deletions

File tree

EasyReader/Application/Controllers/Menu/CSMenuLeftViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <UIKit/UIKit.h>
1010
#import "CSBaseViewController.h"
1111

12-
@class Feed, User, CSEnhancedTableView;
12+
@class User, CSEnhancedTableView;
1313

1414
@interface CSMenuLeftViewController : CSBaseViewController<UITableViewDelegate>
1515

EasyReader/Application/Controllers/Menu/CSMenuLeftViewController.m

Lines changed: 83 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -47,60 +47,61 @@ @implementation CSMenuLeftViewController
4747
*/
4848
- (void)viewDidLoad
4949
{
50-
[super viewDidLoad];
51-
self.currentUser = [User current];
52-
self.feeds = [[NSMutableSet alloc] init];
50+
[super viewDidLoad];
51+
self.currentUser = [User current];
52+
self.feeds = [[NSMutableSet alloc] init];
5353

54-
// Setup the user and search datasources
55-
[self setUpDataSources];
56-
57-
// Setup feedSearch API requestor
58-
feedSearcher = [[CSFeedSearcher alloc] init];
54+
// Setup the user and search datasources
55+
[self setUpDataSources];
5956

60-
// Set tableViewStyle
61-
CSEnhancedTableViewStyle *tableViewStyle = [[CSEnhancedTableViewStyleDark alloc] init];
62-
self.tableView_feeds.tableViewStyle = tableViewStyle;
63-
64-
[[self.textField_searchInput superview] setBackgroundColor: [tableViewStyle tableBackgroundColor]];
65-
[self.textField_searchInput setBackgroundColor: [tableViewStyle headerBackgroundTopColor]];
66-
self.textField_searchInput.textColor = [tableViewStyle headerTitleLabelTextColor];
67-
68-
[self.textField_searchInput addTarget:self action:@selector(searchFieldDidChange)forControlEvents:UIControlEventEditingChanged];
57+
// Setup feedSearch API requestor
58+
feedSearcher = [[CSFeedSearcher alloc] init];
6959

70-
// Add observer
71-
//[self.currentUser addObserver:self forKeyPath:@"feeds" options:NSKeyValueObservingOptionNew context:nil];
72-
[self observeRelationship:@keypath(self.currentUser.feeds)
73-
changeBlock:^(__weak CSMenuLeftViewController *self, NSSet *old, NSSet *new) {
74-
NSMutableArray *addedFeeds = [[new allObjects] mutableCopy];
75-
NSMutableArray *removedFeeds = [[old allObjects] mutableCopy];
76-
77-
[addedFeeds removeObjectsInArray:[old allObjects]];
78-
[removedFeeds removeObjectsInArray:[new allObjects]];
79-
80-
for ( Feed *feed in removedFeeds ){
81-
[[self feeds] removeObject:feed];
82-
}
83-
84-
for ( Feed *feed in addedFeeds ){
85-
[[self feeds] addObject:feed];
60+
// Set tableViewStyle
61+
CSEnhancedTableViewStyle *tableViewStyle = [[CSEnhancedTableViewStyleDark alloc] init];
62+
self.tableView_feeds.tableViewStyle = tableViewStyle;
63+
64+
[[self.textField_searchInput superview] setBackgroundColor: [tableViewStyle tableBackgroundColor]];
65+
[self.textField_searchInput setBackgroundColor: [tableViewStyle headerBackgroundTopColor]];
66+
self.textField_searchInput.textColor = [tableViewStyle headerTitleLabelTextColor];
67+
68+
// Added search method to the user input field
69+
[self.textField_searchInput addTarget:self action:@selector(searchFieldDidChange)forControlEvents:UIControlEventEditingChanged];
70+
71+
// Add observer
72+
//[self.currentUser addObserver:self forKeyPath:@"feeds" options:NSKeyValueObservingOptionNew context:nil];
73+
[self observeRelationship:@keypath(self.currentUser.feeds)
74+
changeBlock:^(__weak CSMenuLeftViewController *self, NSSet *old, NSSet *new) {
75+
NSMutableArray *addedFeeds = [[new allObjects] mutableCopy];
76+
NSMutableArray *removedFeeds = [[old allObjects] mutableCopy];
77+
78+
[addedFeeds removeObjectsInArray:[old allObjects]];
79+
[removedFeeds removeObjectsInArray:[new allObjects]];
80+
81+
for ( Feed *feed in removedFeeds ){
82+
[[self feeds] removeObject:feed];
83+
}
84+
85+
for ( Feed *feed in addedFeeds ){
86+
[[self feeds] addObject:feed];
87+
}
88+
89+
// Update and switch to the userFeed data source
90+
self.tableView_feeds.dataSource = userFeedDataSource;
91+
[userFeedDataSource updateWithFeeds:self.feeds];
92+
93+
[self.tableView_feeds reloadData];
8694
}
87-
88-
// Update and switch to the userFeed data source
89-
self.tableView_feeds.dataSource = userFeedDataSource;
90-
[userFeedDataSource updateWithFeeds:self.feeds];
91-
92-
[self.tableView_feeds reloadData];
93-
}
94-
insertionBlock:nil
95-
removalBlock:nil
96-
replacementBlock:nil
97-
];
98-
99-
[[NSNotificationCenter defaultCenter] addObserver:self
100-
selector:@selector(menuStateEventOccurred:)
101-
name:MFSideMenuStateNotificationEvent
102-
object:nil];
103-
95+
insertionBlock:nil
96+
removalBlock:nil
97+
replacementBlock:nil
98+
];
99+
100+
[[NSNotificationCenter defaultCenter] addObserver:self
101+
selector:@selector(menuStateEventOccurred:)
102+
name:MFSideMenuStateNotificationEvent
103+
object:nil];
104+
104105
self.tableView_feeds.delegate = self;
105106

106107
[userFeedDataSource updateWithFeeds:self.feeds];
@@ -117,38 +118,41 @@ - (void)setUpDataSources
117118
}
118119

119120
- (void)menuStateEventOccurred:(NSNotification *)notification {
120-
MFSideMenuStateEvent event = [[[notification userInfo] objectForKey:@"eventType"] intValue];
121-
122-
__weak CSMenuLeftViewController *weakSelf = self;
123-
121+
MFSideMenuStateEvent event = [[[notification userInfo] objectForKey:@"eventType"] intValue];
122+
123+
__weak CSMenuLeftViewController *weakSelf = self;
124+
124125
switch (event) {
125-
case MFSideMenuStateEventMenuWillOpen:
126-
// the menu will open
127-
break;
128-
case MFSideMenuStateEventMenuDidOpen:
129-
// the menu finished opening
130-
[weakSelf.tableView_feeds reloadData];
131-
break;
132-
case MFSideMenuStateEventMenuWillClose:
133-
// the menu will close
134-
[self.textField_searchInput endEditing:YES];
135-
break;
136-
case MFSideMenuStateEventMenuDidClose:
137-
weakSelf.textField_searchInput.text = @"";
138-
[weakSelf.tableView_feeds setEditing:NO animated:YES];
139-
weakSelf.menuContainerViewController.panMode = MFSideMenuPanModeNone;
126+
case MFSideMenuStateEventMenuWillOpen:
127+
// the menu will open
128+
break;
129+
case MFSideMenuStateEventMenuDidOpen:
130+
// the menu finished opening
131+
[weakSelf.tableView_feeds reloadData];
132+
break;
133+
case MFSideMenuStateEventMenuWillClose:
134+
// the menu will close
135+
[self.textField_searchInput endEditing:YES];
136+
break;
137+
case MFSideMenuStateEventMenuDidClose:
138+
weakSelf.textField_searchInput.text = @"";
139+
[weakSelf.tableView_feeds setEditing:NO animated:YES];
140+
weakSelf.menuContainerViewController.panMode = MFSideMenuPanModeNone;
140141

141-
// Reset to the users feeds
142-
weakSelf.tableView_feeds.dataSource = userFeedDataSource;
143-
[weakSelf.tableView_feeds reloadData];
144-
break;
142+
// Reset to the users feeds
143+
weakSelf.tableView_feeds.dataSource = userFeedDataSource;
144+
[weakSelf.tableView_feeds reloadData];
145+
break;
145146
}
146147
}
147148

149+
/**
150+
* Update the feeds in the menu when a user begins or ends a search
151+
*/
148152
- (void)searchFieldDidChange
149153
{
150154
// If the searchInput has text
151-
if(self.textField_searchInput.text && self.textField_searchInput.text.length > 0){
155+
if (self.textField_searchInput.text && self.textField_searchInput.text.length > 0) {
152156

153157
// Create empty searchFeed set
154158
NSMutableSet *searchedFeeds = [[NSMutableSet alloc] init];
@@ -158,28 +162,26 @@ - (void)searchFieldDidChange
158162
self.tableView_feeds.dataSource = searchFeedDataSource;
159163

160164
// If the user is typing a url
161-
if([self.textField_searchInput.text hasPrefix:@"http"]){
165+
if ([self.textField_searchInput.text hasPrefix:@"http"]) {
162166
// Get the local context
163167
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
164168

165169
// Create a new Feed in the current thread context
166170
Feed *customFeed = [Feed MR_createInContext:localContext];
167171
customFeed.name = self.textField_searchInput.text;
168172
customFeed.url = self.textField_searchInput.text;
169-
173+
170174
// Add custom feed to the searchFeeds
171175
[searchedFeeds addObject:customFeed];
172-
}
173-
else{
176+
} else {
174177
// Return feeds from the API similar to user input
175178
// Add these feeds to the searchFeed datasource
176179
[feedSearcher feedsLike:self.textField_searchInput.text];
177180
}
178-
181+
179182
// Reload the table with new searchFeeds
180183
[self.tableView_feeds reloadData];
181-
}
182-
else{
184+
} else {
183185
// Switch to the userFeeds datasource
184186
self.tableView_feeds.dataSource = userFeedDataSource;
185187
[self.tableView_feeds reloadData];

EasyReader/Application/Controllers/Menu/MenuCells/CSSearchFeedCell.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@
88

99
#import <UIKit/UIKit.h>
1010
#import "CSEnhancedTableViewCell.h"
11-
#import "Feed.h"
11+
12+
@class Feed;
1213

1314
@interface CSSearchFeedCell : CSEnhancedTableViewCell
1415

16+
#pragma mark - IBOutlets
17+
18+
// The feed's icon
1519
@property (weak, nonatomic) IBOutlet UIImageView *imageView_icon;
20+
21+
// The feed's name
1622
@property (weak, nonatomic) IBOutlet UILabel *label_name;
1723

24+
1825
#pragma mark - Other Properties
1926

20-
/// The feed item this cell is based on
27+
// The feed item this cell is based on
2128
@property (nonatomic, weak) Feed *feed;
2229

2330
@end
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// CSUserFeedCellTableViewCell.h
2+
// CSUserFeedCell.h
33
// EasyReader
44
//
55
// Created by Michael Beattie on 3/20/14.
@@ -8,16 +8,23 @@
88

99
#import <UIKit/UIKit.h>
1010
#import "CSEnhancedTableViewCell.h"
11-
#import "Feed.h"
11+
12+
@class Feed;
1213

1314
@interface CSUserFeedCell : CSEnhancedTableViewCell
1415

16+
#pragma mark - IBOutlets
17+
18+
// The feed's icon
1519
@property (weak, nonatomic) IBOutlet UIImageView *imageView_icon;
20+
21+
// The feed's name
1622
@property (weak, nonatomic) IBOutlet UILabel *label_name;
1723

24+
1825
#pragma mark - Other Properties
1926

20-
/// The feed item this cell is based on
27+
// The feed item this cell is based on
2128
@property (nonatomic, weak) Feed *feed;
2229

2330
@end

EasyReader/Application/Controllers/Menu/MenuDataSources/CSMenuSearchFeedDataSource.m

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
//
88

99
#import "CSMenuSearchFeedDataSource.h"
10-
#import "CSUserFeedCell.h"
10+
11+
#import "UIImageView+AFNetworking.h"
12+
13+
#import "CSSearchFeedCell.h"
14+
1115
#import "Feed.h"
1216
#import "FeedItem.h"
13-
#import "UIImageView+AFNetworking.h"
1417

1518
@implementation CSMenuSearchFeedDataSource
1619

@@ -22,8 +25,7 @@ - (id)init
2225
{
2326
self = [super init];
2427

25-
if (self)
26-
{
28+
if (self) {
2729
_feeds = [[NSMutableSet alloc] init];
2830
}
2931

@@ -75,25 +77,27 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
7577
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
7678
{
7779
// Dequeue a styled cell
78-
CSUserFeedCell *cell = (CSUserFeedCell *)[tableView dequeueReusableCellWithIdentifier:@"SearchFeedCell"];
80+
CSSearchFeedCell *cell = (CSSearchFeedCell *)[tableView dequeueReusableCellWithIdentifier:@"SearchFeedCell"];
7981

8082
Feed *feed = [self.feeds allObjects][indexPath.row];
8183
cell.feed = feed;
84+
8285
// Set the label text
8386
cell.label_name.text = feed.name;
8487
cell.label_name.textColor = [UIColor whiteColor];
8588

8689
// Show feed icons
8790
[cell.imageView_icon setHidden:NO];
8891

89-
__weak CSUserFeedCell *currentCell = cell;
92+
__weak CSSearchFeedCell *currentCell = cell;
9093
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:feed.icon]];
9194
[currentCell.imageView setImageWithURLRequest:imageRequest
9295
placeholderImage:nil
9396
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
9497
currentCell.imageView.image = image;
9598
}failure:nil
9699
];
100+
97101
UIView *selectedBackgroundView = [[UIView alloc] init];
98102
[selectedBackgroundView setBackgroundColor: [UIColor colorWithRed:39/255.0 green:45/255.0 blue:58/255.0 alpha:1.0]];
99103
cell.selectedBackgroundView = selectedBackgroundView;
@@ -105,14 +109,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
105109
*/
106110
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
107111
{
108-
if (editingStyle == UITableViewCellEditingStyleDelete)
109-
{
112+
if (editingStyle == UITableViewCellEditingStyleDelete) {
110113
Feed *toDelete = [self.feeds allObjects][indexPath.row];
111114

112115
[self.feeds removeObject:toDelete];
113116
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
114117

115-
for( FeedItem *item in toDelete.feedItems ) [item deleteEntity];
118+
for ( FeedItem *item in toDelete.feedItems ) [item deleteEntity];
116119
[toDelete deleteEntity];
117120

118121
[[NSManagedObjectContext defaultContext] saveToPersistentStoreAndWait];
@@ -124,12 +127,9 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
124127
*/
125128
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
126129
{
127-
if ( indexPath.row == [_feeds count] )
128-
{
130+
if ( indexPath.row == [_feeds count] ) {
129131
return UITableViewCellEditingStyleInsert;
130-
}
131-
else
132-
{
132+
} else {
133133
return UITableViewCellEditingStyleDelete;
134134
}
135135
}

0 commit comments

Comments
 (0)