Skip to content

Commit

Permalink
Further refactoring changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximAlien committed Mar 4, 2019
1 parent 5366ba1 commit b571cdf
Show file tree
Hide file tree
Showing 57 changed files with 1,298 additions and 569 deletions.
144 changes: 115 additions & 29 deletions ARPlayer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ARPlayer/Categories/NSDateFormatter+Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN

@interface NSDateFormatter (Helpers)

+ (NSString *)toString:(CMTime)time;
+ (NSString *)currentTimeStringForTime:(CMTime)time;

@end

Expand Down
28 changes: 23 additions & 5 deletions ARPlayer/Categories/NSDateFormatter+Helpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,32 @@

@implementation NSDateFormatter (Helpers)

+ (NSString *)toString:(CMTime)time {
+ (instancetype)dateFormatter {
static NSDateFormatter *dateFormatter;
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
dateFormatter = [NSDateFormatter new];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
});

return dateFormatter;
}

+ (NSString *)currentTimeStringForTime:(CMTime)time {
Float64 seconds = CMTimeGetSeconds(time);
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:seconds];
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:(NSUInteger)(seconds / 3600) > 0 ? @"HH:mm:ss" : @"mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
NSDateFormatter *dateFormatter = [NSDateFormatter dateFormatter];

NSString *dateFormat = @"mm:ss";
NSUInteger hours = seconds / 3600;
if (hours > 0) {
dateFormat = @"HH:mm:ss";
}

[dateFormatter setDateFormat:dateFormat];
NSString *currentTime = [dateFormatter stringFromDate:date];

return currentTime;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SCNMaterial+Colors.h
// SCNMaterial+Contents.h
// ARPlayer
//
// Created by Maxim Makhun on 03/03/2019.
Expand All @@ -11,7 +11,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface SCNMaterial (Colors)
@interface SCNMaterial (Contents)

+ (instancetype)materialWithColor:(UIColor *)color;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// SCNMaterial+Colors.m
// SCNMaterial+Contents.m
// ARPlayer
//
// Created by Maxim Makhun on 03/03/2019.
// Copyright © 2019 Maxim Makhun. All rights reserved.
//

#import "SCNMaterial+Colors.h"
#import "SCNMaterial+Contents.h"

@implementation SCNMaterial (Colors)
@implementation SCNMaterial (Contents)

+ (SCNMaterial *)materialWithColor:(UIColor *)color {
SCNMaterial *material = [SCNMaterial new];
Expand Down
23 changes: 23 additions & 0 deletions ARPlayer/Categories/UIImpactFeedbackGenerator+Helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// UIImpactFeedbackGenerator+Helpers.h
// ARPlayer
//
// Created by Maxim Makhun on 04/03/2019.
// Copyright © 2019 Maxim Makhun. All rights reserved.
//

@import UIKit;

NS_ASSUME_NONNULL_BEGIN

@interface UIImpactFeedbackGenerator (Helpers)

+ (void)lightImpactOccurred;

+ (void)mediumImpactOccurred;

+ (void)heavyImpactOccurred;

@end

NS_ASSUME_NONNULL_END
29 changes: 29 additions & 0 deletions ARPlayer/Categories/UIImpactFeedbackGenerator+Helpers.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// UIImpactFeedbackGenerator+Helpers.m
// ARPlayer
//
// Created by Maxim Makhun on 04/03/2019.
// Copyright © 2019 Maxim Makhun. All rights reserved.
//

#import "UIImpactFeedbackGenerator+Helpers.h"

@implementation UIImpactFeedbackGenerator (Helpers)

+ (UIImpactFeedbackGenerator *)impactFeedbackGeneratorWithStyle:(UIImpactFeedbackStyle)style {
return [[UIImpactFeedbackGenerator alloc] initWithStyle:style];
}

+ (void)lightImpactOccurred {
[[UIImpactFeedbackGenerator impactFeedbackGeneratorWithStyle:UIImpactFeedbackStyleLight] impactOccurred];
}

+ (void)mediumImpactOccurred {
[[UIImpactFeedbackGenerator impactFeedbackGeneratorWithStyle:UIImpactFeedbackStyleMedium] impactOccurred];
}

+ (void)heavyImpactOccurred {
[[UIImpactFeedbackGenerator impactFeedbackGeneratorWithStyle:UIImpactFeedbackStyleHeavy] impactOccurred];
}

@end
18 changes: 10 additions & 8 deletions ARPlayer/Categories/UIViewController+Helpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
@implementation UIViewController (Helpers)

- (void)showMessage:(NSString *)message {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"ARPlayer"
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:nil];
[alertController addAction:action];
[self presentViewController:alertController animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"ARPlayer"
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:nil];
[alertController addAction:action];
[self presentViewController:alertController animated:YES completion:nil];
});
}

@end
29 changes: 0 additions & 29 deletions ARPlayer/Gestures/GestureHandler.h

This file was deleted.

143 changes: 0 additions & 143 deletions ARPlayer/Gestures/GestureHandler.m

This file was deleted.

19 changes: 19 additions & 0 deletions ARPlayer/Gestures/NodeInsertionHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// NodeInsertionHandler.h
// ARPlayer
//
// Created by Maxim Makhun on 04/03/2019.
// Copyright © 2019 Maxim Makhun. All rights reserved.
//

@import UIKit;

#import "GestureHandleProtocol.h"

NS_ASSUME_NONNULL_BEGIN

@interface NodeInsertionHandler : NSObject <GestureHandleProtocol>

@end

NS_ASSUME_NONNULL_END
41 changes: 41 additions & 0 deletions ARPlayer/Gestures/NodeInsertionHandler.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// NodeInsertionHandler.m
// ARPlayer
//
// Created by Maxim Makhun on 04/03/2019.
// Copyright © 2019 Maxim Makhun. All rights reserved.
//

@import ARKit;

#import "NodeInsertionHandler.h"

// Nodes
#import "MediaPlayerNode.h"

// Utils
#import "PlaylistService.h"

@implementation NodeInsertionHandler

- (void)handleGesture:(UIGestureRecognizer *)gesture inSceneView:(ARSCNView *)sceneView {
NSAssert([gesture isKindOfClass:[UILongPressGestureRecognizer class]], @"Different class type is expected.");

if (gesture.state == UIGestureRecognizerStateBegan) {
CGPoint tapPoint = [gesture locationInView:sceneView];
NSArray<ARHitTestResult *> *arHitTestResults = [sceneView hitTest:tapPoint
types:ARHitTestResultTypeExistingPlaneUsingExtent];

if (arHitTestResults.count != 0) {
ARHitTestResult *hitResult = [arHitTestResults firstObject];
simd_float4 column = hitResult.anchor.transform.columns[3];

MediaPlayerNode *mediaPlayerNode = [[MediaPlayerNode alloc] initWithPlaylist:[PlaylistService playlist]];
mediaPlayerNode.position = SCNVector3Make(column.x, column.y, column.z);
[mediaPlayerNode play];
[sceneView.scene.rootNode addChildNode:mediaPlayerNode];
}
}
}

@end
Loading

0 comments on commit b571cdf

Please sign in to comment.