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

151 lines
5.0 KiB
Mathematica
Raw Normal View History

2017-04-05 20:56:22 +00:00
//==============================================================================
// This file is part of Master Password.
// Copyright (c) 2011-2017, Maarten Billemont.
2014-03-16 00:38:14 +00:00
//
2017-04-05 20:56:22 +00:00
// Master Password is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
2014-03-16 00:38:14 +00:00
//
2017-04-05 20:56:22 +00:00
// Master Password is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
2014-03-16 00:38:14 +00:00
//
2017-04-05 20:56:22 +00:00
// You can find a copy of the GNU General Public License in the
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
//==============================================================================
2014-03-16 00:38:14 +00:00
#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