2016-01-27 20:52:09 -08:00
|
|
|
//
|
|
|
|
// FeedChooserItem.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by David Sinclair on 2016-01-23.
|
|
|
|
// Copyright © 2016 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "FeedChooserItem.h"
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
2020-08-27 21:26:12 -07:00
|
|
|
#import "NewsBlur-Swift.h"
|
2016-01-27 20:52:09 -08:00
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
2016-01-28 21:19:04 -08:00
|
|
|
- (id)identifier {
|
|
|
|
id identifier = self.info[@"id"];
|
|
|
|
|
|
|
|
if ([identifier isEqual:@" "]) {
|
|
|
|
return @"everything";
|
|
|
|
} else {
|
|
|
|
return identifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)identifierString {
|
|
|
|
return [NSString stringWithFormat:@"%@", self.identifier];
|
2016-01-27 20:52:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)title {
|
|
|
|
NSString *title = self.info[@"feed_title"];
|
|
|
|
|
2017-11-05 22:07:43 -08:00
|
|
|
if ([title isEqualToString:@" "] || [title isEqualToString:@"everything"] || [title isEqualToString:@"infrequent"]) {
|
2016-01-27 20:52:09 -08:00
|
|
|
return @"";
|
|
|
|
} else {
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIImage *)icon {
|
|
|
|
if (!_icon) {
|
|
|
|
if (!self.identifier) {
|
#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
|
|
|
self.icon = [UIImage imageNamed:@"folder-open"];
|
2016-01-27 20:52:09 -08:00
|
|
|
} else {
|
2016-01-28 21:19:04 -08:00
|
|
|
self.icon = [self.appDelegate getFavicon:[self.identifier description] isSocial:NO isSaved:NO];
|
2016-01-27 20:52:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2016-02-06 13:55:36 -05:00
|
|
|
return [NSString localizedStringWithFormat:NSLocalizedString(@"%@ subscribers", @"number of subscribers"), self.info[@"num_subscribers"]];
|
2016-01-27 20:52:09 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FeedChooserSortFrequency:
|
2016-02-06 13:55:36 -05:00
|
|
|
return [NSString localizedStringWithFormat:NSLocalizedString(@"%@ stories/month", @"average stories per month"), self.info[@"average_stories_per_month"]];
|
2016-01-27 20:52:09 -08:00
|
|
|
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];
|
|
|
|
|
2021-05-06 19:04:21 -07:00
|
|
|
componentsFormatter.unitsStyle = NSDateComponentsFormatterUnitsStyleFull;
|
2016-01-27 20:52:09 -08:00
|
|
|
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:
|
2016-02-06 13:55:36 -05:00
|
|
|
return [NSString localizedStringWithFormat:NSLocalizedString(@"%@ opens", @"number of feed opens"), self.info[@"feed_opens"]];
|
2016-01-27 20:52:09 -08:00
|
|
|
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
|