-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Reorganizes post options in Settings. #4767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,13 +43,19 @@ | |
| }; | ||
|
|
||
| NS_ENUM(NSInteger, SiteSettingsWriting) { | ||
| SiteSettingsWritingGeotagging = 0, | ||
| SiteSettingsWritingDefaultCategory, | ||
| SiteSettingsWritingDefaultCategory = 0, | ||
| SiteSettingsWritingDefaultPostFormat, | ||
| SiteSettingsWritingRelatedPosts, | ||
| SiteSettingsWritingCount, | ||
| }; | ||
|
|
||
| NS_ENUM(NSInteger, SiteSettingsDevice) { | ||
| SiteSettingsDeviceGeotagging = 0, | ||
| SiteSettingsDeviceDefaultCategory, | ||
| SiteSettingsDeviceDefaultPostFormat, | ||
| SiteSettingsDeviceCount, | ||
| }; | ||
|
|
||
| NS_ENUM(NSInteger, SiteSettingsAdvanced) { | ||
| SiteSettingsAdvancedStartOver = 0, | ||
| SiteSettingsAdvancedDeleteSite, | ||
|
|
@@ -61,6 +67,7 @@ | |
| SiteSettingsSectionAccount, | ||
| SiteSettingsSectionWriting, | ||
| SiteSettingsSectionDiscussion, | ||
| SiteSettingsSectionDevice, | ||
| SiteSettingsSectionRemoveSite, | ||
| SiteSettingsSectionAdvanced, | ||
| }; | ||
|
|
@@ -78,12 +85,13 @@ @interface SiteSettingsViewController () <UITableViewDelegate, UITextFieldDelega | |
| @property (nonatomic, strong) SettingTableViewCell *usernameTextCell; | ||
| @property (nonatomic, strong) SettingTableViewCell *passwordTextCell; | ||
| #pragma mark - Writing Section | ||
| @property (nonatomic, strong) SwitchTableViewCell *geotaggingCell; | ||
| @property (nonatomic, strong) SettingTableViewCell *defaultCategoryCell; | ||
| @property (nonatomic, strong) SettingTableViewCell *defaultPostFormatCell; | ||
| @property (nonatomic, strong) SettingTableViewCell *relatedPostsCell; | ||
| #pragma mark - Discussion | ||
| #pragma mark - Discussion Section | ||
| @property (nonatomic, strong) SettingTableViewCell *discussionSettingsCell; | ||
| #pragma mark - Device Section | ||
| @property (nonatomic, strong) SwitchTableViewCell *geotaggingCell; | ||
| #pragma mark - Removal Section | ||
| @property (nonatomic, strong) UITableViewCell *removeSiteCell; | ||
| #pragma mark - Advanced Section | ||
|
|
@@ -128,12 +136,16 @@ - (void)viewDidLoad | |
| [sections addObject:@(SiteSettingsSectionAccount)]; | ||
| } | ||
|
|
||
| [sections addObject:@(SiteSettingsSectionWriting)]; | ||
| if ([self.blog supports:BlogFeatureWPComRESTAPI] && self.blog.isAdmin) { | ||
| [sections addObject:@(SiteSettingsSectionWriting)]; | ||
| } | ||
|
|
||
| if ([self.blog supports:BlogFeatureWPComRESTAPI]) { | ||
| [sections addObject:@(SiteSettingsSectionDiscussion)]; | ||
| } | ||
|
|
||
| [sections addObject:@(SiteSettingsSectionDevice)]; | ||
|
|
||
| if ([self.blog supports:BlogFeatureRemovable]) { | ||
| [sections addObject:@(SiteSettingsSectionRemoveSite)]; | ||
| } | ||
|
|
@@ -195,21 +207,19 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger | |
| return SiteSettingsAccountCount; | ||
| } | ||
| case SiteSettingsSectionWriting: { | ||
| if (!self.blog.isAdmin) { | ||
| // If we're not admin, we just want to show the geotagging cell | ||
| return 1; | ||
| } | ||
| NSInteger rowsToHide = 0; | ||
| if (![self.blog supports:BlogFeatureWPComRESTAPI]) { | ||
| // NOTE: Sergio Estevao (2015-09-23): Hides the related post for self-hosted sites not in jetpack | ||
| // because this options is not available for them. | ||
| rowsToHide += 1; | ||
| } | ||
| return SiteSettingsWritingCount - rowsToHide; | ||
| return SiteSettingsWritingCount; | ||
| } | ||
| case SiteSettingsSectionDiscussion: { | ||
| return 1; | ||
| } | ||
| case SiteSettingsSectionDevice: { | ||
| if ([self.blog supports:BlogFeatureWPComRESTAPI]) { | ||
| // NOTE: Brent Coursey (2016-02-03): Only show geotagging cell for user of the REST API (REST). | ||
| // Any post default options are available in the Writing section for REST users. | ||
| return 1; | ||
| } | ||
| return SiteSettingsDeviceCount; | ||
| } | ||
| case SiteSettingsSectionRemoveSite: { | ||
| return 1; | ||
| } | ||
|
|
@@ -339,22 +349,28 @@ - (UITableViewCell *)removeSiteCell | |
| return _removeSiteCell; | ||
| } | ||
|
|
||
| - (void)configureDefaultCategoryCell | ||
| { | ||
| PostCategoryService *postCategoryService = [[PostCategoryService alloc] initWithManagedObjectContext:[[ContextManager sharedInstance] mainContext]]; | ||
| PostCategory *postCategory = [postCategoryService findWithBlogObjectID:self.blog.objectID andCategoryID:self.blog.settings.defaultCategoryID]; | ||
| [self.defaultCategoryCell setTextValue:[postCategory categoryName]]; | ||
| } | ||
|
|
||
| - (void)configureDefaultPostFormatCell | ||
| { | ||
| [self.defaultPostFormatCell setTextValue:self.blog.defaultPostFormatText]; | ||
| } | ||
|
|
||
| - (UITableViewCell *)tableView:(UITableView *)tableView cellForWritingSettingsAtRow:(NSInteger)row | ||
| { | ||
| switch (row) { | ||
| case (SiteSettingsWritingGeotagging):{ | ||
| return self.geotaggingCell; | ||
| } | ||
| break; | ||
| case (SiteSettingsWritingDefaultCategory):{ | ||
| PostCategoryService *postCategoryService = [[PostCategoryService alloc] initWithManagedObjectContext:[[ContextManager sharedInstance] mainContext]]; | ||
| PostCategory *postCategory = [postCategoryService findWithBlogObjectID:self.blog.objectID andCategoryID:self.blog.settings.defaultCategoryID]; | ||
| [self.defaultCategoryCell setTextValue:[postCategory categoryName]]; | ||
| [self configureDefaultCategoryCell]; | ||
| return self.defaultCategoryCell; | ||
| } | ||
| break; | ||
| case (SiteSettingsWritingDefaultPostFormat):{ | ||
| [self.defaultPostFormatCell setTextValue:self.blog.defaultPostFormatText]; | ||
| [self configureDefaultPostFormatCell]; | ||
| return self.defaultPostFormatCell; | ||
| } | ||
| case (SiteSettingsWritingRelatedPosts):{ | ||
|
|
@@ -366,6 +382,28 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForWritingSettingsAt | |
| return nil; | ||
| } | ||
|
|
||
| - (UITableViewCell *)tableView:(UITableView *)tableView cellForDeviceSettingsAtRow:(NSInteger)row | ||
| { | ||
| switch (row) { | ||
| case (SiteSettingsDeviceGeotagging):{ | ||
| return self.geotaggingCell; | ||
| } | ||
| break; | ||
| case (SiteSettingsDeviceDefaultCategory):{ | ||
| [self configureDefaultCategoryCell]; | ||
| return self.defaultCategoryCell; | ||
| } | ||
| break; | ||
| case (SiteSettingsDeviceDefaultPostFormat):{ | ||
| [self configureDefaultPostFormatCell]; | ||
| return self.defaultPostFormatCell; | ||
| } | ||
| break; | ||
|
|
||
| } | ||
| return nil; | ||
| } | ||
|
|
||
| - (SettingTableViewCell *)siteTitleCell | ||
| { | ||
| if (_siteTitleCell) { | ||
|
|
@@ -494,6 +532,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N | |
| case SiteSettingsSectionDiscussion: { | ||
| return self.discussionSettingsCell; | ||
| } | ||
| case SiteSettingsSectionDevice: { | ||
| return [self tableView:tableView cellForDeviceSettingsAtRow:indexPath.row]; | ||
| } | ||
| case SiteSettingsSectionRemoveSite: { | ||
| return self.removeSiteCell; | ||
| } | ||
|
|
@@ -546,6 +587,9 @@ - (NSString *)titleForHeaderInSection:(NSInteger)section | |
| case SiteSettingsSectionWriting: | ||
| headingTitle = NSLocalizedString(@"Writing", @"Title for the writing section in site settings screen"); | ||
| break; | ||
| case SiteSettingsSectionDevice: | ||
| headingTitle = NSLocalizedString(@"This Device", @"Title for the device section in site settings screen"); | ||
| break; | ||
| case SiteSettingsSectionAdvanced: | ||
| headingTitle = NSLocalizedString(@"Advanced", @"Title for the advanced section in site settings screen"); | ||
| break; | ||
|
|
@@ -659,6 +703,22 @@ - (void)tableView:(UITableView *)tableView didSelectInAccountSectionRow:(NSInteg | |
| } | ||
| } | ||
|
|
||
| - (void)showDefaultCategorySelector | ||
| { | ||
| PostCategoryService *postCategoryService = [[PostCategoryService alloc] initWithManagedObjectContext:[[ContextManager sharedInstance] mainContext]]; | ||
| NSNumber *defaultCategoryID = self.blog.settings.defaultCategoryID ?: @(PostCategoryUncategorized); | ||
| PostCategory *postCategory = [postCategoryService findWithBlogObjectID:self.blog.objectID andCategoryID:defaultCategoryID]; | ||
| NSArray *currentSelection = @[]; | ||
| if (postCategory){ | ||
| currentSelection = @[postCategory]; | ||
| } | ||
| PostCategoriesViewController *postCategoriesViewController = [[PostCategoriesViewController alloc] initWithBlog:self.blog | ||
| currentSelection:currentSelection | ||
| selectionMode:CategoriesSelectionModeBlogDefault]; | ||
| postCategoriesViewController.delegate = self; | ||
| [self.navigationController pushViewController:postCategoriesViewController animated:YES]; | ||
| } | ||
|
|
||
| - (void)showPostFormatSelector | ||
| { | ||
| NSArray *titles = self.blog.sortedPostFormatNames; | ||
|
|
@@ -685,7 +745,9 @@ - (void)showPostFormatSelector | |
| if ([status isKindOfClass:[NSString class]]) { | ||
| if (weakSelf.blog.settings.defaultPostFormat != status) { | ||
| weakSelf.blog.settings.defaultPostFormat = status; | ||
| [weakSelf saveSettings]; | ||
| if ([weakSelf savingWritingDefaultsIsAvailable]) { | ||
| [weakSelf saveSettings]; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
@@ -704,18 +766,7 @@ - (void)tableView:(UITableView *)tableView didSelectInWritingSectionRow:(NSInteg | |
| { | ||
| switch (row) { | ||
| case SiteSettingsWritingDefaultCategory:{ | ||
| PostCategoryService *postCategoryService = [[PostCategoryService alloc] initWithManagedObjectContext:[[ContextManager sharedInstance] mainContext]]; | ||
| NSNumber *defaultCategoryID = self.blog.settings.defaultCategoryID ?: @(PostCategoryUncategorized); | ||
| PostCategory *postCategory = [postCategoryService findWithBlogObjectID:self.blog.objectID andCategoryID:defaultCategoryID]; | ||
| NSArray *currentSelection = @[]; | ||
| if (postCategory){ | ||
| currentSelection = @[postCategory]; | ||
| } | ||
| PostCategoriesViewController *postCategoriesViewController = [[PostCategoriesViewController alloc] initWithBlog:self.blog | ||
| currentSelection:currentSelection | ||
| selectionMode:CategoriesSelectionModeBlogDefault]; | ||
| postCategoriesViewController.delegate = self; | ||
| [self.navigationController pushViewController:postCategoriesViewController animated:YES]; | ||
| [self showDefaultCategorySelector]; | ||
| } | ||
| break; | ||
| case SiteSettingsWritingDefaultPostFormat:{ | ||
|
|
@@ -726,7 +777,20 @@ - (void)tableView:(UITableView *)tableView didSelectInWritingSectionRow:(NSInteg | |
| [self showRelatedPostsSettings]; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| - (void)tableView:(UITableView *)tableView didSelectInDeviceSectionRow:(NSInteger)row | ||
| { | ||
| switch (row) { | ||
| case SiteSettingsDeviceDefaultCategory:{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the |
||
| [self showDefaultCategorySelector]; | ||
| } | ||
| break; | ||
| case SiteSettingsDeviceDefaultPostFormat:{ | ||
| [self showPostFormatSelector]; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -774,6 +838,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath | |
| case SiteSettingsSectionDiscussion: { | ||
| [self showDiscussionSettingsForBlog:self.blog]; | ||
| } break; | ||
| case SiteSettingsSectionDevice: { | ||
| [self tableView:tableView didSelectInDeviceSectionRow:indexPath.row]; | ||
| } break; | ||
| case SiteSettingsSectionRemoveSite:{ | ||
| [tableView deselectSelectedRowWithAnimation:YES]; | ||
| [self showRemoveSiteForBlog:self.blog]; | ||
|
|
@@ -932,6 +999,11 @@ - (void)saveSettings | |
| }]; | ||
| } | ||
|
|
||
| - (BOOL)savingWritingDefaultsIsAvailable | ||
| { | ||
| return [self.blog supports:BlogFeatureWPComRESTAPI] && self.blog.isAdmin; | ||
| } | ||
|
|
||
| - (IBAction)cancel:(id)sender | ||
| { | ||
| if (self.isCancellable) { | ||
|
|
@@ -1002,7 +1074,9 @@ - (void)postCategoriesViewController:(PostCategoriesViewController *)controller | |
| { | ||
| self.blog.settings.defaultCategoryID = category.categoryID; | ||
| self.defaultCategoryCell.detailTextLabel.text = category.categoryName; | ||
| [self saveSettings]; | ||
| if ([self savingWritingDefaultsIsAvailable]) { | ||
| [self saveSettings]; | ||
| } | ||
| } | ||
|
|
||
| @end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nitpicky code style stuff, but for consistency within the file maybe remove the parenthesis in the
casestatements and remove thebreaks since each case returns?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The style consistency of the switch cases and breaks in this file are all over the place. I'm going to leave this alone for now as it would require touching a lot more code than the context of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough :)