Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jogendra committed Apr 1, 2018
1 parent 2ccf3b0 commit c877fb9
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 95 deletions.
3 changes: 1 addition & 2 deletions Phimpme/Controllers/AccountsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class AccountsTableViewController: UITableViewController {

}


// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
Expand Down Expand Up @@ -49,7 +48,7 @@ class AccountsTableViewController: UITableViewController {
return 44.0
}

@objc func switchChanged(_ sender : UISwitch!){
@objc func switchChanged(_ sender: UISwitch!) {
print("table row switch Changed \(sender.tag)")
print("The switch is \(sender.isOn ? "ON" : "OFF")")
}
Expand Down
2 changes: 1 addition & 1 deletion Phimpme/Controllers/CameraViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CameraViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

}

override var preferredStatusBarStyle: UIStatusBarStyle {
Expand Down
1 change: 0 additions & 1 deletion Phimpme/Controllers/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ class GalleryViewController: UIViewController {
}
}
}

8 changes: 4 additions & 4 deletions Phimpme/Controllers/MainTabBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit
import NMAnimatedTabBarItem

enum TabBarPage : Int {
enum TabBarPage: Int {
case camera
case gallery
case accounts
Expand All @@ -25,11 +25,11 @@ class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
self.delegate = self
}

//MARK: - UITabBarControllerDelegate
// MARK: - UITabBarControllerDelegate

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
let indexOfTab = tabBarController.viewControllers?.index(of:viewController)
var animationType:NMAnimationtype?
let indexOfTab = tabBarController.viewControllers?.index(of: viewController)
var animationType: NMAnimationtype?
switch indexOfTab {
case TabBarPage.camera.rawValue?:
animationType = NMAnimationtype.Bounce
Expand Down
2 changes: 1 addition & 1 deletion Phimpme/Controllers/MenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

fileprivate struct DefaultConstants {
private struct DefaultConstants {
static let menuViewsCornerRadius: CGFloat = 8.0
}

Expand Down
2 changes: 0 additions & 2 deletions Phimpme/Helpers/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ extension UIApplication {
}
}


extension UIViewController {
func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
Expand Down Expand Up @@ -145,7 +144,6 @@ extension UIColor {
return UIColor(red: 255/255, green: 45/255, blue: 85/255, alpha: 1.0)
}


convenience init(rgb: UInt) {
self.init(
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
Expand Down
69 changes: 34 additions & 35 deletions Phimpme/Helpers/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,40 @@ func /(lhs: CGFloat, rhs: Int) -> CGFloat {
*/
let toastDefaultDuration = 2.0
let toastFadeDuration = 0.2
let toastHorizontalMargin : CGFloat = 10.0
let toastVerticalMargin : CGFloat = 10.0
let toastHorizontalMargin: CGFloat = 10.0
let toastVerticalMargin: CGFloat = 10.0

let toastPositionDefault = "bottom"
let toastPositionTop = "top"
let toastPositionCenter = "center"

// activity
let toastActivityWidth : CGFloat = 100.0
let toastActivityHeight : CGFloat = 100.0
let toastActivityWidth: CGFloat = 100.0
let toastActivityHeight: CGFloat = 100.0
let toastActivityPositionDefault = "center"

// image size
let toastImageViewWidth : CGFloat = 80.0
let toastImageViewHeight: CGFloat = 80.0
let toastImageViewWidth: CGFloat = 80.0
let toastImageViewHeight: CGFloat = 80.0

// label setting
let toastMaxWidth : CGFloat = 0.8; // 80% of parent view width
let toastMaxHeight : CGFloat = 0.8;
let toastFontSize : CGFloat = 16.0
let toastMaxWidth: CGFloat = 0.8; // 80% of parent view width
let toastMaxHeight: CGFloat = 0.8
let toastFontSize: CGFloat = 16.0
let toastMaxTitleLines = 0
let toastMaxMessageLines = 0

// shadow appearance
let toastShadowOpacity : CGFloat = 0.8
let toastShadowRadius : CGFloat = 6.0
let toastShadowOffset : CGSize = CGSize(width: CGFloat(4.0), height: CGFloat(4.0))
let toastShadowOpacity: CGFloat = 0.8
let toastShadowRadius: CGFloat = 6.0
let toastShadowOffset: CGSize = CGSize(width: CGFloat(4.0), height: CGFloat(4.0))

let toastOpacity : CGFloat = 0.8
let toastCornerRadius : CGFloat = 10.0
let toastOpacity: CGFloat = 0.8
let toastCornerRadius: CGFloat = 10.0

var toastActivityView: UnsafePointer<UIView>? = nil
var toastTimer: UnsafePointer<Timer>? = nil
var toastView: UnsafePointer<UIView>? = nil
var toastActivityView: UnsafePointer<UIView>?
var toastTimer: UnsafePointer<Timer>?
var toastView: UnsafePointer<UIView>?

/*
* Custom Config
Expand Down Expand Up @@ -111,8 +111,8 @@ extension UIView {
let existToast = objc_getAssociatedObject(self, &toastView) as! UIView?
if existToast != nil {
if let timer = objc_getAssociatedObject(existToast, &toastTimer) as? Timer {
timer.invalidate();
self.hideToast(existToast!, force: false);
timer.invalidate()
self.hideToast(existToast!, force: false)
}
}

Expand All @@ -127,8 +127,8 @@ extension UIView {
if toastHidesOnTap {
let tapRecognizer = UITapGestureRecognizer(target: toast, action: #selector(UIView.handleToastTapped(_:)))
toast.addGestureRecognizer(tapRecognizer)
toast.isUserInteractionEnabled = true;
toast.isExclusiveTouch = true;
toast.isUserInteractionEnabled = true
toast.isExclusiveTouch = true
}

self.addSubview(toast)
Expand All @@ -149,16 +149,16 @@ extension UIView {
self.makeToastActivity(position: toastActivityPositionDefault as AnyObject)
}

func makeToastActivityWithMessage(message msg: String){
func makeToastActivityWithMessage(message msg: String) {
self.makeToastActivity(position: toastActivityPositionDefault as AnyObject, message: msg)
}

func makeToastActivity(position pos: AnyObject, message msg: String = "") {
let existToast = objc_getAssociatedObject(self, &toastView) as! UIView?
if existToast != nil {
if let timer = objc_getAssociatedObject(existToast, &toastTimer) as? Timer {
timer.invalidate();
self.hideToast(existToast!, force: false);
timer.invalidate()
self.hideToast(existToast!, force: false)
}
}

Expand All @@ -184,17 +184,16 @@ extension UIView {
activityView.addSubview(activityIndicatorView)
activityIndicatorView.startAnimating()

if (!msg.isEmpty){
if (!msg.isEmpty) {
activityIndicatorView.frame.origin.y -= 10
let activityMessageLabel = UILabel(frame: CGRect(x: activityView.bounds.origin.x, y: (activityIndicatorView.frame.origin.y + activityIndicatorView.frame.size.height + 10), width: activityView.bounds.size.width, height: 20))
activityMessageLabel.textColor = UIColor.white
activityMessageLabel.font = (msg.characters.count<=10) ? UIFont(name:"Roboto-Light", size: 14) : UIFont(name:"Roboto-Light", size: 13)
activityMessageLabel.font = (msg.characters.count<=10) ? UIFont(name: "Roboto-Light", size: 14) : UIFont(name: "Roboto-Light", size: 13)
activityMessageLabel.textAlignment = .center
activityMessageLabel.text = msg
activityView.addSubview(activityMessageLabel)
}


self.addSubview(activityView)

// associate activity view with self
Expand Down Expand Up @@ -228,11 +227,11 @@ extension UIView {
* private methods (helper)
*/
func hideToast(_ toast: UIView) {
self.hideToast(toast, force: false);
self.hideToast(toast, force: false)
}

func hideToast(_ toast: UIView, force: Bool) {
let completeClosure = { (finish: Bool) -> () in
let completeClosure = { (finish: Bool) -> Void in
toast.removeFromSuperview()
objc_setAssociatedObject(self, &toastTimer, nil, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
Expand All @@ -246,7 +245,7 @@ extension UIView {
animations: {
toast.alpha = 0.0
},
completion:completeClosure)
completion: completeClosure)
}
}

Expand Down Expand Up @@ -326,13 +325,13 @@ extension UIView {
titleLabel!.text = title

// size the title label according to the length of the text
let maxSizeTitle = CGSize(width: (self.bounds.size.width * toastMaxWidth) - imageWidth, height: self.bounds.size.height * toastMaxHeight);
let maxSizeTitle = CGSize(width: (self.bounds.size.width * toastMaxWidth) - imageWidth, height: self.bounds.size.height * toastMaxHeight)
let expectedHeight = title!.stringHeightWithFontSize(toastFontSize, width: maxSizeTitle.width)
titleLabel!.frame = CGRect(x: 0.0, y: 0.0, width: maxSizeTitle.width, height: expectedHeight)
}

if msg != nil {
msgLabel = UILabel();
msgLabel = UILabel()
msgLabel!.numberOfLines = toastMaxMessageLines
msgLabel!.font = UIFont.systemFont(ofSize: toastFontSize)
msgLabel!.lineBreakMode = .byWordWrapping
Expand Down Expand Up @@ -395,16 +394,16 @@ extension UIView {

extension String {

func stringHeightWithFontSize(_ fontSize: CGFloat,width: CGFloat) -> CGFloat {
func stringHeightWithFontSize(_ fontSize: CGFloat, width: CGFloat) -> CGFloat {
let font = UIFont.systemFont(ofSize: fontSize)
let size = CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = .byWordWrapping;
paragraphStyle.lineBreakMode = .byWordWrapping
let attributes = [NSAttributedStringKey.font:font,
NSAttributedStringKey.paragraphStyle:paragraphStyle.copy()]

let text = self as NSString
let rect = text.boundingRect(with: size, options:.usesLineFragmentOrigin, attributes: attributes, context:nil)
let rect = text.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: attributes, context: nil)
return rect.size.height
}

Expand Down
31 changes: 8 additions & 23 deletions Phimpme/Services/CameraController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,13 @@ extension CameraController {
if captureSession.canAddInput(self.rearCameraInput!) { captureSession.addInput(self.rearCameraInput!) }

self.currentCameraPosition = .rear
}

else if let frontCamera = self.frontCamera {
} else if let frontCamera = self.frontCamera {
self.frontCameraInput = try AVCaptureDeviceInput(device: frontCamera)

if captureSession.canAddInput(self.frontCameraInput!) { captureSession.addInput(self.frontCameraInput!) }
else { throw CameraControllerError.inputsAreInvalid }
if captureSession.canAddInput(self.frontCameraInput!) { captureSession.addInput(self.frontCameraInput!) } else { throw CameraControllerError.inputsAreInvalid }

self.currentCameraPosition = .front
}

else { throw CameraControllerError.noCamerasAvailable }
} else { throw CameraControllerError.noCamerasAvailable }
}

func configurePhotoOutput() throws {
Expand All @@ -95,9 +90,7 @@ extension CameraController {
try configureCaptureDevices()
try configureDeviceInputs()
try configurePhotoOutput()
}

catch {
} catch {
DispatchQueue.main.async {
completionHandler(error)
}
Expand Down Expand Up @@ -140,9 +133,7 @@ extension CameraController {
captureSession.addInput(self.frontCameraInput!)

self.currentCameraPosition = .front
}

else {
} else {
throw CameraControllerError.invalidOperation
}
}
Expand All @@ -159,9 +150,7 @@ extension CameraController {
captureSession.addInput(self.rearCameraInput!)

self.currentCameraPosition = .rear
}

else { throw CameraControllerError.invalidOperation }
} else { throw CameraControllerError.invalidOperation }
}

switch currentCameraPosition {
Expand Down Expand Up @@ -190,15 +179,11 @@ extension CameraController {
extension CameraController: AVCapturePhotoCaptureDelegate {
public func photoOutput(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?,
resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Swift.Error?) {
if let error = error { self.photoCaptureCompletionBlock?(nil, error) }

else if let buffer = photoSampleBuffer, let data = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: buffer, previewPhotoSampleBuffer: nil),
if let error = error { self.photoCaptureCompletionBlock?(nil, error) } else if let buffer = photoSampleBuffer, let data = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: buffer, previewPhotoSampleBuffer: nil),
let image = UIImage(data: data) {

self.photoCaptureCompletionBlock?(image, nil)
}

else {
} else {
self.photoCaptureCompletionBlock?(nil, CameraControllerError.unknown)
}
}
Expand Down
3 changes: 0 additions & 3 deletions Phimpme/Supporting Files/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

application.statusBarStyle = .lightContent
Expand Down Expand Up @@ -47,6 +46,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

Loading

0 comments on commit c877fb9

Please sign in to comment.