diff options
author | Satbir Tanda <satbirtanda@gmail.com> | 2019-07-10 15:38:25 -0700 |
---|---|---|
committer | Satbir Tanda <satbirtanda@gmail.com> | 2019-07-10 15:38:25 -0700 |
commit | d681a3cceedad4eb593e9a044d2678e86a99cbbc (patch) | |
tree | 6149419ed2a164b8c5064bcaaf78618dbbdb7f29 | |
parent | 2ecbbe7951830e7f2d48e8ac6819d242424248ef (diff) | |
download | sdl_ios-d681a3cceedad4eb593e9a044d2678e86a99cbbc.tar.gz |
Make recommended fixes
-rw-r--r-- | SmartDeviceLink/SDLLockScreenManager.h | 2 | ||||
-rw-r--r-- | SmartDeviceLink/SDLLockScreenManager.m | 35 | ||||
-rw-r--r-- | SmartDeviceLink/SDLLockScreenViewController.h | 14 | ||||
-rw-r--r-- | SmartDeviceLink/SDLLockScreenViewController.m | 20 |
4 files changed, 44 insertions, 27 deletions
diff --git a/SmartDeviceLink/SDLLockScreenManager.h b/SmartDeviceLink/SDLLockScreenManager.h index 8d48a63b8..113c67846 100644 --- a/SmartDeviceLink/SDLLockScreenManager.h +++ b/SmartDeviceLink/SDLLockScreenManager.h @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN /** * Whether or not the lock screen is currently dismissable */ -@property (assign, nonatomic, readonly) BOOL lockScreenDismissableEnabled; +@property (assign, nonatomic, readonly, getter=isLockScreenDismissable) BOOL lockScreenDismissableEnabled; /** * The lock screen configuration used to set up the manager diff --git a/SmartDeviceLink/SDLLockScreenManager.m b/SmartDeviceLink/SDLLockScreenManager.m index 6bf604a11..02301ccba 100644 --- a/SmartDeviceLink/SDLLockScreenManager.m +++ b/SmartDeviceLink/SDLLockScreenManager.m @@ -30,7 +30,6 @@ NS_ASSUME_NONNULL_BEGIN @property (strong, nonatomic) id<SDLViewControllerPresentable> presenter; @property (strong, nonatomic, nullable) SDLOnLockScreenStatus *lastLockNotification; @property (strong, nonatomic, nullable) SDLOnDriverDistraction *lastDriverDistractionNotification; -@property (strong, nonatomic) UISwipeGestureRecognizer *swipeGesture; @property (assign, nonatomic) BOOL lockScreenDismissableEnabled; @end @@ -97,16 +96,6 @@ NS_ASSUME_NONNULL_BEGIN return self.presenter.lockViewController; } -// Lazy init of swipe gesture -- (UISwipeGestureRecognizer *)swipeGesture { - if (!_swipeGesture) { - UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeUp:)]; - [swipeGesture setDirection: UISwipeGestureRecognizerDirectionUp]; - _swipeGesture = swipeGesture; - } - return _swipeGesture; -} - #pragma mark - Notification Selectors - (void)sdl_lockScreenStatusDidChange:(SDLRPCNotificationNotification *)notification { @@ -171,6 +160,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)sdl_toggleLockscreenDismissalableState { + BOOL lastLockScreenDismissableEnabled = self.lastDriverDistractionNotification.lockScreenDismissalEnabled; if (self.lastDriverDistractionNotification == nil || self.lastDriverDistractionNotification.lockScreenDismissalEnabled == nil || ![self.lastDriverDistractionNotification.lockScreenDismissalEnabled boolValue]) { self.lockScreenDismissableEnabled = NO; @@ -178,26 +168,29 @@ NS_ASSUME_NONNULL_BEGIN self.lockScreenDismissableEnabled = YES; } - [self sdl_toggleLockscreenDismissalableWithState:self.lockScreenDismissableEnabled]; + if (lastLockScreenDismissableEnabled != self.lockScreenDismissableEnabled) { + [self sdl_updateLockscreenDismissalableWithState:self.lockScreenDismissableEnabled]; + } } -- (void)sdl_toggleLockscreenDismissalableWithState:(BOOL)enabled { - // If the VC is our special type, then set the locked label text and swipe gesture. If they passed in a custom VC, there's no current way to update locked label text or swipe gesture. If they're managing it themselves, they can grab the notification themselves. - if (![self.lockScreenViewController isKindOfClass:[UIViewController class]]) { +- (void)sdl_updateLockscreenDismissalableWithState:(BOOL)enabled { + if (![self.lockScreenViewController isKindOfClass:[SDLLockScreenViewController class]]) { return; } - SDLLockScreenManager *__weak weakSelf = self; + __weak typeof(self) weakself = self; dispatch_async(dispatch_get_main_queue(), ^{ - SDLLockScreenManager *strongSelf = weakSelf; + __strong typeof(self)strongSelf = weakself; if (enabled) { - [strongSelf.lockScreenViewController.view addGestureRecognizer:strongSelf.swipeGesture]; + [(SDLLockScreenViewController *)strongSelf.lockScreenViewController addSwipeGestureWithCallback:^{ + [self.presenter dismiss]; + }]; if ([self.lockScreenViewController isKindOfClass:[SDLLockScreenViewController class]]) { ((SDLLockScreenViewController *)self.lockScreenViewController).lockedLabelText = self.lastDriverDistractionNotification.lockScreenDismissalWarning; } } else { - [strongSelf.lockScreenViewController.view removeGestureRecognizer:strongSelf.swipeGesture]; + [(SDLLockScreenViewController *)strongSelf.lockScreenViewController removeSwipeGesture]; if ([self.lockScreenViewController isKindOfClass:[SDLLockScreenViewController class]]) { ((SDLLockScreenViewController *)self.lockScreenViewController).lockedLabelText = nil; @@ -206,10 +199,6 @@ NS_ASSUME_NONNULL_BEGIN }); } -- (void)didSwipeUp:(UISwipeGestureRecognizer *)gesture { - [self.presenter dismiss]; -} - @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLLockScreenViewController.h b/SmartDeviceLink/SDLLockScreenViewController.h index 62646a82d..4db925b1a 100644 --- a/SmartDeviceLink/SDLLockScreenViewController.h +++ b/SmartDeviceLink/SDLLockScreenViewController.h @@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLLockScreenViewController : UIViewController +typedef void (^SwipeGestureCallbackBlock)(void); + /** * The app's icon. This will be set by the lock screen configuration. */ @@ -28,10 +30,20 @@ NS_ASSUME_NONNULL_BEGIN @property (copy, nonatomic, nullable) UIColor *backgroundColor; /** - * The locked label string. This is settable by the lock screen manager to inform in the user about the dismissable state + * The locked label string. This will be set by the lock screen manager to inform the user about the dismissable state. */ @property (copy, nonatomic, nullable) NSString *lockedLabelText; +/** + * Adds a swipe gesture to the lock screen view controller. + */ +- (void)addSwipeGestureWithCallback:(SwipeGestureCallbackBlock)swipeGestureCallback; + +/** + * Remove swipe gesture to the lock screen view controller. + */ +- (void)removeSwipeGesture; + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLLockScreenViewController.m b/SmartDeviceLink/SDLLockScreenViewController.m index c5dffa1fb..895e668f0 100644 --- a/SmartDeviceLink/SDLLockScreenViewController.m +++ b/SmartDeviceLink/SDLLockScreenViewController.m @@ -23,6 +23,7 @@ NS_ASSUME_NONNULL_BEGIN @property (weak, nonatomic) IBOutlet UILabel *lockedLabel; @property (weak, nonatomic) IBOutlet UIImageView *arrowUpImageView; @property (weak, nonatomic) IBOutlet UIImageView *arrowDownImageView; +@property (strong, nonatomic) SwipeGestureCallbackBlock swipeGestureCallback; @end @@ -49,7 +50,6 @@ NS_ASSUME_NONNULL_BEGIN return useWhiteIcon ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault; } - #pragma mark - Setters - (void)setAppIcon:(UIImage *_Nullable)appIcon { @@ -76,6 +76,23 @@ NS_ASSUME_NONNULL_BEGIN [self sdl_layoutViews]; } +#pragma mark - Swipe Gesture + +- (void)addSwipeGestureWithCallback:(SwipeGestureCallbackBlock)swipeGestureCallback { + self.swipeGestureCallback = swipeGestureCallback; + UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeDown:)]; + [swipeGesture setDirection: UISwipeGestureRecognizerDirectionDown]; + [self.view addGestureRecognizer:swipeGesture]; +} + +- (void)removeSwipeGesture { + self.view.gestureRecognizers = [[NSArray alloc] init]; +} + +- (void)didSwipeDown:(UISwipeGestureRecognizer *)gesture { + self.swipeGestureCallback(); +} + #pragma mark - Layout - (void)sdl_layoutViews { @@ -93,7 +110,6 @@ NS_ASSUME_NONNULL_BEGIN self.lockedLabel.textColor = iconColor; - // Translations needed if (self.lockedLabelText != nil) { self.lockedLabel.text = self.lockedLabelText; } else { |