Permalink
Browse files

Moved recording settings to separate controller, using separate windo…

…w to prevent capture
  • Loading branch information...
insidegui committed Nov 15, 2017
1 parent 418fa41 commit 94019b20066ca9894a92ffdb95f770c7e4a7b894
@@ -35,6 +35,7 @@
DDDBBC1B1FB7A28D00291D45 /* RecordingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DDDBBC1A1FB7A28D00291D45 /* RecordingViewController.m */; };
DDDBBC1E1FB7A73300291D45 /* ASPuppetView.m in Sources */ = {isa = PBXBuildFile; fileRef = DDDBBC1D1FB7A73300291D45 /* ASPuppetView.m */; };
DDDBBC211FB7A7E400291D45 /* AvatarKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDDBBC201FB7A7E400291D45 /* AvatarKit.framework */; };
DDF87E3C1FBCE63A00F1A24C /* RecordingSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DDF87E3B1FBCE63A00F1A24C /* RecordingSettingsViewController.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -92,6 +93,8 @@
DDDBBC1C1FB7A73300291D45 /* ASPuppetView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ASPuppetView.h; sourceTree = "<group>"; };
DDDBBC1D1FB7A73300291D45 /* ASPuppetView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASPuppetView.m; sourceTree = "<group>"; };
DDDBBC201FB7A7E400291D45 /* AvatarKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AvatarKit.framework; path = AnimojiStudio/AvatarKit/AvatarKit.framework; sourceTree = "<group>"; };
DDF87E3A1FBCE63A00F1A24C /* RecordingSettingsViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RecordingSettingsViewController.h; sourceTree = "<group>"; };
DDF87E3B1FBCE63A00F1A24C /* RecordingSettingsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RecordingSettingsViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -240,6 +243,8 @@
DDDBBC1A1FB7A28D00291D45 /* RecordingViewController.m */,
DDCE6CA41FB8C615000EAE11 /* RecordingStatusViewController.h */,
DDCE6CA51FB8C615000EAE11 /* RecordingStatusViewController.m */,
DDF87E3A1FBCE63A00F1A24C /* RecordingSettingsViewController.h */,
DDF87E3B1FBCE63A00F1A24C /* RecordingSettingsViewController.m */,
);
path = Recording;
sourceTree = "<group>";
@@ -360,6 +365,7 @@
buildActionMask = 2147483647;
files = (
DDDBBBEE1FB7918000291D45 /* ErrorViewController.m in Sources */,
DDF87E3C1FBCE63A00F1A24C /* RecordingSettingsViewController.m in Sources */,
DDCE6CAD1FB8DAB8000EAE11 /* VideoPreviewViewController.m in Sources */,
DD7135DD1FBB99E900AAA5E7 /* ColorSheetPresentationController.m in Sources */,
DDDBBC081FB797DA00291D45 /* RecordingFlowController.m in Sources */,
@@ -31,6 +31,7 @@ @interface RecordingFlowController () <RPBroadcastActivityViewControllerDelegate
@property (nonatomic, weak) RecordingViewController *recordingController;
@property (nonatomic, strong) UIWindow *statusWindow;
@property (nonatomic, strong) RecordingStatusViewController *statusController;
@property (nonatomic, strong) RecordingCoordinator *coordinator;
@@ -0,0 +1,33 @@
//
// RecordingSettingsViewController.h
// AnimojiStudio
//
// Created by Guilherme Rambo on 15/11/17.
// Copyright © 2017 Guilherme Rambo. All rights reserved.
//
@import UIKit;
@class RecordingSettingsViewController;
@protocol RecordingSettingsViewControllerDelegate <NSObject>
- (void)recordingSettingsViewControllerDidTapKaraoke:(RecordingSettingsViewController *)controller;
- (void)recordingSettingsViewController:(RecordingSettingsViewController *)controller didChangeMicrophoneEnabled:(BOOL)isEnabled;
- (void)recordingSettingsViewControllerDidTapChooseBackgroundColor:(RecordingSettingsViewController *)controller;
@end
@interface RecordingSettingsViewController : UIViewController
@property (nonatomic, weak) id<RecordingSettingsViewControllerDelegate> delegate;
@property (nonatomic, assign, getter=isMicrophoneEnabled) BOOL microphoneEnabled;
@property (nonatomic, copy) UIColor *sceneBackgroundColor;
@property (nonatomic, weak) UIWindow *containerWindow;
@property (nonatomic, weak) UIViewController *containerViewController;
- (void)resizeWindow;
@end
@@ -0,0 +1,207 @@
//
// RecordingSettingsViewController.m
// AnimojiStudio
//
// Created by Guilherme Rambo on 15/11/17.
// Copyright © 2017 Guilherme Rambo. All rights reserved.
//
#import "RecordingSettingsViewController.h"
#import "ASColorWell.h"
@interface RecordingSettingsViewController ()
@property (nonatomic, strong) UIVisualEffectView *settingsContainer;
@property (nonatomic, strong) UIStackView *settingsStack;
@property (nonatomic, strong) UILabel *instructionLabel;
@property (nonatomic, strong) UIStackView *microphoneSettingsStack;
@property (nonatomic, strong) UILabel *microphoneLabel;
@property (nonatomic, strong) UISwitch *microphoneSwitch;
@property (nonatomic, strong) UIStackView *bgColorStack;
@property (nonatomic, strong) UILabel *bgColorLabel;
@property (nonatomic, strong) ASColorWell *bgColorWell;
@property (nonatomic, strong) UIButton *karaokeButton;
@end
@implementation RecordingSettingsViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self build];
}
- (void)build
{
[self _installSettingsUI];
}
- (UIBlurEffect *)_settingsUIEffect
{
return [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
}
- (void)_installSettingsUI
{
self.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.view.widthAnchor constraintEqualToConstant:[UIScreen mainScreen].bounds.size.width].active = YES;
self.settingsContainer = [[UIVisualEffectView alloc] initWithEffect:nil];
self.settingsContainer.translatesAutoresizingMaskIntoConstraints = NO;
self.settingsStack = [UIStackView new];
self.settingsStack.alignment = UIStackViewAlignmentCenter;
self.settingsStack.axis = UILayoutConstraintAxisVertical;
self.settingsStack.spacing = 8;
self.settingsStack.translatesAutoresizingMaskIntoConstraints = NO;
[self.settingsContainer.contentView addSubview:self.settingsStack];
[self.settingsStack.leadingAnchor constraintEqualToAnchor:self.settingsContainer.leadingAnchor].active = YES;
[self.settingsStack.trailingAnchor constraintEqualToAnchor:self.settingsContainer.trailingAnchor].active = YES;
[self.settingsStack.topAnchor constraintEqualToAnchor:self.settingsContainer.topAnchor constant: 16].active = YES;
[self.settingsStack.bottomAnchor constraintEqualToAnchor:self.settingsContainer.safeAreaLayoutGuide.bottomAnchor constant: -36].active = YES;
[self _installMicrophoneSettingsUI];
[self _installColorSettingsUI];
[self _installKaraokeUI];
[self _installInstructionLabel];
[self.settingsStack setCustomSpacing:24 afterView:self.bgColorStack];
[self.view addSubview:self.settingsContainer];
[self.settingsContainer.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES;
[self.settingsContainer.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES;
[self.settingsContainer.topAnchor constraintEqualToAnchor:self.view.topAnchor].active = YES;
[self.settingsContainer.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;
}
- (void)_installMicrophoneSettingsUI
{
self.microphoneLabel = [UILabel new];
self.microphoneLabel.text = @"Enable Microphone";
self.microphoneLabel.textColor = [UIColor darkGrayColor];
self.microphoneSwitch = [UISwitch new];
[self.microphoneSwitch addTarget:self action:@selector(microphoneEnabledSwitchAction:) forControlEvents:UIControlEventValueChanged];
self.microphoneSettingsStack = [[UIStackView alloc] initWithArrangedSubviews:@[self.microphoneLabel, self.microphoneSwitch]];
self.microphoneSettingsStack.axis = UILayoutConstraintAxisHorizontal;
self.microphoneSettingsStack.spacing = 8;
[self.settingsStack addArrangedSubview:self.microphoneSettingsStack];
}
- (void)_installColorSettingsUI
{
self.bgColorLabel = [UILabel new];
self.bgColorLabel.text = @"Background Color";
self.bgColorLabel.textColor = [UIColor darkGrayColor];
self.bgColorWell = [ASColorWell new];
[self.bgColorWell addTarget:self action:@selector(tappedColorWell:) forControlEvents:UIControlEventTouchDown];
self.bgColorStack = [[UIStackView alloc] initWithArrangedSubviews:@[self.bgColorLabel, self.bgColorWell]];
self.bgColorStack.axis = UILayoutConstraintAxisHorizontal;
self.bgColorStack.spacing = 8;
[self.settingsStack addArrangedSubview:self.bgColorStack];
}
- (IBAction)microphoneEnabledSwitchAction:(id)sender
{
[self.delegate recordingSettingsViewController:self didChangeMicrophoneEnabled:self.microphoneSwitch.isOn];
}
- (void)_installInstructionLabel
{
self.instructionLabel = [UILabel new];
self.instructionLabel.text = @"Tap on the screen to start recording, tap again to stop recording.\nDouble tap to live stream.";
self.instructionLabel.numberOfLines = 0;
self.instructionLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
self.instructionLabel.textAlignment = NSTextAlignmentCenter;
self.instructionLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.instructionLabel.textColor = [UIColor grayColor];
[self.settingsStack addArrangedSubview:self.instructionLabel];
[self.instructionLabel.widthAnchor constraintLessThanOrEqualToAnchor:self.settingsStack.widthAnchor multiplier:0.9].active = YES;
}
- (void)_installKaraokeUI
{
self.karaokeButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.karaokeButton setTitle:@"Configure Karaoke" forState:UIControlStateNormal];
[self.karaokeButton addTarget:self action:@selector(karaokeTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.settingsStack addArrangedSubview:self.karaokeButton];
}
- (IBAction)tappedColorWell:(id)sender
{
[self.delegate recordingSettingsViewControllerDidTapChooseBackgroundColor:self];
}
- (IBAction)karaokeTapped:(id)sender
{
[self.delegate recordingSettingsViewControllerDidTapKaraoke:self];
}
- (void)_toggleSettingsBackgroundEffectWithColor:(UIColor *)color
{
CGFloat r;
CGFloat g;
CGFloat b;
if ([color getRed:&r green:&g blue:&b alpha:nil]) {
[UIView animateWithDuration:0.3 animations:^{
if (r < 0.8 || g < 0.8 || b < 0.8) {
[self.settingsContainer setEffect:[self _settingsUIEffect]];
} else {
[self.settingsContainer setEffect:nil];
}
}];
}
}
- (void)setSceneBackgroundColor:(UIColor *)sceneBackgroundColor
{
_sceneBackgroundColor = [sceneBackgroundColor copy];
self.bgColorWell.color = _sceneBackgroundColor;
[self _toggleSettingsBackgroundEffectWithColor:_sceneBackgroundColor];
}
- (void)setMicrophoneEnabled:(BOOL)microphoneEnabled
{
_microphoneEnabled = microphoneEnabled;
self.microphoneSwitch.on = _microphoneEnabled;
}
#pragma mark Floating window layout management
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self resizeWindow];
}
- (void)resizeWindow
{
if (!self.containerWindow || !self.containerViewController) return;
CGSize parentSize = self.containerViewController.view.bounds.size;
CGSize ourSize = self.view.bounds.size;
self.containerWindow.frame = CGRectMake(0, parentSize.height - ourSize.height, ourSize.width, ourSize.height);
}
@end
Oops, something went wrong.

0 comments on commit 94019b2

Please sign in to comment.