2012-07-22 14:23:50 -07:00
|
|
|
//
|
|
|
|
// FTUXaddSitesViewController.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Roy Yang on 7/22/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2012-08-11 15:16:35 -07:00
|
|
|
#import "NewsBlurAppDelegate.h"
|
2012-07-22 14:23:50 -07:00
|
|
|
#import "FirstTimeUserAddSitesViewController.h"
|
|
|
|
#import "FirstTimeUserAddFriendsViewController.h"
|
2012-08-10 21:10:32 -07:00
|
|
|
#import "AuthorizeServicesViewController.h"
|
2012-08-11 15:16:35 -07:00
|
|
|
#import "NewsBlurViewController.h"
|
2012-08-14 17:20:45 -07:00
|
|
|
#import "SiteCell.h"
|
|
|
|
#import "Base64.h"
|
2012-08-11 15:16:35 -07:00
|
|
|
|
|
|
|
@interface FirstTimeUserAddSitesViewController()
|
|
|
|
|
|
|
|
@property (readwrite) int importedFeedCount_;
|
2012-08-14 17:20:45 -07:00
|
|
|
@property (nonatomic) UIButton *currentButton_;
|
|
|
|
@property (nonatomic, strong) NSMutableSet *selectedCategories_;
|
|
|
|
@property (readwrite) BOOL googleImportSuccess_;
|
2012-08-11 15:16:35 -07:00
|
|
|
|
|
|
|
@end;
|
2012-07-22 14:23:50 -07:00
|
|
|
|
|
|
|
@implementation FirstTimeUserAddSitesViewController
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
|
|
|
@synthesize googleReaderButton;
|
|
|
|
@synthesize nextButton;
|
2012-08-11 15:16:35 -07:00
|
|
|
@synthesize activityIndicator;
|
|
|
|
@synthesize instructionLabel;
|
2012-08-14 17:20:45 -07:00
|
|
|
@synthesize categoriesTable;
|
2012-08-12 20:09:45 -07:00
|
|
|
@synthesize googleReaderButtonWrapper;
|
2012-08-11 15:16:35 -07:00
|
|
|
@synthesize importedFeedCount_;
|
2012-08-14 17:20:45 -07:00
|
|
|
@synthesize currentButton_;
|
|
|
|
@synthesize selectedCategories_;
|
|
|
|
@synthesize googleImportSuccess_;
|
2012-07-22 14:23:50 -07:00
|
|
|
|
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
|
|
|
{
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
if (self) {
|
|
|
|
// Custom initialization
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
- (void)viewDidLoad {
|
|
|
|
self.selectedCategories_ = [[NSMutableSet alloc] init];
|
|
|
|
|
2012-07-22 14:23:50 -07:00
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view from its nib.
|
|
|
|
|
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
UIBarButtonItem *next = [[UIBarButtonItem alloc] initWithTitle:@"Next step" style:UIBarButtonSystemItemDone target:self action:@selector(tapNextButton)];
|
2012-07-22 14:23:50 -07:00
|
|
|
self.nextButton = next;
|
2013-09-12 16:40:23 -07:00
|
|
|
self.nextButton.enabled = YES;
|
2012-07-22 14:23:50 -07:00
|
|
|
self.navigationItem.rightBarButtonItem = next;
|
|
|
|
|
2012-08-15 13:04:05 -07:00
|
|
|
self.navigationItem.title = @"Add Sites";
|
2012-08-11 15:16:35 -07:00
|
|
|
self.activityIndicator.hidesWhenStopped = YES;
|
2012-08-10 21:10:32 -07:00
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
self.categoriesTable.delegate = self;
|
|
|
|
self.categoriesTable.dataSource = self;
|
|
|
|
self.categoriesTable.backgroundColor = [UIColor clearColor];
|
|
|
|
// self.categoriesTable.separatorColor = [UIColor clearColor];
|
|
|
|
self.categoriesTable.opaque = NO;
|
|
|
|
self.categoriesTable.backgroundView = nil;
|
|
|
|
|
2012-08-11 18:03:28 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
2013-03-04 18:21:10 -08:00
|
|
|
self.instructionLabel.font = [UIFont systemFontOfSize:20];
|
2012-08-11 18:03:28 -07:00
|
|
|
}
|
2012-08-15 15:38:21 -07:00
|
|
|
|
|
|
|
|
|
|
|
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc]
|
|
|
|
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
|
2012-08-15 19:31:34 -07:00
|
|
|
activityView.frame = CGRectMake(68, 7, 20, 20.0);
|
2012-08-15 15:38:21 -07:00
|
|
|
self.activityIndicator = activityView;
|
2012-07-22 14:23:50 -07:00
|
|
|
}
|
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2014-09-18 11:25:51 -07:00
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
|
|
|
|
[self.categoriesTable reloadData];
|
|
|
|
|
|
|
|
NSLog(@"%f height", self.tableViewHeight);
|
|
|
|
}
|
2012-08-10 21:10:32 -07:00
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
- (void)viewDidUnload {
|
|
|
|
[super viewDidUnload];
|
2012-08-11 15:16:35 -07:00
|
|
|
[self setActivityIndicator:nil];
|
|
|
|
[self setInstructionLabel:nil];
|
2012-08-14 17:20:45 -07:00
|
|
|
[self setCategoriesTable:nil];
|
2012-08-10 21:10:32 -07:00
|
|
|
[self setGoogleReaderButton:nil];
|
|
|
|
[self setNextButton:nil];
|
2012-07-22 14:23:50 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:03:28 -07:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
|
|
// Return YES for supported orientations
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
return YES;
|
|
|
|
} else if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
2012-07-22 14:23:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (IBAction)tapNextButton {
|
|
|
|
[appDelegate.ftuxNavigationController pushViewController:appDelegate.firstTimeUserAddFriendsViewController animated:YES];
|
2012-08-14 17:20:45 -07:00
|
|
|
|
|
|
|
if (self.selectedCategories_.count) {
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/categories/subscribe",
|
2012-08-14 17:20:45 -07:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
|
|
|
|
for(NSObject *category in self.selectedCategories_) {
|
|
|
|
[request addPostValue:category forKey:@"category"];
|
|
|
|
}
|
2012-07-22 14:23:50 -07:00
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
[request setDelegate:self];
|
|
|
|
[request setDidFinishSelector:@selector(finishAddingCategories:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
2012-07-22 14:23:50 -07:00
|
|
|
}
|
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
- (void)finishAddingCategories:(ASIHTTPRequest *)request {
|
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSError *error;
|
|
|
|
NSDictionary *results = [NSJSONSerialization
|
|
|
|
JSONObjectWithData:responseData
|
|
|
|
options:kNilOptions
|
|
|
|
error:&error];
|
|
|
|
NSLog(@"results are %@", results);
|
|
|
|
}
|
|
|
|
|
2012-07-22 14:23:50 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Import Google Reader
|
|
|
|
|
2012-08-15 13:04:05 -07:00
|
|
|
- (void)tapGoogleReaderButton {
|
2012-08-10 21:10:32 -07:00
|
|
|
AuthorizeServicesViewController *service = [[AuthorizeServicesViewController alloc] init];
|
|
|
|
service.url = @"/import/authorize";
|
|
|
|
service.type = @"google";
|
|
|
|
[appDelegate.ftuxNavigationController pushViewController:service animated:YES];
|
2012-07-22 14:23:50 -07:00
|
|
|
}
|
|
|
|
|
2012-08-15 15:38:21 -07:00
|
|
|
- (void)importFromGoogleReader {
|
|
|
|
UIView *header = [self.categoriesTable viewWithTag:0];
|
|
|
|
UIButton *button = (UIButton *)[header viewWithTag:1000];
|
|
|
|
self.googleReaderButton = button;
|
|
|
|
|
2012-08-11 15:16:35 -07:00
|
|
|
self.nextButton.enabled = YES;
|
2012-08-15 15:38:21 -07:00
|
|
|
[self.googleReaderButton setTitle:@"Importing sites..." forState:UIControlStateNormal];
|
2012-08-15 19:31:34 -07:00
|
|
|
self.instructionLabel.textColor = UIColorFromRGB(0x333333);
|
2012-07-22 14:23:50 -07:00
|
|
|
self.googleReaderButton.userInteractionEnabled = NO;
|
2013-03-04 18:21:10 -08:00
|
|
|
self.instructionLabel.text = @"This might take a minute.\nFeel free to continue...";
|
2012-08-15 15:38:21 -07:00
|
|
|
[self.googleReaderButton addSubview:self.activityIndicator];
|
2012-08-11 15:16:35 -07:00
|
|
|
[self.activityIndicator startAnimating];
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/import/import_from_google_reader/",
|
2012-08-11 15:16:35 -07:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
[request setPostValue:@"true" forKey:@"auto_active"];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request setDidFinishSelector:@selector(finishImportFromGoogleReader:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
2012-08-12 21:46:47 -07:00
|
|
|
- (void)importFromGoogleReaderFailed:(NSString *)error {
|
2012-08-11 18:03:28 -07:00
|
|
|
[self.googleReaderButton setTitle:@"Retry Google Reader" forState:UIControlStateNormal];
|
2012-08-15 19:31:34 -07:00
|
|
|
self.instructionLabel.textColor = [UIColor redColor];
|
2012-08-12 21:46:47 -07:00
|
|
|
self.instructionLabel.text = error;
|
2012-08-11 18:03:28 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 15:16:35 -07:00
|
|
|
- (void)finishImportFromGoogleReader:(ASIHTTPRequest *)request {
|
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSError *error;
|
|
|
|
NSDictionary *results = [NSJSONSerialization
|
|
|
|
JSONObjectWithData:responseData
|
|
|
|
options:kNilOptions
|
|
|
|
error:&error];
|
|
|
|
NSLog(@"results are %@", results);
|
|
|
|
|
|
|
|
self.importedFeedCount_ = [[results objectForKey:@"feed_count"] intValue];
|
2012-08-15 15:38:21 -07:00
|
|
|
[self performSelector:@selector(updateSites) withObject:nil afterDelay:1];
|
2012-08-14 17:20:45 -07:00
|
|
|
self.googleImportSuccess_ = YES;
|
2012-08-11 15:16:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateSites {
|
2013-09-25 17:43:00 -07:00
|
|
|
self.instructionLabel.text = [NSString stringWithFormat:@"You are subscribed to %lu sites", (unsigned long)[[appDelegate.dictFeeds allKeys] count]];
|
2012-08-11 15:16:35 -07:00
|
|
|
NSString *msg = [NSString stringWithFormat:@"Imported %i site%@",
|
|
|
|
self.importedFeedCount_,
|
|
|
|
self.importedFeedCount_ == 1 ? @"" : @"s"];
|
|
|
|
[self.googleReaderButton setTitle:msg forState:UIControlStateSelected];
|
|
|
|
self.googleReaderButton.selected = YES;
|
|
|
|
[self.activityIndicator stopAnimating];
|
2012-08-12 16:50:34 -07:00
|
|
|
|
|
|
|
UIImage *checkmark = [UIImage imageNamed:@"258-checkmark"];
|
|
|
|
UIImageView *checkmarkView = [[UIImageView alloc] initWithImage:checkmark];
|
2012-08-12 20:09:45 -07:00
|
|
|
checkmarkView.frame = CGRectMake(self.googleReaderButton.frame.size.width - 24,
|
|
|
|
8,
|
2012-08-12 16:50:34 -07:00
|
|
|
16,
|
|
|
|
16);
|
2012-08-15 15:38:21 -07:00
|
|
|
[self.googleReaderButton addSubview:checkmarkView];
|
2012-07-22 14:23:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Add Categories
|
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
- (void)addCategory:(id)sender {
|
|
|
|
// set the currentButton
|
|
|
|
self.currentButton_ = (UIButton *)sender;
|
2013-09-12 16:40:23 -07:00
|
|
|
UIButton *button = (UIButton *)sender;
|
|
|
|
NSLog(@"self.currentButton_.titleLabel.text is %@", self.currentButton_.titleLabel.text);
|
|
|
|
if (button.selected) {
|
|
|
|
[self.selectedCategories_ removeObject:self.currentButton_.titleLabel.text];
|
|
|
|
|
|
|
|
self.nextButton.enabled = YES;
|
|
|
|
button.selected = NO;
|
|
|
|
UIImageView *imageView = (UIImageView*)[button viewWithTag:100];
|
|
|
|
[imageView removeFromSuperview];
|
2012-08-14 17:20:45 -07:00
|
|
|
} else {
|
2013-09-12 16:40:23 -07:00
|
|
|
[self.selectedCategories_ addObject:self.currentButton_.titleLabel.text];
|
|
|
|
button.selected = YES;
|
2012-08-14 17:20:45 -07:00
|
|
|
}
|
2013-09-12 16:40:23 -07:00
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
if (self.googleImportSuccess_) {
|
|
|
|
self.nextButton.enabled = YES;
|
|
|
|
} else if (self.selectedCategories_.count) {
|
|
|
|
self.nextButton.enabled = YES;
|
|
|
|
} else {
|
2013-09-12 16:40:23 -07:00
|
|
|
self.nextButton.enabled = YES;
|
2012-07-22 14:23:50 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 18:21:10 -08:00
|
|
|
[self.categoriesTable reloadData];
|
2012-07-22 14:23:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishAddFolder:(ASIHTTPRequest *)request {
|
|
|
|
NSLog(@"Successfully added.");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request {
|
|
|
|
NSError *error = [request error];
|
|
|
|
NSLog(@"Error: %@", error);
|
2013-03-06 14:29:40 -08:00
|
|
|
[appDelegate informError:error];
|
2012-07-22 14:23:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Add Site
|
|
|
|
|
|
|
|
- (void)addSite:(NSString *)siteUrl {
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/reader/add_url",
|
2012-07-22 14:23:50 -07:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
|
|
|
|
[request setPostValue:siteUrl forKey:@"url"];
|
|
|
|
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request setDidFinishSelector:@selector(finishAddFolder:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Table View - Interactions List
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
|
|
{
|
2013-09-12 16:40:23 -07:00
|
|
|
return appDelegate.categories.count + 1;
|
2012-08-14 17:20:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
|
|
|
//{
|
|
|
|
// NSDictionary *category = [appDelegate.categories objectAtIndex:section];
|
|
|
|
// return [category objectForKey:@"title"];
|
|
|
|
//}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
2013-03-04 18:21:10 -08:00
|
|
|
if (section == 0) {
|
|
|
|
return 0;
|
2012-08-14 17:20:45 -07:00
|
|
|
} else {
|
2013-09-12 16:40:23 -07:00
|
|
|
NSDictionary *category = [appDelegate.categories objectAtIndex:section - 1];
|
2012-08-14 17:20:45 -07:00
|
|
|
NSArray *categorySiteList = [category objectForKey:@"feed_ids"];
|
|
|
|
return categorySiteList.count;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-04 18:21:10 -08:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2015-10-26 13:29:07 -07:00
|
|
|
return 26.0;
|
2012-08-14 17:20:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
|
2015-10-26 13:29:07 -07:00
|
|
|
return 30.0;
|
2012-08-14 17:20:45 -07:00
|
|
|
}
|
|
|
|
|
2013-03-04 18:21:10 -08:00
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
|
2013-09-12 16:40:23 -07:00
|
|
|
if (section == 0) {
|
2015-10-26 13:29:07 -07:00
|
|
|
UIView* categoryTitleView = [UIView new];
|
|
|
|
UILabel *categoryTitleLabel = [UILabel new];
|
|
|
|
categoryTitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
2013-09-12 16:40:23 -07:00
|
|
|
categoryTitleLabel.text = @"You can always add your own individual sites.";
|
|
|
|
categoryTitleLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
|
2013-03-04 18:21:10 -08:00
|
|
|
[categoryTitleView addSubview:categoryTitleLabel];
|
2013-09-12 16:40:23 -07:00
|
|
|
categoryTitleLabel.textColor = [UIColor darkGrayColor];
|
2013-03-04 18:21:10 -08:00
|
|
|
categoryTitleLabel.backgroundColor = [UIColor clearColor];
|
|
|
|
categoryTitleView.backgroundColor = [UIColor clearColor];
|
|
|
|
categoryTitleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
2015-10-26 13:29:07 -07:00
|
|
|
[NSLayoutConstraint constraintWithItem:categoryTitleLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:categoryTitleView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0].active = YES;
|
|
|
|
[NSLayoutConstraint constraintWithItem:categoryTitleLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:categoryTitleView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0].active = YES;
|
|
|
|
|
2013-03-04 18:21:10 -08:00
|
|
|
return categoryTitleView;
|
|
|
|
}
|
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
// create the parent view that will hold header Label
|
2015-10-26 13:29:07 -07:00
|
|
|
UIView* customView = [UIView new];
|
2012-08-14 17:20:45 -07:00
|
|
|
customView.tag = section;
|
|
|
|
|
2014-09-24 12:37:13 -07:00
|
|
|
UIImage *buttonImage =[[UIImage imageNamed:@"google.png"]
|
|
|
|
stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];
|
2012-08-14 17:20:45 -07:00
|
|
|
UIButton *headerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
2015-10-26 13:29:07 -07:00
|
|
|
headerBtn.translatesAutoresizingMaskIntoConstraints = NO;
|
2012-08-15 15:38:21 -07:00
|
|
|
headerBtn.tag = section + 1000;
|
2012-08-14 17:20:45 -07:00
|
|
|
[headerBtn setBackgroundImage:buttonImage forState:UIControlStateNormal];
|
2012-08-15 19:31:34 -07:00
|
|
|
headerBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
|
|
|
|
|
|
|
|
headerBtn.titleLabel.shadowColor = UIColorFromRGB(0x1E5BDB);
|
|
|
|
headerBtn.titleLabel.shadowOffset = CGSizeMake(0, 1);
|
2012-08-14 17:20:45 -07:00
|
|
|
NSString *categoryTitle;
|
2013-09-12 16:40:23 -07:00
|
|
|
NSDictionary *category = [appDelegate.categories objectAtIndex:section - 1];
|
|
|
|
categoryTitle = [category objectForKey:@"title"];
|
|
|
|
|
2014-09-24 12:37:13 -07:00
|
|
|
BOOL inSelect = [self.selectedCategories_
|
|
|
|
containsObject:[NSString stringWithFormat:@"%@", [category objectForKey:@"title"]]];
|
2013-09-12 16:40:23 -07:00
|
|
|
NSLog(@"inselected %i", inSelect);
|
2015-10-26 13:29:07 -07:00
|
|
|
|
2013-09-12 16:40:23 -07:00
|
|
|
if (inSelect) {
|
|
|
|
headerBtn.selected = YES;
|
|
|
|
UIImage *checkmark = [UIImage imageNamed:@"258-checkmark"];
|
|
|
|
UIImageView *checkmarkView = [[UIImageView alloc] initWithImage:checkmark];
|
2015-10-26 13:29:07 -07:00
|
|
|
checkmarkView.translatesAutoresizingMaskIntoConstraints = NO;
|
2013-09-12 16:40:23 -07:00
|
|
|
checkmarkView.tag = 100;
|
|
|
|
[headerBtn addSubview:checkmarkView];
|
2015-10-26 13:29:07 -07:00
|
|
|
|
|
|
|
NSDictionary *views = @{@"checkmark" : checkmarkView};
|
|
|
|
|
|
|
|
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[checkmark(16)]-10-|" options:0 metrics:nil views:views]];
|
|
|
|
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[checkmark(16)]" options:0 metrics:nil views:views]];
|
|
|
|
[NSLayoutConstraint constraintWithItem:checkmarkView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:headerBtn attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0].active = YES;
|
2012-08-14 17:20:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
[headerBtn setTitle:categoryTitle forState:UIControlStateNormal];
|
|
|
|
[headerBtn addTarget:self action:@selector(addCategory:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
[customView addSubview:headerBtn];
|
2015-10-26 13:29:07 -07:00
|
|
|
|
|
|
|
NSDictionary *views = @{@"button" : headerBtn, @"customView" : customView};
|
|
|
|
|
|
|
|
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[button]-0-|" options:0 metrics:nil views:views]];
|
|
|
|
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[button]-0-|" options:0 metrics:nil views:views]];
|
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
return customView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2013-10-04 14:33:17 -07:00
|
|
|
SiteCell *cell = [tableView
|
|
|
|
dequeueReusableCellWithIdentifier:@"ActivityCell"];
|
2012-08-14 17:20:45 -07:00
|
|
|
if (cell == nil) {
|
|
|
|
cell = [[SiteCell alloc]
|
|
|
|
initWithStyle:UITableViewCellStyleDefault
|
|
|
|
reuseIdentifier:@"ActivityCell"];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *siteTitle;
|
|
|
|
|
2013-09-12 16:40:23 -07:00
|
|
|
NSDictionary *category = [appDelegate.categories objectAtIndex:indexPath.section - 1];
|
|
|
|
NSArray *categorySiteList = [category objectForKey:@"feed_ids"];
|
|
|
|
NSString * feedId = [NSString stringWithFormat:@"%@", [categorySiteList objectAtIndex:indexPath.row ]];
|
|
|
|
|
|
|
|
NSDictionary *feed = [appDelegate.categoryFeeds objectForKey:feedId];
|
|
|
|
siteTitle = [feed objectForKey:@"feed_title"];
|
|
|
|
|
|
|
|
BOOL inSelect = [self.selectedCategories_ containsObject:[NSString stringWithFormat:@"%@", [category objectForKey:@"title"]]];
|
2012-08-15 15:38:21 -07:00
|
|
|
|
2013-09-12 16:40:23 -07:00
|
|
|
if (inSelect) {
|
|
|
|
cell.isRead = NO;
|
|
|
|
} else {
|
|
|
|
cell.isRead = YES;
|
|
|
|
}
|
2012-08-14 17:20:45 -07:00
|
|
|
|
2013-09-12 16:40:23 -07:00
|
|
|
// feed color bar border
|
|
|
|
unsigned int colorBorder = 0;
|
|
|
|
NSString *faviconColor = [feed valueForKey:@"favicon_color"];
|
|
|
|
|
|
|
|
if ([faviconColor class] == [NSNull class]) {
|
|
|
|
faviconColor = @"505050";
|
|
|
|
}
|
|
|
|
NSScanner *scannerBorder = [NSScanner scannerWithString:faviconColor];
|
|
|
|
[scannerBorder scanHexInt:&colorBorder];
|
|
|
|
|
2015-12-07 16:09:49 -08:00
|
|
|
cell.feedColorBar = UIColorFromFixedRGB(colorBorder);
|
2013-09-12 16:40:23 -07:00
|
|
|
|
|
|
|
// feed color bar border
|
|
|
|
NSString *faviconFade = [feed valueForKey:@"favicon_border"];
|
|
|
|
if ([faviconFade class] == [NSNull class]) {
|
|
|
|
faviconFade = @"505050";
|
|
|
|
}
|
|
|
|
scannerBorder = [NSScanner scannerWithString:faviconFade];
|
|
|
|
[scannerBorder scanHexInt:&colorBorder];
|
2015-12-07 16:09:49 -08:00
|
|
|
cell.feedColorBarTopBorder = UIColorFromFixedRGB(colorBorder);
|
2013-09-12 16:40:23 -07:00
|
|
|
|
|
|
|
// favicon
|
|
|
|
|
|
|
|
NSString *faviconStr = [NSString stringWithFormat:@"%@", [feed valueForKey:@"favicon"]];
|
|
|
|
NSData *imageData = [NSData dataWithBase64EncodedString:faviconStr];
|
|
|
|
UIImage *faviconImage = [UIImage imageWithData:imageData];
|
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
|
2013-09-12 16:40:23 -07:00
|
|
|
cell.siteFavicon = faviconImage;
|
2012-08-14 17:20:45 -07:00
|
|
|
|
|
|
|
cell.opaque = NO;
|
|
|
|
cell.siteTitle = siteTitle;
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView
|
|
|
|
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
UIView *header = [self.categoriesTable viewWithTag:indexPath.section];
|
2012-08-15 15:38:21 -07:00
|
|
|
UIButton *button = (UIButton *)[header viewWithTag:indexPath.section + 1000];
|
2012-08-14 17:20:45 -07:00
|
|
|
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
UIView *header = [self.categoriesTable viewWithTag:indexPath.section];
|
2012-08-15 15:38:21 -07:00
|
|
|
UIButton *button = (UIButton *)[header viewWithTag:indexPath.section + 1000];
|
2012-08-14 17:20:45 -07:00
|
|
|
[button sendActionsForControlEvents:UIControlStateSelected];
|
|
|
|
return indexPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)tableViewHeight {
|
|
|
|
[self.categoriesTable layoutIfNeeded];
|
|
|
|
return [self.categoriesTable contentSize].height;
|
|
|
|
}
|
|
|
|
|
2012-07-22 14:23:50 -07:00
|
|
|
@end
|