working stats page
This commit is contained in:
commit
23feaf4ebf
36 changed files with 11368 additions and 6 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,7 +4,7 @@
|
|||
**/[Bb]uild/
|
||||
**/[Bb]uilds/
|
||||
**/Assets/AssetStoreTools*
|
||||
**/Assets/Plugins/*
|
||||
**/Assets/Plugins/Android/AndroidManifest.xml
|
||||
|
||||
# Autogenerated VS/MD solution and project files
|
||||
**/.vs/
|
||||
|
|
BIN
MoCha/Assets/Materials/Blackout.mat
Normal file
BIN
MoCha/Assets/Materials/Blackout.mat
Normal file
Binary file not shown.
10
MoCha/Assets/Materials/Blackout.mat.meta
Normal file
10
MoCha/Assets/Materials/Blackout.mat.meta
Normal file
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8b09d9a7c0cb3ca42a798802c96d28c8
|
||||
timeCreated: 1524748932
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
32
MoCha/Assets/Plugins/Android/Oauthtutorial.meta
Normal file
32
MoCha/Assets/Plugins/Android/Oauthtutorial.meta
Normal file
|
@ -0,0 +1,32 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 29bad9f5cd2fcea41b37212bde01f7ab
|
||||
folderAsset: yes
|
||||
timeCreated: 1524756422
|
||||
licenseType: Free
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application android:icon="@drawable/app_icon" android:label="@string/app_name">
|
||||
<activity android:name=".MainActivity" android:label="@string/app_name" android:launchMode="singleTask" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="sensor">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<data android:scheme="mocha" />
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3451933c2f0cf5048a2d52f76b3de537
|
||||
timeCreated: 1524756427
|
||||
licenseType: Free
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
MoCha/Assets/Plugins/Android/Oauthtutorial/libs.meta
Normal file
10
MoCha/Assets/Plugins/Android/Oauthtutorial/libs.meta
Normal file
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 34e95321666f0c64cbf170b85dc31e24
|
||||
folderAsset: yes
|
||||
timeCreated: 1524756422
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 77748688b0089b24eabef7bed12c009d
|
||||
timeCreated: 1524756423
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
MoCha/Assets/Plugins/Newtonsoft.Json.dll
Normal file
BIN
MoCha/Assets/Plugins/Newtonsoft.Json.dll
Normal file
Binary file not shown.
32
MoCha/Assets/Plugins/Newtonsoft.Json.dll.meta
Normal file
32
MoCha/Assets/Plugins/Newtonsoft.Json.dll.meta
Normal file
|
@ -0,0 +1,32 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fdc6540476175604383ac01213c581ab
|
||||
timeCreated: 1524748515
|
||||
licenseType: Free
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9439
MoCha/Assets/Plugins/Newtonsoft.Json.xml
Normal file
9439
MoCha/Assets/Plugins/Newtonsoft.Json.xml
Normal file
File diff suppressed because it is too large
Load diff
9
MoCha/Assets/Plugins/Newtonsoft.Json.xml.meta
Normal file
9
MoCha/Assets/Plugins/Newtonsoft.Json.xml.meta
Normal file
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4389f1c8a3fe9344886cb991c54bf25a
|
||||
timeCreated: 1523986568
|
||||
licenseType: Free
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -1,6 +1,6 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 326b00dfcab7e8c4da45c990cef3c9b6
|
||||
timeCreated: 1524679668
|
||||
timeCreated: 1524753018
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
23
MoCha/Assets/Scripts/CustomAndroidPlugin.cs
Normal file
23
MoCha/Assets/Scripts/CustomAndroidPlugin.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Assets.Scripts.Fitbit;
|
||||
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public class CustomAndroidPlugin : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject Manager;
|
||||
|
||||
public void PassReturnCode(string value)
|
||||
{
|
||||
Manager.GetComponent<FitBitAPI>().SetReturnCodeFromAndroid(value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
18
MoCha/Assets/Scripts/CustomAndroidPlugin.cs.meta
Normal file
18
MoCha/Assets/Scripts/CustomAndroidPlugin.cs.meta
Normal file
|
@ -0,0 +1,18 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< Updated upstream
|
||||
guid: 80685d60eb42cd340a5c76d410187801
|
||||
timeCreated: 1524716619
|
||||
=======
|
||||
guid: 1d9a971c325c98e4a81ea4ec2e52aed6
|
||||
timeCreated: 1524756178
|
||||
>>>>>>> Stashed changes
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
516
MoCha/Assets/Scripts/FitBitAPI.cs
Normal file
516
MoCha/Assets/Scripts/FitBitAPI.cs
Normal file
|
@ -0,0 +1,516 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Fitbit
|
||||
{
|
||||
|
||||
public class FitBitAPI : MonoBehaviour
|
||||
{
|
||||
|
||||
private const string _consumerSecret = "69307b9f332caf9946ef4e23cabde2e4";
|
||||
private const string _clientId = "22CX4L";
|
||||
private const string _callbackURL = "http://localhost/callback";
|
||||
private const string CustomAndroidScheme = "mocha://";
|
||||
|
||||
private const string _tokenUrl = "https://api.fitbit.com/oauth2/token";
|
||||
private const string _baseGetUrl = "https://api.fitbit.com/1/user/-/";
|
||||
private const string _profileUrl = _baseGetUrl + "profile.json/";
|
||||
private const string _activityUrl = _baseGetUrl + "activities/";
|
||||
|
||||
private string _distanceUrl = _activityUrl + "distance/date/" + _currentDateTime + "/1d.json";
|
||||
|
||||
private string _stepsUrl = _activityUrl + "steps/date/" + _currentDateTime + "/1d.json";
|
||||
|
||||
private string _caloriesUrl = _activityUrl + "calories/date/" + _currentDateTime + "/1d.json";
|
||||
|
||||
private string _sleepUrl = _baseGetUrl + "sleep/minutesAsleep/date/" + _currentDateTime + "/" + _currentDateTime + ".json";
|
||||
|
||||
private static string _currentDateTime = GetCurrentDate();
|
||||
|
||||
private string _returnCode;
|
||||
private WWW _wwwRequest;
|
||||
private bool _bGotTheData = false;
|
||||
private bool _bFirstFire = true;
|
||||
|
||||
private OAuth2AccessToken _oAuth2 = new OAuth2AccessToken();
|
||||
public FitbitData _fitbitData = new FitbitData();
|
||||
|
||||
private string _statusMessage;
|
||||
|
||||
private string CallBackUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
//determine which platform we're running on and use the appropriate url
|
||||
if (Application.platform == RuntimePlatform.WindowsEditor)
|
||||
return WWW.EscapeURL(_callbackURL);
|
||||
else if (Application.platform == RuntimePlatform.Android)
|
||||
{
|
||||
return WWW.EscapeURL(CustomAndroidScheme);
|
||||
}
|
||||
else
|
||||
{
|
||||
return WWW.EscapeURL(CustomAndroidScheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
DontDestroyOnLoad(this);
|
||||
}
|
||||
private void OnGUI()
|
||||
{
|
||||
if (!_bGotTheData && !string.IsNullOrEmpty(_statusMessage) && _bFirstFire)
|
||||
{
|
||||
_bFirstFire = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoginToFitbit()
|
||||
{
|
||||
|
||||
if (PlayerPrefs.HasKey("FitbitRefreshToken"))
|
||||
{
|
||||
UseRefreshToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
UserAcceptOrDeny();
|
||||
}
|
||||
|
||||
}
|
||||
public void UserAcceptOrDeny()
|
||||
{
|
||||
var url =
|
||||
"https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=" + _clientId + "&prompt=login&redirect_uri=" +
|
||||
CallBackUrl +
|
||||
"&scope=activity%20nutrition%20heartrate%20location%20profile%20sleep%20weight%20social";
|
||||
Application.OpenURL(url);
|
||||
// print(url);
|
||||
#if UNITY_EDITOR
|
||||
#endif
|
||||
}
|
||||
|
||||
public void ClearRefreshCode()
|
||||
{
|
||||
PlayerPrefs.DeleteKey("FitbitRefreshToken");
|
||||
Debug.Log("Refresh Token has been CLEARED!");
|
||||
}
|
||||
|
||||
private void UseReturnCode()
|
||||
{
|
||||
Debug.Log("return code isn't empty");
|
||||
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(_clientId + ":" + _consumerSecret);
|
||||
var encoded = Convert.ToBase64String(plainTextBytes);
|
||||
|
||||
var form = new WWWForm();
|
||||
form.AddField("client_id", _clientId);
|
||||
form.AddField("grant_type", "authorization_code");
|
||||
form.AddField("redirect_uri", WWW.UnEscapeURL(CallBackUrl));
|
||||
form.AddField("code", _returnCode);
|
||||
|
||||
var headers = form.headers;
|
||||
headers["Authorization"] = "Basic " + encoded;
|
||||
|
||||
_wwwRequest = new WWW(_tokenUrl, form.data, headers);
|
||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||
|
||||
while (!_wwwRequest.isDone)
|
||||
{
|
||||
}
|
||||
|
||||
Debug.Log("Token: " + _wwwRequest.text);
|
||||
Debug.Log("parsing token");
|
||||
|
||||
var parsed = new JSONObject(_wwwRequest.text);
|
||||
ParseAccessToken(parsed);
|
||||
Debug.Log("\nParsed Token: " + _oAuth2.Token);
|
||||
GetAllData();
|
||||
Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps);
|
||||
_bGotTheData = true;
|
||||
}
|
||||
|
||||
public void UseRefreshToken()
|
||||
{
|
||||
Debug.Log("Using Refresh Token");
|
||||
var plainTextBytes = Encoding.UTF8.GetBytes(_clientId + ":" + _consumerSecret);
|
||||
var encoded = Convert.ToBase64String(plainTextBytes);
|
||||
|
||||
var form = new WWWForm();
|
||||
form.AddField("grant_type", "refresh_token");
|
||||
form.AddField("refresh_token", PlayerPrefs.GetString("FitbitRefreshToken"));
|
||||
|
||||
var headers = form.headers;
|
||||
headers["Authorization"] = "Basic " + encoded;
|
||||
|
||||
_wwwRequest = new WWW(_tokenUrl, form.data, headers);
|
||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||
while (!_wwwRequest.isDone)
|
||||
{
|
||||
}
|
||||
|
||||
Debug.Log("RefreshToken wwwText: " + _wwwRequest.text);
|
||||
if (!String.IsNullOrEmpty(_wwwRequest.error))
|
||||
{
|
||||
PlayerPrefs.DeleteKey("FitbitRefreshToken");
|
||||
UserAcceptOrDeny();
|
||||
UseReturnCode();
|
||||
GetAllData();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Using the Auth Token (UseRefreshToken)");
|
||||
var parsed = new JSONObject(_wwwRequest.text);
|
||||
ParseAccessToken(parsed);
|
||||
GetAllData();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetReturnCodeFromAndroid(string code)
|
||||
{
|
||||
if (string.IsNullOrEmpty(code))
|
||||
return;
|
||||
_returnCode = code.Substring(CustomAndroidScheme.Length + 6);
|
||||
Debug.Log("Return Code is: " + _returnCode);
|
||||
UseReturnCode();
|
||||
}
|
||||
|
||||
public void SetReturnCode(string code)
|
||||
{
|
||||
if (string.IsNullOrEmpty(code))
|
||||
return;
|
||||
|
||||
_returnCode = code;
|
||||
UseReturnCode();
|
||||
}
|
||||
|
||||
public void GetAllData()
|
||||
{
|
||||
GetProfileData();
|
||||
GetAllRelevantData();
|
||||
BuildProfile();
|
||||
_fitbitData.LastSyncTime = DateTime.Now.ToUniversalTime();
|
||||
Debug.Log("LastSyncTime: " + DateTime.Now.ToUniversalTime().ToString("g"));
|
||||
}
|
||||
|
||||
private void GetAllRelevantData()
|
||||
{
|
||||
GetSteps();
|
||||
GetDistance();
|
||||
GetCalories();
|
||||
GetSleep();
|
||||
}
|
||||
|
||||
#region GetData
|
||||
private void GetProfileData()
|
||||
{
|
||||
|
||||
//time for Getting Dataz
|
||||
var headers = new Dictionary<string, string>();
|
||||
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
||||
|
||||
_wwwRequest = new WWW(_profileUrl, null, headers);
|
||||
Debug.Log("Doing GET Request");
|
||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||
|
||||
while (!_wwwRequest.isDone)
|
||||
{
|
||||
}
|
||||
|
||||
ParseProfileData(_wwwRequest.text);
|
||||
|
||||
}
|
||||
|
||||
private void GetCalories()
|
||||
{
|
||||
var headers = new Dictionary<string, string>();
|
||||
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
||||
|
||||
Debug.Log("Calories URL is: " + _caloriesUrl);
|
||||
_wwwRequest = new WWW(_caloriesUrl, null, headers);
|
||||
Debug.Log("Doing Calories GET Request");
|
||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||
|
||||
while (!_wwwRequest.isDone)
|
||||
{
|
||||
}
|
||||
ParseCaloriesData(_wwwRequest.text);
|
||||
}
|
||||
|
||||
private void GetDistance()
|
||||
{
|
||||
var headers = new Dictionary<string, string>();
|
||||
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
||||
|
||||
Debug.Log("Distance URL is: " + _distanceUrl);
|
||||
_wwwRequest = new WWW(_distanceUrl, null, headers);
|
||||
Debug.Log("Doing Distance GET Request");
|
||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||
|
||||
while (!_wwwRequest.isDone)
|
||||
{
|
||||
}
|
||||
|
||||
ParseDistanceData(_wwwRequest.text);
|
||||
}
|
||||
|
||||
private void GetSteps()
|
||||
{
|
||||
var headers = new Dictionary<string, string>();
|
||||
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
||||
|
||||
Debug.Log("Steps URL is: " + _stepsUrl);
|
||||
_wwwRequest = new WWW(_stepsUrl, null, headers);
|
||||
Debug.Log("Doing Steps GET Request");
|
||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||
|
||||
while (!_wwwRequest.isDone)
|
||||
{
|
||||
}
|
||||
|
||||
ParseStepsData(_wwwRequest.text);
|
||||
}
|
||||
|
||||
private void GetSleep()
|
||||
{
|
||||
var headers = new Dictionary<string, string>();
|
||||
headers["Authorization"] = "Bearer " + _oAuth2.Token;
|
||||
|
||||
Debug.Log("Sleep URL is: " + _sleepUrl);
|
||||
_wwwRequest = new WWW(_sleepUrl, null, headers);
|
||||
Debug.Log("Doing Sleep GET Request");
|
||||
StartCoroutine(WaitForAccess(_wwwRequest));
|
||||
|
||||
//DIRTY DIRTY HACK
|
||||
while (!_wwwRequest.isDone)
|
||||
{
|
||||
}
|
||||
|
||||
ParseSleepData(_wwwRequest.text);
|
||||
}
|
||||
|
||||
private void BuildProfile()
|
||||
{
|
||||
var imageWWW = new WWW(_fitbitData.ProfileData["avatar"]);
|
||||
//DIRTY DIRTY HACK
|
||||
while (!imageWWW.isDone)
|
||||
{
|
||||
}
|
||||
|
||||
Debug.Log(_fitbitData.RawProfileData["fullName"]);
|
||||
|
||||
//we should check to see if there is "data" already
|
||||
if (_fitbitData.ProfileData.Count != 0)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> kvp in _fitbitData.ProfileData)
|
||||
{
|
||||
if (kvp.Key == "avatar")
|
||||
continue;
|
||||
|
||||
//put a space between the camelCase
|
||||
var tempKey = Regex.Replace(kvp.Key, "(\\B[A-Z])", " $1");
|
||||
//then capitalize the first letter
|
||||
UppercaseFirst(tempKey);
|
||||
}
|
||||
}
|
||||
_bGotTheData = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Parsing
|
||||
private void ParseAccessToken(JSONObject parsed)
|
||||
{
|
||||
var dict = parsed.ToDictionary();
|
||||
foreach (KeyValuePair<string, string> kvp in dict)
|
||||
{
|
||||
if (kvp.Key == "access_token")
|
||||
{
|
||||
_oAuth2.Token = kvp.Value;
|
||||
PlayerPrefs.SetString("FitbitAccessToken", kvp.Value);
|
||||
}
|
||||
else if (kvp.Key == "expires_in")
|
||||
{
|
||||
var num = 0;
|
||||
Int32.TryParse(kvp.Value, out num);
|
||||
_oAuth2.ExpiresIn = num;
|
||||
|
||||
}
|
||||
else if (kvp.Key == "refresh_token")
|
||||
{
|
||||
_oAuth2.RefreshToken = kvp.Value;
|
||||
Debug.Log("REFRESH TOKEN: " + kvp.Value);
|
||||
PlayerPrefs.SetString("FitbitRefreshToken", kvp.Value);
|
||||
Debug.Log("Token We Just Store: " + PlayerPrefs.GetString("FitbitRefreshToken"));
|
||||
}
|
||||
else if (kvp.Key == "token_type")
|
||||
{
|
||||
_oAuth2.TokenType = kvp.Value;
|
||||
PlayerPrefs.SetString("FitbitTokenType", kvp.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseProfileData(string data)
|
||||
{
|
||||
Debug.Log("inserting json data into fitbitData.RawProfileData");
|
||||
//Debug.LogWarning(data);
|
||||
XmlDocument xmldoc = JsonConvert.DeserializeXmlNode(data);
|
||||
|
||||
var doc = XDocument.Parse(xmldoc.InnerXml);
|
||||
|
||||
|
||||
doc.Descendants("topBadges").Remove();
|
||||
foreach (XElement xElement in doc.Descendants())
|
||||
{
|
||||
//Debug.Log(xElement.Name.LocalName + ": Value:" + xElement.Value);V
|
||||
if (!_fitbitData.RawProfileData.ContainsKey(xElement.Name.LocalName))
|
||||
_fitbitData.RawProfileData.Add(xElement.Name.LocalName, xElement.Value);
|
||||
else
|
||||
{
|
||||
//Debug.LogWarning("Key already found in RawProfileData: " + xElement.Name.LocalName);
|
||||
//if the key is already in the dict, we will just update the value for consistency.
|
||||
_fitbitData.RawProfileData[xElement.Name.LocalName] = xElement.Value;
|
||||
}
|
||||
|
||||
if (_fitbitData.ProfileData.ContainsKey(xElement.Name.LocalName))
|
||||
{
|
||||
_fitbitData.ProfileData[xElement.Name.LocalName] = xElement.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseStepsData(string data)
|
||||
{
|
||||
//convert the json to xml cause json blows hard.
|
||||
XmlDocument json = JsonConvert.DeserializeXmlNode(data);
|
||||
|
||||
XDocument doc = XDocument.Parse(json.InnerXml);
|
||||
var root = doc.Descendants("value").FirstOrDefault();
|
||||
_fitbitData.CurrentSteps = ToInt(root.Value);
|
||||
Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps);
|
||||
}
|
||||
|
||||
private void ParseDistanceData(string data)
|
||||
{
|
||||
XmlDocument json = JsonConvert.DeserializeXmlNode(data);
|
||||
|
||||
XDocument doc = XDocument.Parse(json.InnerXml);
|
||||
var root = doc.Descendants("value").FirstOrDefault().Value;
|
||||
//trim the value
|
||||
if (root.Length > 4)
|
||||
root = root.Substring(0, 4);
|
||||
|
||||
_fitbitData.CurrentDistance = ToDouble(root);
|
||||
|
||||
Debug.Log("Distance from Fitbit is:" + _fitbitData.CurrentDistance);
|
||||
}
|
||||
|
||||
private void ParseCaloriesData(string data)
|
||||
{
|
||||
XmlDocument json = JsonConvert.DeserializeXmlNode(data);
|
||||
|
||||
var doc = XDocument.Parse(json.InnerXml);
|
||||
var calories = doc.Descendants("value").FirstOrDefault().Value;
|
||||
|
||||
_fitbitData.CurrentCalories = ToInt(calories);
|
||||
}
|
||||
|
||||
private void ParseSleepData(string data)
|
||||
{
|
||||
Debug.Log(data);
|
||||
XmlDocument json = JsonConvert.DeserializeXmlNode(data);
|
||||
|
||||
var doc = XDocument.Parse(json.InnerXml);
|
||||
var sleepTimeTotal = doc.Descendants("value").FirstOrDefault().Value;
|
||||
Debug.Log("Minutes asleep for: " + sleepTimeTotal);
|
||||
|
||||
_fitbitData.CurrentSleep = ToInt(sleepTimeTotal);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
static string UppercaseFirst(string s)
|
||||
{
|
||||
// Check for empty string.
|
||||
if (string.IsNullOrEmpty(s))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
// Return char and concat substring.
|
||||
return char.ToUpper(s[0]) + s.Substring(1);
|
||||
}
|
||||
|
||||
IEnumerator WaitForAccess(WWW www)
|
||||
{
|
||||
Debug.Log("waiting for access\n");
|
||||
yield return www;
|
||||
Debug.Log("Past the Yield \n");
|
||||
// check for errors
|
||||
if (www.error == null)
|
||||
{
|
||||
Debug.Log("no error \n");
|
||||
Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps);
|
||||
Debug.Log(www.text);
|
||||
Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps);
|
||||
}
|
||||
if (www.error != null)
|
||||
{
|
||||
Debug.Log("\n Error" + www.error);
|
||||
Debug.Log(www.error);
|
||||
}
|
||||
Debug.Log("end of WaitForAccess \n");
|
||||
}
|
||||
|
||||
//just a utility function to get the correct date format for activity calls that require one
|
||||
public static string GetCurrentDate()
|
||||
{
|
||||
var date = "";
|
||||
date += DateTime.Now.Year;
|
||||
if (DateTime.Now.Month < 10)
|
||||
{
|
||||
date += "-" + "0" + DateTime.Now.Month;
|
||||
}
|
||||
else
|
||||
{
|
||||
date += "-" + DateTime.Now.Month;
|
||||
}
|
||||
|
||||
if (DateTime.Now.Day < 10)
|
||||
{
|
||||
date += "-" + "0" + DateTime.Now.Day;
|
||||
}
|
||||
else
|
||||
{
|
||||
date += "-" + DateTime.Now.Day;
|
||||
}
|
||||
//date += "-" + 15;
|
||||
return date;
|
||||
}
|
||||
|
||||
private int ToInt(string thing)
|
||||
{
|
||||
var temp = 0;
|
||||
Int32.TryParse(thing, out temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
private double ToDouble(string thing)
|
||||
{
|
||||
var temp = 0.0;
|
||||
Double.TryParse(thing, out temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
18
MoCha/Assets/Scripts/FitBitAPI.cs.meta
Normal file
18
MoCha/Assets/Scripts/FitBitAPI.cs.meta
Normal file
|
@ -0,0 +1,18 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< Updated upstream
|
||||
guid: aa5e856e9b878764db7c192f3aa20277
|
||||
timeCreated: 1524716713
|
||||
=======
|
||||
guid: 849590d4a954ae445aa5db73d734450c
|
||||
timeCreated: 1524756213
|
||||
>>>>>>> Stashed changes
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
15
MoCha/Assets/Scripts/FitbitCaller.cs
Normal file
15
MoCha/Assets/Scripts/FitbitCaller.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class FitbitCaller : MonoBehaviour {
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
}
|
18
MoCha/Assets/Scripts/FitbitCaller.cs.meta
Normal file
18
MoCha/Assets/Scripts/FitbitCaller.cs.meta
Normal file
|
@ -0,0 +1,18 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< Updated upstream
|
||||
guid: 36444c03eedb84147a326a329de30d0e
|
||||
timeCreated: 1524716713
|
||||
=======
|
||||
guid: 80ba6a52e9d55564fbe8130844b17f29
|
||||
timeCreated: 1524756213
|
||||
>>>>>>> Stashed changes
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
MoCha/Assets/Scripts/FitbitData.cs
Normal file
54
MoCha/Assets/Scripts/FitbitData.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Assets.Scripts.Fitbit
|
||||
{
|
||||
/// <summary>
|
||||
/// Holder class for Fitbit pulled Data.
|
||||
/// </summary>
|
||||
public class FitbitData
|
||||
{
|
||||
public string CurrentTab = "Profile";
|
||||
|
||||
public Dictionary<string, string> RawProfileData;
|
||||
public Dictionary<string, string> ProfileData;
|
||||
|
||||
public int CurrentSteps;
|
||||
public int LastSteps;
|
||||
|
||||
public double CurrentDistance;
|
||||
public double LastDistance;
|
||||
|
||||
public int CurrentCalories;
|
||||
public int LastCalories;
|
||||
|
||||
public int CurrentSleep;
|
||||
public int LastSleep;
|
||||
|
||||
public DateTime LastSyncTime;
|
||||
|
||||
public enum summary
|
||||
{
|
||||
activityCalories,caloriesBMR,caloriesOut,distances,activityDistance,distance,
|
||||
elevation,fairlyActiveMinutes,floors,lightlyActiveMinutes,marginalCalories,sedentaryMinutes,
|
||||
steps,veryActiveMinutes
|
||||
}
|
||||
|
||||
public FitbitData()
|
||||
{
|
||||
RawProfileData =new Dictionary<string, string>();
|
||||
ProfileData = new Dictionary<string, string>();
|
||||
|
||||
//we will build the Profile Data Keys that we want so we can compare them later
|
||||
//to decide what we keep and what we don't when we get the actual data
|
||||
ProfileData.Add("age","");
|
||||
ProfileData.Add("avatar","");
|
||||
ProfileData.Add("averageDailySteps","");
|
||||
ProfileData.Add("city","");
|
||||
ProfileData.Add("country","");
|
||||
ProfileData.Add("dateOfBirth","");
|
||||
ProfileData.Add("gender","");
|
||||
ProfileData.Add("memberSince","");
|
||||
}
|
||||
}
|
||||
}
|
18
MoCha/Assets/Scripts/FitbitData.cs.meta
Normal file
18
MoCha/Assets/Scripts/FitbitData.cs.meta
Normal file
|
@ -0,0 +1,18 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< Updated upstream
|
||||
guid: 7a928c029cb14204588724261a513ec1
|
||||
timeCreated: 1524716713
|
||||
=======
|
||||
guid: 1d8622418b8bead4cad17658d650c6c2
|
||||
timeCreated: 1524756213
|
||||
>>>>>>> Stashed changes
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -10,6 +10,8 @@ using System.Text;
|
|||
namespace PedometerU.Tests {
|
||||
|
||||
public class GetGoals : MonoBehaviour {
|
||||
|
||||
public Image background;
|
||||
private string[] items = { "circle_eye", "crazy_hair", "circle_head", "gap_mouth", "pig_nose", "crown" };
|
||||
|
||||
public Text goalText;
|
||||
|
@ -20,7 +22,7 @@ public class GetGoals : MonoBehaviour {
|
|||
//Progress Bar...
|
||||
public float barDisplay; //current progress
|
||||
private Vector2 barPos;
|
||||
private Vector2 barSize = new Vector2(227,20);
|
||||
private Vector2 barSize = new Vector2(725, 39);
|
||||
|
||||
//Pedometer
|
||||
private Pedometer pedometer;
|
||||
|
@ -78,8 +80,9 @@ public class GetGoals : MonoBehaviour {
|
|||
|
||||
//goalText.text = prefKey;
|
||||
goalText.color = new Color(0f, 0f, 0f);
|
||||
Debug.Log(goalText.transform.position.x.ToString() + " " + goalText.transform.position.y.ToString());
|
||||
barPos = new Vector2(goalText.transform.position.x, goalText.transform.position.y);
|
||||
Debug.Log(background.rectTransform.anchoredPosition.x.ToString() + " " + background.rectTransform.anchoredPosition.y.ToString());
|
||||
|
||||
barPos = new Vector2(background.transform.position.x, 2135 - background.transform.position.y);
|
||||
|
||||
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
||||
goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
||||
|
@ -111,7 +114,7 @@ public class GetGoals : MonoBehaviour {
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
void OnGUI() {
|
||||
//draw the background:
|
||||
GUI.BeginGroup(new Rect(barPos.x, barPos.y, barSize.x, barSize.y));
|
||||
|
@ -124,6 +127,7 @@ public class GetGoals : MonoBehaviour {
|
|||
GUI.EndGroup();
|
||||
}
|
||||
|
||||
|
||||
void Update() {
|
||||
//needs current points counting toward this goal (daily?)
|
||||
//needs the total required points for this goal
|
||||
|
|
1017
MoCha/Assets/Scripts/JSONObject.cs
Normal file
1017
MoCha/Assets/Scripts/JSONObject.cs
Normal file
File diff suppressed because it is too large
Load diff
18
MoCha/Assets/Scripts/JSONObject.cs.meta
Normal file
18
MoCha/Assets/Scripts/JSONObject.cs.meta
Normal file
|
@ -0,0 +1,18 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< Updated upstream
|
||||
guid: da64cad21a33a6444ac511376fcb771b
|
||||
timeCreated: 1524716713
|
||||
=======
|
||||
guid: 9101b04121334074fb6e70fc34eeb3f9
|
||||
timeCreated: 1524756213
|
||||
>>>>>>> Stashed changes
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
MoCha/Assets/Scripts/NavigationManager.cs
Normal file
25
MoCha/Assets/Scripts/NavigationManager.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class NavigationManager : MonoBehaviour
|
||||
{
|
||||
private GameObject navMenu;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
//navMenu = GameObject.Find("Navigation Menu");
|
||||
navMenu = gameObject.transform.Find("Navigation Menu").gameObject;
|
||||
}
|
||||
|
||||
public void OpenNavMenu()
|
||||
{
|
||||
navMenu.SetActive (true);
|
||||
}
|
||||
|
||||
public void CloseNavMenu()
|
||||
{
|
||||
navMenu.SetActive (false);
|
||||
}
|
||||
}
|
13
MoCha/Assets/Scripts/NavigationManager.cs.meta
Normal file
13
MoCha/Assets/Scripts/NavigationManager.cs.meta
Normal file
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 658e48ac784a5d543bc76161835f7156
|
||||
timeCreated: 1524750227
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
MoCha/Assets/Scripts/OAuth2AccessToken.cs
Normal file
10
MoCha/Assets/Scripts/OAuth2AccessToken.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace Assets.Scripts
|
||||
{
|
||||
public class OAuth2AccessToken
|
||||
{
|
||||
public string Token { get; set; }
|
||||
public string TokenType { get; set; } // "Bearer" is expected
|
||||
public int ExpiresIn { get; set; } //maybe convert this to a DateTime ?
|
||||
public string RefreshToken { get; set; }
|
||||
}
|
||||
}
|
18
MoCha/Assets/Scripts/OAuth2AccessToken.cs.meta
Normal file
18
MoCha/Assets/Scripts/OAuth2AccessToken.cs.meta
Normal file
|
@ -0,0 +1,18 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< Updated upstream
|
||||
guid: 2e4069fa83cbbb041aa91e83f7ece28e
|
||||
timeCreated: 1524716713
|
||||
=======
|
||||
guid: 1d4c10710438d404085599a6fe50d37b
|
||||
timeCreated: 1524756213
|
||||
>>>>>>> Stashed changes
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -10,6 +10,8 @@ public class SceneLoader : MonoBehaviour {
|
|||
public void Start()
|
||||
{
|
||||
buttontext = GetComponentInChildren<Text> ();
|
||||
// grab a UI element, set its rectTransform.anchoredPosition = to a Vector2 of the new position coordinates.
|
||||
//buttontext.rectTransform.anchoredPosition = new Vector2(buttontext.rectTransform.anchoredPosition.x, buttontext.rectTransform.anchoredPosition.y + 100);
|
||||
}
|
||||
|
||||
public void LoadScene()
|
||||
|
@ -26,6 +28,14 @@ public class SceneLoader : MonoBehaviour {
|
|||
if (!(SceneManager.GetActiveScene ().name == "StepCounter"))
|
||||
SceneManager.LoadScene ("StepCounter");
|
||||
break;
|
||||
case "Profile":
|
||||
if (!(SceneManager.GetActiveScene ().name == "Stats"))
|
||||
SceneManager.LoadScene ("Stats");
|
||||
break;
|
||||
case "Monster Creator":
|
||||
if (!(SceneManager.GetActiveScene ().name == "MonsterCreator"))
|
||||
SceneManager.LoadScene ("MonsterCreator");
|
||||
break;
|
||||
default:
|
||||
if (!(SceneManager.GetActiveScene ().name == scenetext))
|
||||
SceneManager.LoadScene (scenetext);
|
||||
|
|
BIN
MoCha/UpgradeLog.htm
Normal file
BIN
MoCha/UpgradeLog.htm
Normal file
Binary file not shown.
Reference in a new issue