public void RestoreTrainingData() { TrainingDataInit TrainingDataString = new TrainingDataInit(); SaveTrainingData tempTraining = (SaveTrainingData)DeserializeObject(TrainingDataString.InitData, "SaveTrainingData"); for (var k = 0; k < tempTraining.Training.Length; k++) { int foundIndex = -1; for (var i = 0; i < UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData.Training.Length; i++) { if (UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData.Training[i].Name == tempTraining.Training[k].Name) { foundIndex = i; } } if (foundIndex < 0) { //add the Training UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData.Add(tempTraining.Training[k]); UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData.Training = UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData.Training.OrderBy(x => x.Name).ToArray(); UserBlobManager.GetComponent <UserBlobManager>().SaveTraining(); } else { // found duplicate dont add the Training } } if (PopUpActive == false) { PopUpOkDialog("Training Data Restored", this.gameObject.GetComponent <UI_Settings>(), "RestoredData"); } }
public void LoadTrainingData() { _data = LoadXML(_FileLocation + "/" + _TrainingDataFileName); if (_data.ToString() != "") { UserTrainingData = (SaveTrainingData)DeserializeObject(_data, "SaveTrainingData"); } }
public bool FindDuplicateTrainingName(string myName) { // List<TrainingData> tempTrainingData = new List<TrainingData> (); SaveTrainingData tempTrainingData = new SaveTrainingData(); tempTrainingData = UserBlobManager.GetComponent <UserBlobManager> ().UserTrainingData; for (int i = 0; i < tempTrainingData.Training.Length; i++) { if (myName.ToLower() == tempTrainingData.Training[i].Name.ToLower()) { return(true); } } return(false); }
public void Init() { Initialize = false; ShareTrainingList = new List<string> (); UserTrainingData = UserBlobManager.GetComponent<UserBlobManager>().UserTrainingData; SelectedTraining = -1; // UserBlobManager.GetComponent<UserBlobManager> ().CurrentTrainingIndex = SelectedTraining; ClearScrollList (); PopulateScrollList (); if(UserBlobManager.GetComponent<UserBlobManager> ().UserTrainingData.Training.Length > 6) { SetScrollRectPositionFromIntWithOffset (0, 2.5, 200, UserBlobManager.GetComponent<UserBlobManager> ().UserTrainingData.Training.Length, TrainingContentPanel); } else { TrainingContentPanel.localPosition = new Vector3 (0, 0, 0); } }
public void DeleteTraining() { int myIndex = UserBlobManager.GetComponent <UserBlobManager> ().CurrentTrainingIndex; if (myIndex < UserBlobManager.GetComponent <UserBlobManager> ().UserTrainingData.Training.Length) { UserBlobManager.GetComponent <UserBlobManager> ().UserTrainingData.RemoveAt(myIndex); // UserBlobManager.GetComponent<UserBlobManager> ().UserTrainingData.TrimExcess(); UserTrainingData = UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData; UserBlobManager.GetComponent <UserBlobManager> ().SaveTraining(); if (myIndex >= UserTrainingData.Training.Length) { myIndex = UserTrainingData.Training.Length - 1; UserBlobManager.GetComponent <UserBlobManager> ().CurrentTrainingIndex = myIndex; } SelectedTraining = myIndex; ClearScrollList(); PopulateScrollList(); } }
public void Init() { Initialize = false; UserTrainingData = UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData; if (UserBlobManager.GetComponent <UserBlobManager>().CurrentTrainingIndex > UserTrainingData.Training.Length) { UserBlobManager.GetComponent <UserBlobManager>().CurrentTrainingIndex = 0; } if (UserTrainingData.Training.Length == 0) { UserBlobManager.GetComponent <UserBlobManager>().CurrentTrainingIndex = -1; } if (UserBlobManager.GetComponent <UserBlobManager>().CurrentTrainingIndex < 0 && UserTrainingData.Training.Length > 0) { UserBlobManager.GetComponent <UserBlobManager>().CurrentTrainingIndex = 0; } SelectedTraining = UserBlobManager.GetComponent <UserBlobManager>().CurrentTrainingIndex; int scrollIndex = SelectedTraining; if (scrollIndex > UserTrainingData.Training.Length - 6) { scrollIndex = UserTrainingData.Training.Length - 6; } ClearScrollList(); PopulateScrollList(); if (UserBlobManager.GetComponent <UserBlobManager> ().UserTrainingData.Training.Length > 6) { SetScrollRectPositionFromIntWithOffset(0, 2.5, 200, UserBlobManager.GetComponent <UserBlobManager> ().UserTrainingData.Training.Length, TrainingContentPanel); } else { TrainingContentPanel.localPosition = new Vector3(0, 0, 0); } }
// Use this for initialization void Start() { UserTrainingData = UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData; }
IEnumerator MergeTrainingFile(string ScreenNameType, string Type, string DownloadString, string ActionType) { // remove old data string URL = UserBlobManager.GetComponent <UserBlobManager>().ServerURL + "uw.php"; string hash = UserBlobManager.GetComponent <UserBlobManager>().ServerHash; string Action = "remove_upload_data"; if (ActionType == "Everyone") { Action = "remove_share_data"; } WWWForm form = new WWWForm(); form.AddField("myform_hash", hash); form.AddField("action", Action); form.AddField("myform_screennametype", ScreenNameType); WWW w = new WWW(URL, form); yield return(w); if (w.error != null) { print(w.error); } else { SaveTrainingData tempTraining = new SaveTrainingData(); tempTraining = (SaveTrainingData)DeserializeObject(DownloadString, "SaveTrainingData"); // get data to add SaveTrainingData UserTrainingData = new SaveTrainingData(); for (int i = 0; i < UserBlobManager.GetComponent <UserBlobManager>().ShareTrainingData.Count; i++) { UserTrainingData.Add(UserBlobManager.GetComponent <UserBlobManager>().ShareTrainingData[i]); } // merge data for (int i = 0; i < tempTraining.Training.Length; i++) { // check for duplicates bool duplicateFound = false; for (int j = 0; j < UserTrainingData.Training.Length; j++) { if (tempTraining.Training[i].Name == UserTrainingData.Training[j].Name) { duplicateFound = true; } } if (!duplicateFound) { UserTrainingData.Add(tempTraining.Training[i]); } } // upload file string Data = SerializeObject(UserTrainingData, "SaveTrainingData"); int index = Data.IndexOf(System.Environment.NewLine); Data = Data.Substring(index + System.Environment.NewLine.Length); StartCoroutine(UploadFile(ScreenNameType, "Training", Data, ActionType)); } w.Dispose(); }
IEnumerator UploadTrainingFile(string FriendName, string ActionType) { string formText = ""; string URL = UserBlobManager.GetComponent <UserBlobManager>().ServerURL + "uw.php"; string hash = UserBlobManager.GetComponent <UserBlobManager>().ServerHash; string ScreenNameType = FriendName + "_Training"; string Action = "get_upload_data"; if (ActionType == "Everyone") { Action = "get_share_data"; } WWWForm form = new WWWForm(); form.AddField("action", Action); form.AddField("myform_screennametype", ScreenNameType); form.AddField("myform_type", "Training"); form.AddField("myform_hash", hash); WWW w = new WWW(URL, form); yield return(w); formText = w.text.ToString(); print(formText); if (w.error != null) { print(w.error); } else { if (formText.Contains("HASH code is different from your app")) { print("Can't connect"); } else { if (!formText.Contains("Cant Find Upload Data") && formText != "\r\n") { // merge file print("Merge Upload File"); StartCoroutine(MergeTrainingFile(ScreenNameType, "Training", formText, ActionType)); } else { // serialize SaveTrainingData UserTrainingData = new SaveTrainingData(); for (int i = 0; i < UserBlobManager.GetComponent <UserBlobManager>().ShareTrainingData.Count; i++) { UserTrainingData.Add(UserBlobManager.GetComponent <UserBlobManager>().ShareTrainingData[i]); } string Data = SerializeObject(UserTrainingData, "SaveTrainingData"); int index = Data.IndexOf(System.Environment.NewLine); Data = Data.Substring(index + System.Environment.NewLine.Length); // upload file print("Upload File"); StartCoroutine(UploadFile(ScreenNameType, "Training", Data, ActionType)); } } } w.Dispose(); }
// Use this for initialization void Awake() { VersionNumber = "1.0"; ExerciseTypeList.Clear(); ExerciseTypeList.Add("General"); ExerciseTypeList.Add("Warm-Up"); ExerciseTypeList.Add("Stretch"); ExerciseTypeList.Add("Weights"); ExerciseTypeList.Add("Cardio-Light"); ExerciseTypeList.Add("Cardio-Moderate"); ExerciseTypeList.Add("Cardio-Intense"); ExerciseTypeList.Add("Yoga"); ExerciseTypeList.Add("Body Weight"); ExerciseTypeList.Add("Cross-Fit"); ExerciseTypeList.Add("Fighting"); WorkoutTypeList.Clear(); WorkoutTypeList.Add("General"); WorkoutTypeList.Add("Warm-Up"); WorkoutTypeList.Add("Stretch"); WorkoutTypeList.Add("Weights"); WorkoutTypeList.Add("Cardio"); WorkoutTypeList.Add("Yoga"); WorkoutTypeList.Add("Fighting"); WorkoutTypeList.Add("Cross-Fit"); TrainingTypeList.Clear(); TrainingTypeList.Add("General"); TrainingTypeList.Add("Warm-Up"); TrainingTypeList.Add("Stretch"); TrainingTypeList.Add("Weights"); TrainingTypeList.Add("Cardio"); TrainingTypeList.Add("Yoga"); TrainingTypeList.Add("Fighting"); TrainingTypeList.Add("Cross-Fit"); BodyPartList.Clear(); BodyPartList.Add("Body"); BodyPartList.Add("Arms"); BodyPartList.Add("Abs"); BodyPartList.Add("Back"); BodyPartList.Add("Chest"); BodyPartList.Add("Core"); BodyPartList.Add("Legs"); BodySide.Clear(); BodySide.Add("None"); BodySide.Add("Left"); BodySide.Add("Right"); NumberList.Clear(); NumberList.Add(0); NumberList.Add(1); NumberList.Add(2); NumberList.Add(3); NumberList.Add(4); NumberList.Add(5); NumberList.Add(6); NumberList.Add(7); NumberList.Add(8); NumberList.Add(9); NumberListToFive.Clear(); NumberListToFive.Add(0); NumberListToFive.Add(1); NumberListToFive.Add(2); NumberListToFive.Add(3); NumberListToFive.Add(4); NumberListToFive.Add(5); YesNoList.Clear(); YesNoList.Add("Yes"); YesNoList.Add("No"); MonthList.Clear(); MonthList.Add("January"); MonthList.Add("February"); MonthList.Add("March"); MonthList.Add("April"); MonthList.Add("May"); MonthList.Add("June"); MonthList.Add("July"); MonthList.Add("August"); MonthList.Add("September"); MonthList.Add("October"); MonthList.Add("November"); MonthList.Add("December"); FilterExerciseTypeList.Clear(); FilterExerciseTypeList.Add("None"); foreach (string item in ExerciseTypeList) { FilterExerciseTypeList.Add(item); } FilterBodyPartList.Clear(); FilterBodyPartList.Add("None"); foreach (string item in BodyPartList) { FilterBodyPartList.Add(item); } UIManager = GameObject.Find("UI_Manager_Prefab"); UserDownloadTrainingData = new SaveDownloadTrainingData(); UserDownloadWorkoutData = new SaveDownloadWorkoutData(); UserDownloadExerciseData = new SaveDownloadExerciseData(); UserDownloadTrainingDataString = ""; UserDownloadWorkoutDataString = ""; UserDownloadExerciseDataString = ""; UserWorkoutData = new SaveWorkoutData(); UserExerciseData = new SaveExerciseData(); UserFriendData = new SaveFriendData(); UserTrainingData = new SaveTrainingData(); UserDayData = new SaveDayData(); _FileLocation = Application.persistentDataPath; _DownloadTrainingDataFileName = "DownloadTrainingData.xml"; // temporarily get these locally. change this to be downloaded from the server _DownloadWorkoutDataFileName = "DownloadWorkoutData.xml"; // temporarily get these locally. change this to be downloaded from the server _DownloadExerciseDataFileName = "DownloadExerciseData.xml"; // temporarily get these locally. change this to be downloaded from the server _FileName = "SaveData.xml"; _TrainingDataFileName = "TrainingData.xml"; _WorkoutDataFileName = "WorkoutData.xml"; _ExerciseDataFileName = "ExerciseData.xml"; _DayDataFileName = "DayData.xml"; _SettingsDataFileName = "SettingsData.xml"; _FriendDataFileName = "FriendData.xml"; myData = new SaveData(); mySettingsData = new SaveSettingsData(); }
IEnumerator DownloadTrainingFile(string FilePath, string FileString, string ActionType) { string formText = ""; string URL = UserBlobManager.GetComponent <UserBlobManager>().ServerURL + "uw.php"; string hash = UserBlobManager.GetComponent <UserBlobManager>().ServerHash; string Action = "get_download_data"; if (ActionType == "Friends") { Action = "get_upload_data"; } WWWForm form = new WWWForm(); form.AddField("action", Action); form.AddField("myform_screennametype", FileString); form.AddField("myform_name", FileString); form.AddField("myform_type", "Training"); form.AddField("myform_hash", hash); WWW w = new WWW(URL, form); yield return(w); formText = w.text.ToString(); if (w.error != null || formText.Contains("Cant Find Download Data") || formText.Contains("Cant Find Upload Data")) { if (formText.Contains("Cant Find Download Data")) { MessageText.GetComponent <Text>().text += "Failed to Download " + FileString + "\n"; print(w.error); } } else { string DownloadString = formText; SaveTrainingData tempTraining = new SaveTrainingData(); tempTraining = (SaveTrainingData)DeserializeObject(DownloadString, "SaveTrainingData"); // need to check for duplicate Trainings for (var k = 0; k < tempTraining.Training.Length; k++) { int foundIndex = -1; for (var i = 0; i < UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData.Training.Length; i++) { if (UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData.Training[i].Name == tempTraining.Training[k].Name) { foundIndex = i; } } if (foundIndex < 0) { //add the Training UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData.Add(tempTraining.Training[k]); UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData.Training = UserBlobManager.GetComponent <UserBlobManager>().UserTrainingData.Training.OrderBy(x => x.Name).ToArray(); UserBlobManager.GetComponent <UserBlobManager>().SaveTraining(); print(" downloaded " + tempTraining.Training[k].Name); } else { // found duplicate dont add the Training } } if (DownloadFromFriends == true) { StartCoroutine(DeleteFile(FileString, "remove_upload_data")); } } DownloadCount++; if (DownloadFromFriends == true) { FriendTrainingFileDownloaded = true; } }