Skip to content

Commit

Permalink
Refactor code a little
Browse files Browse the repository at this point in the history
  • Loading branch information
Keiran Smith committed Mar 10, 2017
1 parent 2f68580 commit d4b58a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
4 changes: 0 additions & 4 deletions MobTimer/FullScreenViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class FullScreenViewController: NSViewController {
FullView.window?.close()
}

func performSegue(for segue: NSStoryboardSegue, withIdentifier identifier: String, sender: Any?) {
print(identifier)
segue.perform()
}
override func viewDidLoad() {
super.viewDidLoad()

Expand Down
48 changes: 25 additions & 23 deletions MobTimer/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class ViewController: NSViewController,NSTableViewDataSource,NSTableViewDelegate
if state == 0 {
timer.invalidate()
startTimer()
startButton.title = "Stop"
state = 1
} else {
timer.invalidate()
state = 0
Expand All @@ -52,13 +50,6 @@ class ViewController: NSViewController,NSTableViewDataSource,NSTableViewDelegate
}
}


override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
let fullScreenVC = segue.destinationController as! FullScreenViewController
let nm = sender as! String
fullScreenVC.nextMobber = nm
}

@IBAction func addMobber(_ sender: Any) {
if mobName.stringValue != "" {
mobberArray.add(mobName.stringValue)
Expand All @@ -67,15 +58,39 @@ class ViewController: NSViewController,NSTableViewDataSource,NSTableViewDelegate
}
}

// ViewController Methods

override func viewDidLoad() {
super.viewDidLoad()

mobberTable.delegate = self
mobberTable.dataSource = self
}

override func viewDidDisappear() {
exit(0)
}

// Send data to the FullScreenViewController
override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
let fullScreenVC = segue.destinationController as! FullScreenViewController
let nm = sender as! String
fullScreenVC.nextMobber = nm
}

func startTimer() {
timer = Timer.scheduledTimer(timeInterval: (TimeInterval(timeInterval.intValue * 60)), target: self, selector: #selector(updateMob), userInfo: nil, repeats: true)
startButton.title = "Stop"
state = 1
}


func updateMob()
{
// We want to steal focus from others
NSApp.activate(ignoringOtherApps: true)
timer.invalidate()
// Play the Sound
let url = Bundle.main.url(forResource: "foghorn", withExtension: "wav")!
do {
player = try AVAudioPlayer(contentsOf: url)
Expand All @@ -97,21 +112,8 @@ class ViewController: NSViewController,NSTableViewDataSource,NSTableViewDelegate
}


override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
mobberTable.delegate = self
mobberTable.dataSource = self
}


override func viewDidDisappear() {
exit(0)
}


// DELEGATE METHODS
// NSTableViewDelegate Methods

func numberOfRows(in tableView: NSTableView) -> Int {
return self.mobberArray.count
Expand Down

0 comments on commit d4b58a3

Please sign in to comment.