<commit_before>//
//  AppDelegate.swift
//  HackTX
//
//  Created by <NAME> on 7/11/15.
//  Copyright (c) 2015 HackTX. All rights reserved.
//

import UIKit
import Fabric
import TwitterKit
import Parse


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

	var window: UIWindow?


	func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        UserPrefs.shared().registerDefaults()
        Fabric.with([Twitter()])
        setNavTabBarLayout()
		
        setupGoogleAnalytics()
		initParse(application, launchOptions: launchOptions)
		UIApplication.sharedApplication().applicationIconBadgeNumber = 0

		return true
	}
    
    func setupGoogleAnalytics() {
        // Configure tracker from GoogleService-Info.plist.
        var configureError:NSError?
        GGLContext.sharedInstance().configureWithError(&configureError)
        assert(configureError == nil, "Error configuring Google services: \(configureError)")
        
        // Optional: configure GAI options.
        let gai = GAI.sharedInstance()
        gai.trackUncaughtExceptions = true  // report uncaught exceptions
    }
	
	func initParse(application: UIApplication, launchOptions: [NSObject: AnyObject]?) {
		
		
		let parseAppID = getParseAppID()
		let parseClientID = getParseClientID()
		Parse.setApplicationId(parseAppID,
			clientKey: parseClientID)
		
		if application.applicationState != UIApplicationState.Background {
			// Track an app open here if we launch with a push, unless
			// "content_available" was used to trigger a background push (introduced in iOS 7).
			// In that case, we skip tracking here to avoid double counting the app-open.
			
			let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
			let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
			var pushPayload = false
			if let options = launchOptions {
				pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
			}
			if (preBackgroundPush || oldPushHandlerOnly || pushPayload) {
				PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
			}
		}
		if application.respondsToSelector("registerUserNotificationSettings:") {
			let userNotificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
			let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
			application.registerUserNotificationSettings(settings)
			application.registerForRemoteNotifications()
		} else {
			application.registerForRemoteNotifications()
		}
		
		let currentInstallation = PFInstallation.currentInstallation()
		currentInstallation.addUniqueObject("announcements", forKey: "channels")
		currentInstallation.saveInBackground()
		
		
		//Remind attendees to check in to the event
		if (!UserPrefs.shared().isRegisteredForCheckInNotif()) {
			let notification = UILocalNotification()
			notification.alertBody = "Remember to check in for HackTX in the app!"
			notification.alertAction = "check in"
			notification.fireDate = NSDate(timeIntervalSince1970: 1443274200)
			notification.soundName = UILocalNotificationDefaultSoundName
			UIApplication.sharedApplication().scheduleLocalNotification(notification)
			UserPrefs.shared().setIsCheckedIn(true)
		}
	}
	
	func getParseKeyDict() -> NSDictionary {
		var parseDict : NSDictionary?
		if let path = NSBundle.mainBundle().pathForResource("ApiKeys", ofType: "plist") {
			parseDict = NSDictionary(contentsOfFile: path)
		}
		return parseDict!
	}
	
	func getParseAppID() -> String {
		let parseDict = getParseKeyDict()
		return parseDict["ApplicationID"] as! String
	}
	
	func getParseClientID() -> String {
		let parseDict = getParseKeyDict()
		return parseDict["ClientID"] as! String
	}
    
    func setNavTabBarLayout() {
//        UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
//        UINavigationBar.appearance().barTintColor = UIColor(red: 10/255.0, green: 166/255.0, blue: 182/255.0, alpha: 1.0)
//        UINavigationBar.appearance().tintColor = UIColor.whiteColor()
//        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
//        
//        UITabBar.appearance().barTintColor = UIColor(red: 10/255.0, green: 166/255.0, blue: 182/255.0, alpha: 1.0)
        UITabBar.appearance().tintColor = UIColor(red: 125/255.0, green: 211/255.0, blue: 244/255.0, alpha: 1.0) //UIColor.whiteColor()
        
        
    }
	
	func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
		let installation = PFInstallation.currentInstallation()
		installation.setDeviceTokenFromData(deviceToken)
		installation.saveInBackground()
	}
 
	func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
		if error.code == 3010 {
			print("Push notifications are not supported in the iOS Simulator.")
		} else {
			print("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
		}
	}
 
	func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
		PFPush.handlePush(userInfo)
		if application.applicationState == UIApplicationState.Inactive {
			PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
		}
		
		self.window?.makeKeyAndVisible()
		let rootController = window?.rootViewController as! UITabBarController
		rootController.selectedIndex = 1;
		NSNotificationCenter.defaultCenter().postNotificationName("reloadTheTable", object: nil)
		
	}

	func applicationWillResignActive(application: UIApplication) {
		// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
		// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
	}

	func applicationDidEnterBackground(application: UIApplication) {
		// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
		// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
	}

	func applicationWillEnterForeground(application: UIApplication) {
		// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
		UIApplication.sharedApplication().applicationIconBadgeNumber = 0

	}<commit_msg>Changes to support full 3D Touch support<commit_after>//
//  AppDelegate.swift
//  HackTX
//
//  Created by <NAME> on 7/11/15.
//  Copyright (c) 2015 HackTX. All rights reserved.
//

import UIKit
import Fabric
import TwitterKit
import Parse


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

	var window: UIWindow?


	func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        UserPrefs.shared().registerDefaults()
        Fabric.with([Twitter()])
        setNavTabBarLayout()
		
        setupGoogleAnalytics()
		initParse(application, launchOptions: launchOptions)
		UIApplication.sharedApplication().applicationIconBadgeNumber = 0

		return true
	}
    
    func setupGoogleAnalytics() {
        // Configure tracker from GoogleService-Info.plist.
        var configureError:NSError?
        GGLContext.sharedInstance().configureWithError(&configureError)
        assert(configureError == nil, "Error configuring Google services: \(configureError)")
        
        // Optional: configure GAI options.
        let gai = GAI.sharedInstance()
        gai.trackUncaughtExceptions = true  // report uncaught exceptions
    }
	
	func initParse(application: UIApplication, launchOptions: [NSObject: AnyObject]?) {
		
		
		let parseAppID = getParseAppID()
		let parseClientID = getParseClientID()
		Parse.setApplicationId(parseAppID,
			clientKey: parseClientID)
		
		if application.applicationState != UIApplicationState.Background {
			// Track an app open here if we launch with a push, unless
			// "content_available" was used to trigger a background push (introduced in iOS 7).
			// In that case, we skip tracking here to avoid double counting the app-open.
			
			let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
			let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
			var pushPayload = false
			if let options = launchOptions {
				pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
			}
			if (preBackgroundPush || oldPushHandlerOnly || pushPayload) {
				PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
			}
		}
		if application.respondsToSelector("registerUserNotificationSettings:") {
			let userNotificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
			let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
			application.registerUserNotificationSettings(settings)
			application.registerForRemoteNotifications()
		} else {
			application.registerForRemoteNotifications()
		}
		
		let currentInstallation = PFInstallation.currentInstallation()
		currentInstallation.addUniqueObject("announcements", forKey: "channels")
		currentInstallation.saveInBackground()
		
		
		//Remind attendees to check in to the event
		if (!UserPrefs.shared().isRegisteredForCheckInNotif()) {
			let notification = UILocalNotification()
			notification.alertBody = "Remember to check in for HackTX in the app!"
			notification.alertAction = "check in"
			notification.fireDate = NSDate(timeIntervalSince1970: 1443274200)
			notification.soundName = UILocalNotificationDefaultSoundName
			UIApplication.sharedApplication().scheduleLocalNotification(notification)
			UserPrefs.shared().setIsCheckedIn(true)
		}
	}
	
	func getParseKeyDict() -> NSDictionary {
		var parseDict : NSDictionary?
		if let path = NSBundle.mainBundle().pathForResource("ApiKeys", ofType: "plist") {
			parseDict = NSDictionary(contentsOfFile: path)
		}
		return parseDict!
	}
	
	func getParseAppID() -> String {
		let parseDict = getParseKeyDict()
		return parseDict["ApplicationID"] as! String
	}
	
	func getParseClientID() -> String {
		let parseDict = getParseKeyDict()
		return parseDict["ClientID"] as! String
	}
    
    func setNavTabBarLayout() {
//        UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
//        UINavigationBar.appearance().barTintColor = UIColor(red: 10/255.0, green: 166/255.0, blue: 182/255.0, alpha: 1.0)
//        UINavigationBar.appearance().tintColor = UIColor.whiteColor()
//        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
//        
//        UITabBar.appearance().barTintColor = UIColor(red: 10/255.0, green: 166/255.0, blue: 182/255.0, alpha: 1.0)
        UITabBar.appearance().tintColor = UIColor(red: 125/255.0, green: 211/255.0, blue: 244/255.0, alpha: 1.0) //UIColor.whiteColor()
        
        
    }
	
	func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
		let installation = PFInstallation.currentInstallation()
		installation.setDeviceTokenFromData(deviceToken)
		installation.saveInBackground()
	}
 
	func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
		if error.code == 3010 {
			print("Push notifications are not supported in the iOS Simulator.")
		} else {
			print("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
		}
	}
 
	func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
		PFPush.handlePush(userInfo)
		if application.applicationState == UIApplicationState.Inactive {
			PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
		}
		
		self.window?.makeKeyAndVisible()
		let rootController = window?.rootViewController as! UITabBarController
		rootController.selectedIndex = 1;
		NSNotificationCenter.defaultCenter().postNotificationName("reloadTheTable", object: nil)
		
	}
	
	@available(iOS 9.0, *)
	func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
		print("Application performActionForShortcutItem")
		completionHandler(handleShortcut(shortcutItem))
	}
	
	@available(iOS 9.0, *)
	func handleShortcut(shortcutItem: UIApplicationShortcutItem) -> Bool {
		print("handling shortcut")
		var succeeded = false
		
		self.window?.makeKeyAndVisible()
		let rootController = window?.rootViewController as! UITabBarController
		if (shortcutItem.type == "schedule") {
			//Debugging code
			print("- Handling \(shortcutItem.type)")
			
			rootController.selectedIndex = 0
			succeeded = true
			
		} else if (shortcutItem.type == "announcements") {
			print("- Handling \(shortcutItem.type)")
			
			rootController.selectedIndex = 1;
			succeeded = true
			
		} else if (shortcutItem.type == "maps") {
			print("- Handling \(shortcutItem.type)")
			
			rootController.selectedIndex = 3
			succeeded = true
		}
		
		return succeeded
	}

	func applicationWillResignActive(application: UIApplication) {
		// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
		// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
	}

	func applicationDidEnterBackground(application: UIApplication) {
		// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
		// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
	}

	func applicationWillEnterForeground(application: UIApplication) {
		// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
		UIApplication.sharedApplication().applicationIconBadgeNumber = 0

	}
{'fraction_non_alphanumeric': 0.08665557404326123, 'fraction_numerical': 0.013577371048252912, 'mean_word_length': 4.596275605214153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3360325', 'n_tokens_mistral': 4566, 'n_tokens_neox': 3973, 'n_words': 1073}