Exemplo n.º 1
0
        /********** Tracker Content View : END **********/

        /********** Profile Chart View : START **********/

        private void GetTrackerData()
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                await Task.Factory.StartNew(() =>
                {
                    Entries      = new List <Entry>();
                    UserTrackers = UserTrackers.OrderBy(t => t.ModifyDate).ToList();
                    int index    = 0;
                    foreach (var tracker in UserTrackers)
                    {
                        index++;
                        var barColor = ChartColor.Get(index);
                        double.TryParse(tracker.CurrentWeight, out double currentWeight);
                        tracker.WeightLost      = StartWeight - currentWeight;
                        tracker.BackgroundColor = Xamarin.Forms.Color.FromHex(ChartColor.GetString(index));
                        Entries.Add(new Entry((float)tracker.WeightLost)
                        {
                            Label      = tracker.RevisionNumberDisplayShort,
                            ValueLabel = tracker.WeightLostDisplay.ToString(),
                            Color      = barColor,
                            TextColor  = barColor
                        });
                    }

                    SetChart(App.Configuration.GetUserGraph());
                });
            });
        }
Exemplo n.º 2
0
        public void GetUserTracker()
        {
            if (UserTrackers.Count > 0)
            {
                var trackerFirst = UserTrackers.OrderBy(t => t.ModifyDate).FirstOrDefault();
                var trackerLast  = UserTrackers.OrderByDescending(t => t.ModifyDate).FirstOrDefault();
                if (trackerFirst != null && trackerLast != null)
                {
                    if (short.TryParse(trackerLast.CurrentWeight.ToString(), out short previous))
                    {
                        PreviousWeight = previous;

                        // CHANGED
                        CurrentWeightValue = PreviousWeight;
                        ChangeSliderValue(CurrentWeightValue);
                    }

                    if (short.TryParse(trackerFirst.CurrentWeight.ToString(), out short start))
                    {
                        StartWeight = start;
                    }
                }
            }

            GetMilestoneExtendedAsync();
        }
Exemplo n.º 3
0
        public async Task ShowTrackerDetailAsync()
        {
            PopType = PopupType.Detail;
            TrackerWeightMinimumValue = 0;
            TrackerWeightMaximumValue = _converter.DisplayWeightVolume(
                App.Configuration.AppConfig.MAXIMUM_CURRENT_WEIGHT_KG,
                App.Configuration.AppConfig.MAXIMUM_CURRENT_WEIGHT_LB);
            TrackerWeightValue = TrackerWeightMinimumValue;

            UserTrackersDescending = new List <TrackerPivot>();
            UserTrackersDescending = UserTrackers.OrderByDescending(t => t.ModifyDate).ToList();
            await PushModalAsync(TrackerPage);
        }
Exemplo n.º 4
0
        private void LoadGauge()
        {
            // Gauge Values
            var trackerFirst = UserTrackers.OrderBy(t => t.ModifyDate).FirstOrDefault();
            var trackerLast  = UserTrackers.OrderBy(t => t.ModifyDate).LastOrDefault();

            if (trackerFirst != null && trackerLast != null)
            {
                double.TryParse(trackerFirst.CurrentWeight, out double firstCurrent);
                double.TryParse(trackerLast.CurrentWeight, out double lastCurrent);
                var gaugeCurrent = firstCurrent - lastCurrent;
                GaugeCurrentConstant = (gaugeCurrent * 100) / (double)YourGoal;
                GaugeCurrent         = GaugeCurrentConstant > 100 ? 100 : GaugeCurrentConstant;
                ChangeSliderValue(SliderGaugeModel, GaugeCurrent, 6);
            }
        }
Exemplo n.º 5
0
        private async void GetUserTracker()
        {
            UserTrackers = await trackerService.GetUserTrackerAsync();

            if (UserTrackers.Count > 0)
            {
                var trackerFirst = UserTrackers.OrderBy(t => t.RevisionNumber).FirstOrDefault();
                var trackerLast  = UserTrackers.OrderByDescending(t => t.RevisionNumber).FirstOrDefault();
                if (trackerFirst != null && trackerLast != null)
                {
                    if (short.TryParse(trackerLast.CurrentWeight.ToString(), out short previous))
                    {
                        PreviousWeight = previous;
                    }
                    if (short.TryParse(trackerFirst.CurrentWeight.ToString(), out short start))
                    {
                        StartWeight = start;
                    }
                }
            }

            UserMetas = await metaService.GetMetaAsync(new string[]
                                                       { MetaConstants.WEIGHT_LOSS_GOAL, MetaConstants.GENDER });

            if (UserMetas != null)
            {
                if (short.TryParse(UserMetas.WeightGoal.ToString(), out short weightLossGoal))
                {
                    WeightLossGoal = weightLossGoal;
                }
                GetUserGenderAsync();
            }

            BaseContent = new Pages.Milestone.BasicMilestonePage(this).Content;

            await GetMilestoneExtendedAsync();
        }
Exemplo n.º 6
0
        /********** Profile Content View : START **********/

        public async Task GetUserAsync(bool showTracker = false)
        {
            try
            {
                TrackerPage       = null;
                MilestoneRequired = false;
                UserDetail        = await _userPivotService.GetFullAsync();

                if (UserDetail == null)
                {
                    App.GoToAccountPage();
                    return;
                }

                UserGreeting = string.Format(TextResources.GreetingUser, UserDetail.DisplayName);
                if ((UserDetail.Achievement?.AchievementIcon ?? null) != null)
                {
                    BadgeAchievedImage = ImageResizer.ResizeImage(DependencyService.Get <IMessage>()
                                                                  .GetResource(UserDetail.Achievement.AchievementIcon), _imageSizeBadge);
                }

                JoiningDate = string.Format(CommonConstants.DATE_FORMAT_MMM_d_yyyy, UserDetail.UserRegistered);
                double.TryParse(UserDetail.MetaPivot.WeightLossGoal, out double yourGoal);
                YourGoal   = yourGoal;
                TargetDate = UserDetail.TargetDate; // "Sunday, March 9, 2008"

                UserTrackers = UserDetail.TrackerPivot.OrderBy(t => t.ModifyDate).ToList();
                var trackerFirst = UserTrackers.OrderBy(t => t.ModifyDate).FirstOrDefault();
                var trackerLast  = UserTrackers.OrderBy(t => t.ModifyDate).LastOrDefault();
                MilestoneRequired = trackerFirst == null;
                if (trackerFirst != null && trackerLast != null)
                {
                    double.TryParse(trackerFirst.CurrentWeight, out double firstWeight);
                    StartWeight    = firstWeight;
                    Weight         = StartWeight;
                    WeightLossGoal = YourGoal;
                    double.TryParse(trackerLast.CurrentWeight, out double lastWeight);
                    YouLost = (short)(StartWeight - lastWeight);
                    ToLoose = (short)(YourGoal - YouLost);
                    ToLoose = (short)(ToLoose >= 0 ? ToLoose : 0);

                    if (UserTrackers.Count != 1)
                    {
                        double.TryParse(UserTrackers.OrderBy(t => t.ModifyDate)
                                        .LastOrDefault(t => t.RevisionNumber != trackerLast?.RevisionNumber)?.CurrentWeight,
                                        out double previousWeight);
                        YouLostThisWeek = (short)(previousWeight - lastWeight);
                    }

                    // Milestone Requirement Check
                    MilestoneRequired = UserDetail.IsWeightSubmissionRequired;
                }

                if (showTracker && MilestoneRequired)
                {
                    await Task.Delay(TimeSpan.FromMilliseconds(750));

                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        await App.CurrentApp.MainPage.Navigation.PushModalAsync(
                            new UserMilestonePage(Root, this));
                    });
                }

                GetTrackerData();
                LoadGauge();
                if (!(showTracker && MilestoneRequired))
                {
                    await ProduceTrackerLog();
                }
            }
            catch (Exception ex)
            {
                _ = new ExceptionHandler(typeof(ProfileEnhancedViewModel).FullName, ex);
            }
        }