diff --git a/WordPress/Classes/System/WordPress-Bridging-Header.h b/WordPress/Classes/System/WordPress-Bridging-Header.h index c3ca7e875e35..964e933cabd6 100644 --- a/WordPress/Classes/System/WordPress-Bridging-Header.h +++ b/WordPress/Classes/System/WordPress-Bridging-Header.h @@ -65,6 +65,7 @@ #import "WPRichTextView.h" #import #import +#import "WPStyleGuide+ReadableMargins.h" #import "WPTableViewHandler.h" #import #import "WPWebViewController.h" diff --git a/WordPress/Classes/ViewRelated/Me/MeViewController.m b/WordPress/Classes/ViewRelated/Me/MeViewController.m index a30fff14ab4b..9d27b2d53e15 100644 --- a/WordPress/Classes/ViewRelated/Me/MeViewController.m +++ b/WordPress/Classes/ViewRelated/Me/MeViewController.m @@ -8,7 +8,6 @@ // | Log out #import "MeViewController.h" -#import "SettingsViewController.h" #import "SupportViewController.h" #import "UIImageView+AFNetworkingExtra.h" #import "MeHeaderView.h" diff --git a/WordPress/Classes/ViewRelated/Settings/SettingsViewController.h b/WordPress/Classes/ViewRelated/Settings/SettingsViewController.h deleted file mode 100644 index 9c846d774d55..000000000000 --- a/WordPress/Classes/ViewRelated/Settings/SettingsViewController.h +++ /dev/null @@ -1,3 +0,0 @@ -@interface SettingsViewController : UITableViewController - -@end diff --git a/WordPress/Classes/ViewRelated/Settings/SettingsViewController.m b/WordPress/Classes/ViewRelated/Settings/SettingsViewController.m deleted file mode 100644 index 56c44a63ae10..000000000000 --- a/WordPress/Classes/ViewRelated/Settings/SettingsViewController.m +++ /dev/null @@ -1,287 +0,0 @@ -/* - - Settings contents: - - - Image Resize - - Visual Editor - - Shake to Feedback (Internal Beta only) - - */ - -#import "SettingsViewController.h" -#import "WordPressComApi.h" -#import "SupportViewController.h" -#import "WPAccount.h" -#import "WPPostViewController.h" -#import "WPTableViewSectionHeaderFooterView.h" -#import "SupportViewController.h" -#import "ContextManager.h" -#import "NotificationsManager.h" -#import "ContextManager.h" -#import "AccountService.h" -#import "Constants.h" -#import "Mediaservice.h" -#import "WPLookbackPresenter.h" -#import "WordPress-Swift.h" -#import - -#ifdef LOOKBACK_ENABLED -#import -#endif - -typedef enum { - SettingsSectionMedia = 0, - SettingsSectionEditor, - SettingsSectionInternalBeta, - SettingsSectionCount -} SettingsSection; - -static NSString * const WPSettingsRestorationID = @"WPSettingsRestorationID"; -static NSString * const SwitchTableViewCellIdentifier = @"SwitchTableViewCell"; -static NSString * const MediaSizeSliderCellIdentifier = @"MediaSizeSliderCell"; - -static CGFloat const SettingsRowHeight = 44.0; - -static NSInteger const MediaSizeSliderStep = 50; - -@interface SettingsViewController () - -@property (nonatomic, assign) BOOL showInternalBetaSection; - -@end - -@implementation SettingsViewController - -+ (UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder -{ - return [[self alloc] init]; -} - -- (instancetype)init -{ - self = [super initWithStyle:UITableViewStyleGrouped]; - if (self) { - self.restorationIdentifier = WPSettingsRestorationID; - self.restorationClass = [self class]; - } - return self; -} - -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} - -#pragma mark - View lifecycle - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - self.title = NSLocalizedString(@"Settings", @"App Settings"); - -#ifdef LOOKBACK_ENABLED - self.showInternalBetaSection = YES; -#else - self.showInternalBetaSection = NO; -#endif - - [self.tableView registerNib:[UINib nibWithNibName:@"MediaSizeSliderCell" bundle:nil] forCellReuseIdentifier:MediaSizeSliderCellIdentifier]; - [self.tableView registerClass:[SwitchTableViewCell class] forCellReuseIdentifier:SwitchTableViewCellIdentifier]; - - [WPStyleGuide resetReadableMarginsForTableView:self.tableView]; - [WPStyleGuide configureColorsForView:self.view andTableView:self.tableView]; -} - -- (void)viewWillAppear:(BOOL)animated -{ - [super viewWillAppear:animated]; - [self.navigationController setNavigationBarHidden:NO animated:animated]; - [self.tableView reloadData]; -} - - -#pragma mark - Cell Actions - -- (void)handleImageSizeChanged:(NSInteger)value -{ - [MediaService setMaxImageSizeSetting:CGSizeMake(value, value)]; -} - -- (void)handleEditorChanged:(BOOL)value -{ - if (value) { - [WPAnalytics track:WPAnalyticsStatEditorToggledOn]; - } else { - [WPAnalytics track:WPAnalyticsStatEditorToggledOff]; - } - [WPPostViewController setNewEditorEnabled:value]; -} - -- (void)handleShakeToPullUpFeedbackChanged:(BOOL)value -{ -#ifdef LOOKBACK_ENABLED - [[NSUserDefaults standardUserDefaults] setBool:value forKey:WPLookbackPresenterShakeToPullUpFeedbackKey]; - [Lookback lookback].shakeToRecord = value; -#endif -} - -#pragma mark - Table view data source - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView -{ - return [self.tableView isEditing] ? 1 : SettingsSectionCount; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - switch (section) { - case SettingsSectionMedia: - return 1; - - case SettingsSectionEditor: { - if (![WPPostViewController isNewEditorAvailable]) { - return 0; - } else { - return 1; - } - } - - case SettingsSectionInternalBeta: - if (self.showInternalBetaSection) { - return 1; - } - else { - return 0; - } - default: - return 0; - - } -} - -- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section -{ - if (section == SettingsSectionEditor && ![WPPostViewController isNewEditorAvailable]) { - return nil; - } - - WPTableViewSectionHeaderFooterView *header = [[WPTableViewSectionHeaderFooterView alloc] initWithReuseIdentifier:nil style:WPTableViewSectionStyleHeader]; - header.title = [self titleForHeaderInSection:section]; - return header; -} - -- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section -{ - if (section == SettingsSectionEditor && ![WPPostViewController isNewEditorAvailable]) { - return 1; - } - - NSString *title = [self titleForHeaderInSection:section]; - return [WPTableViewSectionHeaderFooterView heightForHeader:title width:CGRectGetWidth(self.view.bounds)]; -} - -- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section -{ - static const CGFloat kDefaultFooterHeight = 16.0f; - - if (section == SettingsSectionEditor && ![WPPostViewController isNewEditorAvailable]) { - return 1; - } else { - return kDefaultFooterHeight; - } -} - -- (NSString *)titleForHeaderInSection:(NSInteger)section -{ - if (section == SettingsSectionMedia) { - return NSLocalizedString(@"Media", @"Title label for the media settings section in the app settings"); - - } else if (section == SettingsSectionEditor) { - return NSLocalizedString(@"Editor", @"Title label for the editor settings section in the app settings"); - - } else if (section == SettingsSectionInternalBeta) { - if (self.showInternalBetaSection) { - return NSLocalizedString(@"Internal Beta", @""); - } else { - return @""; - } - } - - return nil; -} - -- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath -{ - if (indexPath.section == SettingsSectionMedia) { - return [MediaSizeSliderCell height]; - } - return SettingsRowHeight; -} - -- (UITableViewCell *)cellForMediaSizeInTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath { - MediaSizeSliderCell *cell = [tableView dequeueReusableCellWithIdentifier:MediaSizeSliderCellIdentifier forIndexPath:indexPath]; - cell.title = NSLocalizedString(@"Max Image Upload Size", @"Title for the image size settings option."); - cell.minValue = MediaMinImageSizeDimension; - cell.maxValue = MediaMaxImageSizeDimension; - cell.step = MediaSizeSliderStep; - cell.value = [MediaService maxImageSizeSetting].width; - - __weak SettingsViewController *weakSelf = self; - cell.onChange = ^(NSInteger value) { - [weakSelf handleImageSizeChanged:value]; - }; - - return cell; -} - -- (UITableViewCell *)cellForVisualEditorInTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath { - SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SwitchTableViewCellIdentifier forIndexPath:indexPath]; - cell.name = NSLocalizedString(@"Visual Editor", @"Option to enable the visual editor"); - cell.on = [WPPostViewController isNewEditorEnabled]; - - __weak SettingsViewController *weakSelf = self; - cell.onChange = ^(BOOL value) { - [weakSelf handleEditorChanged:value]; - }; - - return cell; -} - -- (UITableViewCell *)cellForFeedbackInTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath { -#ifndef LOOKBACK_ENABLED - NSAssert(NO, @"Should never execute this when Lookback is disabled."); -#endif - SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SwitchTableViewCellIdentifier forIndexPath:indexPath]; - cell.name = NSLocalizedString(@"Shake for Feedback", @"Option to allow the user to shake the device to pull up the feedback mechanism"); - cell.on = [[NSUserDefaults standardUserDefaults] boolForKey:WPLookbackPresenterShakeToPullUpFeedbackKey]; - - __weak SettingsViewController *weakSelf = self; - cell.onChange = ^(BOOL value) { - [weakSelf handleShakeToPullUpFeedbackChanged:value]; - }; - return cell; -} - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - UITableViewCell *cell = nil; - switch (indexPath.section) { - case SettingsSectionMedia: - cell = [self cellForMediaSizeInTableView:tableView indexPath:indexPath]; - break; - case SettingsSectionEditor: - cell = [self cellForVisualEditorInTableView:tableView indexPath:indexPath]; - break; - case SettingsSectionInternalBeta: - cell = [self cellForFeedbackInTableView:tableView indexPath:indexPath]; - break; - } - NSAssert(cell != nil, @"We should have a cell by now"); - - [WPStyleGuide configureTableViewCell:cell]; - - return cell; -} - -@end diff --git a/WordPress/Classes/ViewRelated/Settings/SettingsViewController.swift b/WordPress/Classes/ViewRelated/Settings/SettingsViewController.swift new file mode 100644 index 000000000000..48297cf51bfd --- /dev/null +++ b/WordPress/Classes/ViewRelated/Settings/SettingsViewController.swift @@ -0,0 +1,78 @@ +import Foundation +import UIKit +import WordPressShared +import WordPressComAnalytics + +class SettingsViewController: UITableViewController { + var handler: ImmuTableViewHandler! + + required convenience init() { + self.init(style: .Grouped) + } + + override func viewDidLoad() { + super.viewDidLoad() + + self.title = NSLocalizedString("Settings", comment: "App Settings"); + + ImmuTable.registerRows([ + MediaSizeRow.self, + SwitchRow.self + ], tableView: self.tableView) + handler = ImmuTableViewHandler(takeOver: self) + + WPStyleGuide.resetReadableMarginsForTableView(tableView) + WPStyleGuide.configureColorsForView(view, andTableView: tableView) + + buildViewModel() + } + + func buildViewModel() { + let uploadSize = MediaSizeRow( + title: NSLocalizedString("Max Image Upload Size", comment: "Title for the image size settings option."), + value: Int(MediaService.maxImageSizeSetting().width), + onChange: mediaSizeChanged()) + + let visualEditor = SwitchRow( + title: NSLocalizedString("Visual Editor", comment: "Option to enable the visual editor"), + value: WPPostViewController.isNewEditorEnabled(), + onChange: visualEditorChanged() + ) + + handler.viewModel = ImmuTable(sections: [ + ImmuTableSection( + headerText: NSLocalizedString("Media", comment: "Title label for the media settings section in the app settings"), + rows: [ + uploadSize + ], + footerText: nil), + ImmuTableSection( + headerText: NSLocalizedString("Editor", comment: "Title label for the editor settings section in the app settings"), + rows: [ + visualEditor + ], + footerText: nil) + ]) + } + + func mediaSizeChanged() -> Int -> Void { + return { + value in + let size = CGSize(width: value, height: value) + MediaService.setMaxImageSizeSetting(size) + } + } + + func visualEditorChanged() -> Bool -> Void { + return { + enabled in + if enabled { + WPAnalytics.track(.EditorToggledOn) + } else { + WPAnalytics.track(.EditorToggledOff) + } + WPPostViewController.setNewEditorEnabled(enabled) + } + } +} + diff --git a/WordPress/Classes/ViewRelated/Stats/StatsViewController.m b/WordPress/Classes/ViewRelated/Stats/StatsViewController.m index 8e7a749462ad..6e8948dbc7c4 100644 --- a/WordPress/Classes/ViewRelated/Stats/StatsViewController.m +++ b/WordPress/Classes/ViewRelated/Stats/StatsViewController.m @@ -7,7 +7,6 @@ #import "WPAccount.h" #import "ContextManager.h" #import "BlogService.h" -#import "SettingsViewController.h" #import "SFHFKeychainUtils.h" #import "TodayExtensionService.h" #import diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index df2836d7a221..9f58833a73cd 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -458,6 +458,7 @@ CEBD3EAB0FF1BA3B00C1396E /* Blog.m in Sources */ = {isa = PBXBuildFile; fileRef = CEBD3EAA0FF1BA3B00C1396E /* Blog.m */; }; E100C6BB1741473000AE48D8 /* WordPress-11-12.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = E100C6BA1741472F00AE48D8 /* WordPress-11-12.xcmappingmodel */; }; E10A2E9B134E8AD3007643F9 /* PostAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 833AF25A114575A50016DE8F /* PostAnnotation.m */; }; + E10AEA061C1196F2000829DC /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E10AEA051C1196F2000829DC /* SettingsViewController.swift */; }; E10B3652158F2D3F00419A93 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E10B3651158F2D3F00419A93 /* QuartzCore.framework */; }; E10B3654158F2D4500419A93 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E10B3653158F2D4500419A93 /* UIKit.framework */; }; E10B3655158F2D7800419A93 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 834CE7371256D0F60046A4A3 /* CoreGraphics.framework */; }; @@ -533,7 +534,6 @@ E1A6DBE119DC7D140071AC1E /* PostServiceRemoteREST.m in Sources */ = {isa = PBXBuildFile; fileRef = E1A6DBDE19DC7D140071AC1E /* PostServiceRemoteREST.m */; }; E1A6DBE219DC7D140071AC1E /* PostServiceRemoteXMLRPC.m in Sources */ = {isa = PBXBuildFile; fileRef = E1A6DBE019DC7D140071AC1E /* PostServiceRemoteXMLRPC.m */; }; E1A6DBE519DC7D230071AC1E /* PostService.m in Sources */ = {isa = PBXBuildFile; fileRef = E1A6DBE419DC7D230071AC1E /* PostService.m */; }; - E1AB07AD1578D34300D6AD64 /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E1AB07AC1578D34300D6AD64 /* SettingsViewController.m */; }; E1AC282D18282423004D394C /* SFHFKeychainUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 292CECFF1027259000BD407D /* SFHFKeychainUtils.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; E1B289DB19F7AF7000DB0707 /* RemoteBlog.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B289DA19F7AF7000DB0707 /* RemoteBlog.m */; }; E1B4A9E112FC8B1000EB3F67 /* EGORefreshTableHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B4A9E012FC8B1000EB3F67 /* EGORefreshTableHeaderView.m */; }; @@ -1480,6 +1480,7 @@ E105E9CE1726955600C0D9E7 /* WPAccount.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WPAccount.m; sourceTree = ""; }; E10675C7183F82E900E5CE5C /* SettingsViewControllerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingsViewControllerTest.m; sourceTree = ""; }; E10675C9183FA78E00E5CE5C /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; + E10AEA051C1196F2000829DC /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; E10B3651158F2D3F00419A93 /* QuartzCore.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; E10B3653158F2D4500419A93 /* UIKit.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; E10DB0061771926D00B7A0A3 /* GooglePlusActivity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GooglePlusActivity.h; sourceTree = ""; }; @@ -1607,8 +1608,6 @@ E1A6DBE019DC7D140071AC1E /* PostServiceRemoteXMLRPC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PostServiceRemoteXMLRPC.m; sourceTree = ""; }; E1A6DBE319DC7D230071AC1E /* PostService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostService.h; sourceTree = ""; }; E1A6DBE419DC7D230071AC1E /* PostService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = PostService.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; - E1AB07AB1578D34300D6AD64 /* SettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsViewController.h; sourceTree = ""; }; - E1AB07AC1578D34300D6AD64 /* SettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = SettingsViewController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; E1B289D919F7AF7000DB0707 /* RemoteBlog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RemoteBlog.h; path = "Remote Objects/RemoteBlog.h"; sourceTree = ""; }; E1B289DA19F7AF7000DB0707 /* RemoteBlog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RemoteBlog.m; path = "Remote Objects/RemoteBlog.m"; sourceTree = ""; }; E1B4A9DF12FC8B1000EB3F67 /* EGORefreshTableHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EGORefreshTableHeaderView.h; sourceTree = ""; }; @@ -2416,8 +2415,7 @@ 93069F581762410B000C966D /* ActivityLogDetailViewController.m */, 93069F54176237A4000C966D /* ActivityLogViewController.h */, 93069F55176237A4000C966D /* ActivityLogViewController.m */, - E1AB07AB1578D34300D6AD64 /* SettingsViewController.h */, - E1AB07AC1578D34300D6AD64 /* SettingsViewController.m */, + E10AEA051C1196F2000829DC /* SettingsViewController.swift */, 93027BB61758332300483FFD /* SupportViewController.h */, 93027BB71758332300483FFD /* SupportViewController.m */, ); @@ -4680,7 +4678,6 @@ B55853F31962337500FAF6C3 /* NSScanner+Helpers.m in Sources */, B5EFB1C21B31B98E007608A3 /* NotificationsService.swift in Sources */, 5903AE1B19B60A98009D5354 /* WPButtonForNavigationBar.m in Sources */, - E1AB07AD1578D34300D6AD64 /* SettingsViewController.m in Sources */, E13EB7A5157D230000885780 /* WordPressComApi.m in Sources */, 5D5D0027187DA9D30027CEF6 /* PostCategoriesViewController.m in Sources */, E1E4CE0B1773C59B00430844 /* WPAvatarSource.m in Sources */, @@ -4862,6 +4859,7 @@ 5D44EB381986D8BA008B7175 /* ReaderSiteService.m in Sources */, E1A03F48174283E10085D192 /* BlogToJetpackAccount.m in Sources */, 31F4F6671A1385BE00196A98 /* MeViewController.m in Sources */, + E10AEA061C1196F2000829DC /* SettingsViewController.swift in Sources */, B522C4F81B3DA79B00E47B59 /* NotificationSettingsViewController.swift in Sources */, B587797C19B799D800E57C5A /* NSParagraphStyle+Helpers.swift in Sources */, 5D6C4B121B604190005E3C43 /* RichTextView.swift in Sources */,