Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
Really hope I didn't leave any sensitive information in here...
  • Loading branch information
amiantos committed Mar 7, 2018
0 parents commit ed3e892
Show file tree
Hide file tree
Showing 70 changed files with 8,786 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Pods/

build/
DerivedData/

*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

*.moved-aside
*.xccheckout
*.xcscmblueprint

*.hmap
*.ipa
*.dSYM.zip
*.dSYM

timeline.xctimeline
playground.xcworkspace

*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
705 changes: 705 additions & 0 deletions Numu Tracker.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Numu Tracker.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Numu Tracker/.DS_Store
Binary file not shown.
36 changes: 36 additions & 0 deletions Numu Tracker/AboutViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AboutViewController.swift
// Numu Tracker
//
// Created by Bradley Root on 9/16/17.
// Copyright © 2017 Numu Tracker. All rights reserved.
//

import UIKit
import Crashlytics

class AboutViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
Answers.logCustomEvent(withName: "About View", customAttributes: nil)
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

}
141 changes: 141 additions & 0 deletions Numu Tracker/AddArtistsViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
//
// AddArtistsViewController.swift
// Numu Tracker
//
// Created by Bradley Root on 10/16/16.
// Copyright © 2016 Numu Tracker. All rights reserved.
//

import UIKit
import MediaPlayer
import Crashlytics

class AddArtistsViewController: UIViewController {


@IBOutlet weak var addFromAppleMusic: UIButton!
@IBAction func addFromAppleMusicPress(_ sender: AnyObject) {
if (defaults.bool(forKey: "logged")) {
self.addArtistsActivity.startAnimating()
addFromAppleMusic.isHidden = true
MPMediaLibrary.requestAuthorization { (status) in
if status == .authorized {
self.runImportArtists()
} else {
self.displayError()
}
}
} else {
if (UIDevice().screenType == UIDevice.ScreenType.iPhone4) {
let loginViewController = storyboard?.instantiateViewController(withIdentifier: "LogRegPromptSmall") as! UINavigationController
DispatchQueue.main.async {
self.present(loginViewController, animated: true, completion: nil)
}
} else {
let loginViewController = storyboard?.instantiateViewController(withIdentifier: "LogRegPrompt") as! UINavigationController
DispatchQueue.main.async {
self.present(loginViewController, animated: true, completion: nil)
}
}
/*
let controller = UIAlertController(title: "Apple Music Import", message: "Please log in first.", preferredStyle: .alert)
controller.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(controller, animated: true, completion: nil)
*/
}

}

@IBOutlet weak var addArtistsActivity: UIActivityIndicatorView!

override func viewDidLoad() {
super.viewDidLoad()

self.navigationController?.navigationBar.tintColor = .white

addFromAppleMusic.backgroundColor = UIColor.clear
addFromAppleMusic.layer.cornerRadius = 5
addFromAppleMusic.layer.borderWidth = 1
addFromAppleMusic.layer.borderColor = UIColor.gray.cgColor




// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/


func runImportArtists() {


let query = MPMediaQuery.artists()
var artists_found: [String] = []
query.groupingType = MPMediaGrouping.artist
if let items = query.items {
for artist in items {
if let artist_name = artist.artist {
artists_found += [artist_name]
}
}
}
let uniques = Array(Set(artists_found))


DispatchQueue.global(qos: .background).async(execute: {
JSONClient.sharedClient.postArtists(artists: uniques) { success in
DispatchQueue.main.async(execute: {
self.addArtistsActivity.stopAnimating()
self.addFromAppleMusic.isHidden = false
if (success == "Success") {
NotificationCenter.default.post(name: Notification.Name(rawValue: updatedArtistsNotificationKey), object: self)
let controller = UIAlertController(title: "Success", message: "Your artists have been imported. Please allow several minutes for all artists to appear.", preferredStyle: .alert)
controller.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(controller, animated: true, completion: nil)

Answers.logCustomEvent(withName: "AM Artist Import", customAttributes: ["Artists":uniques.count])

} else {
let controller = UIAlertController(title: "Error", message: "An error occurred which prevented artists from being imported.", preferredStyle: .alert)
controller.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(controller, animated: true, completion: nil)

}
})
}
})
}

func displayError() {
var error: String
switch MPMediaLibrary.authorizationStatus() {
case .restricted:
error = "Media library access restricted by corporate or parental settings"
case .denied:
error = "Media library access denied by user"
default:
error = "Unknown error"
}

let controller = UIAlertController(title: "Error", message: error, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(controller, animated: true, completion: nil)
}


}

0 comments on commit ed3e892

Please sign in to comment.