#1604 (preference for automatically opening folder)

- Added a new “When opening app” preference for what folder to show on launch.
- Implemented for both iPhone and iPad.
- Fixed loading default prefs.
- Removed the obsolete restore position preference.
- Enhanced the preferences views to support letting the app add custom values, to enable choosing any folder.
This commit is contained in:
David Sinclair 2022-04-22 19:23:40 -07:00
parent d05a506b33
commit a76429431f
10 changed files with 111 additions and 87 deletions

View file

@ -377,7 +377,12 @@ typedef NS_ENUM(NSUInteger, MarkReadShowMenu)
}
if (storiesCollection == nil) {
[self.appDelegate loadRiverFeedDetailView:(FeedDetailViewController *)self withFolder:@"placeholder"];
NSString *appOpening = [userPreferences stringForKey:@"app_opening"];
if ([appOpening isEqualToString:@"feeds"] && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.messageLabel.text = @"Select a feed to read";
self.messageView.hidden = NO;
}
}
if (storiesCollection.isSocialView) {
@ -986,6 +991,7 @@ typedef NS_ENUM(NSUInteger, MarkReadShowMenu)
self.pageFetching = YES;
NSInteger storyCount = storiesCollection.storyCount;
if (storyCount == 0) {
self.messageView.hidden = YES;
[self.storyTitlesTable reloadData];
[storyTitlesTable scrollRectToVisible:CGRectMake(0, 0, CGRectGetHeight(self.searchBar.frame), 1) animated:YES];
}
@ -1532,7 +1538,11 @@ typedef NS_ENUM(NSUInteger, MarkReadShowMenu)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger storyCount = storiesCollection.storyLocationsCount;
if (!self.messageView.hidden) {
return 0;
}
// The +1 is for the finished/loading bar.
return storyCount + 1;
}

View file

@ -1290,6 +1290,29 @@ static NSArray<NSString *> *NewsBlurTopSectionNames;
[[ThemeManager themeManager] updateTheme];
}
- (void)settingsUpdateSpecifierDictionary:(NSMutableDictionary *)dictionary {
NSMutableArray *titles = dictionary[@"Titles"];
NSMutableArray *values = dictionary[@"Values"];
[titles removeAllObjects];
[values removeAllObjects];
[titles addObject:@"Show feed list"];
[titles addObject:@"Open All Stories"];
[values addObject:@"feeds"];
[values addObject:@"everything"];
for (NSString *folder in self.appDelegate.dictFoldersArray) {
if ([folder hasPrefix:@"river_"] || [folder isEqualToString:@"everything"] || [folder isEqualToString:@"infrequent"] || [folder isEqualToString:@"widget"] || [folder isEqualToString:@"read_stories"] || [folder hasPrefix:@"saved_"]) {
continue;
}
[titles addObject:[NSString stringWithFormat:@"Open %@", folder]];
[values addObject:folder];
}
}
- (void)settingDidChange:(NSNotification*)notification {
NSString *identifier = notification.object;

View file

@ -270,6 +270,7 @@ SFSafariViewControllerDelegate> {
@property (nonatomic) NSArray *notificationFeedIds;
@property (nonatomic, readonly) NSString *widgetFolder;
@property (nonatomic, strong) NSString *pendingFolder;
@property (nonatomic) NSArray *categories;
@property (nonatomic) NSDictionary *categoryFeeds;

View file

@ -261,6 +261,14 @@
withCompletionHandler:nil];
}
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
NSString *appOpening = [userPreferences stringForKey:@"app_opening"];
if (![appOpening isEqualToString:@"feeds"]) {
self.pendingFolder = appOpening;
// [self loadRiverFeedDetailView:self.feedDetailViewController withFolder:appOpening];
}
return YES;
}
@ -444,7 +452,8 @@
return;
}
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"]];
NSString *name = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ? @"Root~ipad.plist" : @"Root.plist";
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:name]];
NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]];
@ -1738,6 +1747,9 @@
[self loadFeed:self.tryFeedFeedId withStory:self.tryFeedStoryId animated:NO];
} else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad && !self.isCompactWidth && self.storiesCollection == nil) {
[self loadRiverFeedDetailView:self.feedDetailViewController withFolder:storiesCollection.activeFolder];
} else if (self.pendingFolder != nil) {
[self loadRiverFeedDetailView:self.feedDetailViewController withFolder:self.pendingFolder];
self.pendingFolder = nil;
}
}
@ -1918,11 +1930,6 @@
- (void)loadRiverFeedDetailView:(FeedDetailViewController *)feedDetailView withFolder:(NSString *)folder {
self.readStories = [NSMutableArray array];
NSMutableArray *feeds = [NSMutableArray array];
BOOL isPlaceholder = [folder isEqualToString:@"placeholder"];
if (isPlaceholder) {
folder = @"everything";
}
self.inFeedDetail = YES;
[feedDetailView resetFeedDetail];
@ -2020,7 +2027,7 @@
detailViewController.navigationItem.titleView = [self makeFeedTitle:storiesCollection.activeFeed];
if (self.isCompactWidth && !isPlaceholder && feedDetailView == feedDetailViewController && feedDetailView.view.window == nil) {
if (self.isCompactWidth && feedDetailView == feedDetailViewController && feedDetailView.view.window == nil) {
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"All"
style: UIBarButtonItemStylePlain
target: nil

View file

@ -56,6 +56,9 @@
- (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForKey:(NSString*)key __attribute__((deprecated)); // use the method below with specifier instead
- (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForSpecifier:(IASKSpecifier*)specifier;
- (void)settingsViewController:(IASKAppSettingsViewController*)sender tableView:(UITableView *)tableView didSelectCustomViewSpecifier:(IASKSpecifier*)specifier;
#pragma mark - DJS custom multiple values
- (void)settingsUpdateSpecifierDictionary:(NSMutableDictionary *)dictionary;
@end

View file

@ -71,6 +71,7 @@ CGRect IASKCGRectSwap(CGRect rect);
- (IASKSettingsReader*)settingsReader {
if (!_settingsReader) {
_settingsReader = [[IASKSettingsReader alloc] initWithFile:self.file];
_settingsReader.delegate = self.delegate; // DJS
if (self.neverShowPrivacySettings) {
_settingsReader.showPrivacySettings = NO;
}

View file

@ -252,6 +252,7 @@ __VA_ARGS__ \
@property (nonatomic, retain) NSSet *hiddenKeys;
@property (nonatomic) BOOL showPrivacySettings;
@property (nonatomic, assign) id delegate; // DJS
#pragma mark - internal use. public only for testing
- (NSString *)file:(NSString *)file

View file

@ -16,6 +16,7 @@
#import "IASKSettingsReader.h"
#import "IASKSpecifier.h"
#import "IASKAppSettingsViewController.h" // DJS
#pragma mark -
@interface IASKSettingsReader () {
@ -138,7 +139,16 @@
}
for (NSDictionary *specifierDictionary in preferenceSpecifiers) {
IASKSpecifier *newSpecifier = [[IASKSpecifier alloc] initWithSpecifier:specifierDictionary];
NSDictionary *localDictionary = specifierDictionary;
// DJS: added support for updating a specifier
if (self.delegate != nil && [localDictionary[@"WantUpdate"] boolValue]) {
NSMutableDictionary *mutableDictionary = localDictionary.mutableCopy;
[self.delegate settingsUpdateSpecifierDictionary:mutableDictionary];
localDictionary = mutableDictionary;
}
IASKSpecifier *newSpecifier = [[IASKSpecifier alloc] initWithSpecifier:localDictionary];
newSpecifier.settingsReader = self;
[newSpecifier sortIfNeeded];
@ -156,7 +166,7 @@
if ([type isEqualToString:kIASKPSRadioGroupSpecifier]) {
for (NSString *value in newSpecifier.multipleValues) {
IASKSpecifier *valueSpecifier =
[[IASKSpecifier alloc] initWithSpecifier:specifierDictionary radioGroupValue:value];
[[IASKSpecifier alloc] initWithSpecifier:localDictionary radioGroupValue:value];
valueSpecifier.settingsReader = self;
[valueSpecifier sortIfNeeded];
[newArray addObject:valueSpecifier];

View file

@ -268,6 +268,28 @@
<key>DefaultValue</key>
<false/>
</dict>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>WantUpdate</key>
<true/>
<key>Title</key>
<string>When opening app</string>
<key>Titles</key>
<array>
<string>Show feed list</string>
<string>Open All Stories</string>
</array>
<key>DefaultValue</key>
<string>feeds</string>
<key>Values</key>
<array>
<string>feeds</string>
<string>everything</string>
</array>
<key>Key</key>
<string>app_opening</string>
</dict>
<dict>
<key>Title</key>
<string>Text Size</string>
@ -780,44 +802,6 @@
<key>Key</key>
<string>story_browser</string>
</dict>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Title</key>
<string>Restore position</string>
<key>Titles</key>
<array>
<string>Always</string>
<string>Within 1 hour</string>
<string>Within 2 hours</string>
<string>Within 4 hours</string>
<string>Within 6 hours</string>
<string>Within 8 hours</string>
<string>Within 12 hours</string>
<string>Within 1 day</string>
<string>Within 2 days</string>
<string>Within 1 week</string>
<string>Never</string>
</array>
<key>DefaultValue</key>
<string>24</string>
<key>Values</key>
<array>
<string>always</string>
<string>1</string>
<string>2</string>
<string>4</string>
<string>6</string>
<string>8</string>
<string>12</string>
<string>24</string>
<string>48</string>
<string>168</string>
<string>never</string>
</array>
<key>Key</key>
<string>restore_state</string>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>

View file

@ -314,6 +314,28 @@
<key>DefaultValue</key>
<false/>
</dict>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Title</key>
<string>When opening app</string>
<key>WantUpdate</key>
<true/>
<key>Titles</key>
<array>
<string>Show feed list</string>
<string>Open All Stories</string>
</array>
<key>DefaultValue</key>
<string>everything</string>
<key>Values</key>
<array>
<string>feeds</string>
<string>everything</string>
</array>
<key>Key</key>
<string>app_opening</string>
</dict>
<dict>
<key>Title</key>
<string>Text Size</string>
@ -848,44 +870,6 @@
<key>Key</key>
<string>video_playback</string>
</dict>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Title</key>
<string>Restore position</string>
<key>Titles</key>
<array>
<string>Always</string>
<string>Within 1 hour</string>
<string>Within 2 hours</string>
<string>Within 4 hours</string>
<string>Within 6 hours</string>
<string>Within 8 hours</string>
<string>Within 12 hours</string>
<string>Within 1 day</string>
<string>Within 2 days</string>
<string>Within 1 week</string>
<string>Never</string>
</array>
<key>DefaultValue</key>
<string>24</string>
<key>Values</key>
<array>
<string>always</string>
<string>1</string>
<string>2</string>
<string>4</string>
<string>6</string>
<string>8</string>
<string>12</string>
<string>24</string>
<string>48</string>
<string>168</string>
<string>never</string>
</array>
<key>Key</key>
<string>restore_state</string>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>