Skip to content

Commit fd4fde5

Browse files
author
Michael Beattie
committed
[#67767620] modified to display searched feeds from api
1 parent 3a84ed0 commit fd4fde5

2 files changed

Lines changed: 45 additions & 17 deletions

File tree

EasyReader/Application/Controllers/Menu/CSMenuLeftViewController.m

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ - (void)menuStateEventOccurred:(NSNotification *)notification {
139139
}
140140
}
141141

142+
143+
#pragma mark - DataSource Methods
142144
/**
143145
* Update the feeds in the menu when a user begins or ends a search
144146
*/
@@ -157,32 +159,57 @@ - (void)searchFieldDidChange
157159

158160
// Add custom feed to the searchFeeds
159161
[searchedFeeds addObject:customFeed];
162+
163+
// Update the searchFeed datasource
164+
[searchFeedDataSource updateWithFeeds:searchedFeeds];
165+
[self updateSearchFeedDataSource];
160166
} else {
161167
// Return feeds from the API similar to user input
162168
// Add these feeds to the searchFeed datasource
163169

164170
[Feed requestFeedsByName:self.textField_searchInput.text
165171
success:^(id responseData, NSInteger httpStatus){
166-
NSLog(@"Search for feeds successful");
172+
NSDictionary *feeds = [responseData objectForKey:@"feeds"];
173+
for ( NSDictionary *feed in feeds){
174+
[searchedFeeds addObject:feed];
175+
}
176+
// Update the searchFeed datasource
177+
[searchFeedDataSource updateWithFeeds:searchedFeeds];
178+
[self updateSearchFeedDataSource];
167179
}
168180
failure:^(id responseData, NSInteger httpStatus, NSError *error){
169181
NSLog(@"Error searching for feeds");
170182
}];
171183
}
172-
173-
// Switch to the searchFeed datasource and update the table
174-
[searchFeedDataSource updateWithFeeds:searchedFeeds];
175-
self.tableView_feeds.dataSource = searchFeedDataSource;
176-
177-
// Reload the table with new searchFeeds
178-
[self.tableView_feeds reloadData];
179184
} else {
180185
// Switch to the userFeeds datasource
181-
self.tableView_feeds.dataSource = userFeedDataSource;
182-
[self.tableView_feeds reloadData];
186+
[self updateUserFeedDataSource];
183187
}
184188
}
185189

190+
/**
191+
* Switch to and reload the menu from the searchFeedDataSource
192+
*/
193+
- (void)updateSearchFeedDataSource
194+
{
195+
// Switch to the searchFeed datasource
196+
self.tableView_feeds.dataSource = searchFeedDataSource;
197+
198+
// Reload the table with new searchFeeds
199+
[self.tableView_feeds reloadData];
200+
}
201+
202+
/**
203+
* Switch to and reload the menu from the userFeedDataSource
204+
*/
205+
- (void)updateUserFeedDataSource
206+
{
207+
// Switch to the searchFeed datasource
208+
self.tableView_feeds.dataSource = userFeedDataSource;
209+
210+
// Reload the table with new searchFeeds
211+
[self.tableView_feeds reloadData];
212+
}
186213

187214
#pragma mark - Count Methods
188215
/**

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,20 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
9090
*/
9191
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
9292
{
93-
if ([[self.sortedFeeds objectAtIndex:indexPath.row] isKindOfClass:[Feed class]]) {
93+
if ([[self.sortedFeeds objectAtIndex:indexPath.row] objectForKey:@"feed_items"]) {
9494
// Dequeue a styled cell
9595
CSSearchFeedCell *cell = (CSSearchFeedCell *)[tableView dequeueReusableCellWithIdentifier:@"SearchFeedCell"];
96-
97-
Feed *feed = [self.sortedFeeds objectAtIndex:indexPath.row];
98-
cell.feed = feed;
96+
97+
NSDictionary *searchedFeed = [self.sortedFeeds objectAtIndex:indexPath.row];
9998

10099
// Set the label text
101-
cell.label_name.text = feed.name;
100+
cell.label_name.text = [searchedFeed objectForKey:@"name"];
102101

103102
// Show feed icons
104-
[cell.imageView_icon setHidden:NO];
105-
[cell.imageView setImageWithURL:[NSURL URLWithString:feed.icon] placeholderImage:nil];
103+
NSString *iconUrl = [searchedFeed objectForKey:@"icon"];
104+
if (!iconUrl.isBlank) {
105+
[cell.imageView setImageWithURL:[NSURL URLWithString:[searchedFeed objectForKey:@"icon"]] placeholderImage:nil];
106+
}
106107

107108
UIView *selectedBackgroundView = [[UIView alloc] init];
108109
[selectedBackgroundView setBackgroundColor: [UIColor EZR_charcoal]];

0 commit comments

Comments
 (0)