NewsBlur/clients/ios/Classes/FeedChooserItem.m
David Sinclair 375e3757e2 #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

156 lines
4.6 KiB
Objective-C

//
// FeedChooserItem.m
// NewsBlur
//
// Created by David Sinclair on 2016-01-23.
// Copyright © 2016 NewsBlur. All rights reserved.
//
#import "FeedChooserItem.h"
#import "NewsBlurAppDelegate.h"
#import "NewsBlur-Swift.h"
@interface FeedChooserItem ()
@property (nonatomic, strong) UIImage *icon;
@property (nonatomic, readonly) NewsBlurAppDelegate *appDelegate;
@end
@implementation FeedChooserItem
+ (instancetype)makeFolderWithTitle:(NSString *)title {
return [self makeItemWithInfo:@{@"id" : [[NewsBlurAppDelegate sharedAppDelegate] extractFolderName:title], @"feed_title" : title}];
}
+ (instancetype)makeItemWithInfo:(NSDictionary *)info {
FeedChooserItem *item = [self new];
item.info = info;
return item;
}
- (id)identifier {
id identifier = self.info[@"id"];
if ([identifier isEqual:@" "]) {
return @"everything";
} else {
return identifier;
}
}
- (NSString *)identifierString {
return [NSString stringWithFormat:@"%@", self.identifier];
}
- (NSString *)title {
NSString *title = self.info[@"feed_title"];
if ([title isEqualToString:@" "] || [title isEqualToString:@"everything"] || [title isEqualToString:@"infrequent"]) {
return @"";
} else {
return title;
}
}
- (UIImage *)icon {
if (!_icon) {
if (!self.identifier) {
self.icon = [UIImage imageNamed:@"folder-open"];
} else {
self.icon = [self.appDelegate getFavicon:[self.identifier description] isSocial:NO isSaved:NO];
}
}
return _icon;
}
- (void)addItemWithInfo:(NSDictionary *)info {
if (!self.contents) {
self.contents = [NSMutableArray array];
}
[self.contents addObject:[FeedChooserItem makeItemWithInfo:info]];
}
+ (NSString *)keyForSort:(FeedChooserSort)sort {
switch (sort) {
case FeedChooserSortName:
return @"info.feed_title";
break;
case FeedChooserSortSubscribers:
return @"info.num_subscribers";
break;
case FeedChooserSortFrequency:
return @"info.average_stories_per_month";
break;
case FeedChooserSortRecency:
return @"info.last_story_seconds_ago";
break;
default:
return @"info.feed_opens";
break;
}
}
- (NSString *)detailForSort:(FeedChooserSort)sort {
switch (sort) {
case FeedChooserSortSubscribers:
return [NSString localizedStringWithFormat:NSLocalizedString(@"%@ subscribers", @"number of subscribers"), self.info[@"num_subscribers"]];
break;
case FeedChooserSortFrequency:
return [NSString localizedStringWithFormat:NSLocalizedString(@"%@ stories/month", @"average stories per month"), self.info[@"average_stories_per_month"]];
break;
case FeedChooserSortRecency:
{
static NSDateFormatter *dateFormatter = nil;
static NSDateComponentsFormatter *componentsFormatter = nil;
if (!dateFormatter) {
dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
}
if (!componentsFormatter)
{
componentsFormatter = [NSDateComponentsFormatter new];
componentsFormatter.unitsStyle = NSDateComponentsFormatterUnitsStyleFull;
componentsFormatter.maximumUnitCount = 1;
componentsFormatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorDropAll;
}
NSDate *date = [dateFormatter dateFromString:self.info[@"last_story_date"]];
return [NSString stringWithFormat:@"%@ ago", [componentsFormatter stringFromTimeInterval:-date.timeIntervalSinceNow]];
break;
}
default:
return [NSString localizedStringWithFormat:NSLocalizedString(@"%@ opens", @"number of feed opens"), self.info[@"feed_opens"]];
break;
}
}
- (NSString *)description {
if (self.contents) {
return [NSString stringWithFormat:@"%@ %@ (contains %@ items)", [super description], self.title, @(self.contents.count)];
} else {
return [NSString stringWithFormat:@"%@ %@ (%@)", [super description], self.title, self.identifier];
}
}
- (NewsBlurAppDelegate *)appDelegate {
return [NewsBlurAppDelegate sharedAppDelegate];
}
@end