2
0
MasterPassword/platform-darwin/Source/iOS/MPCombinedViewController.m

151 lines
4.6 KiB
Mathematica
Raw Normal View History

2014-03-16 00:38:14 +00:00
/**
2014-09-22 12:48:51 +00:00
* Copyright Maarten Billemont (http://www.lhunath.com, lhunath@lyndir.com)
*
* See the enclosed file LICENSE for license information (LGPLv3). If you did
* not receive this file, see http://www.gnu.org/licenses/lgpl-3.0.txt
*
* @author Maarten Billemont <lhunath@lyndir.com>
* @license http://www.gnu.org/licenses/lgpl-3.0.txt
*/
2014-03-16 00:38:14 +00:00
//
// MPCombinedViewController.h
// MPCombinedViewController
//
// Created by lhunath on 2014-03-08.
// Copyright, lhunath (Maarten Billemont) 2014. All rights reserved.
//
#import "MPCombinedViewController.h"
#import "MPUsersViewController.h"
#import "MPPasswordsViewController.h"
#import "MPEmergencyViewController.h"
#import "MPPasswordsSegue.h"
2014-03-16 00:38:14 +00:00
@implementation MPCombinedViewController
2014-03-16 00:38:14 +00:00
#pragma mark - Life
2014-03-16 00:38:14 +00:00
- (void)viewDidLoad {
[super viewDidLoad];
_mode = MPCombinedModeUserSelection;
[self performSegueWithIdentifier:@"users" sender:self];
}
- (void)viewWillAppear:(BOOL)animated {
2014-03-16 00:38:14 +00:00
[super viewWillAppear:animated];
2014-03-16 00:38:14 +00:00
[[self navigationController] setNavigationBarHidden:YES animated:animated];
2014-03-16 00:38:14 +00:00
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
2014-09-27 16:52:17 +00:00
PearlAddNotificationObserver( MPSignedInNotification, nil, [NSOperationQueue mainQueue],
^(MPCombinedViewController *self, NSNotification *note) {
[self setMode:MPCombinedModePasswordSelection];
} );
PearlAddNotificationObserver( MPSignedOutNotification, nil, [NSOperationQueue mainQueue],
^(MPCombinedViewController *self, NSNotification *note) {
[self setMode:MPCombinedModeUserSelection animated:[note.userInfo[@"animated"] boolValue]];
} );
2014-03-16 00:38:14 +00:00
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
PearlRemoveNotificationObservers();
2014-03-16 00:38:14 +00:00
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
2014-03-16 00:38:14 +00:00
if ([segue.identifier isEqualToString:@"users"])
self.usersVC = segue.destinationViewController;
if ([segue.identifier isEqualToString:@"passwords"]) {
2014-09-22 12:48:51 +00:00
NSAssert( [segue isKindOfClass:[MPPasswordsSegue class]], @"passwords segue should be MPPasswordsSegue: %@", segue );
NSAssert( [sender isKindOfClass:[NSDictionary class]], @"sender should be dictionary: %@", sender );
NSAssert( [[sender objectForKey:@"animated"] isKindOfClass:[NSNumber class]], @"sender should contain 'animated': %@", sender );
[(MPPasswordsSegue *)segue setAnimated:[sender[@"animated"] boolValue]];
UIViewController *destinationVC = segue.destinationViewController;
_passwordsVC = [destinationVC isKindOfClass:[MPPasswordsViewController class]]? (MPPasswordsViewController *)destinationVC: nil;
}
if ([segue.identifier isEqualToString:@"emergency"])
self.emergencyVC = segue.destinationViewController;
2014-03-16 00:38:14 +00:00
}
2014-04-13 19:45:08 +00:00
- (BOOL)prefersStatusBarHidden {
return self.mode == MPCombinedModeUserSelection;
}
- (UIStatusBarStyle)preferredStatusBarStyle {
2014-03-16 00:38:14 +00:00
return UIStatusBarStyleLightContent;
2014-03-16 00:38:14 +00:00
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (motion == UIEventSubtypeMotionShake && !self.emergencyVC)
[self performSegueWithIdentifier:@"emergency" sender:self];
}
#pragma mark - Actions
- (IBAction)unwindToCombined:(UIStoryboardSegue *)sender {
dbg( @"unwindToCombined:%@", sender );
}
2014-03-16 00:38:14 +00:00
#pragma mark - State
2014-03-16 00:38:14 +00:00
- (void)setMode:(MPCombinedMode)mode {
2014-03-16 00:38:14 +00:00
[self setMode:mode animated:YES];
2014-03-16 00:38:14 +00:00
}
- (void)setMode:(MPCombinedMode)mode animated:(BOOL)animated {
2014-03-16 00:38:14 +00:00
if (_mode == mode && animated)
return;
_mode = mode;
2014-03-16 00:38:14 +00:00
2014-04-13 19:45:08 +00:00
[self setNeedsStatusBarAppearanceUpdate];
[self becomeFirstResponder];
2014-04-13 19:45:08 +00:00
[self.usersVC setNeedsStatusBarAppearanceUpdate];
[self.usersVC.view setNeedsUpdateConstraints];
[self.usersVC.view setNeedsLayout];
2014-03-16 00:38:14 +00:00
switch (self.mode) {
case MPCombinedModeUserSelection: {
self.usersVC.view.userInteractionEnabled = YES;
[self.usersVC setActive:YES animated:animated];
if (_passwordsVC) {
MPPasswordsSegue *segue = [[MPPasswordsSegue alloc] initWithIdentifier:@"passwords" source:_passwordsVC destination:self];
2017-04-01 04:30:25 +00:00
[self prepareForSegue:segue sender:@{ @"animated": @(animated) }];
[segue perform];
}
break;
}
case MPCombinedModePasswordSelection: {
self.usersVC.view.userInteractionEnabled = NO;
[self.usersVC setActive:NO animated:animated];
2017-04-01 04:30:25 +00:00
[self performSegueWithIdentifier:@"passwords" sender:@{ @"animated": @(animated) }];
break;
}
}
2014-03-16 00:38:14 +00:00
}
#pragma mark - Private
2014-03-16 00:38:14 +00:00
@end