//slide handler void slideValueChangedHandler(SLIDE_NAME slideName) { Debug.Log("slideValueChangedHandler :: " + slideName.ToString()); if (slideName == SLIDE_NAME.SLIDE_NAME_SPEAKING_SPEED) { TemporarilyStatus.getInstance().speaking_speed = slideSpeakingSpeed.value; FirebaseHelper.getInstance().updateSettingSpeakingSpeed(TemporarilyStatus.getInstance().speaking_speed); } else if (slideName == SLIDE_NAME.SLIDE_NAME_TOTAL_PER_DAY) { TemporarilyStatus.getInstance().total_card_a_day = Mathf.RoundToInt(slideTotalPerDay.value); totalPerDayValue.text = TemporarilyStatus.getInstance().total_card_a_day.ToString(); FirebaseHelper.getInstance().updateSettingTotalPerDay(TemporarilyStatus.getInstance().total_card_a_day); } else if (slideName == SLIDE_NAME.SLIDE_NAME_WAITING_TIME) { TemporarilyStatus.getInstance().time_to_show_answer = Mathf.RoundToInt(slideWaitingTime.value); waitingTimevalue.text = TemporarilyStatus.getInstance().time_to_show_answer.ToString(); FirebaseHelper.getInstance().updateSettingTimeShowAnswer(TemporarilyStatus.getInstance().time_to_show_answer); } else if (slideName == SLIDE_NAME.SLIDE_NAME_WORD_PER_DAY) { TemporarilyStatus.getInstance().new_card_a_day = Mathf.RoundToInt(slideWordPerDay.value); wordPerDayValue.text = TemporarilyStatus.getInstance().new_card_a_day.ToString(); FirebaseHelper.getInstance().updateSettingWordPerDay(TemporarilyStatus.getInstance().new_card_a_day); } }
//add more word to learn private void _loadMoreData() { //do not need to update the loaded data date showHideLoadingIndicator(true); FirebaseHelper.getInstance().checkStreakToday(isCompletedTarget => { if (isCompletedTarget == true) { FirebaseHelper.getInstance().prepareListNewWordsToLearn(TemporarilyStatus.getInstance().new_card_a_day, newRes => { showHideLoadingIndicator(false); Debug.Log("New count :: " + newRes); if (newRes > 0) { OnBtnStartClickHandle(); } else { //show alert: no words to learn showDialogNoWordToLearn(); } }); } else { showHideLoadingIndicator(false); //show alert: you have to comleted daily target... showDialogNotCompleteDailyTarget(); } }); }
private void _timerElapsed(object sender, ElapsedEventArgs e) { int curDate = DateTimeHelper.getCurrentDateTimeInSeconds(); if (curDate >= TemporarilyStatus.getInstance().timeLoadedData + CommonDefine.SECONDS_PERDAY) { needToReloadData = true; //reload data if study scene is not on top //else if study scene is on top, reload data from study scene when user finish their target //if user come back home scene when they do not finish target, _timerElapsed is still called and reload data. if (isShowingStudyScene == false) { _loadNewData(); } } //check internet connection if (Application.internetReachability == NetworkReachability.NotReachable) { showHideNoConnectionPanel(true); } else { showHideNoConnectionPanel(false); } }
public static TemporarilyStatus getInstance() { if (_instance == null) { _instance = new TemporarilyStatus(); } return(_instance); }
public bool isShowingStudyScene = false; //must be public to access it from study scene //load when a new day was come private void _loadNewData() { needToReloadData = false; int beginOfDay = DateTimeHelper.getBeginOfDayInSec(); TemporarilyStatus.getInstance().timeLoadedData = beginOfDay; showHideLoadingIndicator(true); _loadTodayData(); }
private void _loadTodayData() { Debug.Log("loadTodayData"); int reviewCount = 0; int newCount = 0; int againCount = 0; try { FirebaseHelper.getInstance().resetCompletedTodayFlag(); FirebaseHelper.getInstance().prepareInreviewList(TemporarilyStatus.getInstance().total_card_a_day, reviewRes => { reviewCount = reviewRes; Debug.Log("Review count :: " + reviewRes); againCount = TemporarilyStatus.getInstance().total_card_a_day - reviewCount; FirebaseHelper.getInstance().prepareAgainList(againCount, againRes => { againCount = againRes; Debug.Log("Again count :: " + againRes); newCount = TemporarilyStatus.getInstance().total_card_a_day - againCount - reviewCount; if (newCount > TemporarilyStatus.getInstance().new_card_a_day) { newCount = TemporarilyStatus.getInstance().new_card_a_day; } FirebaseHelper.getInstance().prepareListNewWordsToLearn(newCount, newRes => { showHideLoadingIndicator(false); Debug.Log("New count :: " + newRes); }); }); }); } catch (Exception e) { showHideLoadingIndicator(false); Debug.Log("HomeController :: _loadTodayData :: " + e.ToString()); } }
// Use this for initialization void Start() { Debug.Log("Logged in already"); //load today learning data //get datetime in /newwords field, check if it is obsolete, prepare new list //date in /newwords is always equal to /inreview showHideLoadingIndicator(true); FirebaseHelper.getInstance().getCurrentDatetimeInNewWordsField(date => { Debug.Log("HomeController :: date :: " + date.ToString()); int curDate = DateTimeHelper.getBeginOfDayInSec(); Debug.Log("HomeController :: curDate :: " + curDate.ToString()); if (date != curDate) { Debug.Log("HomeController :: load new data"); TemporarilyStatus.getInstance().timeLoadedData = curDate; //in timer handler function, if current time is greater than this time 86400, reload data. _loadTodayData(); } else { showHideLoadingIndicator(false); TemporarilyStatus.getInstance().timeLoadedData = date; Debug.Log("HomeController :: do not load new data"); } }); //can load/set streak here, because it is used right now //when use streak info, should check days != null FirebaseHelper.getInstance().getUserStreaks(isSuccessful => { if (isSuccessful == false) { FirebaseHelper.getInstance().updateUserStreaks(); } }); //set timer to check date time, if it is changed to new day, reload data timer.Interval = 5000; //millisecond timer.Enabled = true; timer.Elapsed += new ElapsedEventHandler(_timerElapsed); timer.Start(); }
void Start() { UserInfo currenUser = TemporarilyStatus.getInstance().userInfo; if (TemporarilyStatus.getInstance().userInfo.isAnonymous == true) { btnLinkFB.gameObject.SetActive(true); btnUnlinkFB.gameObject.SetActive(false); UserName.text = currenUser.userID; } else { btnLinkFB.gameObject.SetActive(false); btnUnlinkFB.gameObject.SetActive(true); UserName.text = currenUser.username; } //display user info: name, avatar... }
//toggle handler void toggleValueChangedHandler(TOGGLE_NAME toggleName) { Debug.Log("toggleValueChangedHandler :: " + toggleName.ToString()); if (toggleName == TOGGLE_NAME.TOGGLE_NAME_AUTOPLAY_SOUND) { TemporarilyStatus.getInstance().auto_play_sound = toggleAutoPlay.isOn == true? 1 : 0; FirebaseHelper.getInstance().updateSettingAutoplaySound(TemporarilyStatus.getInstance().auto_play_sound); } else if (toggleName == TOGGLE_NAME.TOGGLE_NAME_DISPLAY_MEANING) { TemporarilyStatus.getInstance().display_meaning = toggleDisplayMeaing.isOn == true? 1 : 0; FirebaseHelper.getInstance().updateSettingDisplayMeaning(TemporarilyStatus.getInstance().display_meaning); } else if (toggleName == TOGGLE_NAME.TOGGLE_NAME_NOTIFICATION) { TemporarilyStatus.getInstance().notification = toggleNotification.isOn == true? 1 : 0; FirebaseHelper.getInstance().updateSettingOnOffNotification(TemporarilyStatus.getInstance().notification); } }
// Use this for initialization void Start() { int my_level = TemporarilyStatus.getInstance().my_level; int new_card_a_day = TemporarilyStatus.getInstance().new_card_a_day; int total_card_a_day = TemporarilyStatus.getInstance().total_card_a_day; int time_to_show_answer = TemporarilyStatus.getInstance().time_to_show_answer; int auto_play_sound = TemporarilyStatus.getInstance().auto_play_sound; int display_meaning = TemporarilyStatus.getInstance().display_meaning; int notification = TemporarilyStatus.getInstance().notification; float speaking_speed = TemporarilyStatus.getInstance().speaking_speed; Debug.Log("new cards a day :: " + new_card_a_day.ToString()); /* DROPDOWN CONTROLLER */ //level optionsLevels.value = my_level - 1; //optionsLevels.value is counted from 0 optionsLevels.onValueChanged.AddListener(delegate { levelDropdownValueChangedHandler(); }); /* SLIDE CONTROLLER */ //word per day slideWordPerDay.value = new_card_a_day; slideWordPerDay.onValueChanged.AddListener(delegate { slideValueChangedHandler(SLIDE_NAME.SLIDE_NAME_WORD_PER_DAY); }); wordPerDayValue.text = new_card_a_day.ToString(); //total per day slideTotalPerDay.value = total_card_a_day; slideTotalPerDay.onValueChanged.AddListener(delegate { slideValueChangedHandler(SLIDE_NAME.SLIDE_NAME_TOTAL_PER_DAY); }); totalPerDayValue.text = total_card_a_day.ToString(); //waiting time slideWaitingTime.value = time_to_show_answer; slideWaitingTime.onValueChanged.AddListener(delegate { slideValueChangedHandler(SLIDE_NAME.SLIDE_NAME_WAITING_TIME); }); waitingTimevalue.text = time_to_show_answer.ToString(); //speaking speed slideSpeakingSpeed.value = speaking_speed; slideSpeakingSpeed.onValueChanged.AddListener(delegate { slideValueChangedHandler(SLIDE_NAME.SLIDE_NAME_SPEAKING_SPEED); }); /* TOGGLE CONTROLLER */ //autoplay sound toggleAutoPlay.isOn = (auto_play_sound == 0) ? false : true; toggleAutoPlay.onValueChanged.AddListener(delegate { toggleValueChangedHandler(TOGGLE_NAME.TOGGLE_NAME_AUTOPLAY_SOUND); }); //display meaning toggleDisplayMeaing.isOn = (display_meaning == 0) ? false : true; toggleDisplayMeaing.onValueChanged.AddListener(delegate { toggleValueChangedHandler(TOGGLE_NAME.TOGGLE_NAME_DISPLAY_MEANING); }); //on off notification toggleNotification.isOn = (notification == 0) ? false : true; toggleNotification.onValueChanged.AddListener(delegate { toggleValueChangedHandler(TOGGLE_NAME.TOGGLE_NAME_NOTIFICATION); }); //get user setting // FirebaseHelper.getInstance().getUserSettings(handlerGetUserSetting); //do not need to load User settings here, User settings were loaded right away after login successfully }
//drop down handler void levelDropdownValueChangedHandler() { TemporarilyStatus.getInstance().my_level = optionsLevels.value + 1; //optionsLevels.value is counted from 0 FirebaseHelper.getInstance().updateSettingLevel(TemporarilyStatus.getInstance().my_level); }
public static string createHTMLForAnswer(WordInfo word) { Debug.Log("createHTMLForQuestion"); string htmlString = ""; string strExplanation = word.common.explain; string strExample = word.common.example; string strMeaning = word.common.meaning; /* maybe must replace " " by "" */ //remove html tag, use for playing speech string plainExplanation = @""; string plainExample = @""; if (strExplanation != null) { strExplanation = removeNBSP(strExplanation); plainExplanation = removeHTML(strExplanation); } else { strExplanation = ""; } if (strExample != null) { strExample = removeNBSP(strExample); plainExample = removeHTML(strExample); } else { strExample = ""; } if (strMeaning != null) { strMeaning = strMeaning.Replace("<p>", String.Empty); strMeaning = strMeaning.Replace("</p>", String.Empty); } else { strMeaning = ""; } string strPronounciation = word.pronoun; if (strPronounciation.Equals("//") == true) { strPronounciation = ""; } //check display meaning setting if (TemporarilyStatus.getInstance().auto_play_sound == 0) { strMeaning = ""; } float speed = TemporarilyStatus.getInstance().speaking_speed; string strExplainIconTag = @""; string strExampleIconTag = @""; string strWordIconTag = @""; string strNoteTag = @""; //create html try { strWordIconTag = "<div style='float:right;width:10%%'>" + "<a onclick='playText(\"{0}\", {1:0.0});'><img width=100%% src='{2}'/></a>\n" + "</div>\n"; strWordIconTag = String.Format(strWordIconTag, word.word, speed, SPEAKER_IMG_LINK); if (strExplanation != null && strExplanation.Length > 0) { strExplainIconTag = "<div style=\"float:left;width:90%%; font-size:14pt;\">" + " <em>{0}</em> \n" + //%@ will be replaced by strExplanation "</div>\n" + "<div style=\"float:right;width:10%%\">\n " + " <p><a onclick='playText(\"{1}\", {2:0.0});'><img width=100%% src='{3}'/></a></p>\n" + //%@ will be replaced by strExplanation "</div>\n"; strExplainIconTag = String.Format(strExplainIconTag, strExplanation, plainExplanation, speed, SPEAKER_IMG_LINK); } if (strExample != null && strExample.Length > 0) { strExampleIconTag = "<div style=\"width:90%%; font-size:12pt;\"><strong>Example: </strong></div>\n" + "<div style=\"float:left;width:90%%; font-size:14pt;\">" + " <em>{0}</em> \n" + //%@ will be replaced by strExample "</div>\n" + "<div style=\"float:right;width:10%%\">\n " + " <p><a onclick='playText(\"{1}\", {2:0.0});'><img width=100%% src='{3}'/></a></p>\n" + //%@ will be replaced by strExample "</div>\n"; strExampleIconTag = String.Format(strExampleIconTag, strExample, plainExample, speed, SPEAKER_IMG_LINK); } string userNote = word.usernote; if (userNote != null && userNote.Length > 0) { userNote = userNote.Replace("\n", "<br>"); string userNoteLabel = "User note"; strNoteTag = "<div style=\"width:100%%; font-size:12pt;\"><br><center><hr></center></div>\n" + "<div style=\"width:100%%; font-size:12pt;\"><strong>{0}: </strong></div>\n" + "<div style=\"width:100%%; font-size:14pt;\">" + " <em>{1}</em> \n" + //%@ will be replaced by word.userNote "</div>\n"; strNoteTag = String.Format(strNoteTag, userNoteLabel, userNote); } htmlString = @"<html>" + "<head>" + "<meta content=\"width=device-width, initial-scale=1.0, user-scalable=yes\"\n" + "name=\"viewport\">\n" + "<style>\n" + "figure {{" + " text-align: center;" + " margin: auto;" + "}}" + "figure.image img {{" + " width: 100%% !important;" + " height: auto !important;" + "}}" + "figcaption {{" + " font-size: 10px;" + "}}" + "a {{" + " margin-top:10px;" + "}}" + "hr {{" + "border: 0;" + "border-top: 3px double #8c8c8c;" + "text-align:center;" + "}}" + "</style>\n" + "<script>" + //play the text "function playText(content, rate) {{" + " var speaker = new SpeechSynthesisUtterance();" + " speaker.text = content;" + " speaker.lang = 'en-US';" + " speaker.rate = rate;" + //0.1 " speaker.pitch = 1.0;" + " speaker.volume = 1.0;" + " speechSynthesis.cancel();" + " speechSynthesis.speak(speaker);" + "}}" + //cancel speech "function cancelSpeech() {{" + " speechSynthesis.pause();" + " speechSynthesis.cancel();" + "}}" + "</script>" + "</head>" + "<body>" + " <div style='width:100%%'>" + " <div style='float:left;width:90%%;text-align: center;'>" + " <strong style='font-size:18pt;'> {0} </strong>" + //%@ will be replaced by word " </div>" + " {1}" + //%@ will be replaced by strWordIconTag " <div style='width:90%%'>" + " <center><font size='4'> {2} </font></center>" + //%@ will be replaced by pronunciation " </div>\n" + " <p style=\"text-align: center;\"> </p>" + //%@ will be replaced by image link, temporary leave it blank " <div style=\"width:100%%\"></div>" + " {3} \n" + //%@ will be replaced by strExplainIconTag " {4} \n" + //%@ will be replaced by strExampleIconTag " <div style='width:90%%'>" + " <br><br><br><br><center><font size='4' color='blue'><em style='margin-left: 10px'> {5} </em></font></center>" + //%@ will be replaced by meaning " </div>" + " </div>" + " {6} " + //%@ will be replaced by strNoteTag " </body>" + "</html>\n"; Debug.Log("createHTMLForQuestion 1 :: " + htmlString); htmlString = String.Format(htmlString, word.word, strWordIconTag, strPronounciation, strExplainIconTag, strExampleIconTag, strMeaning, strNoteTag); Debug.Log("createHTMLForQuestion 2 :: " + htmlString); } catch (Exception e) { Debug.Log("createHTMLForAnswer :: Exception :; " + e.ToString()); } return(htmlString); }
public static string createHTMLForQuestion(WordInfo word) { Debug.Log("createHTMLForQuestion"); string htmlString = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<style>\n" + "figure {{" + " text-align: center;" + " margin: auto;" + "}}" + "figure.image img {{" + " width: 100%% !important;" + " height: auto !important;" + "}}" + "figcaption {{" + " font-size: 10px;" + "}}" + "a {{" + " margin-top:10px;" + "}}" + "</style>\n" + "<script>" + //play the text "function playText(content, rate) {{" + " var speaker = new SpeechSynthesisUtterance();" + " speaker.text = content;" + " speaker.lang = 'en-US';" + " speaker.rate = rate;" + //0.1 " speaker.pitch = 1.0;" + " speaker.volume = 1.0;" + " speechSynthesis.cancel();" + " speechSynthesis.speak(speaker);" + "}}" + //cancel speech "function cancelSpeech() {{" + " speechSynthesis.pause();" + " speechSynthesis.cancel();" + "}}" + "</script>" + "</head>" + "<body>" + "<div style='width:100%%'>" + "{0}" + //strWordIconTag "</div>\n" + "</body>\n" + "</html>"; try { float speed = TemporarilyStatus.getInstance().speaking_speed; Debug.Log("createHTMLForQuestion speed :: " + speed.ToString()); string strWordIconTag = @"<div style='float:left;width:90%%;text-align: center;'>" + "<strong style='font-size:18pt;'> {0} </strong>\n" + //%@ will be replaced by word.question "</div>\n" + "<div style='float:right;width:10%%'>\n" + "<a onclick='playText(\"{1}\", {2:0.0});'><img width=100%% src='{3}'/><p>\n" + "</div>\n"; strWordIconTag = String.Format(strWordIconTag, word.word, word.word, speed, SPEAKER_IMG_LINK); Debug.Log("createHTMLForQuestion 2 :: " + strWordIconTag); Debug.Log("======================="); Debug.Log("createHTMLForQuestion htmlString :: " + htmlString); htmlString = String.Format(htmlString, strWordIconTag); Debug.Log("createHTMLForQuestion 3"); Debug.Log(htmlString); } catch (Exception e) { Debug.Log("createHTMLForQuestion :: Exception :; " + e.ToString()); } return(htmlString); }