2015-11-13 21:54:32 -08:00
//
// MarkReadMenuViewController . m
// NewsBlur
//
// Created by David Sinclair on 2015 -11 -13.
// Copyright © 2015 NewsBlur . All rights reserved .
//
# import "MarkReadMenuViewController.h"
# import "NewsBlurAppDelegate.h"
# import "StoriesCollection.h"
# import "MenuTableViewCell.h"
2020-08-27 21:26:12 -07:00
# import "NewsBlur-Swift.h"
2015-11-13 21:54:32 -08:00
NSString * const MarkReadMenuTitle = @ "title" ;
NSString * const MarkReadMenuIcon = @ "icon" ;
#1693 (2022 Redesign)
- Laboriously updated the icons (finding the names in the web inspector, updating the code, inspecting the colors, setting those separately, dealing with scaling issues, etc etc).
- Let me know if you spot any icons that I missed, or unscaled icons (they have to be explicitly sized, otherwise appear huge).
- More space between story title and story content.
- More space when reading a folder.
- Added Compact/Comfortable to feed detail menu.
- Changing Compact/Comfortable also adjusts the feed detail list.
- Adjusted the color of the story content etc in the feed detail list.
- Removed top and bottom borders from feed title gradient in story detail.
- More space in story detail header.
- The feed detail is offset when selected.
- Updated the feeds social, search, and saved background colors.
- Unread counts no longer have a shadow, and have more space.
- Folders and feeds remain selected in the feeds list when returning from a story or refreshing.
- Folders in the feeds list no longer have a different background color.
- The folders and feeds highlight is now rounded and unbordered like on web.
2022-07-20 21:35:16 -07:00
NSString * const MarkReadMenuIconColor = @ "iconColor" ;
2015-11-13 21:54:32 -08:00
NSString * const MarkReadMenuDays = @ "days" ;
2015-11-29 18:08:44 -08:00
NSString * const MarkReadMenuOlderNewer = @ "olderNewer" ;
2016-01-08 21:53:16 -08:00
NSString * const MarkReadMenuHandler = @ "handler" ;
2015-11-29 18:08:44 -08:00
typedef NS_ENUM ( NSUInteger , MarkReadMenuOlderNewerMode )
{
MarkReadMenuOlderNewerModeOlder = -1 ,
MarkReadMenuOlderNewerModeToggle = 0 ,
MarkReadMenuOlderNewerModeNewer = 1
} ;
2015-11-13 21:54:32 -08:00
@ interface MarkReadMenuViewController ( )
@ property ( nonatomic , strong , readonly ) NewsBlurAppDelegate * appDelegate ;
@ property ( nonatomic , strong ) NSMutableArray * menuOptions ;
@ property ( nonatomic ) BOOL marked ;
@ end
@ implementation MarkReadMenuViewController
# define kMenuOptionHeight 38
- ( void ) viewDidLoad {
[ super viewDidLoad ] ;
self . menuTableView . backgroundColor = UIColorFromRGB ( 0 xECEEEA ) ;
self . menuTableView . separatorColor = UIColorFromRGB ( 0 x909090 ) ;
}
- ( void ) viewWillAppear : ( BOOL ) animated {
[ super viewWillAppear : animated ] ;
[ self buildMenuOptions ] ;
[ self . menuTableView reloadData ] ;
}
- ( void ) viewDidDisappear : ( BOOL ) animated {
[ super viewDidDisappear : animated ] ;
if ( self . completionHandler ) {
self . completionHandler ( self . marked ) ;
}
}
2016-03-19 13:19:06 -04:00
// allow keyboard comands
- ( BOOL ) canBecomeFirstResponder {
return YES ;
}
2015-11-13 21:54:32 -08:00
- ( CGSize ) preferredContentSize {
2016-01-08 21:53:16 -08:00
CGSize size = CGSizeMake ( 300.0 , 190.0 ) ;
2015-11-29 18:08:44 -08:00
if ( self . olderNewerStoriesCollection ) {
2016-01-08 21:53:16 -08:00
size = CGSizeMake ( 300.0 , 114.0 ) ;
2015-11-29 18:08:44 -08:00
} else if ( self . visibleUnreadCount ) {
2016-01-08 21:53:16 -08:00
size = CGSizeMake ( 300.0 , 228.0 ) ;
2015-11-13 21:54:32 -08:00
}
2016-01-08 21:53:16 -08:00
size . height = size . height + ( self . extraItems . count * 38.0 ) ;
return size ;
2015-11-13 21:54:32 -08:00
}
- ( void ) buildMenuOptions {
self . marked = NO ;
self . menuOptions = [ NSMutableArray array ] ;
2015-11-29 18:08:44 -08:00
if ( self . olderNewerStoriesCollection ) {
[ self . olderNewerStoriesCollection calculateStoryLocations ] ;
if ( [ self . olderNewerStoriesCollection isStoryUnread : self . olderNewerStory ] ) {
[ self addTitle : @ "Mark as read" iconName : @ "menu_icn_markread.png" olderNewerMode : MarkReadMenuOlderNewerModeToggle ] ;
} else {
[ self addTitle : @ "Mark as unread" iconName : @ "menu_icn_markread.png" olderNewerMode : MarkReadMenuOlderNewerModeToggle ] ;
}
if ( [ self . olderNewerStoriesCollection . activeOrder isEqualToString : @ "newest" ] ) {
[ self addTitle : @ "Mark newer stories read" iconName : @ "menu_icn_markread.png" olderNewerMode : MarkReadMenuOlderNewerModeNewer ] ;
[ self addTitle : @ "Mark older stories read" iconName : @ "menu_icn_markread.png" olderNewerMode : MarkReadMenuOlderNewerModeOlder ] ;
} else {
[ self addTitle : @ "Mark older stories read" iconName : @ "menu_icn_markread.png" olderNewerMode : MarkReadMenuOlderNewerModeOlder ] ;
[ self addTitle : @ "Mark newer stories read" iconName : @ "menu_icn_markread.png" olderNewerMode : MarkReadMenuOlderNewerModeNewer ] ;
}
} else {
[ self addTitle : [ NSString stringWithFormat : @ "Mark %@ as read" , self . collectionTitle ] iconName : @ "menu_icn_markread.png" days : 0 ] ;
if ( self . visibleUnreadCount ) {
NSString * stories = self . visibleUnreadCount = = 1 ? @ "Mark this story as read" : [ NSString stringWithFormat : @ "Mark these %@ stories read" , @ ( self . visibleUnreadCount ) ] ;
[ self addTitle : stories iconName : @ "menu_icn_markread.png" days : -1 ] ;
}
2015-11-13 21:54:32 -08:00
2015-11-29 18:08:44 -08:00
// Might want different icons for each
[ self addTitle : @ "Mark read older than 1 day" iconName : @ "menu_icn_markread.png" days : 1 ] ;
[ self addTitle : @ "Mark read older than 3 days" iconName : @ "menu_icn_markread.png" days : 3 ] ;
[ self addTitle : @ "Mark read older than 7 days" iconName : @ "menu_icn_markread.png" days : 7 ] ;
[ self addTitle : @ "Mark read older than 14 days" iconName : @ "menu_icn_markread.png" days : 14 ] ;
2015-11-13 21:54:32 -08:00
}
2016-01-08 21:53:16 -08:00
for ( NSDictionary * item in self . extraItems ) {
#1693 (2022 Redesign)
- Laboriously updated the icons (finding the names in the web inspector, updating the code, inspecting the colors, setting those separately, dealing with scaling issues, etc etc).
- Let me know if you spot any icons that I missed, or unscaled icons (they have to be explicitly sized, otherwise appear huge).
- More space between story title and story content.
- More space when reading a folder.
- Added Compact/Comfortable to feed detail menu.
- Changing Compact/Comfortable also adjusts the feed detail list.
- Adjusted the color of the story content etc in the feed detail list.
- Removed top and bottom borders from feed title gradient in story detail.
- More space in story detail header.
- The feed detail is offset when selected.
- Updated the feeds social, search, and saved background colors.
- Unread counts no longer have a shadow, and have more space.
- Folders and feeds remain selected in the feeds list when returning from a story or refreshing.
- Folders in the feeds list no longer have a different background color.
- The folders and feeds highlight is now rounded and unbordered like on web.
2022-07-20 21:35:16 -07:00
if ( item [ MarkReadMenuIconColor ] ) {
[ self addTitle : item [ MarkReadMenuTitle ] iconName : item [ MarkReadMenuIcon ] iconColor : item [ MarkReadMenuIconColor ] handler : item [ MarkReadMenuHandler ] ] ;
} else {
[ self addTitle : item [ MarkReadMenuTitle ] iconName : item [ MarkReadMenuIcon ] handler : item [ MarkReadMenuHandler ] ] ;
}
2016-01-08 21:53:16 -08:00
}
2015-11-29 18:08:44 -08:00
}
- ( void ) addTitle : ( NSString * ) title iconName : ( NSString * ) iconName olderNewerMode : ( MarkReadMenuOlderNewerMode ) mode {
2021-03-26 21:51:02 -07:00
[ self . menuOptions addObject : @ { MarkReadMenuTitle : title , MarkReadMenuIcon : [ UIImage imageNamed : iconName ] , MarkReadMenuOlderNewer : @ ( mode ) } ] ;
2015-11-13 21:54:32 -08:00
}
- ( void ) addTitle : ( NSString * ) title iconName : ( NSString * ) iconName days : ( NSInteger ) days {
2021-03-26 21:51:02 -07:00
[ self . menuOptions addObject : @ { MarkReadMenuTitle : title , MarkReadMenuIcon : [ UIImage imageNamed : iconName ] , MarkReadMenuDays : @ ( days ) } ] ;
2015-11-13 21:54:32 -08:00
}
2016-01-08 21:53:16 -08:00
- ( void ) addTitle : ( NSString * ) title iconName : ( NSString * ) iconName handler : ( void ( ^ ) ( void ) ) handler {
2021-03-26 21:51:02 -07:00
[ self . menuOptions addObject : @ { MarkReadMenuTitle : title , MarkReadMenuIcon : [ UIImage imageNamed : iconName ] , MarkReadMenuHandler : handler } ] ;
2016-01-08 21:53:16 -08:00
}
#1693 (2022 Redesign)
- Laboriously updated the icons (finding the names in the web inspector, updating the code, inspecting the colors, setting those separately, dealing with scaling issues, etc etc).
- Let me know if you spot any icons that I missed, or unscaled icons (they have to be explicitly sized, otherwise appear huge).
- More space between story title and story content.
- More space when reading a folder.
- Added Compact/Comfortable to feed detail menu.
- Changing Compact/Comfortable also adjusts the feed detail list.
- Adjusted the color of the story content etc in the feed detail list.
- Removed top and bottom borders from feed title gradient in story detail.
- More space in story detail header.
- The feed detail is offset when selected.
- Updated the feeds social, search, and saved background colors.
- Unread counts no longer have a shadow, and have more space.
- Folders and feeds remain selected in the feeds list when returning from a story or refreshing.
- Folders in the feeds list no longer have a different background color.
- The folders and feeds highlight is now rounded and unbordered like on web.
2022-07-20 21:35:16 -07:00
- ( void ) addTitle : ( NSString * ) title iconName : ( NSString * ) iconName iconColor : ( UIColor * ) iconColor handler : ( void ( ^ ) ( void ) ) handler {
UIImage * image = [ Utilities imageWithImage : [ UIImage imageNamed : iconName ] convertToSize : CGSizeMake ( 20.0 , 20.0 ) ] ;
image = [ image imageWithRenderingMode : UIImageRenderingModeAlwaysTemplate ] ;
[ self . menuOptions addObject : @ { MarkReadMenuTitle : title , MarkReadMenuIcon : image , MarkReadMenuIconColor : iconColor , MarkReadMenuHandler : handler } ] ;
}
2015-11-13 21:54:32 -08:00
# pragma mark -
# pragma mark - Table view data source
- ( NSInteger ) tableView : ( UITableView * ) tableView numberOfRowsInSection : ( NSInteger ) section {
return self . menuOptions . count ;
}
- ( UITableViewCell * ) tableView : ( UITableView * ) tableView cellForRowAtIndexPath : ( NSIndexPath * ) indexPath {
static NSString * CellIndentifier = @ "Cell" ;
UITableViewCell * cell = [ tableView dequeueReusableCellWithIdentifier : CellIndentifier ] ;
if ( cell = = nil ) {
cell = [ [ MenuTableViewCell alloc ] initWithStyle : UITableViewCellStyleDefault reuseIdentifier : CellIndentifier ] ;
}
2016-01-08 21:53:16 -08:00
NSDictionary * options = self . menuOptions [ indexPath . row ] ;
cell . textLabel . text = options [ MarkReadMenuTitle ] ;
cell . imageView . image = options [ MarkReadMenuIcon ] ;
#1693 (2022 Redesign)
- Laboriously updated the icons (finding the names in the web inspector, updating the code, inspecting the colors, setting those separately, dealing with scaling issues, etc etc).
- Let me know if you spot any icons that I missed, or unscaled icons (they have to be explicitly sized, otherwise appear huge).
- More space between story title and story content.
- More space when reading a folder.
- Added Compact/Comfortable to feed detail menu.
- Changing Compact/Comfortable also adjusts the feed detail list.
- Adjusted the color of the story content etc in the feed detail list.
- Removed top and bottom borders from feed title gradient in story detail.
- More space in story detail header.
- The feed detail is offset when selected.
- Updated the feeds social, search, and saved background colors.
- Unread counts no longer have a shadow, and have more space.
- Folders and feeds remain selected in the feeds list when returning from a story or refreshing.
- Folders in the feeds list no longer have a different background color.
- The folders and feeds highlight is now rounded and unbordered like on web.
2022-07-20 21:35:16 -07:00
cell . imageView . contentMode = UIViewContentModeScaleAspectFit ;
if ( options [ MarkReadMenuIconColor ] ) {
cell . imageView . tintColor = options [ MarkReadMenuIconColor ] ;
} else {
cell . imageView . tintColor = nil ;
}
2015-11-13 21:54:32 -08:00
return cell ;
}
- ( CGFloat ) tableView : ( UITableView * ) tableView heightForRowAtIndexPath : ( NSIndexPath * ) indexPath {
return kMenuOptionHeight ;
}
- ( NSIndexPath * ) tableView : ( UITableView * ) tableView willSelectRowAtIndexPath : ( NSIndexPath * ) indexPath {
if ( indexPath . row >= self . menuOptions . count ) {
return nil ;
}
return indexPath ;
}
- ( void ) tableView : ( UITableView * ) tableView didSelectRowAtIndexPath : ( NSIndexPath * ) indexPath {
self . marked = YES ;
2016-01-08 21:53:16 -08:00
NSDictionary * options = self . menuOptions [ indexPath . row ] ;
if ( options [ MarkReadMenuHandler ] ) {
void ( ^ handler ) ( void ) = options [ MarkReadMenuHandler ] ;
[ self dismissViewControllerAnimated : YES completion : ^ {
handler ( ) ;
[ tableView deselectRowAtIndexPath : indexPath animated : YES ] ;
} ] ;
return ;
}
else if ( self . olderNewerStoriesCollection ) {
MarkReadMenuOlderNewerMode mode = [ options [ MarkReadMenuOlderNewer ] integerValue ] ;
2015-11-29 18:08:44 -08:00
if ( mode = = MarkReadMenuOlderNewerModeToggle ) {
[ self . olderNewerStoriesCollection toggleStoryUnread ] ;
} else {
NSInteger timestamp = [ [ self . olderNewerStory objectForKey : @ "story_timestamp" ] integerValue ] ;
BOOL older = mode = = MarkReadMenuOlderNewerModeOlder ;
[ self . appDelegate . feedDetailViewController markFeedsReadFromTimestamp : timestamp andOlder : older ] ;
}
2015-11-13 21:54:32 -08:00
} else {
2016-01-08 21:53:16 -08:00
NSInteger days = [ options [ MarkReadMenuDays ] integerValue ] ;
2015-11-29 18:08:44 -08:00
if ( days < 0 ) {
[ self . appDelegate . feedsViewController markVisibleStoriesRead ] ;
} else {
[ self . appDelegate . feedsViewController markFeedsRead : self . feedIds cutoffDays : days ] ;
}
2015-11-13 21:54:32 -08:00
}
[ self dismissViewControllerAnimated : YES completion : nil ] ;
[ tableView deselectRowAtIndexPath : indexPath animated : YES ] ;
}
- ( NewsBlurAppDelegate * ) appDelegate {
return [ NewsBlurAppDelegate sharedAppDelegate ] ;
}
@ end