'use strict';

/***
 * @file Use Hockey App Crash Reporting and Event Telemetrics
 * @module ti.hockeyapp
 * @author Adam Armstrong <adam.t.armstrong@icloud.com>
 * @requires Hyperloop
 * @requires Speech
 * @version 1.0.0
 * @since 1.0.0
 */
var BITHockeyManager;
var BITMetricsManager;
var CrashManager;
var Activity;
var activity;
var OSName = Ti.Platform.osname;


/**
 * @function initialize
 * @summary Creates an instance of HockeyApp
 * @param {string} appIdentifier - String to use for identifying iOS HockeyApp Applications
 * 	- Android App Identifier is set in tiapp.xml
 * 	<meta-data android:name="net.hockeyapp.android.appIdentifier" android:value="APP_IDENTIFIER_KEY_HERE"/>
 * @since 1.0.0
 */
exports.init = function(appIdentifier) {
	if (OSName == "iphone") {
		BITHockeyManager = require('HockeySDK/BITHockeyManager');
		BITHockeyManager.sharedHockeyManager().configureWithIdentifier(appIdentifier);
		BITHockeyManager.sharedHockeyManager().startManager();
		BITHockeyManager.sharedHockeyManager().authenticator.authenticateInstallation(); // This line is obsolete in the crash only builds
		
		BITMetricsManager = BITHockeyManager.sharedHockeyManager().metricsManager;
	} else if (OSName == "android") {
		CrashManager = require("net.hockeyapp.android.CrashManager");
	    Activity = require('android.app.Activity');
	    activity = new Activity(Ti.Android.currentActivity);
	    BITMetricsManager = require("net.hockeyapp.android.metrics.MetricsManager");
	    
	    CrashManager.register(activity);
		BITMetricsManager.register(activity.getApplication());
	}
    
};

/**
 * @function trackEventWithName
 * @summary Submits a Telemetry Cusotm Event
 * @param {Object} - Object passed as either a single name or a set or properties
 * 
 * @since 1.0.0
 */
exports.trackEventWithName = function(eventObject) {
	if (OSName == "iphone") {
		BITMetricsManager.trackEventWithName(eventObject);
	} else if (OSName == "android") {
		BITMetricsManager.trackEvent(eventObject);
	}
};

@@ -195,14 +195,17 @@
 res 
-Speech
+HockeySDK
 %0A * 
@@ -364,17 +364,16 @@
 sname;%0A%0A
-%0A
 /**%0A * @
@@ -757,33 +757,34 @@
 f (OSName ==
- %22
+= '
 iphone
-%22
+'
 ) %7B%0A%09%09BITHoc
@@ -832,24 +832,28 @@
 Manager');%0A%09
+    
 %09BITHockeyMa
@@ -917,24 +917,28 @@
 entifier);%0A%09
+    
 %09BITHockeyMa
@@ -978,24 +978,28 @@
 Manager();%0A%09
+    
 %09BITHockeyMa
@@ -1122,12 +1122,14 @@
 lds%0A
-%09%09
 %0A%09
+    
 %09BIT
@@ -1221,31 +1221,36 @@
 SName ==
- %22
+= '
 android
-%22
+'
 ) %7B%0A%09
+    
 %09CrashMa
@@ -1309,16 +1309,17 @@
 );%0A%09    
+%09
 Activity
@@ -1359,16 +1359,17 @@
 );%0A%09    
+%09
 activity
@@ -1418,16 +1418,17 @@
 );%0A%09    
+%09
 BITMetri
@@ -1500,19 +1500,15 @@
 %22);%0A
+%0A
 %09    
-%0A%09    
+%09
 Cras
@@ -1537,16 +1537,20 @@
 vity);%0A%09
+    
 %09BITMetr
@@ -1603,13 +1603,120 @@
 ;%0A%09%7D
-%0A    
+ else%C2%A0%7B%0A%09%09Ti.API.error('The target platform (' + OSNAME + ') does not support %5C'trackEventWithName%5C', yet.');%0A%09%7D
 %0A%7D;%0A
@@ -1974,17 +1974,18 @@
 e ==
- %22
+= '
 iphone
-%22
+'
 ) %7B%0A
@@ -2062,18 +2062,19 @@
 e ==
- %22
+= '
 android
-%22
+'
 ) %7B%0A
@@ -2118,14 +2118,126 @@
 bject);%0A
+%09%7D else%C2%A0%7B%0A%09%09Ti.API.error('The target platform (' + OSNAME + ') does not support %5C'trackEventWithName%5C', yet.');%0A
 %09%7D%0A%7D;%0A

Update ti.hockeyapp.js