Exemplo n.º 1
0
        private IEnumerator RequestRecipeRoutine()
        {
            configKey = FindObjectOfType <FoodPlanner>().GetWidgetConfigKey();
            config    = Config.instance.GetWidgetConfig();
            plannerId = config[configKey]["plannerId"];

            string label = "";

            foreach (char c in day.ToString().Substring(0, 3).ToUpper())
            {
                label += c + "\n";
            }

            dayText.text = label;
            recipe.text  = "Loading...";

            UnityWebRequest request = Postman.CreateGetRequest(Endpoints.instance.PLANNER(day.ToString()));

            yield return(request.SendWebRequest());

            bool ok = request.error == null ? true : false;

            if (!ok)
            {
                WidgetLogger.instance.Log("Error: " + (string)JSON.Parse(request.downloadHandler.text)["message"]);
                yield break;
            }

            recipe.text = (string)JSON.Parse(request.downloadHandler.text)["recipe"];
        }
        private IEnumerator PopulateRecipesRoutine()
        {
            ClearExistingRecipes();

            loadingText.text = "Loading...";

            UnityWebRequest request = Postman.CreateGetRequest(Endpoints.instance.RECIPES());

            yield return(request.SendWebRequest());

            string response = request.downloadHandler.text;

            JSONNode json = JSON.Parse(response);

            foreach (JSONNode recipe in json)
            {
                RecipeEntry entry = Instantiate(recipeEntryPrefab.gameObject, scrollViewContent).GetComponent <RecipeEntry>();
                entry.SetIngredients(recipe["ingredients"].AsArray);
                entry.SetParentDialog(this);
                entry.SetRecipeText(recipe["name"]);
                entry.SetSteps(recipe["steps"].AsArray);
            }

            loadingText.text = "";
        }
Exemplo n.º 3
0
        private IEnumerator RunRoutine()
        {
            UnityWebRequest request = Postman.CreateGetRequest(Endpoints.instance.WEATHER());

            yield return(request.SendWebRequest());

            bool ok = request.error == null ? true : false;

            if (!ok)
            {
                WidgetLogger.instance.Log(this, "Error: " + request.error);
                yield break;
            }

            JSONNode        json = JSON.Parse(request.downloadHandler.text);
            List <JSONNode> hourlyWeatherData = GetHourlyWeatherData(json);
            List <JSONNode> dailyWeatherData  = GetDailyWeatherData(json);

            for (int i = 0; i < hourlyWeatherData.Count; i++)
            {
                JSONNode data        = hourlyWeatherData[i];
                TimeSpan time        = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(data["time"]).ToLocalTime().TimeOfDay;
                string   iconCode    = GetFontCodeFor(data["icon"]);
                string   temperature = string.Format("{0}°", Mathf.RoundToInt((float)data["temperature"]));

                WeatherEntry entry = hourlyWeatherEntries[i];
                entry.SetDayColour(GetTextColour());
                entry.SetDayText(string.Format("{0:D2}:{1:D2}", time.Hours, time.Minutes));
                entry.SetIcon(iconCode);
                entry.SetIconColour(spriteColour);
                entry.SetTemperatureText(temperature);
                entry.SetTemperatureTextColour(GetTextColour());
            }

            for (int i = 0; i < dailyWeatherData.Count; i++)
            {
                JSONNode data        = dailyWeatherData[i];
                DateTime date        = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(data["time"]);
                string   day         = date.DayOfWeek.ToString().Substring(0, 3);
                string   iconCode    = GetFontCodeFor(data["icon"]);
                string   temperature = string.Format("{0}°", Mathf.RoundToInt((float)data["temperatureHigh"]));

                WeatherEntry entry = dailyWeatherEntries[i];
                entry.SetDayColour(GetTextColour());
                entry.SetDayText(day.ToLower());
                entry.SetIcon(iconCode);
                entry.SetIconColour(spriteColour);
                entry.SetTemperatureText(temperature);
                entry.SetTemperatureTextColour(GetTextColour());
            }
        }
Exemplo n.º 4
0
        private IEnumerator RunRoutine()
        {
            // Clear out existing entries
            foreach (Transform child in scrollContent)
            {
                Destroy(child.gameObject);
            }

            foreach (JSONNode journey in journeys)
            {
                List <string> stops = new List <string>();
                if (journey["stops"] != null)
                {
                    foreach (JSONNode stop in journey["stops"])
                    {
                        stops.Add(stop);
                    }
                }

                UnityWebRequest request = Postman.CreateGetRequest(Endpoints.instance.JOURNEY_PLANNER(journey["startPoint"], stops, journey["endPoint"]));
                yield return(request.SendWebRequest());

                bool ok = request.error == null ? true : false;
                if (!ok)
                {
                    WidgetLogger.instance.Log(this, "Error: " + request.error);
                    yield break;
                }

                JSONNode json = JSON.Parse(request.downloadHandler.text);

                int duration            = json["resourceSets"][0]["resources"][0]["travelDuration"];
                int durationWithTraffic = json["resourceSets"][0]["resources"][0]["travelDurationTraffic"];
                int timeDifference      = (durationWithTraffic - duration) / 60;

                Color trafficColour = noTrafficColour;

                if (timeDifference > mediumTrafficMinutes && timeDifference < heavyTrafficMinutes)
                {
                    trafficColour = mediumTrafficColour;
                }
                else if (timeDifference > heavyTrafficMinutes)
                {
                    trafficColour = heavyTrafficColour;
                }

                GameObject prefab = journeys.Count == 1 ? singleEntry.gameObject : scrollEntry.gameObject;
                Transform  parent = journeys.Count == 1 ? this.transform : scrollContent;
                Instantiate(prefab, parent).GetComponent <JourneyPlannerEntry>().Initialise(journey["name"], ConvertToTimeString(durationWithTraffic), trafficColour);
            }
        }
Exemplo n.º 5
0
        private IEnumerator AddToShoppingListRoutine()
        {
            ConfirmDialog dialog = FindObjectOfType <ConfirmDialog>();

            dialog.ApplyColours();
            dialog.Show();
            dialog.SetNone();
            dialog.SetInfoMessage("Add all ingredients from each recipe to the shopping list?");

            while (dialog.IsNone())
            {
                yield return(null);
            }

            if (dialog.IsNo())
            {
                dialog.Hide();
                dialog.SetNone();
                yield break;
            }

            if (dialog.IsYes())
            {
                TMP_Text addButtonText = addButton.GetComponentInChildren <TMP_Text>();
                addButtonText.text     = "Please wait...";
                addButton.interactable = false;

                dialog.Hide();

                OnlineList      shoppingList = FindObjectsOfType <OnlineList>().Where(x => x.GetListType().Equals(TodoistList.shoppingList)).First();
                UnityWebRequest request      = Postman.CreateGetRequest(Endpoints.instance.SHOPPING_LIST());
                yield return(request.SendWebRequest());

                JSONArray json = JSON.Parse(request.downloadHandler.text).AsArray;
                foreach (KeyValuePair <string, JSONNode> obj in json)
                {
                    string item = obj.Value.Value;
                    yield return(StartCoroutine(shoppingList.AddItemRoutine(item)));
                }

                shoppingList.Refresh();
                dialog.SetNone();

                addButton.interactable = true;
                addButtonText.text     = "Add To Shopping List";

                yield break;
            }
        }
Exemplo n.º 6
0
    private IEnumerator GetVersionInfoRoutine()
    {
        UnityWebRequest request = Postman.CreateGetRequest(Config.instance.GetEndpoint("release"));

        yield return(request.SendWebRequest());

        repoInfo         = JSON.Parse(request.downloadHandler.text);
        repoVersion      = repoInfo[0]["name"];
        installedVersion = Application.version;

        FindObjectOfType <VersionButton>().SetVersionText("Version: " + installedVersion);

        installedVersionText.text  = installedVersion;
        installedVersionText.color = string.Equals(installedVersion, repoVersion) ? correctVersionColour : incorrectVersionColour;
        repoVersionText.text       = repoVersion;
        infoText.text = string.Equals(installedVersion, repoVersion) ? "You have the latest version!" : "Your version is out of date. Please contact Tom for the latest version.";
    }
Exemplo n.º 7
0
        private IEnumerator RunRoutine()
        {
            UnityWebRequest request = Postman.CreateGetRequest(Endpoints.instance.GOOGLE_CALENDAR(gmailAddress, numberOfEvents, apiKey));

            yield return(request.SendWebRequest());

            json = JSON.Parse(request.downloadHandler.text);

            bool ok = request.error == null ? true : false;

            if (!ok)
            {
                WidgetLogger.instance.Log(this, "Error: " + request.error);
                yield break;
            }

            // Remove old events
            foreach (Transform child in scrollParent)
            {
                Destroy(child.gameObject);
            }

            for (int i = 0; i < json["events"].Count; i++)
            {
                JSONNode item      = json["events"][i];
                DateTime startDate = DateTime.Parse(item["start"]);
                DateTime endDate   = DateTime.Parse(item["end"]);

                GoogleCalendarEvent eventEntry = Instantiate(googleCalendarEventPrefab, scrollParent).GetComponent <GoogleCalendarEvent>();
                eventEntry.SetDescription(item["description"]);
                eventEntry.SetEndDateText(endDate.ToString("dd MMM"));
                eventEntry.SetEndTime(item["endTime"]);
                eventEntry.SetGoogleCalendar(this);
                eventEntry.SetLocation(item["location"]);
                eventEntry.SetStartDateText(startDate.ToString("dd MMM"));
                eventEntry.SetStartDateTextColour(GetTextColour());
                eventEntry.SetStartTime(item["startTime"]);
                eventEntry.SetSummaryText(item["summary"]);
                eventEntry.SetSummaryTextColour(GetTextColour());
            }

            scrollbarBackground.color = Colours.Darken(GetWidgetColour());
            scrollbarHandle.color     = Colours.Lighten(GetWidgetColour(), 0.1f);
        }
Exemplo n.º 8
0
        private IEnumerator DownloadConfigRoutine()
        {
            statusText.SetText("Please wait...");
            UnityWebRequest request = Postman.CreateGetRequest(cmsApiUrl + "?token=" + cmsApiKey);

            yield return(request.SendWebRequest());

            JSONNode json = JSON.Parse(request.downloadHandler.text);

            if (request.result != UnityWebRequest.Result.ProtocolError)
            {
                SaveToConfig(json["config"].ToString());
                statusText.SetText("Download success!");
            }
            else
            {
                statusText.SetText(request.error);
            }
        }
Exemplo n.º 9
0
    private IEnumerator RunRoutine()
    {
        UnityWebRequest request = Postman.CreateGetRequest(Endpoints.instance.SPLITWISE());

        yield return(request.SendWebRequest());

        bool ok = request.error == null ? true : false;

        if (!ok)
        {
            WidgetLogger.instance.Log(this, "Error: " + request.error);
            yield break;
        }

        JSONNode json = JSON.Parse(request.downloadHandler.text);
        JSONNode exp  = json["expenses"][0];

        groupName.text    = json["groupName"];
        people.text       = exp == null ? "" : exp["who"] + " owes " + exp["owes"];
        allSettledUp.text = exp == null ? "All settled up!" : "";
        amount.text       = exp["amount"];
    }
Exemplo n.º 10
0
        private IEnumerator RunRoutine()
        {
            UnityWebRequest request = Postman.CreateGetRequest(Endpoints.instance.TODOIST_PROJECT(projectId));

            request.SetRequestHeader("Authorization", "Bearer " + apiKey);
            yield return(request.SendWebRequest());

            bool ok = request.error == null ? true : false;

            if (!ok)
            {
                WidgetLogger.instance.Log(this, "Error: " + request.error + "\n URL: " + Endpoints.instance.TODOIST_PROJECT(projectId));
                yield break;
            }

            // Remove previous entries so there are no duplicates
            foreach (Transform g in content)
            {
                Destroy(g.gameObject);
            }

            JSONNode json = JSON.Parse(request.downloadHandler.text);

            foreach (JSONNode task in json)
            {
                OnlineListEntry e = Instantiate(entryPrefab, content).GetComponent <OnlineListEntry>();
                e.SetApiKey(apiKey);
                e.SetNameText(Utility.CapitaliseFirstLetter(task["content"].Value));
                e.SetNameTextColour(GetTextColour());
                e.SetRemoveButtonTextColour(GetTextColour());
                e.SetTaskId(task["id"].Value);
            }

            addButtonColour.color     = Colours.Darken(GetWidgetColour());
            addButtonText.color       = GetTextColour();
            scrollbarBackground.color = Colours.Darken(GetWidgetColour());
            scrollbarHandle.color     = Colours.Lighten(GetWidgetColour());
        }
Exemplo n.º 11
0
        private IEnumerator RunRoutine()
        {
            UnityWebRequest request = Postman.CreateGetRequest(Endpoints.instance.TRAIN_DEPARTURES(trainEntries.Length));

            yield return(request.SendWebRequest());

            JSONNode json = JSON.Parse(request.downloadHandler.text);

            bool ok = request.error == null ? true : false;

            if (!ok)
            {
                WidgetLogger.instance.Log(this, "Error: " + request.error);
                yield break;
            }

            foreach (TrainEntry entry in trainEntries)
            {
                entry.SetDestinationText("");
                entry.SetTimeText("");
            }

            int lastRowNumber = 0;

            timetable.Clear();
            PopulateTimetable(json, "trainServices");
            PopulateTimetable(json, "busServices");

            foreach (KeyValuePair <string, string> x in timetable)
            {
                TrainEntry entry = trainEntries[lastRowNumber];
                entry.SetDestinationText(x.Value);
                entry.SetTimeText(x.Key);
                lastRowNumber++;
            }
        }