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"
|
2014-03-20 00:09:25 +00:00
|
|
|
#import "MPUsersViewController.h"
|
|
|
|
#import "MPPasswordsViewController.h"
|
2014-04-12 18:43:41 +00:00
|
|
|
#import "MPEmergencyViewController.h"
|
|
|
|
#import "MPPasswordsSegue.h"
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-09-27 05:27:05 +00:00
|
|
|
@implementation MPCombinedViewController
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-09-23 02:32:31 +00:00
|
|
|
#pragma mark - Life
|
|
|
|
|
2014-03-16 00:38:14 +00:00
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
2014-09-12 00:31:23 +00:00
|
|
|
_mode = MPCombinedModeUserSelection;
|
2014-09-26 04:32:07 +00:00
|
|
|
[self performSegueWithIdentifier:@"users" sender:self];
|
2014-03-20 00:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-03-20 00:09:25 +00:00
|
|
|
[super viewWillAppear:animated];
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-03-20 00:09:25 +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];
|
|
|
|
|
2014-09-27 05:27:05 +00:00
|
|
|
PearlRemoveNotificationObservers();
|
2014-03-16 00:38:14 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 00:09:25 +00:00
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-03-20 00:09:25 +00:00
|
|
|
if ([segue.identifier isEqualToString:@"users"])
|
|
|
|
self.usersVC = segue.destinationViewController;
|
2014-04-12 18:43:41 +00:00
|
|
|
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 );
|
2014-04-12 18:43:41 +00:00
|
|
|
[(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;
|
|
|
|
}
|
|
|
|
|
2014-03-20 00:09:25 +00:00
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle {
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-03-20 00:09:25 +00:00
|
|
|
return UIStatusBarStyleLightContent;
|
2014-03-16 00:38:14 +00:00
|
|
|
}
|
|
|
|
|
2014-04-12 18:43:41 +00:00
|
|
|
- (BOOL)canBecomeFirstResponder {
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
|
|
|
|
|
|
|
|
if (motion == UIEventSubtypeMotionShake && !self.emergencyVC)
|
|
|
|
[self performSegueWithIdentifier:@"emergency" sender:self];
|
|
|
|
}
|
|
|
|
|
2014-09-23 02:32:31 +00:00
|
|
|
#pragma mark - Actions
|
2014-04-12 18:43:41 +00:00
|
|
|
|
2014-09-23 02:32:31 +00:00
|
|
|
- (IBAction)unwindToCombined:(UIStoryboardSegue *)sender {
|
2014-04-12 18:43:41 +00:00
|
|
|
|
2014-09-23 02:32:31 +00:00
|
|
|
dbg( @"unwindToCombined:%@", sender );
|
2014-04-12 18:43:41 +00:00
|
|
|
}
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-09-23 02:32:31 +00:00
|
|
|
#pragma mark - State
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-03-20 00:09:25 +00:00
|
|
|
- (void)setMode:(MPCombinedMode)mode {
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-03-20 00:09:25 +00:00
|
|
|
[self setMode:mode animated:YES];
|
2014-03-16 00:38:14 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 00:09:25 +00:00
|
|
|
- (void)setMode:(MPCombinedMode)mode animated:(BOOL)animated {
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-04-12 18:43:41 +00:00
|
|
|
if (_mode == mode && animated)
|
|
|
|
return;
|
2014-03-20 00:09:25 +00:00
|
|
|
_mode = mode;
|
2014-03-16 00:38:14 +00:00
|
|
|
|
2014-04-13 19:45:08 +00:00
|
|
|
[self setNeedsStatusBarAppearanceUpdate];
|
2014-03-20 00:09:25 +00:00
|
|
|
[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
|
|
|
|
2014-04-12 18:43:41 +00:00
|
|
|
switch (self.mode) {
|
|
|
|
case MPCombinedModeUserSelection: {
|
2014-09-26 04:32:07 +00:00
|
|
|
self.usersVC.view.userInteractionEnabled = YES;
|
2014-04-12 18:43:41 +00:00
|
|
|
[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) }];
|
2014-04-12 18:43:41 +00:00
|
|
|
[segue perform];
|
2014-03-20 00:09:25 +00:00
|
|
|
}
|
2014-04-12 18:43:41 +00:00
|
|
|
break;
|
2014-03-20 00:09:25 +00:00
|
|
|
}
|
2014-04-12 18:43:41 +00:00
|
|
|
case MPCombinedModePasswordSelection: {
|
2014-09-26 04:32:07 +00:00
|
|
|
self.usersVC.view.userInteractionEnabled = NO;
|
2014-04-12 18:43:41 +00:00
|
|
|
[self.usersVC setActive:NO animated:animated];
|
2017-04-01 04:30:25 +00:00
|
|
|
[self performSegueWithIdentifier:@"passwords" sender:@{ @"animated": @(animated) }];
|
2014-04-12 18:43:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-03-16 00:38:14 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 00:09:25 +00:00
|
|
|
#pragma mark - Private
|
2014-03-16 00:38:14 +00:00
|
|
|
|
|
|
|
@end
|