private void fetchWordUserLearningInfo() { Debug.Log("fetchWordUserLearningInfo :: " + currentWord); showHideLoadingIndicator(true); if (currentWord.Length > 0) { FirebaseHelper.getInstance().fetchWordUserLearningInfo(currentWord, userLearning => { if (userLearning.wordInfo != null) { Debug.Log("fetchWordUserLearningInfo :: display HTML"); wordUserLearning = userLearning; Debug.Log("wordUserLearning :: wordInfo.word :: " + wordUserLearning.wordInfo.word); showHideLoadingIndicator(false); loadQuestion(); } else { wordUserLearning = null; endSessionStudy(); } }); } else { endSessionStudy(); } }
private void getUserData() { //review list, again list, new word list had been prepared in home screen, //so do not need to count number of each list //just load them currentWordInd = 0; currentWord = ""; wordUserLearning = null; reviewWords.Clear(); againWords.Clear(); newWords.Clear(); subAgainWords.Clear(); curListName = CURRENT_LIST_NAME.LIST_REVIEW; //reset, review is default bool found = false; showHideLoadingIndicator(true); try { FirebaseHelper.getInstance().getCurrentReviewList(rwords => { reviewWords.AddRange(rwords); FirebaseHelper.getInstance().getAgainList(agwords => { againWords.AddRange(agwords); FirebaseHelper.getInstance().getCurrentNewWordsList(nwords => { newWords.AddRange(nwords); Debug.Log("reviewWords :: count :: " + reviewWords.Count); Debug.Log("againWords :: count :: " + againWords.Count); Debug.Log("newWords :: count :: " + newWords.Count); if (reviewWords.Count > 0) { Debug.Log("reviewWords :: " + reviewWords); curListName = CURRENT_LIST_NAME.LIST_REVIEW; currentWord = reviewWords.ElementAt(currentWordInd); found = true; } else if (againWords.Count > 0) { Debug.Log("againWords :: " + againWords); curListName = CURRENT_LIST_NAME.LIST_AGAIN; currentWord = againWords.ElementAt(currentWordInd); found = true; } else if (newWords.Count > 0) { Debug.Log("newWords :: " + newWords); curListName = CURRENT_LIST_NAME.LIST_NEW; currentWord = newWords.ElementAt(currentWordInd); found = true; } if (found == false) { showHideLoadingIndicator(false); //show alert: no word to learn Scene home = SceneManager.GetSceneByName("Home"); GameObject[] gameObjs = home.GetRootGameObjects(); foreach (GameObject gObj in gameObjs) { if (gObj.name.Equals("ScriptHolder") == true) { Debug.Log("Study Controller :: ScriptHolder found"); HomeController homeController = gObj.GetComponent <HomeController>(); homeController.showDialogNowordToLearnFromStudyScene(); } } //close screen Debug.Log("UnloadSceneAsync(\"Study\")"); unloadSceneAsync(); } else { //fetch word info and learning progress fetchWordUserLearningInfo(); } }); }); }); } catch (Exception e) { Debug.Log("StudyController :: getUserData :: exception :: " + e.ToString()); showHideLoadingIndicator(false); } }
void endSessionStudy() { Debug.Log("endSessionStudy"); btnShowAnswer.gameObject.SetActive(true); ButtonAnswer.SetActive(false); bool needRemoveWord = true; currentWordInd = 0; currentWord = ""; wordUserLearning = null; showHideLoadingIndicator(true); if (curListName == CURRENT_LIST_NAME.LIST_REVIEW) { if (needRemoveWord == true) { reviewWords.RemoveAt(currentWordInd); needRemoveWord = false; FirebaseHelper.getInstance().updateInreviewFieldInLearningProgressToday(reviewWords.ToArray()); } if (reviewWords.Count == 0) { curListName = CURRENT_LIST_NAME.LIST_AGAIN; currentWordInd = 0; } else { //currentWordInd++; //always get item at 0 because we remove words after learn them currentWord = reviewWords.ElementAt(currentWordInd); } } if (curListName == CURRENT_LIST_NAME.LIST_AGAIN) { if (needRemoveWord == true) { againWords.RemoveAt(currentWordInd); needRemoveWord = false; updateAgainFieldInLearningProgressToday(); } if (againWords.Count == 0) { curListName = CURRENT_LIST_NAME.LIST_NEW; currentWordInd = 0; } else { currentWord = againWords.ElementAt(currentWordInd); } } if (curListName == CURRENT_LIST_NAME.LIST_NEW) { if (needRemoveWord == true) { newWords.RemoveAt(currentWordInd); needRemoveWord = false; FirebaseHelper.getInstance().updateNewWordsFieldInLearningProgressToday(newWords.ToArray()); } if (newWords.Count == 0) { currentWordInd = 0; //check subAgainlist for current session if (subAgainWords.Count > 0) { curListName = CURRENT_LIST_NAME.LIST_AGAIN; againWords.AddRange(subAgainWords.ToArray()); currentWord = againWords.ElementAt(currentWordInd); subAgainWords.Clear(); } else { //finish daily target, record daily target here. //check streak FirebaseHelper.getInstance().checkStreakAfterLearningFinished(isStreak => { Debug.Log("Is Count streak :: " + isStreak.ToString()); //close study screen showHideLoadingIndicator(false); Scene home = SceneManager.GetSceneByName("Home"); GameObject[] gameObjs = home.GetRootGameObjects(); foreach (GameObject gObj in gameObjs) { if (gObj.name.Equals("ScriptHolder") == true) { Debug.Log("Study Controller :: ScriptHolder found"); HomeController homeController = gObj.GetComponent <HomeController>(); homeController.completedDailyTargetHandle(isStreak); } } unloadSceneAsync(); }); } } else { currentWord = newWords.ElementAt(currentWordInd); } } if (currentWord.Length > 0) { fetchWordUserLearningInfo(); } else { showHideLoadingIndicator(false); } }