Skip to content

Commit

Permalink
Updating Unity plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenzhi committed Jul 27, 2016
1 parent 9216fa5 commit 55166b0
Show file tree
Hide file tree
Showing 142 changed files with 820 additions and 24,208 deletions.
26 changes: 26 additions & 0 deletions Assets/Editor/Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;
using System.IO;
using UnityEditor;

namespace Appboy.Editor {
public static class Build {
private static string[] AssetPathNames = {
"Assets/Plugins/Android",
"Assets/Plugins/Appboy",
"Assets/Plugins/iOS"
};

public static void ExportPackage() {
Debug.Log("Exporting Appboy Unity Package...");
System.IO.Directory.CreateDirectory("unity-package");
AssetDatabase.ExportPackage(AssetPathNames, "unity-package/Appboy.unitypackage", ExportPackageOptions.Recurse);
}

public static void ExportPackageWithoutDependencies() {
Debug.Log("Exporting Appboy Unity Package without dependencies...");
System.IO.Directory.CreateDirectory("unity-package");
AssetDatabase.ExportPackage(AssetPathNames, "unity-package/Appboy-nodeps.unitypackage", ExportPackageOptions.Recurse);
}
}
}
File renamed without changes.
File renamed without changes.
Binary file added Assets/Plugins/Android/libs/appboy-ui.aar
Binary file not shown.
Binary file added Assets/Plugins/Android/libs/appboy-unity.aar
Binary file not shown.
Binary file added Assets/Plugins/Android/libs/appboy.jar
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Appboy.Utilities;
using System;

/// <summary>
/// These methods can be called by Unity applications using iOS or Android in order to report
Expand All @@ -19,13 +20,16 @@ namespace Appboy {
public class AppboyBinding : MonoBehaviour {
public const string Version = "1.2.1";

// Overloads
// These will call the associated binding method for the current live platform
public static void LogPurchase(string productId, string currencyCode, decimal price) {
LogPurchase(productId, currencyCode, price, 1);
}

public static void IncrementCustomUserAttribute(string key) {
IncrementCustomUserAttribute(key, 1);
}
// End Overloads

#if UNITY_IOS
void Start() {
Expand Down Expand Up @@ -156,7 +160,7 @@ public static void LogCustomEvent(string eventName) {
_logCustomEvent(eventName, null);
}

public static void LogCustomEvent(string eventName, Dictionary<string, string> properties) {
public static void LogCustomEvent(string eventName, Dictionary<string, object> properties) {
var propertiesString = Json.Serialize(properties);
_logCustomEvent(eventName, propertiesString);
}
Expand All @@ -165,7 +169,7 @@ public static void LogPurchase(string productId, string currencyCode, decimal pr
_logPurchase(productId, currencyCode, price.ToString(), quantity, null);
}

public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary<string, string> properties) {
public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary<string, object> properties) {
var propertiesString = Json.Serialize(properties);
_logPurchase(productId, currencyCode, price.ToString(), quantity, propertiesString);
}
Expand Down Expand Up @@ -375,17 +379,38 @@ public static void LogCustomEvent(string eventName) {
Appboy.Call<bool>("logCustomEvent", eventName);
}

public static AndroidJavaObject ParsePropertiesToAppboyProperties(Dictionary<string, string> properties) {
public static AndroidJavaObject ParsePropertiesToAppboyProperties(Dictionary<string, object> properties) {
AndroidJavaObject appboyProperties = new AndroidJavaObject("com.appboy.models.outgoing.AppboyProperties");
if (properties != null && properties.Count > 0) {
foreach (KeyValuePair<string, string> entry in properties) {
appboyProperties.Call<AndroidJavaObject>("addProperty", entry.Key, entry.Value);
foreach (KeyValuePair<string, object> entry in properties) {
if (entry.Value == null) {
continue;
}

// Public API only supports int/string/double/bool/DateTime. Other values can't get mapped
// to Android AppboyProperty methods without casting.
if (entry.Value.GetType() == typeof(int) || entry.Value.GetType() == typeof(string) ||
entry.Value.GetType() == typeof(double) || entry.Value.GetType() == typeof(bool)) {
appboyProperties.Call<AndroidJavaObject>("addProperty", entry.Key, entry.Value);
} else {
appboyProperties.Call<AndroidJavaObject>("addProperty", entry.Key, entry.Value.ToString());
}
}
}
return appboyProperties;
}

public static void LogCustomEvent(string eventName, Dictionary<string, string> properties) {
/// <summary>
/// Logs a custom event for the user with the given properties.
/// </summary>
/// <param name='eventName'>
/// The name of the custom event.
/// </param>
/// <param name='properties'>
/// A properties dictionary. Values that are int/string/double/bool/DateTime will be passed to Android
/// and mapped to java types. All other values will be passed as strings.
/// </param>
public static void LogCustomEvent(string eventName, Dictionary<string, object> properties) {
AndroidJavaObject appboyProperties = ParsePropertiesToAppboyProperties(properties);
Appboy.Call<bool>("logCustomEvent", eventName, appboyProperties);
}
Expand All @@ -395,7 +420,7 @@ public static void LogPurchase(string productId, string currencyCode, decimal pr
Appboy.Call<bool>("logPurchase", productId, currencyCode, javaPrice, quantity);
}

public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary<string, string> properties) {
public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary<string, object> properties) {
var javaPrice = new AndroidJavaObject("java.math.BigDecimal", price.ToString());
AndroidJavaObject appboyProperties = ParsePropertiesToAppboyProperties(properties);
Appboy.Call<bool>("logPurchase", productId, currencyCode, javaPrice, quantity, appboyProperties);
Expand Down Expand Up @@ -877,170 +902,8 @@ public static void LogFeedbackDisplayed() {
WindowsUniversalUnityAdapter.AppboyAdapter.LogFeedbackDisplayed();
}

#elif UNITY_WP8
void Start() {
Debug.Log("Starting Appboy binding for Windows Phone8 clients.");
}

public static void LogCustomEvent(string eventName) {
WindowsPhone8UnityAdapter.AppboyAdapter.LogCustomEvent(eventName);
}

public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity) {
WindowsPhone8UnityAdapter.AppboyAdapter.LogPurchase(productId, currencyCode, price, quantity);
}

public static void ChangeUser(string userId) {
WindowsPhone8UnityAdapter.AppboyAdapter.ChangeUser(userId);
}

public static void SetUserFirstName(string firstName) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserFirstName(firstName);
}

public static void SetUserLastName(string lastName) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserLastName(lastName);
}

public static void SetUserEmail(string email) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserEmail(email);
}

public static void SetUserBio(string bio) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserBio(bio);
}

public static void SetUserGender(Gender gender) {
if (gender == Gender.Female) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserGender("FEMALE");
} else {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserGender("MALE");
}
}

public static void SetUserDateOfBirth(int year, int month, int day) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserDateOfBirth(year, month, day);
}

public static void SetUserCountry(string country) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserCountry(country);
}

public static void SetUserHomeCity(string city) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserHomeCity(city);
}

public static void SetUserIsSubscribedToEmails(bool isSubscribedToEmails) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserIsSubscribedToEmails(isSubscribedToEmails);
}

public static void SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType emailNotificationSubscriptionType) {
if (emailNotificationSubscriptionType == AppboyNotificationSubscriptionType.OPTED_IN) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserEmailNotificationSubscriptionType("OPTED_IN");
} else if (emailNotificationSubscriptionType == AppboyNotificationSubscriptionType.SUBSCRIBED) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserEmailNotificationSubscriptionType("SUBSCRIBED");
} else {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserEmailNotificationSubscriptionType("UNSUBSCRIBED");
}
}

public static void SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType pushNotificationSubscriptionType) {
if (pushNotificationSubscriptionType == AppboyNotificationSubscriptionType.OPTED_IN) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserPushNotificationSubscriptionType("OPTED_IN");
} else if (pushNotificationSubscriptionType == AppboyNotificationSubscriptionType.SUBSCRIBED) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserPushNotificationSubscriptionType("SUBSCRIBED");
} else {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserPushNotificationSubscriptionType("UNSUBSCRIBED");
}
}

public static void SetUserPhoneNumber(string phoneNumber) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserPhoneNumber(phoneNumber);
}

public static void SetUserAvatarImageURL(string imageURL) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetUserAvatarImageURL(imageURL);
}

public static void SetCustomUserAttribute(string key, bool value) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetCustomUserAttribute(key, value);
}

public static void SetCustomUserAttribute(string key, int value) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetCustomUserAttribute(key, value);
}

public static void SetCustomUserAttribute(string key, float value) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetCustomUserAttribute(key, value);
}

public static void SetCustomUserAttribute(string key, string value) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetCustomUserAttribute(key, value);
}

public static void SetCustomUserAttributeToNow(string key) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetCustomUserAttributeToNow(key);
}

public static void SetCustomUserAttributeToSecondsFromEpoch(string key, long secondsFromEpoch) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetCustomUserAttributeToSecondsFromEpoch(key, secondsFromEpoch);
}

public static void UnsetCustomUserAttribute(string key) {
WindowsPhone8UnityAdapter.AppboyAdapter.UnsetCustomUserAttribute(key);
}

public static void IncrementCustomUserAttribute(string key, int incrementValue) {
WindowsPhone8UnityAdapter.AppboyAdapter.IncrementCustomUserAttribute(key, incrementValue);
}

public static void SetCustomUserAttributeArray(string key, List<string> array, int size) {
WindowsPhone8UnityAdapter.AppboyAdapter.SetCustomUserAttributeArray(key, array, size);
}

public static void AddToCustomUserAttributeArray(string key, string value) {
WindowsPhone8UnityAdapter.AppboyAdapter.AddToCustomUserAttributeArray(key, value);
}

public static void RemoveFromCustomUserAttributeArray(string key, string value) {
WindowsPhone8UnityAdapter.AppboyAdapter.RemoveFromCustomUserAttributeArray(key, value);
}

public static void SubmitFeedback(string replyToEmail, string message, bool isReportingABug) {
WindowsPhone8UnityAdapter.AppboyAdapter.SubmitFeedback(replyToEmail, message, isReportingABug);
}

public static void RequestSlideup() {
WindowsPhone8UnityAdapter.AppboyAdapter.RequestSlideup();
}

public static void RequestFeedRefresh() {
WindowsPhone8UnityAdapter.AppboyAdapter.RequestFeedRefresh();
}

public static void RequestFeedRefreshFromCache() {
WindowsPhone8UnityAdapter.AppboyAdapter.RequestFeedRefreshFromCache();
}

public static void LogSlideupClicked(string slideupJSONString) {
WindowsPhone8UnityAdapter.AppboyAdapter.LogSlideupClicked(slideupJSONString);
}

public static void LogSlideupImpression(string slideupJSONString) {
WindowsPhone8UnityAdapter.AppboyAdapter.LogSlideupImpression(slideupJSONString);
}

public static void LogFeedDisplayed() {
WindowsPhone8UnityAdapter.AppboyAdapter.LogFeedDisplayed();
}

public static void LogFeedbackDisplayed() {
WindowsPhone8UnityAdapter.AppboyAdapter.LogFeedbackDisplayed();
}

#else


// Empty implementations of the API, in case the application is being compiled for a platform other than iOS or Android.
void Start() {
Debug.Log("Starting no-op Appboy binding for non iOS/Android clients.");
Expand All @@ -1049,13 +912,13 @@ void Start() {
public static void LogCustomEvent(string eventName) {
}

public static void LogCustomEvent(string eventName, Dictionary<string, string> properties) {
public static void LogCustomEvent(string eventName, Dictionary<string, object> properties) {
}

public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity) {
}

public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary<string, string> properties) {
public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary<string, object> properties) {
}

public static void ChangeUser(string userId) {
Expand Down
Loading

0 comments on commit 55166b0

Please sign in to comment.