From 214808d26ad55ed7d1a6d920c6b88c225cdbd788 Mon Sep 17 00:00:00 2001 From: Andrei Yangabishev Date: Sat, 13 Jan 2018 23:38:26 +0300 Subject: [PATCH 01/10] add settings DocSetAlphabetizing key --- Dash/DHRepo.h | 1 + Dash/DHRepo.m | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Dash/DHRepo.h b/Dash/DHRepo.h index 9210d6d4..cad6d8f7 100644 --- a/Dash/DHRepo.h +++ b/Dash/DHRepo.h @@ -52,6 +52,7 @@ - (void)backgroundCheckForUpdatesIfNeeded; - (NSString *)repoIdentifier; // Used to find a corresponding repo for a installed docset - (NSString *)defaultsAutomaticallyCheckForUpdatesKey; +@property (nonatomic, strong, readonly, class) NSString *defaultsAlphabetizingKey; - (void)emptyTrashAtPath:(NSString *)trashPath; - (NSString *)docsetInstallFolderPath; - (NSString *)uniqueTrashPath; diff --git a/Dash/DHRepo.m b/Dash/DHRepo.m index f3c195eb..af7e922d 100644 --- a/Dash/DHRepo.m +++ b/Dash/DHRepo.m @@ -864,6 +864,10 @@ - (NSString *)defaultsAutomaticallyCheckForUpdatesKey return @"AutomaticallyCheckForUpdates"; } ++ (NSString *)defaultsAlphabetizingKey { + return @"DocSetAlphabetizing"; +} + - (NSString *)defaultsUpdateLastCheckDateKey { return [[self defaultsKey] stringByAppendingString:@"LastUpdateCheck"]; From 09b73eddf40871b798f476c8fbb5ea28851992ee Mon Sep 17 00:00:00 2001 From: Andrei Yangabishev Date: Sat, 13 Jan 2018 23:44:14 +0300 Subject: [PATCH 02/10] add DHDocsetBrowserViewModel --- Dash/DHDocsetBrowserViewModel.h | 11 ++++++ Dash/DHDocsetBrowserViewModel.m | 52 +++++++++++++++++++++++++ Dash/Dash iOS.xcodeproj/project.pbxproj | 6 +++ 3 files changed, 69 insertions(+) create mode 100644 Dash/DHDocsetBrowserViewModel.h create mode 100644 Dash/DHDocsetBrowserViewModel.m diff --git a/Dash/DHDocsetBrowserViewModel.h b/Dash/DHDocsetBrowserViewModel.h new file mode 100644 index 00000000..81b09fa1 --- /dev/null +++ b/Dash/DHDocsetBrowserViewModel.h @@ -0,0 +1,11 @@ + +#import + +@interface DHDocsetBrowserViewModel : NSObject +@property (nonatomic, strong, readonly) NSArray *sections; +@property (nonatomic, strong) NSMutableArray *keyDocsets; +@property (nonatomic, strong) NSArray *shownDocsets; +@property (nonatomic, readonly) BOOL canMoveRows; +- (void)updateSectionsForEditing:(BOOL)editing andSearching:(BOOL)searching; +- (NSArray *)docsetsForEditing:(BOOL)editing; +@end diff --git a/Dash/DHDocsetBrowserViewModel.m b/Dash/DHDocsetBrowserViewModel.m new file mode 100644 index 00000000..6caa0045 --- /dev/null +++ b/Dash/DHDocsetBrowserViewModel.m @@ -0,0 +1,52 @@ + +#import "DHDocsetBrowserViewModel.h" +#import "DHDocsetManager.h" +#import "DHDocsetDownloader.h" + +@interface DHDocsetBrowserViewModel () +@property (nonatomic, strong) NSArray *sections; +@end + +@implementation DHDocsetBrowserViewModel + +- (BOOL)alphabetizing { + return [NSUserDefaults.standardUserDefaults boolForKey:DHDocsetDownloader.defaultsAlphabetizingKey]; +} + +- (BOOL)canMoveRows { + return !self.alphabetizing; +} + +- (NSArray *)sort:(NSArray *)array { + if (self.alphabetizing) { + NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]; + array = [array sortedArrayUsingDescriptors:@[sortDescriptor]]; + } + return array; +} + +- (NSArray *)docsetsForEditing:(BOOL)editing { + NSArray *docsets = (editing) ? [DHDocsetManager sharedManager].docsets : (self.keyDocsets) ? self.keyDocsets : [DHDocsetManager sharedManager].enabledDocsets; + return [self sort:docsets]; +} + +- (void)updateSectionsForEditing:(BOOL)editing andSearching:(BOOL)searching +{ + NSMutableArray *sections = [NSMutableArray array]; + if([DHRemoteServer sharedServer].remotes.count) + { + if(!editing && !searching) + { + [sections addObject:[self sort:DHRemoteServer.sharedServer.remotes]]; + } + } + NSArray *docsets = [self docsetsForEditing:editing]; + self.shownDocsets = docsets; + if(docsets.count) + { + [sections addObject:docsets]; + } + self.sections = sections; +} + +@end diff --git a/Dash/Dash iOS.xcodeproj/project.pbxproj b/Dash/Dash iOS.xcodeproj/project.pbxproj index e0fe3e7d..c11354b1 100644 --- a/Dash/Dash iOS.xcodeproj/project.pbxproj +++ b/Dash/Dash iOS.xcodeproj/project.pbxproj @@ -249,6 +249,7 @@ 43FD2F0219BB8D87007E594D /* DHWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 43FD2F0119BB8D87007E594D /* DHWebViewController.m */; }; 43FD2F0419BB8D87007E594D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 43FD2F0319BB8D87007E594D /* Images.xcassets */; }; 45D28F8ABD1FC392B1930467 /* libPods-Dash.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A2364AD2032B0714BCD2265 /* libPods-Dash.a */; }; + F5C39C00200A836D00734571 /* DHDocsetBrowserViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = F5C39BFF200A836D00734571 /* DHDocsetBrowserViewModel.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -486,6 +487,8 @@ 9A2364AD2032B0714BCD2265 /* libPods-Dash.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Dash.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 9FB91D369AD27465BED375AD /* libPods-Dash-Dash App Store.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Dash-Dash App Store.a"; sourceTree = BUILT_PRODUCTS_DIR; }; BAE47FF5DEE33300EBFF9AEA /* Pods-Dash.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Dash.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-Dash/Pods-Dash.debug.xcconfig"; sourceTree = ""; }; + F5C39BFE200A836D00734571 /* DHDocsetBrowserViewModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DHDocsetBrowserViewModel.h; sourceTree = ""; }; + F5C39BFF200A836D00734571 /* DHDocsetBrowserViewModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DHDocsetBrowserViewModel.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -664,6 +667,8 @@ 438D58C119E575D600012881 /* DHLoadingCell.xib */, 43FD2EFD19BB8D87007E594D /* DHDocsetBrowser.h */, 43FD2EFE19BB8D87007E594D /* DHDocsetBrowser.m */, + F5C39BFE200A836D00734571 /* DHDocsetBrowserViewModel.h */, + F5C39BFF200A836D00734571 /* DHDocsetBrowserViewModel.m */, 437FE06419E2AC0D0022ADF4 /* DHTypeBrowser.h */, 437FE06519E2AC0D0022ADF4 /* DHTypeBrowser.m */, 439051F719E684160083A55E /* DHEntryBrowser.h */, @@ -1473,6 +1478,7 @@ 43F25F9C19EBDEF30025CDC4 /* DHBlockProtocol.m in Sources */, 43B0956C19BFD57500F8611B /* DHRepo.m in Sources */, 43D7E4F01BB4C62E00FC1DEF /* DHWindow.m in Sources */, + F5C39C00200A836D00734571 /* DHDocsetBrowserViewModel.m in Sources */, 43BD6BF41DCE379B0005A1E7 /* DHAppUpdateChecker.m in Sources */, 439051FC19E68FE20083A55E /* NSString+GTM.m in Sources */, 43D4F06719E7D68100C22AF5 /* DHDBSearcher.m in Sources */, From 80453a805cdec49a831363ad54232b55baa58455 Mon Sep 17 00:00:00 2001 From: Andrei Yangabishev Date: Sat, 13 Jan 2018 23:47:53 +0300 Subject: [PATCH 03/10] move shownDocsets,keyDocsets and sections into DHDocsetBrowserViewModel --- Dash/DHDocsetBrowser.h | 4 +--- Dash/DHDocsetBrowser.m | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Dash/DHDocsetBrowser.h b/Dash/DHDocsetBrowser.h index f439afaa..e29521ce 100644 --- a/Dash/DHDocsetBrowser.h +++ b/Dash/DHDocsetBrowser.h @@ -25,12 +25,10 @@ @property (assign) BOOL didFirstReload; @property (strong) DHDBSearchController *searchController; -@property (strong) NSMutableArray *shownDocsets; -@property (strong) NSArray *sections; +@property (strong, readonly) NSArray *shownDocsets; @property (assign) BOOL didLoad; @property (assign) BOOL isSearching; @property (assign) BOOL needsToReloadWhenDoneSearching; -@property (strong) NSMutableArray *keyDocsets; - (IBAction)openSettings:(id)sender; + (NSAttributedString *)titleBarItemAttributedStringTemplate; diff --git a/Dash/DHDocsetBrowser.m b/Dash/DHDocsetBrowser.m index 2f6a871d..1e918ec1 100644 --- a/Dash/DHDocsetBrowser.m +++ b/Dash/DHDocsetBrowser.m @@ -25,11 +25,20 @@ #import "DHDocsetDownloader.h" #import "DHRemoteBrowser.h" #import "DHWebView.h" +#import "DHDocsetBrowserViewModel.h" static NSAttributedString *_titleBarItemAttributedStringTemplate = nil; @implementation DHDocsetBrowser +- (NSArray *)shownDocsets { + return self.viewModel.shownDocsets; +} + +- (NSArray *)sections { + return self.viewModel.sections; +} + - (void)viewDidLoad { [super viewDidLoad]; @@ -179,7 +188,7 @@ - (void)performURLSearch:(NSNotification *)notification dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.00 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if(keywordDocsets.count) { - self.keyDocsets = [NSMutableArray arrayWithArray:[keywordDocsets array]]; + self.viewModel.keyDocsets = [NSMutableArray arrayWithArray:[keywordDocsets array]]; } [self.searchDisplayController setActive:YES animated:NO]; self.searchDisplayController.searchBar.text = query; @@ -455,7 +464,7 @@ - (void)tableViewDidEndEditing:(UITableView *)tableView - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { - if(self.keyDocsets) + if(self.viewModel.keyDocsets) { [self reload:nil]; } @@ -478,9 +487,9 @@ - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)cont - (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller { self.isSearching = NO; - if(self.needsToReloadWhenDoneSearching || self.keyDocsets) + if(self.needsToReloadWhenDoneSearching || self.viewModel.keyDocsets) { - self.keyDocsets = nil; + self.viewModel.keyDocsets = nil; self.needsToReloadWhenDoneSearching = NO; [self reload:nil]; } From 6f671d231a1fb33374ef0e2b3333f6bcbb80bfa8 Mon Sep 17 00:00:00 2001 From: Andrei Yangabishev Date: Sat, 13 Jan 2018 23:49:21 +0300 Subject: [PATCH 04/10] move updateSections into DHDocsetBrowserViewModel as updateSectionsForEditing --- Dash/DHDocsetBrowser.m | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/Dash/DHDocsetBrowser.m b/Dash/DHDocsetBrowser.m index 1e918ec1..32ca3814 100644 --- a/Dash/DHDocsetBrowser.m +++ b/Dash/DHDocsetBrowser.m @@ -29,6 +29,10 @@ static NSAttributedString *_titleBarItemAttributedStringTemplate = nil; +@interface DHDocsetBrowser () +@property (nonatomic, strong) DHDocsetBrowserViewModel *viewModel; +@end + @implementation DHDocsetBrowser - (NSArray *)shownDocsets { @@ -42,6 +46,7 @@ - (NSArray *)sections { - (void)viewDidLoad { [super viewDidLoad]; + self.viewModel = [[DHDocsetBrowserViewModel alloc] init]; self.clearsSelectionOnViewWillAppear = NO; self.searchController = [DHDBSearchController searchControllerWithDocsets:nil typeLimit:nil viewController:self]; @@ -273,21 +278,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView - (void)updateSections:(BOOL)withTitleUpdate { - NSMutableArray *sections = [NSMutableArray array]; - if([DHRemoteServer sharedServer].remotes.count) - { - if(!self.isEditing && !self.isSearching) - { - [sections addObject:[DHRemoteServer sharedServer].remotes]; - } - } - NSMutableArray *docsets = (self.isEditing) ? [DHDocsetManager sharedManager].docsets : (self.keyDocsets) ? self.keyDocsets : [DHDocsetManager sharedManager].enabledDocsets; - self.shownDocsets = docsets; - if(docsets.count) - { - [sections addObject:docsets]; - } - self.sections = sections; + [self.viewModel updateSectionsForEditing:self.isEditing andSearching:self.isSearching]; if(withTitleUpdate) { [self updateTitle]; From f57bcb136006a9b551bf4e0ef1db4b61875488ab Mon Sep 17 00:00:00 2001 From: Andrei Yangabishev Date: Sat, 13 Jan 2018 23:50:06 +0300 Subject: [PATCH 05/10] disable manual reordering while Alphabetizing --- Dash/DHDocsetBrowser.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dash/DHDocsetBrowser.m b/Dash/DHDocsetBrowser.m index 32ca3814..5964c3b3 100644 --- a/Dash/DHDocsetBrowser.m +++ b/Dash/DHDocsetBrowser.m @@ -335,7 +335,7 @@ - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fro - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { - return YES; + return self.viewModel.canMoveRows; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath From b3abeba7dce20c211f8ac441d99d98885801e384 Mon Sep 17 00:00:00 2001 From: Andrei Yangabishev Date: Sat, 13 Jan 2018 23:51:03 +0300 Subject: [PATCH 06/10] docsetsForEditing should return records according to Alphabetizing state --- Dash/DHDocsetBrowser.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dash/DHDocsetBrowser.m b/Dash/DHDocsetBrowser.m index 5964c3b3..2c12dcdd 100644 --- a/Dash/DHDocsetBrowser.m +++ b/Dash/DHDocsetBrowser.m @@ -386,8 +386,8 @@ - (void)tableViewDidBeginEditing:(UITableView *)tableView } // NSArray *current = self.shownDocsets; - NSMutableArray *new = [DHDocsetManager sharedManager].docsets; - self.shownDocsets = new; + NSArray *new = [self.viewModel docsetsForEditing:YES]; + self.viewModel.shownDocsets = new; NSMutableArray *toInsert = [NSMutableArray array]; for(NSInteger i = 0; i < new.count; i++) { @@ -419,7 +419,7 @@ - (void)tableViewDidBeginEditing:(UITableView *)tableView - (void)tableViewDidEndEditing:(UITableView *)tableView { NSArray *current = self.shownDocsets; - self.shownDocsets = [DHDocsetManager sharedManager].enabledDocsets; + self.viewModel.shownDocsets = [self.viewModel docsetsForEditing:NO]; NSMutableArray *toDelete = [NSMutableArray array]; BOOL docsetsShouldBeShown = NO; for(int i = 0; i < current.count; i++) From 17a3216fb0654be5595dc72be03062a540da7897 Mon Sep 17 00:00:00 2001 From: Andrei Yangabishev Date: Sat, 13 Jan 2018 23:52:28 +0300 Subject: [PATCH 07/10] Alphabetizing settings key --- Dash/DHDocsetBrowser.m | 1 + Dash/DHPreferences.h | 1 + Dash/DHPreferences.m | 7 +++++++ Dash/DHRepo.h | 2 ++ 4 files changed, 11 insertions(+) diff --git a/Dash/DHDocsetBrowser.m b/Dash/DHDocsetBrowser.m index 2c12dcdd..5b7d7f18 100644 --- a/Dash/DHDocsetBrowser.m +++ b/Dash/DHDocsetBrowser.m @@ -54,6 +54,7 @@ - (void)viewDidLoad [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reload:) name:DHDocsetsChangedNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reload:) name:DHRemotesChangedNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reload:) name:DHSettingsChangedNotification object:nil]; self.tableView.rowHeight = 44; self.navigationController.delegate = self; self.navigationController.interactivePopGestureRecognizer.delegate = (id)self; diff --git a/Dash/DHPreferences.h b/Dash/DHPreferences.h index 061b432e..05ede9f8 100644 --- a/Dash/DHPreferences.h +++ b/Dash/DHPreferences.h @@ -20,6 +20,7 @@ @interface DHPreferences : UITableViewController @property (assign) IBOutlet UISwitch *updatesSwitch; +@property (assign) IBOutlet UISwitch *alphabetizingSwitch; @property (assign) BOOL didSetUpdateLabelBefore; - (IBAction)updatesSwitchValueChanged:(id)sender; diff --git a/Dash/DHPreferences.m b/Dash/DHPreferences.m index 0bb9fcc1..af31ca51 100644 --- a/Dash/DHPreferences.m +++ b/Dash/DHPreferences.m @@ -33,6 +33,7 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.updatesSwitch setOn:[[NSUserDefaults standardUserDefaults] boolForKey:[[DHDocsetDownloader sharedDownloader] defaultsAutomaticallyCheckForUpdatesKey]]]; + [self.alphabetizingSwitch setOn:[NSUserDefaults.standardUserDefaults boolForKey:DHDocsetDownloader.defaultsAlphabetizingKey]]; } - (void)viewDidAppear:(BOOL)animated @@ -238,6 +239,12 @@ - (IBAction)updatesSwitchValueChanged:(id)sender [self updateUpdatesSwitchFooterView:nil]; } +- (IBAction)alphabetizingSwitchValueChanged:(id)sender +{ + [[NSUserDefaults standardUserDefaults] setBool:[sender isOn] forKey:DHDocsetDownloader.defaultsAlphabetizingKey]; + [NSNotificationCenter.defaultCenter postNotificationName:DHSettingsChangedNotification object:DHDocsetDownloader.defaultsAlphabetizingKey]; +} + - (void)tableView:(UITableView *)tableView willDisplayFooterView:(UITableViewHeaderFooterView *)view forSection:(NSInteger)section { [self updateUpdatesSwitchFooterView:view]; diff --git a/Dash/DHRepo.h b/Dash/DHRepo.h index cad6d8f7..c32ec49a 100644 --- a/Dash/DHRepo.h +++ b/Dash/DHRepo.h @@ -68,3 +68,5 @@ @end NSInteger compareFeeds(id feed1, id feed2, void *context); + +#define DHSettingsChangedNotification @"DHSettingsChangedNotification" From e958aa5518bb2814b5619eb5539a32cd0c0eea11 Mon Sep 17 00:00:00 2001 From: Andrei Yangabishev Date: Sat, 13 Jan 2018 23:57:54 +0300 Subject: [PATCH 08/10] Alphabetizing settings screen --- Dash/Base.lproj/Main.storyboard | 34 ++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Dash/Base.lproj/Main.storyboard b/Dash/Base.lproj/Main.storyboard index 7249f9a2..db7be1f4 100644 --- a/Dash/Base.lproj/Main.storyboard +++ b/Dash/Base.lproj/Main.storyboard @@ -209,10 +209,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -264,6 +295,7 @@ + From 83e7028cf69430b59ca2287251b56236b1dd7559 Mon Sep 17 00:00:00 2001 From: Kapeli Date: Sun, 14 Jan 2018 17:56:53 +0200 Subject: [PATCH 09/10] Add DHDocsetBrowserViewModel to Dash App Store target --- Dash/Dash iOS.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dash/Dash iOS.xcodeproj/project.pbxproj b/Dash/Dash iOS.xcodeproj/project.pbxproj index c11354b1..e7305f56 100644 --- a/Dash/Dash iOS.xcodeproj/project.pbxproj +++ b/Dash/Dash iOS.xcodeproj/project.pbxproj @@ -232,6 +232,7 @@ 43EE932A19CD079600FFF30C /* libarchive.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 43EE932919CD079600FFF30C /* libarchive.a */; }; 43EED91C1B607DB800F3DC35 /* on_page_load.js in Resources */ = {isa = PBXBuildFile; fileRef = 43EED91B1B607DB800F3DC35 /* on_page_load.js */; }; 43F25F9C19EBDEF30025CDC4 /* DHBlockProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 43F25F9B19EBDEF30025CDC4 /* DHBlockProtocol.m */; }; + 43F31AAE200BB52F0082066C /* DHDocsetBrowserViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = F5C39BFF200A836D00734571 /* DHDocsetBrowserViewModel.m */; }; 43F70AC019CBBD20000849C8 /* Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = 43F70ABF19CBBD20000849C8 /* Defaults.plist */; }; 43F7527319CD1C2000D76F58 /* UIButton+DHUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 43F7527219CD1C2000D76F58 /* UIButton+DHUtils.m */; }; 43F7527519CD31D100D76F58 /* DHRepoCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 43F7527419CD31D100D76F58 /* DHRepoCell.xib */; }; @@ -1373,6 +1374,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 43F31AAE200BB52F0082066C /* DHDocsetBrowserViewModel.m in Sources */, 43AB65341ED19D2F00A6EC18 /* DHAppDelegate.m in Sources */, 43AB65351ED19D2F00A6EC18 /* DHType.m in Sources */, 43AB65361ED19D2F00A6EC18 /* UIViewController+DHUtils.m in Sources */, From 4b19146f84e3960f6ceb56f45c53278acc4edeef Mon Sep 17 00:00:00 2001 From: Kapeli Date: Sun, 14 Jan 2018 19:07:36 +0200 Subject: [PATCH 10/10] Add alphabetic sort explanation --- Dash/Base.lproj/Main.storyboard | 118 ++++++++++++++++---------------- Dash/DHPreferences.h | 2 + Dash/DHPreferences.m | 29 ++++++-- 3 files changed, 86 insertions(+), 63 deletions(-) diff --git a/Dash/Base.lproj/Main.storyboard b/Dash/Base.lproj/Main.storyboard index db7be1f4..2861cb7a 100644 --- a/Dash/Base.lproj/Main.storyboard +++ b/Dash/Base.lproj/Main.storyboard @@ -13,7 +13,7 @@ - + @@ -29,7 +29,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -120,63 +120,63 @@ - + - + - + - + - + - + - + - + - + @@ -187,21 +187,21 @@ - + - + - + @@ -209,63 +209,63 @@ - + - - + + - + - - - + + - + - - + + - - + + - - - + + @@ -295,7 +295,9 @@ + + @@ -320,7 +322,7 @@ - + @@ -332,7 +334,7 @@ - + @@ -382,7 +384,7 @@ - + @@ -394,7 +396,7 @@ - + @@ -435,7 +437,7 @@ - + @@ -447,7 +449,7 @@ - + @@ -491,7 +493,7 @@ - + @@ -521,7 +523,7 @@ - + @@ -568,7 +570,7 @@ - + @@ -637,7 +639,7 @@ - + @@ -657,7 +659,7 @@ - + @@ -670,7 +672,7 @@ - + @@ -713,7 +715,7 @@ - + @@ -734,7 +736,7 @@ - + @@ -780,11 +782,11 @@ - - - - + + + + diff --git a/Dash/DHPreferences.h b/Dash/DHPreferences.h index 05ede9f8..302712c8 100644 --- a/Dash/DHPreferences.h +++ b/Dash/DHPreferences.h @@ -21,6 +21,8 @@ @property (assign) IBOutlet UISwitch *updatesSwitch; @property (assign) IBOutlet UISwitch *alphabetizingSwitch; +@property (assign) IBOutlet UITableViewCell *updatesCell; +@property (assign) IBOutlet UITableViewCell *alphabetizingCell; @property (assign) BOOL didSetUpdateLabelBefore; - (IBAction)updatesSwitchValueChanged:(id)sender; diff --git a/Dash/DHPreferences.m b/Dash/DHPreferences.m index af31ca51..f664fbb4 100644 --- a/Dash/DHPreferences.m +++ b/Dash/DHPreferences.m @@ -34,6 +34,10 @@ - (void)viewWillAppear:(BOOL)animated [super viewWillAppear:animated]; [self.updatesSwitch setOn:[[NSUserDefaults standardUserDefaults] boolForKey:[[DHDocsetDownloader sharedDownloader] defaultsAutomaticallyCheckForUpdatesKey]]]; [self.alphabetizingSwitch setOn:[NSUserDefaults.standardUserDefaults boolForKey:DHDocsetDownloader.defaultsAlphabetizingKey]]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self updateAlphabetizingSwitchFooterView:nil]; + [self updateUpdatesSwitchFooterView:nil]; + }); } - (void)viewDidAppear:(BOOL)animated @@ -243,18 +247,33 @@ - (IBAction)alphabetizingSwitchValueChanged:(id)sender { [[NSUserDefaults standardUserDefaults] setBool:[sender isOn] forKey:DHDocsetDownloader.defaultsAlphabetizingKey]; [NSNotificationCenter.defaultCenter postNotificationName:DHSettingsChangedNotification object:DHDocsetDownloader.defaultsAlphabetizingKey]; + [self updateAlphabetizingSwitchFooterView:nil]; } -- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UITableViewHeaderFooterView *)view forSection:(NSInteger)section +- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UITableViewHeaderFooterView *)footer forSection:(NSInteger)section { - [self updateUpdatesSwitchFooterView:view]; + if(section == [tableView indexPathForCell:self.updatesCell].section) + { + [self updateUpdatesSwitchFooterView:footer]; + } + else if(section == [tableView indexPathForCell:self.alphabetizingCell].section) + { + [self updateAlphabetizingSwitchFooterView:footer]; + } } - (void)updateUpdatesSwitchFooterView:(UITableViewHeaderFooterView *)footer { - footer = (footer) ?: [self.tableView footerViewForSection:1]; - [footer textLabel].text = [NSString stringWithFormat:@"Dash %@ notify you when docset updates are available. ", (self.updatesSwitch.isOn) ? @"will" : @"won't"]; - + footer = (footer) ? footer : [self.tableView footerViewForSection:[self.tableView indexPathForCell:self.updatesCell].section]; + [footer textLabel].text = [NSString stringWithFormat:@"Dash %@ notify you when docset updates are available.", (self.updatesSwitch.isOn) ? @"will" : @"won't"]; + [[footer textLabel] sizeToFit]; +} + +- (void)updateAlphabetizingSwitchFooterView:(UITableViewHeaderFooterView *)footer +{ + footer = (footer) ? footer : [self.tableView footerViewForSection:[self.tableView indexPathForCell:self.alphabetizingCell].section]; + [footer textLabel].text = [NSString stringWithFormat:@"Docsets %@ be sorted alphabetically in the docset browser.", (self.alphabetizingSwitch.isOn) ? @"will" : @"won't"]; + [[footer textLabel] sizeToFit]; } - (void)prepareForURLSearch:(id)sender