2016-11-23 08:09:19 -08:00
//
// NotificationsViewController . m
// NewsBlur
//
// Created by Samuel Clay on 11 / 23 / 16.
// Copyright © 2016 NewsBlur . All rights reserved .
//
# import "NotificationsViewController.h"
2016-11-23 09:29:29 -08:00
# import "NotificationFeedCell.h"
2016-11-23 08:09:19 -08:00
@ interface NotificationsViewController ( )
@ end
@ implementation NotificationsViewController
2016-11-23 09:29:29 -08:00
@ synthesize notificationsTable ;
@ synthesize appDelegate ;
@ synthesize feedId ;
2016-11-23 08:09:19 -08:00
- ( void ) viewDidLoad {
[ super viewDidLoad ] ;
2016-11-23 09:29:29 -08:00
self . navigationItem . title = @ "Notifications" ;
UIBarButtonItem * cancelButton = [ [ UIBarButtonItem alloc ] initWithTitle : @ "Done"
style : UIBarButtonItemStylePlain
target : self
action : @ selector ( doCancelButton ) ] ;
[ self . navigationItem setRightBarButtonItem : cancelButton ] ;
// Do any additional setup after loading the view from its nib .
self . appDelegate = ( NewsBlurAppDelegate * ) [ [ UIApplication sharedApplication ] delegate ] ;
notificationsTable = [ [ UITableView alloc ] init ] ;
notificationsTable . delegate = self ;
notificationsTable . dataSource = self ;
notificationsTable . frame = CGRectMake ( 0 , 0 , self . view . frame . size . width , self . view . frame . size . height ) ;;
notificationsTable . autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ;
notificationsTable . separatorStyle = UITableViewCellSeparatorStyleNone ;
[ self . view addSubview : notificationsTable ] ;
2016-11-23 08:09:19 -08:00
}
- ( void ) didReceiveMemoryWarning {
[ super didReceiveMemoryWarning ] ;
// Dispose of any resources that can be recreated .
}
2016-11-23 09:29:29 -08:00
- ( void ) doCancelButton {
[ self dismissViewControllerAnimated : YES completion : nil ] ;
}
- ( void ) viewWillAppear : ( BOOL ) animated {
[ super viewWillAppear : animated ] ;
2017-04-11 17:07:29 -07:00
notificationFeedIds = [ appDelegate . notificationFeedIds copy ] ;
2016-11-23 09:29:29 -08:00
[ notificationsTable reloadData ] ;
2017-04-11 17:21:14 -07:00
[ notificationsTable setContentOffset : CGPointZero ] ;
2016-11-23 09:29:29 -08:00
self . view . backgroundColor = UIColorFromRGB ( NEWSBLUR_WHITE _COLOR ) ;
}
- ( void ) viewDidAppear : ( BOOL ) animated {
[ super viewDidAppear : animated ] ;
NSLog ( @ "notifications table: %@ / %@" , NSStringFromCGRect ( notificationsTable . frame ) , NSStringFromCGRect ( self . view . frame ) ) ;
}
# pragma mark - Table view delegate
- ( CGFloat ) tableView : ( UITableView * ) tableView heightForHeaderInSection : ( NSInteger ) section {
return 36 ;
}
- ( UIView * ) tableView : ( UITableView * ) tableView
viewForHeaderInSection : ( NSInteger ) section {
int headerLabelHeight , folderImageViewY ;
if ( [ [ UIDevice currentDevice ] userInterfaceIdiom ] = = UIUserInterfaceIdiomPad ) {
headerLabelHeight = 36 ;
2016-11-23 10:13:22 -08:00
folderImageViewY = 8 ;
2016-11-23 09:29:29 -08:00
} else {
headerLabelHeight = 36 ;
2016-11-23 10:13:22 -08:00
folderImageViewY = 8 ;
2016-11-23 09:29:29 -08:00
}
// create the parent view that will hold header Label
UIControl * customView = [ [ UIControl alloc ]
initWithFrame : CGRectMake ( 0.0 , 0.0 ,
tableView . bounds . size . width , headerLabelHeight + 1 ) ] ;
UIView * borderTop = [ [ UIView alloc ]
initWithFrame : CGRectMake ( 0.0 , 0 ,
tableView . bounds . size . width , 1.0 ) ] ;
borderTop . backgroundColor = UIColorFromRGB ( 0 xe0e0e0 ) ;
borderTop . opaque = NO ;
[ customView addSubview : borderTop ] ;
UIView * borderBottom = [ [ UIView alloc ]
initWithFrame : CGRectMake ( 0.0 , headerLabelHeight ,
tableView . bounds . size . width , 1.0 ) ] ;
borderBottom . backgroundColor = [ UIColorFromRGB ( 0 xB7BDC6 ) colorWithAlphaComponent : 0.5 ] ;
borderBottom . opaque = NO ;
[ customView addSubview : borderBottom ] ;
UILabel * headerLabel = [ [ UILabel alloc ] initWithFrame : CGRectZero ] ;
customView . opaque = NO ;
headerLabel . backgroundColor = [ UIColor clearColor ] ;
headerLabel . opaque = NO ;
headerLabel . textColor = [ UIColor colorWithRed : 0.3 green : 0.3 blue : 0.3 alpha : 1.0 ] ;
headerLabel . highlightedTextColor = UIColorFromRGB ( NEWSBLUR_WHITE _COLOR ) ;
headerLabel . font = [ UIFont boldSystemFontOfSize : 11 ] ;
headerLabel . frame = CGRectMake ( 36.0 , 1.0 , 286.0 , headerLabelHeight ) ;
headerLabel . shadowColor = [ UIColor colorWithRed : .94 green : 0.94 blue : 0.97 alpha : 1.0 ] ;
headerLabel . shadowOffset = CGSizeMake ( 0.0 , 1.0 ) ;
if ( self . feedId && section = = 0 ) {
headerLabel . text = @ "SITE NOTIFICATIONS" ;
} else {
headerLabel . text = @ "ALL NOTIFICATIONS" ;
}
2016-11-23 15:05:30 -06:00
customView . backgroundColor = [ UIColorFromRGB ( 0 xF7F7F5 )
2016-11-23 09:29:29 -08:00
colorWithAlphaComponent : 0.8 ] ;
[ customView addSubview : headerLabel ] ;
UIImage * folderImage ;
int folderImageViewX = 10 ;
if ( self . feedId && section = = 0 ) {
folderImage = [ UIImage imageNamed : @ "menu_icn_notifications.png" ] ;
} else {
folderImage = [ UIImage imageNamed : @ "menu_icn_notifications.png" ] ;
}
folderImageViewX = 9 ;
UIImageView * folderImageView = [ [ UIImageView alloc ] initWithImage : folderImage ] ;
2016-11-23 10:13:22 -08:00
folderImageView . frame = CGRectMake ( folderImageViewX , folderImageViewY , 20 , 20 ) ;
2016-11-23 09:29:29 -08:00
[ customView addSubview : folderImageView ] ;
[ customView setAutoresizingMask : UIViewAutoresizingNone ] ;
return customView ;
}
- ( NSInteger ) numberOfSectionsInTableView : ( UITableView * ) tableView {
if ( self . feedId ) {
return 2 ;
}
return 1 ;
}
- ( CGFloat ) tableView : ( UITableView * ) tableView heightForRowAtIndexPath : ( NSIndexPath * ) indexPath {
2016-11-23 14:37:49 -06:00
return 118 ;
2016-11-23 09:29:29 -08:00
}
- ( NSInteger ) tableView : ( UITableView * ) tableView numberOfRowsInSection : ( NSInteger ) section {
if ( self . feedId && section = = 0 ) {
return 1 ;
}
2017-04-11 17:07:29 -07:00
return MAX ( notificationFeedIds . count , 1 ) ;
2016-11-23 09:29:29 -08:00
}
2016-11-23 08:09:19 -08:00
2016-11-23 09:29:29 -08:00
- ( UITableViewCell * ) tableView : ( UITableView * ) tableView cellForRowAtIndexPath : ( NSIndexPath * ) indexPath {
CGRect vb = self . view . bounds ;
static NSString * CellIdentifier = @ "NotificationFeedCellIdentifier" ;
2016-11-23 10:13:22 -08:00
NotificationFeedCell * cell = [ tableView
2016-11-23 09:29:29 -08:00
dequeueReusableCellWithIdentifier : CellIdentifier ] ;
if ( cell = = nil ) {
cell = [ [ NotificationFeedCell alloc ]
2016-11-23 10:13:22 -08:00
initWithStyle : UITableViewCellStyleValue1
reuseIdentifier : CellIdentifier ] ;
2016-11-23 09:29:29 -08:00
}
2017-04-11 17:07:29 -07:00
if ( notificationFeedIds . count = = 0 ) {
2016-11-23 09:29:29 -08:00
UILabel * msg = [ [ UILabel alloc ] initWithFrame : CGRectMake ( 0 , 0 , vb . size . width , 140 ) ] ;
[ cell . contentView addSubview : msg ] ;
msg . text = @ "No results." ;
msg . textColor = UIColorFromRGB ( 0 x7a7a7a ) ;
if ( vb . size . width > 320 ) {
msg . font = [ UIFont fontWithName : @ "Helvetica-Bold" size : 20.0 ] ;
} else {
msg . font = [ UIFont fontWithName : @ "Helvetica-Bold" size : 14.0 ] ;
}
msg . textAlignment = NSTextAlignmentCenter ;
2016-11-23 10:13:22 -08:00
} else {
NSDictionary * feed ;
NSString * feedIdStr ;
if ( self . feedId && indexPath . section = = 0 ) {
feedIdStr = feedId ;
feed = [ appDelegate . dictFeeds objectForKey : feedId ] ;
} else {
feedIdStr = [ NSString stringWithFormat : @ "%@" ,
2017-04-11 17:07:29 -07:00
notificationFeedIds [ indexPath . row ] ] ;
2016-11-23 10:13:22 -08:00
feed = [ appDelegate . dictFeeds objectForKey : feedIdStr ] ;
}
2016-11-23 15:05:30 -06:00
cell . feedId = feedIdStr ;
2016-11-23 10:13:22 -08:00
cell . textLabel . text = [ feed objectForKey : @ "feed_title" ] ;
cell . imageView . image = [ self . appDelegate getFavicon : feedIdStr isSocial : NO isSaved : NO ] ;
cell . detailTextLabel . text = [ NSString localizedStringWithFormat : NSLocalizedString ( @ "%@ stories/month" , @ "average stories per month" ) , feed [ @ "average_stories_per_month" ] ] ;
2016-11-23 09:29:29 -08:00
}
cell . selectionStyle = UITableViewCellSelectionStyleNone ;
return cell ;
2016-11-23 08:09:19 -08:00
}
@ end