diff options
Diffstat (limited to 'Example Apps')
5 files changed, 30 insertions, 14 deletions
diff --git a/Example Apps/Example ObjC/ConnectionContainerViewController.m b/Example Apps/Example ObjC/ConnectionContainerViewController.m index 544a9f3c9..6075ccc8b 100644 --- a/Example Apps/Example ObjC/ConnectionContainerViewController.m +++ b/Example Apps/Example ObjC/ConnectionContainerViewController.m @@ -8,7 +8,7 @@ #import "ConnectionIAPTableViewController.h" #import "ConnectionTransitionContext.h" #import "ConnectionAnimatedTransition.h" - +#import "Preferences.h" @interface ConnectionContainerViewController () @@ -42,13 +42,13 @@ [self.view addGestureRecognizer:self.panGestureRecognizer]; // Setup initial view controller state - self.connectionTypeSegmentedControl.selectedSegmentIndex = 0; + self.connectionTypeSegmentedControl.selectedSegmentIndex = [Preferences sharedPreferences].lastUsedSegment; [self loadInitialChildViewController]; } - (void)loadInitialChildViewController { // On the initial load, we just add the new child VC with no animation - UIViewController *initialViewController = self.viewControllers[0]; + UIViewController *initialViewController = self.viewControllers[[Preferences sharedPreferences].lastUsedSegment]; [self addChildViewController:initialViewController]; [self.view addSubview:initialViewController.view]; [initialViewController didMoveToParentViewController:self]; @@ -60,6 +60,7 @@ #pragma mark - IBActions - (IBAction)connectionTypeSegmentedControlSelectedIndexDidChange:(UISegmentedControl *)sender { + [Preferences sharedPreferences].lastUsedSegment = sender.selectedSegmentIndex; [self transitionToViewControllerForSelectedIndex:sender.selectedSegmentIndex]; } diff --git a/Example Apps/Example ObjC/Preferences.h b/Example Apps/Example ObjC/Preferences.h index 4a982b7fc..eb20758fd 100644 --- a/Example Apps/Example ObjC/Preferences.h +++ b/Example Apps/Example ObjC/Preferences.h @@ -16,6 +16,7 @@ // Connection @property (strong, nonatomic) NSString *ipAddress; @property (assign, nonatomic) UInt16 port; +@property (assign, nonatomic) UInt8 lastUsedSegment; + (instancetype)sharedPreferences; diff --git a/Example Apps/Example ObjC/Preferences.m b/Example Apps/Example ObjC/Preferences.m index a3082bd4f..8d2c8e680 100644 --- a/Example Apps/Example ObjC/Preferences.m +++ b/Example Apps/Example ObjC/Preferences.m @@ -7,21 +7,14 @@ NSString *const IPAddressPreferencesKey = @"SDLExampleAppIPAddress"; NSString *const PortPreferencesKey = @"SDLExampleAppPort"; +NSString *const LastUsedSegmentPreferencesKey = @"SDLExampleLastSegment"; NSString *const DefaultIPAddressValue = @"192.168.1.1"; UInt16 const DefaultPortValue = 12345; - - - -@interface Preferences () - -@end - - +UInt8 const DefaultSegment = 0; @implementation Preferences - #pragma mark - Singleton / Initializers + (instancetype)sharedPreferences { @@ -53,6 +46,7 @@ UInt16 const DefaultPortValue = 12345; - (void)resetPreferences { self.ipAddress = DefaultIPAddressValue; self.port = DefaultPortValue; + self.lastUsedSegment = DefaultSegment; } @@ -74,6 +68,14 @@ UInt16 const DefaultPortValue = 12345; [self setInteger:port forKey:PortPreferencesKey]; } +- (UInt8)lastUsedSegment { + return (UInt8)[self integerForKey:LastUsedSegmentPreferencesKey]; +} + +- (void)setLastUsedSegment:(UInt8)lastUsedSegment { + [self setInteger:lastUsedSegment forKey:LastUsedSegmentPreferencesKey]; +} + #pragma mark - Private User Defaults Helpers diff --git a/Example Apps/Example Swift/AppUserDefaults.swift b/Example Apps/Example Swift/AppUserDefaults.swift index 2589ab467..5fc63c437 100644 --- a/Example Apps/Example Swift/AppUserDefaults.swift +++ b/Example Apps/Example Swift/AppUserDefaults.swift @@ -10,6 +10,7 @@ class AppUserDefaults { struct Keys { static let ipAddress = "ipAddress" static let port = "port" + static let lastUsedSegment = "lastUsedSegment" } static let shared = AppUserDefaults() @@ -19,6 +20,7 @@ class AppUserDefaults { defaults[Keys.ipAddress] = String() defaults[Keys.port] = String() + defaults[Keys.lastUsedSegment] = 0 UserDefaults.standard.register(defaults: defaults) } @@ -40,4 +42,13 @@ class AppUserDefaults { UserDefaults.standard.setValue(newValue!, forKeyPath: Keys.port) } } + + var lastUsedSegment: Int? { + get { + return UserDefaults.standard.integer(forKey: Keys.lastUsedSegment) + } + set { + UserDefaults.standard.set(newValue!, forKey: Keys.lastUsedSegment) + } + } } diff --git a/Example Apps/Example Swift/ConnectionContainerViewController.swift b/Example Apps/Example Swift/ConnectionContainerViewController.swift index e990712fa..de7f12898 100644 --- a/Example Apps/Example Swift/ConnectionContainerViewController.swift +++ b/Example Apps/Example Swift/ConnectionContainerViewController.swift @@ -22,8 +22,9 @@ class ConnectionContainerViewController: UIViewController { viewControllers.append(tcpController) viewControllers.append(iapController) - segmentedControl.selectedSegmentIndex = 0 - loadChildViewController(index: 0) + let defaultSegment = AppUserDefaults.shared.lastUsedSegment! + segmentedControl.selectedSegmentIndex = defaultSegment + loadChildViewController(index: defaultSegment) let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(slideToLeftWithGestureRecognizer(gestureRecognizer:))) let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(slideToRightWithGestureRecognizer(gestureRecognizer:))) |