Skip to content

Commit

Permalink
Major code refactor + bug fixes (#23)
Browse files Browse the repository at this point in the history
* Refactors to adhere to MVVM architecture (#14, #21)
* Adds CI pipeline (#19)
* Fixes bugs (#20)
* README updates
  • Loading branch information
Elliot Boschwitz authored Feb 13, 2021
1 parent a24e335 commit 49d5e89
Show file tree
Hide file tree
Showing 25 changed files with 1,309 additions and 522 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: App-CI

on:
push:
branches: [ u/elbosc/main ]
pull_request:
branches: [ u/elbosc/main ]

jobs:
build:
name: Build and Test Default Scheme
runs-on: macos-11.0

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set Default Scheme
run: |
scheme_list=$(xcodebuild -list -json | tr -d "\n")
default=$(echo $scheme_list | ruby -e "require 'json'; puts JSON.parse(STDIN.gets)['project']['targets'][0]")
echo $default | cat >default
echo Using default scheme: $default
- name: Build
env:
scheme: ${{ 'default' }}
platform: ${{ 'iOS Simulator' }}
run: |
device=`instruments -s -devices | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}'`
if [ $scheme = default ]; then scheme=$(cat default); fi
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device"
- name: Test
env:
scheme: ${{ 'default' }}
platform: ${{ 'iOS Simulator' }}
run: |
device=`instruments -s -devices | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}'`
if [ $scheme = default ]; then scheme=$(cat default); fi
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
xcodebuild test-without-building -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device"
22 changes: 22 additions & 0 deletions LobeTests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
33 changes: 33 additions & 0 deletions LobeTests/LobeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// LobeTests.swift
// LobeTests
//
// Created by Elliot Boschwitz on 12/8/20.
// Copyright © 2020 Microsoft. All rights reserved.
//

import XCTest

class LobeTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
measure {
// Put the code you want to measure the time of here.
}
}

}
233 changes: 212 additions & 21 deletions Lobe_iOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Lobe_iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//
// AppDelegate.swift
// Lobe_iOS
//
// Created by Adam Menges on 5/20/20.
// Copyright © 2020 Microsoft. All rights reserved.
//

import UIKit

@UIApplicationMain
Expand Down
109 changes: 109 additions & 0 deletions Lobe_iOS/CaptureSessionViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// CaptureSessionViewController.swift
// Lobe_iOS
//
// Created by Kathy Zhou on 6/4/20.
// Copyright © 2020 Microsoft. All rights reserved.
//

import AVKit
import Foundation

/// Defines tap gesture delegate protocol.
protocol CaptureSessionGestureDelegate {
func viewRecognizedDoubleTap()
func viewRecognizedTripleTap(_ view: UIView)
}

/// View controller for video capture session. It's responsibilities include:
/// 1. Setting camera output to UI view.
/// 2. Handling orientation changes.
/// 3. Managing tap gestures.
class CaptureSessionViewController: UIViewController {
var previewLayer: AVCaptureVideoPreviewLayer?
var tripleTapGesture: UITapGestureRecognizer?
var doubleTapGesture: UITapGestureRecognizer?
var gestureDelegate: CaptureSessionGestureDelegate?

override func viewDidLoad() {
super.viewDidLoad()

/// Define gesture event listeners. We don't use SwiftUI since there isn't support for
/// recognizing a double tap gesture when a triple tap gesture is also present.
let doubleTapGesture = UITapGestureRecognizer(target: self, action:#selector(self.handleDoubleTap(_:)))
doubleTapGesture.numberOfTapsRequired = 2
view.addGestureRecognizer(doubleTapGesture)

let tripleTapGesture = UITapGestureRecognizer(target: self, action:#selector(self.handleTripleTap(_:)))
tripleTapGesture.numberOfTapsRequired = 3
view.addGestureRecognizer(tripleTapGesture)
doubleTapGesture.require(toFail: tripleTapGesture)
}

/// Set video configuration for subview layout
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.configureVideoOrientation(for: self.previewLayer)
}

/// Update video configuration when device orientation changes
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
self.configureVideoOrientation(for: self.previewLayer)
}

/// Configures orientation of preview layer for AVCapture session.
func configureVideoOrientation(for previewLayer: AVCaptureVideoPreviewLayer?) {
if let preview = previewLayer,
let connection = preview.connection {
let orientation = UIDevice.current.orientation

if connection.isVideoOrientationSupported {
var videoOrientation: AVCaptureVideoOrientation

switch orientation {
case .portrait:
videoOrientation = .portrait
case .portraitUpsideDown:
videoOrientation = .portraitUpsideDown
case .landscapeLeft:
videoOrientation = .landscapeRight
case .landscapeRight:
videoOrientation = .landscapeLeft
default:
videoOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.asAVCaptureVideoOrientation() ?? .portrait
}
connection.videoOrientation = videoOrientation
}
preview.frame = self.view.bounds
}
}

/// Double tap flips camera.
@objc func handleDoubleTap(_ sender: UITapGestureRecognizer? = nil) {
self.gestureDelegate?.viewRecognizedDoubleTap()
}

/// Triple tap creates screen shot.
@objc func handleTripleTap(_ sender: UITapGestureRecognizer? = nil) {
self.gestureDelegate?.viewRecognizedTripleTap(self.view)
}
}

/// Conversion helper for AVCaptureSession orientation changes.
extension UIInterfaceOrientation {
func asAVCaptureVideoOrientation() -> AVCaptureVideoOrientation {
switch self {
case .portrait:
return .portrait
case .landscapeLeft:
return .landscapeLeft
case .landscapeRight:
return .landscapeRight
case .portraitUpsideDown:
return .portraitUpsideDown
default:
return .portrait
}
}
}
152 changes: 0 additions & 152 deletions Lobe_iOS/ContentView.swift

This file was deleted.

Loading

0 comments on commit 49d5e89

Please sign in to comment.