예제 #1
0
    //Red button clickevent
    public void Knop(float value)
    {
        this.value = value;

        UpdateClick(value, false);

        //if statement for the bar. When the red button is pressed the bar gets full.
        if ((Click / 100f) >= 1)
        {
            //start cyclus when the app is opened for the first time.
            AppOpenDate appOpenDate = new AppOpenDate();
            appOpenDate.writeToJSON();

            LaatsteDatum laatstedatum = new LaatsteDatum();
            DateTime     lastDate     = laatstedatum.GetLastDate();

            //if the cyclus has reached the 7th day show "Cyclusmanager".
            //also show after every 7 days.
            if ((DateTime.Now - lastDate).Days >= 0)
            {
                SceneManager.LoadScene("CyclusManager");
            }
            else
            {
                RandomScene.loadRandomScene();
            }
        }
    }
예제 #2
0
    //if statement to show the questionscene once a week
    public void Knop(bool antwoord)
    {
        if (antwoord)
        {
            Cyclus cyclusmanager = new Cyclus();
            cyclusmanager.ChangeCyclus();
        }

        LaatsteDatum laatstedatum = new LaatsteDatum();

        laatstedatum.WriteFirstDate(DateTime.Now);
        RandomScene.loadRandomScene();
    }
예제 #3
0
        /// <summary>
        /// Write AppOpenDate to a local json file
        /// </summary>
        public void writeToJSON()
        {
            string path = Application.persistentDataPath + "/AppOpenDate.json";

            //Check if json file is empty or not.

            if (File.Exists(path))
            {
                List <AppOpenDate> appOpenDateList;
                using (StreamReader r = new StreamReader(path))
                {
                    string json = r.ReadToEnd();
                    appOpenDateList = JsonConvert.DeserializeObject <List <AppOpenDate> >(json, Constants.jsonSerializerSettings);
                    foreach (AppOpenDate item in appOpenDateList)
                    {
                        //set to localtime since datetime from json are UTC
                        item.datetimeOpened = item.datetimeOpened.ToLocalTime();
                    }
                    r.Close();
                }

                DateTime endOfCyclusCalculationPeriod = appOpenDateList.First().datetimeOpened.AddDays(CALCULATION_DURATION_DAYS);

                LaatsteDatum laatstedatum = new LaatsteDatum();
                laatstedatum.CreateFirstDate(endOfCyclusCalculationPeriod);

                DateTime lastOpened = appOpenDateList.Last().datetimeOpened.AddMinutes(MINUTES_BETWEEN_SMOKES);

                //DateTime is before end of cyclus calculation period and atleast 1 hour after the last datetime added.
                if (datetimeOpened < endOfCyclusCalculationPeriod && lastOpened < datetimeOpened)
                {
                    appOpenDateList.Add(this);
                    File.WriteAllText(path, JsonConvert.SerializeObject(appOpenDateList, Constants.jsonSerializerSettings));
                }
                else if (datetimeOpened >= endOfCyclusCalculationPeriod)
                {
                    Cyclus cyclus = new Cyclus();
                    cyclus.createCyclus(appOpenDateList);
                }
            }
            else
            {
                //Json file doesn't exist so create file and write down the first datetime
                File.Create(path).Close();
                File.WriteAllText(path, "[" + JsonConvert.SerializeObject(this, Constants.jsonSerializerSettings) + "]");
            }
        }