Skip to content

Commit 7698cac

Browse files
Michael BeattieAlfredo Uribe
authored andcommitted
[#67863352] added API call for searched feeds
1 parent 1ca9113 commit 7698cac

3 files changed

Lines changed: 28 additions & 21 deletions

File tree

EasyReader/Application/Api/CSFeedSearcher.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010

1111
@interface CSFeedSearcher : NSObject
1212

13+
- (void)feedsLike:(NSString *)name;
14+
1315
@end

EasyReader/Application/Controllers/Menu/CSMenuLeftViewController.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
#pragma mark - Properties
2323
@property (nonatomic, retain) NSMutableSet *feeds;
24-
@property (nonatomic, retain) NSMutableSet *usersFeeds;
2524
@property (nonatomic, retain) User *currentUser;
26-
@property (nonatomic) BOOL searchingFeeds;
27-
2825

2926
@end

EasyReader/Application/Controllers/Menu/CSMenuLeftViewController.m

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
#import "CSMenuUserFeedDataSource.h"
2929
#import "CSMenuSearchFeedDataSource.h"
3030

31+
#import "CSFeedSearcher.h"
32+
3133
@interface CSMenuLeftViewController ()
3234
{
3335
CSMenuUserFeedDataSource *userFeedDataSource;
3436
CSMenuSearchFeedDataSource *searchFeedDataSource;
37+
CSFeedSearcher *feedSearcher;
3538
}
3639

3740
@end
@@ -46,9 +49,11 @@ - (void)viewDidLoad
4649
[super viewDidLoad];
4750
self.currentUser = [User current];
4851
self.feeds = [[NSMutableSet alloc] init];
49-
self.usersFeeds = [[NSMutableSet alloc] init];
5052
[self setUpDataSources];
5153

54+
// Setup feedSearch API
55+
feedSearcher = [[CSFeedSearcher alloc] init];
56+
5257
// Set tableViewStyle
5358
CSEnhancedTableViewStyle *tableViewStyle = [[CSEnhancedTableViewStyleDark alloc] init];
5459
self.tableView_feeds.tableViewStyle = tableViewStyle;
@@ -70,13 +75,15 @@ - (void)viewDidLoad
7075
[removedFeeds removeObjectsInArray:[new allObjects]];
7176

7277
for ( Feed *feed in removedFeeds ){
73-
[[self usersFeeds] removeObject:feed];
78+
[[self feeds] removeObject:feed];
7479
}
7580

7681
for ( Feed *feed in addedFeeds ){
77-
[[self usersFeeds] addObject:feed];
82+
[[self feeds] addObject:feed];
7883
}
79-
self.feeds = self.usersFeeds;
84+
self.tableView_feeds.dataSource = userFeedDataSource;
85+
[userFeedDataSource updateWithFeeds:self.feeds];
86+
8087
[self.tableView_feeds reloadData];
8188
}
8289
insertionBlock:nil
@@ -93,8 +100,6 @@ - (void)viewDidLoad
93100

94101
[userFeedDataSource updateWithFeeds:self.feeds];
95102
self.tableView_feeds.dataSource = userFeedDataSource;
96-
97-
self.searchingFeeds = NO;
98103
}
99104

100105
- (void)setUpDataSources
@@ -124,34 +129,39 @@ - (void)menuStateEventOccurred:(NSNotification *)notification {
124129
weakSelf.textField_searchInput.text = @"";
125130
[weakSelf.tableView_feeds setEditing:NO animated:YES];
126131
weakSelf.menuContainerViewController.panMode = MFSideMenuPanModeDefault;
132+
weakSelf.tableView_feeds.dataSource = userFeedDataSource;
133+
[weakSelf.tableView_feeds reloadData];
127134
break;
128135
}
129136
}
130137

131138
- (void)searchFieldDidChange
132139
{
133140
if(self.textField_searchInput.text && self.textField_searchInput.text.length > 0){
134-
[searchFeedDataSource updateWithFeeds:self.feeds];
141+
NSMutableSet *searchedFeeds = [[NSMutableSet alloc] init];
142+
[searchFeedDataSource updateWithFeeds:searchedFeeds];
135143
self.tableView_feeds.dataSource = searchFeedDataSource;
136-
[self.tableView_feeds reloadData];
137144

138-
NSMutableSet *searchedFeeds = [[NSMutableSet alloc] init];
139145
if([self.textField_searchInput.text hasPrefix:@"http"]){
140-
NSLog(@"ADDING A URL");
146+
// Get the local context
147+
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
148+
149+
// Create a new Feed in the current thread context
150+
Feed *customFeed = [Feed MR_createInContext:localContext];
151+
customFeed.name = self.textField_searchInput.text;
152+
customFeed.url = self.textField_searchInput.text;
153+
154+
[searchedFeeds addObject:customFeed];
141155
}
142156
else{
143-
NSLog(@"SEARCHING");
157+
[feedSearcher feedsLike:self.textField_searchInput.text];
144158
}
145-
146-
self.feeds = searchedFeeds;
159+
147160
[self.tableView_feeds reloadData];
148161
}
149162
else{
150163
self.tableView_feeds.dataSource = userFeedDataSource;
151164
[self.tableView_feeds reloadData];
152-
153-
self.feeds = self.usersFeeds;
154-
[self.tableView_feeds reloadData];
155165
}
156166
}
157167

@@ -178,8 +188,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
178188
} else {
179189
[tableView deselectRowAtIndexPath:indexPath animated:YES];
180190
}
181-
182-
//[self.menuContainerViewController setMenuState:MFSideMenuStateClosed completion:^{}];
183191
}
184192

185193
@end

0 commit comments

Comments
 (0)