void ConvertWatchModelToDataArry()
        {
            globalWatchModelHold = ConvertRestNumberCellToRestStar(globalWatchModelHold);

            DataArrayModel convertedFromWatch = new DataArrayModel();

            convertedFromWatch.DataArray = new List <List <string> >();

            List <string> WeekAndDay = new List <string>();

            WeekAndDay.Add(globalWatchModelHold.Week);
            WeekAndDay.Add(globalWatchModelHold.Day);

            convertedFromWatch.DataArray.Add(WeekAndDay);

            List <string> tmpWeights = new List <string>();


            // starts at workout string list index 2 to get past workout name and rep
            int index = 2;


            while (index < globalWatchModelHold.Workouts.Count)
            {
                tmpWeights.AddRange(globalWatchModelHold.Workouts.GetRange(index, globalWatchModelHold.Sets.Count));

                convertedFromWatch.DataArray.Add(tmpWeights);
                tmpWeights = new List <string>();

                // skips to next set count plus 2 because of name and rep
                index = index + globalWatchModelHold.Sets.Count + 2;
            }

            ApplyJsonToSheet(convertedFromWatch);
        }
        async void ApplyJsonToSheet(DataArrayModel dataArrayModel)
        {
            var client     = new HttpClient();
            var uri        = ScriptUrl;
            var jsonString = JsonConvert.SerializeObject(dataArrayModel);


            var requestContent = new StringContent(jsonString);

            var result = await client.PostAsync(uri, requestContent);

            var resultContent = await result.Content.ReadAsStringAsync();

            ResponseModel response = JsonConvert.DeserializeObject <ResponseModel>(resultContent);

            ProcessResponse(response);
        }
Ejemplo n.º 3
0
        void DoneFunction()
        {
            dataArray.DataArrayObject           = new DataArrayModel();
            dataArray.DataArrayObject.DataArray = new List <List <string> >();

            List <string> firstIndexObject = new List <string>();

            firstIndexObject.Add(watch.WatchObject.Week);
            firstIndexObject.Add(watch.WatchObject.Day);

            dataArray.DataArrayObject.DataArray.Add(firstIndexObject);

            List <List <string> > orderedWorkoutWeight = DivideWorkout();

            foreach (List <string> item in orderedWorkoutWeight)
            {
                dataArray.DataArrayObject.DataArray.Add(item);
            }


            dataArray.DataArrayObject.DataArray.Add(prevReps);
            dataArray.DataArrayObject.DataArray.Add(prevWorkoutName);

            var model = new DataArrayModel()
            {
                DataArray = dataArray.DataArrayObject.DataArray
            };

            SendJsonString = JsonConvert.SerializeObject(model);

            SaveText = @"Save successful
Tap 'Upload' next time connected to phone to update spreadsheet";

            ShowSavedMessage();

            Preferences.Set("SendJson", SendJsonString);
        }
        async void ApplyJsonToSheet()
        {
            var client = new HttpClient();


            var model = new DataArrayModel()
            {
                DataArray = setArray
            };

            // todo: for debugging where this Json data is sent to google sheet, make it user entered url
            var uri        = "https://script.google.com/macros/s/AKfycby2BGbNJwvzgqp4hay1CR0V3cznlND4u3Ra2-mysvdELCbO3II/exec";
            var jsonString = JsonConvert.SerializeObject(model);


            // from jsonString
            string tmp            = "{\"DataArray\":[[\"Week 0\",\"DAY 1\"],[\"69\",\"69\",\"420\",\"420\",\"42069\",\"6969\"],[\"69\",\"69\",\"420\",\"420\",\"42069\",\"6969\"],[\"69\",\"69\",\"420\",\"420\",\"42069\",\"6969\"],[\"69\",\"69\",\"420\",\"420\",\"42069\",\"6969\"]]}";
            var    requestContent = new StringContent(tmp);
            //

            //var requestContent = new StringContent(jsonString);

            var result = await client.PostAsync(uri, requestContent);

            var resultContent = await result.Content.ReadAsStringAsync();

            ResponseModel response = null;

            try
            {
                response = JsonConvert.DeserializeObject <ResponseModel>(resultContent);
            }
            catch { }

            ProcessResponse(response);
        }