mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			163 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			Matlab
		
	
		
		
			
		
	
	
			163 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			Matlab
		
	
| 
											8 years ago
										 | // | ||
| 
											7 years ago
										 | //  Copyright (c) 2019 Open Whisper Systems. All rights reserved. | ||
| 
											8 years ago
										 | // | ||
|  | 
 | ||
|  | #import "ScreenLockViewController.h" | ||
|  | #import "UIColor+OWS.h" | ||
|  | #import "UIFont+OWS.h" | ||
|  | #import "UIView+OWS.h" | ||
| 
											5 years ago
										 | #import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h> | ||
| 
											5 years ago
										 | #import <SessionUIKit/SessionUIKit.h> | ||
| 
											8 years ago
										 | 
 | ||
|  | NSString *NSStringForScreenLockUIState(ScreenLockUIState value) | ||
|  | { | ||
|  |     switch (value) { | ||
|  |         case ScreenLockUIStateNone: | ||
|  |             return @"ScreenLockUIStateNone"; | ||
|  |         case ScreenLockUIStateScreenProtection: | ||
|  |             return @"ScreenLockUIStateScreenProtection"; | ||
|  |         case ScreenLockUIStateScreenLock: | ||
|  |             return @"ScreenLockUIStateScreenLock"; | ||
|  |     } | ||
|  | } | ||
|  | 
 | ||
|  | @interface ScreenLockViewController () | ||
|  | 
 | ||
|  | @property (nonatomic) UIView *screenBlockingImageView; | ||
|  | @property (nonatomic) UIView *screenBlockingButton; | ||
|  | @property (nonatomic) NSArray<NSLayoutConstraint *> *screenBlockingConstraints; | ||
|  | @property (nonatomic) NSString *screenBlockingSignature; | ||
|  | 
 | ||
|  | @end | ||
|  | 
 | ||
|  | #pragma mark - | ||
|  | 
 | ||
|  | @implementation ScreenLockViewController | ||
|  | 
 | ||
|  | - (void)loadView | ||
|  | { | ||
|  |     [super loadView]; | ||
| 
											6 years ago
										 |      | ||
|  |     // Loki: Set gradient background | ||
|  |     self.view.backgroundColor = UIColor.clearColor; | ||
|  |     CAGradientLayer *layer = [CAGradientLayer new]; | ||
|  |     layer.frame = UIScreen.mainScreen.bounds; | ||
| 
											5 years ago
										 |     UIColor *gradientStartColor = LKAppModeUtilities.isLightMode ? [UIColor colorWithRGBHex:0xFCFCFC] : [UIColor colorWithRGBHex:0x171717]; | ||
|  |     UIColor *gradientEndColor = LKAppModeUtilities.isLightMode ? [UIColor colorWithRGBHex:0xFFFFFF] : [UIColor colorWithRGBHex:0x121212]; | ||
|  |     layer.colors = @[ (id)gradientStartColor.CGColor, (id)gradientEndColor.CGColor ]; | ||
| 
											6 years ago
										 |     [self.view.layer insertSublayer:layer atIndex:0]; | ||
| 
											8 years ago
										 | 
 | ||
|  |     UIView *edgesView = [UIView containerView]; | ||
|  |     [self.view addSubview:edgesView]; | ||
|  |     [edgesView autoPinEdgeToSuperviewEdge:ALEdgeTop]; | ||
|  |     [edgesView autoPinEdgeToSuperviewEdge:ALEdgeBottom]; | ||
|  |     [edgesView autoPinWidthToSuperview]; | ||
|  | 
 | ||
| 
											6 years ago
										 |     UIImage *image = [UIImage imageNamed:@"SessionGreen64"]; | ||
| 
											8 years ago
										 |     UIImageView *imageView = [UIImageView new]; | ||
|  |     imageView.image = image; | ||
| 
											6 years ago
										 |     imageView.contentMode = UIViewContentModeScaleAspectFit; | ||
| 
											8 years ago
										 |     [edgesView addSubview:imageView]; | ||
|  |     [imageView autoHCenterInSuperview]; | ||
|  | 
 | ||
| 
											6 years ago
										 |     [imageView autoSetDimension:ALDimensionWidth toSize:64]; | ||
|  |     [imageView autoSetDimension:ALDimensionHeight toSize:64]; | ||
| 
											8 years ago
										 | 
 | ||
|  |     const CGFloat kButtonHeight = 40.f; | ||
|  |     OWSFlatButton *button = | ||
| 
											6 years ago
										 |         [OWSFlatButton buttonWithTitle:NSLocalizedString(@"Unlock Session", @"") | ||
| 
											6 years ago
										 |                                   font:[UIFont boldSystemFontOfSize:LKValues.mediumFontSize] | ||
| 
											5 years ago
										 |                             titleColor:LKAppModeUtilities.isLightMode ? UIColor.blackColor : UIColor.whiteColor | ||
| 
											6 years ago
										 |                        backgroundColor:UIColor.clearColor | ||
| 
											8 years ago
										 |                                 target:self | ||
|  |                               selector:@selector(showUnlockUI)]; | ||
|  |     [edgesView addSubview:button]; | ||
|  | 
 | ||
|  |     [button autoSetDimension:ALDimensionHeight toSize:kButtonHeight]; | ||
|  |     [button autoPinLeadingToSuperviewMarginWithInset:50.f]; | ||
|  |     [button autoPinTrailingToSuperviewMarginWithInset:50.f]; | ||
|  |     const CGFloat kVMargin = 65.f; | ||
|  |     [button autoPinBottomToSuperviewMarginWithInset:kVMargin]; | ||
|  | 
 | ||
|  |     self.screenBlockingImageView = imageView; | ||
|  |     self.screenBlockingButton = button; | ||
| 
											8 years ago
										 | 
 | ||
|  |     [self updateUIWithState:ScreenLockUIStateScreenProtection isLogoAtTop:NO animated:NO]; | ||
| 
											8 years ago
										 | } | ||
|  | 
 | ||
|  | // The "screen blocking" window has three possible states: | ||
|  | // | ||
|  | // * "Just a logo".  Used when app is launching and in app switcher.  Must match the "Launch Screen" | ||
|  | //    storyboard pixel-for-pixel. | ||
|  | // * "Screen Lock, local auth UI presented". Move the Signal logo so that it is visible. | ||
|  | // * "Screen Lock, local auth UI not presented". Move the Signal logo so that it is visible, | ||
|  | //    show "unlock" button. | ||
|  | - (void)updateUIWithState:(ScreenLockUIState)uiState isLogoAtTop:(BOOL)isLogoAtTop animated:(BOOL)animated | ||
|  | { | ||
|  |     OWSAssertIsOnMainThread(); | ||
|  | 
 | ||
| 
											8 years ago
										 |     if (!self.isViewLoaded) { | ||
| 
											8 years ago
										 |         return; | ||
|  |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     BOOL shouldShowBlockWindow = uiState != ScreenLockUIStateNone; | ||
|  |     BOOL shouldHaveScreenLock = uiState == ScreenLockUIStateScreenLock; | ||
|  | 
 | ||
|  |     self.screenBlockingImageView.hidden = !shouldShowBlockWindow; | ||
|  | 
 | ||
|  |     NSString *signature = [NSString stringWithFormat:@"%d %d", shouldHaveScreenLock, isLogoAtTop]; | ||
|  |     if ([NSObject isNullableObject:self.screenBlockingSignature equalTo:signature]) { | ||
|  |         // Skip redundant work to avoid interfering with ongoing animations. | ||
|  |         return; | ||
|  |     } | ||
|  | 
 | ||
|  |     [NSLayoutConstraint deactivateConstraints:self.screenBlockingConstraints]; | ||
|  | 
 | ||
|  |     NSMutableArray<NSLayoutConstraint *> *screenBlockingConstraints = [NSMutableArray new]; | ||
|  | 
 | ||
|  |     self.screenBlockingButton.hidden = !shouldHaveScreenLock; | ||
|  | 
 | ||
|  |     if (isLogoAtTop) { | ||
|  |         const CGFloat kVMargin = 60.f; | ||
|  |         [screenBlockingConstraints addObject:[self.screenBlockingImageView autoPinEdge:ALEdgeTop | ||
|  |                                                                                 toEdge:ALEdgeTop | ||
|  |                                                                                 ofView:self.view | ||
|  |                                                                             withOffset:kVMargin]]; | ||
|  |     } else { | ||
|  |         [screenBlockingConstraints addObject:[self.screenBlockingImageView autoVCenterInSuperview]]; | ||
|  |     } | ||
|  | 
 | ||
|  |     self.screenBlockingConstraints = screenBlockingConstraints; | ||
|  |     self.screenBlockingSignature = signature; | ||
|  | 
 | ||
|  |     if (animated) { | ||
|  |         [UIView animateWithDuration:0.35f | ||
|  |                          animations:^{ | ||
|  |                              [self.view layoutIfNeeded]; | ||
|  |                          }]; | ||
|  |     } else { | ||
|  |         [self.view layoutIfNeeded]; | ||
|  |     } | ||
|  | } | ||
|  | 
 | ||
|  | - (void)showUnlockUI | ||
|  | { | ||
|  |     OWSAssertIsOnMainThread(); | ||
|  | 
 | ||
|  |     [self.delegate unlockButtonWasTapped]; | ||
|  | } | ||
|  | 
 | ||
| 
											8 years ago
										 | - (BOOL)canBecomeFirstResponder | ||
|  | { | ||
|  |     return YES; | ||
|  | } | ||
|  | 
 | ||
| 
											7 years ago
										 | #pragma mark - Orientation | ||
|  | 
 | ||
|  | - (UIInterfaceOrientationMask)supportedInterfaceOrientations | ||
|  | { | ||
| 
											7 years ago
										 |     return UIInterfaceOrientationMaskAllButUpsideDown; | ||
| 
											7 years ago
										 | } | ||
|  | 
 | ||
| 
											8 years ago
										 | @end |