Skip to content

Commit b3fb8ac

Browse files
author
Michael Beattie
committed
[#67767620] added the ability to add searched feeds to the database
1 parent fd4fde5 commit b3fb8ac

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88

99
#import <UIKit/UIKit.h>
1010

11-
@class Feed;
12-
1311
@interface CSSearchFeedCell : UITableViewCell
1412

1513
#pragma mark - IBOutlets
1614

17-
// The feed's icon
15+
/// The feed's icon
1816
@property (weak, nonatomic) IBOutlet UIImageView *imageView_icon;
1917

20-
// The feed's name
18+
/// The feed's name
2119
@property (weak, nonatomic) IBOutlet UILabel *label_name;
2220

21+
/// The add feed action
22+
- (IBAction)addFeedToUser:(id)sender;
2323

2424
#pragma mark - Other Properties
2525

26-
// The feed item this cell is based on
27-
@property (nonatomic, weak) Feed *feed;
26+
// The NSDictionary of the feed this cell is based on
27+
@property (nonatomic, weak) NSDictionary *feed;
2828

2929
@end

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//
88

99
#import "CSSearchFeedCell.h"
10+
#import "Feed.h"
11+
#import "User.h"
1012

1113
@implementation CSSearchFeedCell
1214

@@ -31,4 +33,20 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated
3133
// Configure the view for the selected state
3234
}
3335

36+
/**
37+
* Add the feed to the user and save it in the database
38+
*/
39+
- (IBAction)addFeedToUser:(id)sender {
40+
// Create a new Feed object and associated FeedItem objetcs
41+
Feed *newFeed = [Feed createOrUpdateFirstFromAPIData:self.feed];
42+
43+
// Add the feed to the currentUsers feeds
44+
User *currentUser = [User current];
45+
NSMutableSet *mutableSet = [NSMutableSet setWithSet:currentUser.feeds];
46+
[mutableSet addObject:newFeed];
47+
currentUser.feeds = mutableSet;
48+
49+
// Save the feed and feed items in the database
50+
[[NSManagedObjectContext defaultContext] saveToPersistentStoreAndWait];
51+
}
3452
@end

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
9696

9797
NSDictionary *searchedFeed = [self.sortedFeeds objectAtIndex:indexPath.row];
9898

99+
// Associate the feed to the cell
100+
cell.feed = searchedFeed;
101+
99102
// Set the label text
100103
cell.label_name.text = [searchedFeed objectForKey:@"name"];
101104

EasyReader/Application/Views/Main_iPhone.storyboard

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@
229229
<state key="normal" title="+">
230230
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
231231
</state>
232+
<connections>
233+
<action selector="addFeedToUser:" destination="Vg0-Ic-Bi4" eventType="touchUpInside" id="vVw-rK-cbR"/>
234+
</connections>
232235
</button>
233236
</subviews>
234237
</tableViewCellContentView>

0 commit comments

Comments
 (0)