diff --git a/MoCha/Assets/Scenes/Stats.unity b/MoCha/Assets/Scenes/Stats.unity index 9f5418d..8180af6 100644 Binary files a/MoCha/Assets/Scenes/Stats.unity and b/MoCha/Assets/Scenes/Stats.unity differ diff --git a/MoCha/Assets/Scripts/FitBitAPI.cs b/MoCha/Assets/Scripts/FitBitAPI.cs index 0877b91..0770a24 100644 --- a/MoCha/Assets/Scripts/FitBitAPI.cs +++ b/MoCha/Assets/Scripts/FitBitAPI.cs @@ -11,10 +11,10 @@ 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"; @@ -42,7 +42,7 @@ namespace Assets.Scripts.Fitbit private OAuth2AccessToken _oAuth2 = new OAuth2AccessToken(); public FitbitData _fitbitData = new FitbitData(); - + private string _statusMessage; private string CallBackUrl @@ -124,7 +124,7 @@ namespace Assets.Scripts.Fitbit _wwwRequest = new WWW(_tokenUrl, form.data, headers); StartCoroutine(WaitForAccess(_wwwRequest)); - + while (!_wwwRequest.isDone) { } @@ -193,7 +193,7 @@ namespace Assets.Scripts.Fitbit _returnCode = code; UseReturnCode(); } - + public void GetAllData() { GetProfileData(); @@ -222,7 +222,7 @@ namespace Assets.Scripts.Fitbit _wwwRequest = new WWW(_profileUrl, null, headers); Debug.Log("Doing GET Request"); StartCoroutine(WaitForAccess(_wwwRequest)); - + while (!_wwwRequest.isDone) { } @@ -240,7 +240,7 @@ namespace Assets.Scripts.Fitbit _wwwRequest = new WWW(_caloriesUrl, null, headers); Debug.Log("Doing Calories GET Request"); StartCoroutine(WaitForAccess(_wwwRequest)); - + while (!_wwwRequest.isDone) { } @@ -256,7 +256,7 @@ namespace Assets.Scripts.Fitbit _wwwRequest = new WWW(_distanceUrl, null, headers); Debug.Log("Doing Distance GET Request"); StartCoroutine(WaitForAccess(_wwwRequest)); - + while (!_wwwRequest.isDone) { } @@ -273,7 +273,7 @@ namespace Assets.Scripts.Fitbit _wwwRequest = new WWW(_stepsUrl, null, headers); Debug.Log("Doing Steps GET Request"); StartCoroutine(WaitForAccess(_wwwRequest)); - + while (!_wwwRequest.isDone) { } @@ -316,7 +316,7 @@ namespace Assets.Scripts.Fitbit { 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 @@ -398,6 +398,7 @@ namespace Assets.Scripts.Fitbit var root = doc.Descendants("value").FirstOrDefault(); _fitbitData.CurrentSteps = ToInt(root.Value); Debug.Log("Steps from Fitbit: " + _fitbitData.CurrentSteps); + PlayerPrefs.SetInt("fitbitSteps", _fitbitData.CurrentSteps); } private void ParseDistanceData(string data) @@ -413,6 +414,7 @@ namespace Assets.Scripts.Fitbit _fitbitData.CurrentDistance = ToDouble(root); Debug.Log("Distance from Fitbit is:" + _fitbitData.CurrentDistance); + PlayerPrefs.SetFloat("fitbitDistance", (float)_fitbitData.CurrentDistance); } private void ParseCaloriesData(string data) @@ -423,6 +425,7 @@ namespace Assets.Scripts.Fitbit var calories = doc.Descendants("value").FirstOrDefault().Value; _fitbitData.CurrentCalories = ToInt(calories); + PlayerPrefs.SetInt("fitbitCalories", ToInt(calories)); } private void ParseSleepData(string data) diff --git a/MoCha/Assets/Scripts/StatsUpdate.cs b/MoCha/Assets/Scripts/StatsUpdate.cs index f05c58f..23e511d 100644 --- a/MoCha/Assets/Scripts/StatsUpdate.cs +++ b/MoCha/Assets/Scripts/StatsUpdate.cs @@ -9,12 +9,25 @@ public class StatsUpdate : MonoBehaviour { public Text score; public Text steps; public Text distance; + public Text calories; // Use this for initialization void Start () { - steps.text = PlayerPrefs.GetInt("currentSteps").ToString(); + //steps.text = PlayerPrefs.GetInt("currentSteps").ToString(); + steps.text = PlayerPrefs.GetInt("fitbitSteps").ToString(); score.text = PlayerPrefs.GetInt("totalPoints").ToString(); - distance.text = ((float)PlayerPrefs.GetInt("currentSteps")/2000.0f).ToString() + " mi."; + //distance.text = ((float)PlayerPrefs.GetInt("currentSteps")/2000.0f).ToString() + " mi."; + distance.text = PlayerPrefs.GetFloat("fitbitDistance").ToString() + " mi."; + calories.text = PlayerPrefs.GetInt("fitbitCalories").ToString(); + } + + public void refreshPrefs() { + //steps.text = PlayerPrefs.GetInt("currentSteps").ToString(); + steps.text = PlayerPrefs.GetInt("fitbitSteps").ToString(); + score.text = PlayerPrefs.GetInt("totalPoints").ToString(); + //distance.text = ((float)PlayerPrefs.GetInt("currentSteps")/2000.0f).ToString() + " mi."; + distance.text = PlayerPrefs.GetFloat("fitbitDistance").ToString() + " mi."; + calories.text = PlayerPrefs.GetInt("fitbitCalories").ToString(); } // Update is called once per frame