Exemple #1
0
        private async Task UpdateTimeLine()
        {
            Device.BeginInvokeOnMainThread(() => { _viewModel.TimeLineItems.Clear(); });

            List <TimeLineItem> timeLineList = await ProgenyService.GetTimeLineYearAgo(_viewModel.Progeny.Id,
                                                                                       _viewModel.UserAccessLevel, _viewModel.UserInfo.Timezone).ConfigureAwait(false);

            if (timeLineList.Any())
            {
                foreach (TimeLineItem ti in timeLineList)
                {
                    ti.VisibleBefore = false;
                    Device.BeginInvokeOnMainThread(() => { _viewModel.TimeLineItems.Add(ti); });
                }

                // RemainingItemsThreshold not implemented yet. When it is available try out CollectionView instead of ListView.
                // https://github.com/xamarin/Xamarin.Forms/issues/5623
            }

            // TimeLineListView.ScrollTo(timeLineList.FirstOrDefault(), ScrollToPosition.Start, false);
        }
        private async Task UpdateMeasurements()
        {
            _viewModel.IsBusy = true;
            if (_viewModel.PageNumber < 1)
            {
                _viewModel.PageNumber = 1;
            }

            _viewModel.ItemsPerPage = Preferences.Get(Constants.MeasurementsPerPage, 20);
            MeasurementsListPage measurementsListPage = await ProgenyService.GetMeasurementsListPage(_viewModel.PageNumber, _viewModel.ItemsPerPage, _viewModel.ViewChild, _viewModel.UserAccessLevel, 1);

            if (measurementsListPage.MeasurementsList != null)
            {
                measurementsListPage.MeasurementsList =
                    measurementsListPage.MeasurementsList.OrderByDescending(m => m.Date).ToList();
                _viewModel.MeasurementItems.ReplaceRange(measurementsListPage.MeasurementsList);
                _viewModel.PageNumber = measurementsListPage.PageNumber;
                _viewModel.PageCount  = measurementsListPage.TotalPages;
                MeasurementsListView.ScrollTo(0);
            }
            _viewModel.IsBusy = false;
        }
        private async Task UpdateVocabulary()
        {
            _viewModel.IsBusy = true;
            if (_viewModel.PageNumber < 1)
            {
                _viewModel.PageNumber = 1;
            }

            _viewModel.ItemsPerPage = Preferences.Get(Constants.VocabularyPerPage, 20);
            VocabularyListPage vocabularyListPage = await ProgenyService.GetVocabularyListPage(_viewModel.PageNumber, _viewModel.ItemsPerPage, _viewModel.ViewChild, _viewModel.UserAccessLevel, 1);

            if (vocabularyListPage.VocabularyList != null)
            {
                vocabularyListPage.VocabularyList =
                    vocabularyListPage.VocabularyList.OrderByDescending(v => v.Date).ToList();
                _viewModel.VocabularyItems.ReplaceRange(vocabularyListPage.VocabularyList);
                _viewModel.PageNumber = vocabularyListPage.PageNumber;
                _viewModel.PageCount  = vocabularyListPage.TotalPages;
                VocabularyListView.ScrollTo(0);
            }
            _viewModel.IsBusy = false;
        }
Exemple #4
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            await ProgenyService.GetProgenyList(await UserService.GetUserEmail());

            List <Progeny> progenyList = await ProgenyService.GetProgenyAdminList();

            if (progenyList.Any())
            {
                foreach (Progeny progeny in progenyList)
                {
                    _addPhotoViewModel.ProgenyCollection.Add(progeny);
                }

                string userviewchild = await SecureStorage.GetAsync(Constants.UserViewChildKey);

                bool    viewchildParsed = int.TryParse(userviewchild, out int viewChild);
                Progeny viewProgeny     = new Progeny();
                if (viewchildParsed)
                {
                    viewProgeny = _addPhotoViewModel.ProgenyCollection.SingleOrDefault(p => p.Id == viewChild);
                }

                if (viewProgeny != null)
                {
                    ProgenyCollectionView.SelectedItem =
                        _addPhotoViewModel.ProgenyCollection.SingleOrDefault(p => p.Id == viewChild);
                    ProgenyCollectionView.ScrollTo(ProgenyCollectionView.SelectedItem);
                    _addPhotoViewModel.LocationAutoSuggestList = await ProgenyService.GetLocationAutoSuggestList(viewProgeny.Id, 0);

                    _addPhotoViewModel.TagsAutoSuggestList = await ProgenyService.GetTagsAutoSuggestList(viewProgeny.Id, 0);
                }
                else
                {
                    ProgenyCollectionView.SelectedItem = _addPhotoViewModel.ProgenyCollection[0];
                }
            }
        }
        private async Task UpdateSkills()
        {
            _viewModel.IsBusy = true;
            if (_viewModel.PageNumber < 1)
            {
                _viewModel.PageNumber = 1;
            }

            _viewModel.ItemsPerPage = Preferences.Get(Constants.SkillsPerPage, 20);
            SkillsListPage skillsListPage = await ProgenyService.GetSkillsListPage(_viewModel.PageNumber, _viewModel.ItemsPerPage, _viewModel.ViewChild, _viewModel.UserAccessLevel, 1);

            if (skillsListPage.SkillsList != null)
            {
                skillsListPage.SkillsList =
                    skillsListPage.SkillsList.OrderByDescending(m => m.SkillFirstObservation).ToList();
                _viewModel.SkillsItems.ReplaceRange(skillsListPage.SkillsList);
                _viewModel.PageNumber = skillsListPage.PageNumber;
                _viewModel.PageCount  = skillsListPage.TotalPages;
                SkillsListView.ScrollTo(0);
            }
            _viewModel.IsBusy = false;
        }
Exemple #6
0
        private async Task UpdateContacts()
        {
            _viewModel.IsBusy = true;
            List <Contact> contactsList = await ProgenyService.GetProgenyContacts(_viewModel.Progeny.Id, _viewModel.UserAccessLevel);

            if (ActiveContactsOnlySwitch.IsToggled)
            {
                contactsList = contactsList.Where(c => c.Active).ToList();
            }

            foreach (Contact cnt in contactsList)
            {
                cnt.FullName = cnt.FirstName + " " + cnt.MiddleName + " " + cnt.LastName;
            }
            if (SortByPicker.SelectedIndex == 0)
            {
                contactsList = contactsList.OrderBy(f => f.DisplayName).ToList();
            }

            if (SortByPicker.SelectedIndex == 1)
            {
                contactsList = contactsList.OrderBy(f => f.FirstName).ToList();
            }

            if (SortByPicker.SelectedIndex == 2)
            {
                contactsList = contactsList.OrderBy(f => f.LastName).ToList();
            }

            _viewModel.ContactItems.Clear();
            if (contactsList.Any())
            {
                foreach (Contact cnt in contactsList)
                {
                    _viewModel.ContactItems.Add(cnt);
                }
            }
            _viewModel.IsBusy = false;
        }
Exemple #7
0
        private async void EditButton_OnClicked(object sender, EventArgs e)
        {
            if (_viewModel.EditMode)
            {
                _viewModel.EditMode = false;
                _viewModel.IsBusy   = true;
                _viewModel.IsSaving = true;
                CheckDates();
                DateTime start = new DateTime(_viewModel.StartYear, _viewModel.StartMonth, _viewModel.StartDay, _viewModel.StartHours, _viewModel.StartMinutes, 0);
                DateTime end   = new DateTime(_viewModel.EndYear, _viewModel.EndMonth, _viewModel.EndDay, _viewModel.EndHours, _viewModel.EndMinutes, 0);
                _viewModel.CurrentSleep.SleepStart  = start;
                _viewModel.CurrentSleep.SleepEnd    = end;
                _viewModel.CurrentSleep.AccessLevel = _viewModel.AccessLevel;
                _viewModel.CurrentSleep.SleepRating = _viewModel.Rating;
                _viewModel.CurrentSleep.SleepNotes  = NotesEditor.Text;
                // Todo: Add timezone selection: Use progeny timezone or user timezone, if they are not the same?

                // Save changes.
                Sleep resultSleep = await ProgenyService.UpdateSleep(_viewModel.CurrentSleep);

                _viewModel.IsBusy   = false;
                _viewModel.IsSaving = false;
                EditButton.Text     = IconFont.AccountEdit;
                if (resultSleep != null)                            // Todo: Error message if update fails.
                {
                    MessageLabel.Text            = "Sleep Updated"; // Todo: Translate
                    MessageLabel.BackgroundColor = Color.DarkGreen;
                    MessageLabel.IsVisible       = true;
                    await Reload();
                }
            }
            else
            {
                EditButton.Text = IconFont.ContentSave;

                _viewModel.EditMode = true;
            }
        }
        private async Task SetUserAndProgeny()
        {
            _viewModel.UserInfo = OfflineDefaultData.DefaultUserInfo;

            string userEmail = await UserService.GetUserEmail();

            string userviewchild = await SecureStorage.GetAsync(Constants.UserViewChildKey);

            bool viewchildParsed = int.TryParse(userviewchild, out int viewChildId);

            if (viewchildParsed)
            {
                _viewModel.ViewChild = viewChildId;
                try
                {
                    _viewModel.Progeny = await App.Database.GetProgenyAsync(_viewModel.ViewChild);
                }
                catch (Exception)
                {
                    _viewModel.Progeny = await ProgenyService.GetProgeny(_viewModel.ViewChild);
                }

                _viewModel.UserInfo = await App.Database.GetUserInfoAsync(userEmail);
            }

            if (String.IsNullOrEmpty(_viewModel.UserInfo.Timezone))
            {
                _viewModel.UserInfo.Timezone = Constants.DefaultTimeZone;
            }
            try
            {
                TimeZoneInfo.FindSystemTimeZoneById(_viewModel.UserInfo.Timezone);
            }
            catch (Exception)
            {
                _viewModel.UserInfo.Timezone = TZConvert.WindowsToIana(_viewModel.UserInfo.Timezone);
            }
        }
Exemple #9
0
        private async void SaveAccessButton_OnClicked(object sender, EventArgs e)
        {
            _viewModel.IsBusy   = true;
            _viewModel.EditMode = false;
            _viewModel.SelectedAccess.AccessLevel = AccessLevelPicker.SelectedIndex;
            UserAccess updatedUserAccess = await ProgenyService.UpdateUserAccess(_viewModel.SelectedAccess);

            if (updatedUserAccess.AccessId != 0)
            {
                _viewModel.EditMode                   = false;
                _viewModel.SelectedAccess             = null;
                UserAccessCollectionView.SelectedItem = null;
                // Todo: Show success message
                await Reload();
            }
            else
            {
                _viewModel.EditMode = true;
                // Todo: Show failed message
            }

            _viewModel.IsBusy = false;
        }
        private async void EditButton_OnClicked(object sender, EventArgs e)
        {
            if (_viewModel.EditMode)
            {
                _viewModel.EditMode = false;
                _viewModel.IsBusy   = true;
                _viewModel.IsSaving = true;

                DateTime skillDate = new DateTime(_viewModel.DateYear, _viewModel.DateMonth, _viewModel.DateDay);
                _viewModel.CurrentSkillItem.SkillFirstObservation = skillDate;
                _viewModel.CurrentSkillItem.Name        = _viewModel.Name;
                _viewModel.CurrentSkillItem.Description = _viewModel.Description;
                _viewModel.CurrentSkillItem.Category    = CategoryEntry.Text.Trim();
                _viewModel.CurrentSkillItem.AccessLevel = _viewModel.AccessLevel;

                // Save changes.
                Skill resultSkillItem = await ProgenyService.UpdateSkill(_viewModel.CurrentSkillItem);

                _viewModel.IsBusy   = false;
                _viewModel.IsSaving = false;
                EditButton.Text     = IconFont.CalendarEdit;
                if (resultSkillItem != null)                        // Todo: Error message if update fails.
                {
                    MessageLabel.Text            = "Skill Updated"; // Todo: Translate
                    MessageLabel.BackgroundColor = Color.DarkGreen;
                    MessageLabel.IsVisible       = true;
                    await Reload();
                }
            }
            else
            {
                EditButton.Text = IconFont.ContentSave;

                _viewModel.EditMode = true;
                _viewModel.CategoryAutoSuggestList = await ProgenyService.GetCategoryAutoSuggestList(_viewModel.CurrentSkillItem.ProgenyId, 0);
            }
        }
Exemple #11
0
        private async void EditButton_OnClicked(object sender, EventArgs e)
        {
            if (_viewModel.EditMode)
            {
                _viewModel.EditMode = false;
                _viewModel.IsBusy   = true;
                _viewModel.IsSaving = true;

                DateTime wordDate = new DateTime(_viewModel.DateYear, _viewModel.DateMonth, _viewModel.DateDay);
                _viewModel.CurrentVocabularyItem.Date        = wordDate;
                _viewModel.CurrentVocabularyItem.Word        = _viewModel.Word;
                _viewModel.CurrentVocabularyItem.SoundsLike  = _viewModel.SoundsLike;
                _viewModel.CurrentVocabularyItem.Description = _viewModel.Description;
                _viewModel.CurrentVocabularyItem.Language    = _viewModel.Language;
                _viewModel.CurrentVocabularyItem.AccessLevel = _viewModel.AccessLevel;

                // Save changes.
                VocabularyItem resultVocabularyItem = await ProgenyService.UpdateVocabularyItem(_viewModel.CurrentVocabularyItem);

                _viewModel.IsBusy   = false;
                _viewModel.IsSaving = true;
                EditButton.Text     = IconFont.CalendarEdit;
                if (resultVocabularyItem != null)                  // Todo: Error message if update fails.
                {
                    MessageLabel.Text            = "Word Updated"; // Todo: Translate
                    MessageLabel.BackgroundColor = Color.DarkGreen;
                    MessageLabel.IsVisible       = true;
                    await Reload();
                }
            }
            else
            {
                EditButton.Text = IconFont.ContentSave;

                _viewModel.EditMode = true;
            }
        }
Exemple #12
0
        private async void EditButton_OnClicked(object sender, EventArgs e)
        {
            if (_viewModel.EditMode)
            {
                _viewModel.EditMode = false;
                _viewModel.IsBusy   = true;
                _viewModel.IsSaving = true;

                DateTime vacDate = new DateTime(_viewModel.DateYear, _viewModel.DateMonth, _viewModel.DateDay);
                _viewModel.CurrentVaccination.VaccinationDate        = vacDate;
                _viewModel.CurrentVaccination.VaccinationName        = _viewModel.Name;
                _viewModel.CurrentVaccination.VaccinationDescription = _viewModel.Description;
                _viewModel.CurrentVaccination.Notes       = _viewModel.Notes;
                _viewModel.CurrentVaccination.AccessLevel = _viewModel.AccessLevel;

                // Save changes.
                Vaccination resultVaccination = await ProgenyService.UpdateVaccination(_viewModel.CurrentVaccination);

                _viewModel.IsBusy = false;
                _viewModel.IsBusy = false;
                EditButton.Text   = IconFont.CalendarEdit;
                if (resultVaccination != null)                            // Todo: Error message if update fails.
                {
                    MessageLabel.Text            = "Vaccination Updated"; // Todo: Translate
                    MessageLabel.BackgroundColor = Color.DarkGreen;
                    MessageLabel.IsVisible       = true;
                    await Reload();
                }
            }
            else
            {
                EditButton.Text = IconFont.ContentSave;

                _viewModel.EditMode = true;
            }
        }
Exemple #13
0
        private async Task UpdateEditInfo()
        {
            MessageLabel.Text            = "";
            MessageLabel.IsVisible       = false;
            CancelButton.BackgroundColor = Color.DimGray;

            _viewModel.LocationAutoSuggestList = await ProgenyService.GetLocationAutoSuggestList(_viewModel.Progeny.Id, _viewModel.UserAccessLevel);

            _viewModel.TagsAutoSuggestList = await ProgenyService.GetTagsAutoSuggestList(_viewModel.Progeny.Id, _viewModel.UserAccessLevel);

            TagsEditor.Text = _viewModel.CurrentVideoViewModel.Tags;
            if (_viewModel.CurrentVideoViewModel.VideoTime.HasValue)
            {
                PhotoDatePicker.Date = _viewModel.CurrentVideoViewModel.VideoTime.Value.Date;
                PhotoTimePicker.Time = _viewModel.CurrentVideoViewModel.VideoTime.Value.TimeOfDay;
            }

            if (_viewModel.CurrentVideoViewModel.Duration.HasValue)
            {
                _viewModel.VideoHours   = _viewModel.CurrentVideoViewModel.Duration.Value.Hours;
                _viewModel.VideoMinutes = _viewModel.CurrentVideoViewModel.Duration.Value.Minutes;
                _viewModel.VideoSeconds = _viewModel.CurrentVideoViewModel.Duration.Value.Seconds;
            }

            LocationEntry.Text              = _viewModel.CurrentVideoViewModel.Location;
            LatitudeEntry.Text              = _viewModel.CurrentVideoViewModel.Latitude;
            LongitudeEntry.Text             = _viewModel.CurrentVideoViewModel.Longtitude;
            AltitudeEntry.Text              = _viewModel.CurrentVideoViewModel.Altitude;
            AccessLevelPicker.SelectedIndex = _viewModel.CurrentVideoViewModel.AccessLevel;

            DeleteButton.IsVisible = true;
            CancelButton.IsVisible = true;
            CancelButton.Text      = IconFont.Cancel;
            SaveButton.IsVisible   = true;
            _dataChanged           = false;
        }
        private async Task CheckAccount()
        {
            string userEmail = await UserService.GetUserEmail();

            _viewModel.AccessToken = await UserService.GetAuthAccessToken();

            bool accessTokenCurrent = false;

            if (_viewModel.AccessToken != "")
            {
                accessTokenCurrent = await UserService.IsAccessTokenCurrent();

                if (!accessTokenCurrent)
                {
                    bool loginSuccess = await UserService.LoginIdsAsync();

                    if (loginSuccess)
                    {
                        _viewModel.AccessToken = await UserService.GetAuthAccessToken();

                        accessTokenCurrent = true;
                    }

                    await Reload();
                }
            }

            if (String.IsNullOrEmpty(_viewModel.AccessToken) || !accessTokenCurrent)
            {
                _viewModel.IsLoggedIn  = false;
                _viewModel.AccessToken = "";
                _viewModel.UserInfo    = OfflineDefaultData.DefaultUserInfo;
            }
            else
            {
                _viewModel.IsLoggedIn = true;
                _viewModel.UserInfo   = await UserService.GetUserInfo(userEmail);
            }

            await SetUserAndProgeny();

            Progeny progeny = await ProgenyService.GetProgeny(_viewModel.ViewChild);

            try
            {
                TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone);
            }
            catch (Exception)
            {
                progeny.TimeZone = TZConvert.WindowsToIana(progeny.TimeZone);
            }
            _viewModel.Progeny = progeny;

            List <Progeny> progenyList = await ProgenyService.GetProgenyList(userEmail);

            _viewModel.ProgenyCollection.Clear();
            _viewModel.CanUserAddItems = false;
            foreach (Progeny prog in progenyList)
            {
                _viewModel.ProgenyCollection.Add(prog);
                if (prog.Admins.ToUpper().Contains(_viewModel.UserInfo.UserEmail.ToUpper()))
                {
                    _viewModel.CanUserAddItems = true;
                }
            }

            _viewModel.UserAccessLevel = await ProgenyService.GetAccessLevel(_viewModel.ViewChild);
        }
Exemple #15
0
        private async Task UpdateMeasurements()
        {
            _viewModel.IsBusy    = true;
            _viewModel.TodayDate = DateTime.Now;

            // _viewModel.MeasurementsList = await ProgenyService.GetMeasurementsList(_viewChild, _viewModel.UserAccessLevel, _userInfo.Timezone);

            List <Measurement> measurementsList = await ProgenyService.GetMeasurementsList(_viewModel.ViewChild, _viewModel.UserAccessLevel);

            if (measurementsList != null && measurementsList.Count > 0)
            {
                measurementsList = measurementsList.OrderBy(m => m.Date).ToList();
                LineSeries heightLineSeries = new LineSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = HeightLabel.Text
                };

                StairStepSeries heightStairStepSeries = new StairStepSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = HeightLabel.Text
                };

                StemSeries heightStemSeries = new StemSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = HeightLabel.Text
                };

                LineSeries weightLineSeries = new LineSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = WeightLabel.Text
                };

                StairStepSeries weightStairStepSeries = new StairStepSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = WeightLabel.Text
                };

                StemSeries weightStemSeries = new StemSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = WeightLabel.Text
                };

                double   maxHeight            = 0;
                double   maxWeight            = 0;
                double   minHeight            = 1000;
                double   minWeight            = 1000;
                DateTime firstMeasurementItem = _viewModel.EndDate;
                DateTime lastMeasurementItem  = _viewModel.StartDate;

                foreach (Measurement mes in measurementsList)
                {
                    if (mes.Date >= StartDatePicker.Date && mes.Date <= EndDatePicker.Date)
                    {
                        double dateDouble = DateTimeAxis.ToDouble(mes.Date.Date);
                        if (mes.Height > 0)
                        {
                            heightLineSeries.Points.Add(new DataPoint(dateDouble, mes.Height));
                            heightStairStepSeries.Points.Add(new DataPoint(dateDouble, mes.Height));
                            heightStemSeries.Points.Add(new DataPoint(dateDouble, mes.Height));
                            if (mes.Height > maxHeight)
                            {
                                maxHeight = mes.Height;
                            }

                            if (mes.Height < minHeight)
                            {
                                minHeight = mes.Height;
                            }
                        }

                        if (mes.Weight > 0)
                        {
                            weightLineSeries.Points.Add(new DataPoint(dateDouble, mes.Weight));
                            weightStairStepSeries.Points.Add(new DataPoint(dateDouble, mes.Weight));
                            weightStemSeries.Points.Add(new DataPoint(dateDouble, mes.Weight));
                            if (mes.Weight > maxWeight)
                            {
                                maxWeight = mes.Weight;
                            }

                            if (mes.Weight < minWeight)
                            {
                                minWeight = mes.Weight;
                            }
                        }
                    }
                    if (mes.Date < firstMeasurementItem)
                    {
                        firstMeasurementItem = mes.Date;
                    }

                    if (mes.Date > lastMeasurementItem)
                    {
                        lastMeasurementItem = mes.Date;
                    }
                }

                _viewModel.HeightMinValue = Math.Floor(minHeight);
                _viewModel.HeightMaxValue = Math.Ceiling(maxHeight);
                _viewModel.WeightMinValue = Math.Floor(minWeight);
                _viewModel.WeightMaxValue = Math.Ceiling(maxWeight);
                _viewModel.FirstDate      = firstMeasurementItem;
                _viewModel.LastDate       = lastMeasurementItem;

                LinearAxis heightAxis = new LinearAxis();
                heightAxis.Key                = "HeightAxis";
                heightAxis.Minimum            = _viewModel.HeightMinValue * 0.9;
                heightAxis.Maximum            = _viewModel.HeightMaxValue * 1.1;
                heightAxis.Position           = AxisPosition.Left;
                heightAxis.MajorStep          = 10;
                heightAxis.MinorStep          = 5;
                heightAxis.MajorGridlineStyle = LineStyle.Solid;
                heightAxis.MinorGridlineStyle = LineStyle.Solid;
                heightAxis.MajorGridlineColor = OxyColor.FromRgb(200, 190, 170);
                heightAxis.MinorGridlineColor = OxyColor.FromRgb(250, 225, 205);
                heightAxis.AxislineColor      = OxyColor.FromRgb(0, 0, 0);

                LinearAxis weightAxis = new LinearAxis();
                weightAxis.Key                = "WeightAxis";
                weightAxis.Minimum            = _viewModel.WeightMinValue * 0.9;
                weightAxis.Maximum            = _viewModel.WeightMaxValue * 1.1;
                weightAxis.Position           = AxisPosition.Left;
                weightAxis.MajorStep          = 2;
                weightAxis.MinorStep          = 1;
                weightAxis.MajorGridlineStyle = LineStyle.Solid;
                weightAxis.MinorGridlineStyle = LineStyle.Solid;
                weightAxis.MajorGridlineColor = OxyColor.FromRgb(200, 190, 170);
                weightAxis.MinorGridlineColor = OxyColor.FromRgb(250, 225, 205);
                weightAxis.AxislineColor      = OxyColor.FromRgb(0, 0, 0);

                DateTimeAxis dateAxis = new DateTimeAxis();
                dateAxis.Key                = "DateAxisHeight";
                dateAxis.Minimum            = DateTimeAxis.ToDouble(StartDatePicker.Date);
                dateAxis.Maximum            = DateTimeAxis.ToDouble(EndDatePicker.Date);
                dateAxis.Position           = AxisPosition.Bottom;
                dateAxis.AxislineColor      = OxyColor.FromRgb(0, 0, 0);
                dateAxis.StringFormat       = "dd-MMM-yyyy";
                dateAxis.MajorGridlineStyle = LineStyle.Solid;
                dateAxis.MajorGridlineColor = OxyColor.FromRgb(230, 190, 190);
                dateAxis.IntervalType       = DateTimeIntervalType.Auto;
                dateAxis.FirstDayOfWeek     = DayOfWeek.Monday;
                dateAxis.MinorIntervalType  = DateTimeIntervalType.Auto;

                DateTimeAxis dateAxisWeight = new DateTimeAxis();
                dateAxisWeight.Key                = "DateAxisWeight";
                dateAxisWeight.Minimum            = DateTimeAxis.ToDouble(StartDatePicker.Date);
                dateAxisWeight.Maximum            = DateTimeAxis.ToDouble(EndDatePicker.Date);
                dateAxisWeight.Position           = AxisPosition.Bottom;
                dateAxisWeight.AxislineColor      = OxyColor.FromRgb(0, 0, 0);
                dateAxisWeight.StringFormat       = "dd-MMM-yyyy";
                dateAxisWeight.MajorGridlineStyle = LineStyle.Solid;
                dateAxisWeight.MajorGridlineColor = OxyColor.FromRgb(230, 190, 190);
                dateAxisWeight.IntervalType       = DateTimeIntervalType.Auto;
                dateAxisWeight.FirstDayOfWeek     = DayOfWeek.Monday;
                dateAxisWeight.MinorIntervalType  = DateTimeIntervalType.Auto;

                _viewModel.PlotModelHeight            = new PlotModel();
                _viewModel.PlotModelHeight.Background = OxyColors.White;
                _viewModel.PlotModelHeight.Axes.Add(heightAxis);
                _viewModel.PlotModelHeight.Axes.Add(dateAxis);
                _viewModel.PlotModelHeight.LegendPosition   = LegendPosition.BottomCenter;
                _viewModel.PlotModelHeight.LegendBackground = OxyColors.LightYellow;

                _viewModel.PlotModelWeight            = new PlotModel();
                _viewModel.PlotModelWeight.Background = OxyColors.White;
                _viewModel.PlotModelWeight.Axes.Add(weightAxis);
                _viewModel.PlotModelWeight.Axes.Add(dateAxisWeight);
                _viewModel.PlotModelWeight.LegendPosition   = LegendPosition.BottomCenter;
                _viewModel.PlotModelWeight.LegendBackground = OxyColors.LightYellow;


                if (ChartTypePicker.SelectedIndex == 0)
                {
                    _viewModel.PlotModelHeight.Series.Add(heightLineSeries);
                    _viewModel.PlotModelWeight.Series.Add(weightLineSeries);
                }
                if (ChartTypePicker.SelectedIndex == 1)
                {
                    _viewModel.PlotModelHeight.Series.Add(heightStairStepSeries);
                    _viewModel.PlotModelWeight.Series.Add(weightStairStepSeries);
                }
                if (ChartTypePicker.SelectedIndex == 2)
                {
                    _viewModel.PlotModelHeight.Series.Add(heightStemSeries);
                    _viewModel.PlotModelWeight.Series.Add(weightStemSeries);
                }

                _viewModel.PlotModelHeight.InvalidatePlot(true);
                _viewModel.PlotModelWeight.InvalidatePlot(true);
            }


            _viewModel.IsBusy = false;
        }
        private async void SaveContactButton_OnClicked(object sender, EventArgs e)
        {
            Progeny progeny = ProgenyCollectionView.SelectedItem as Progeny;

            if (progeny == null)
            {
                return;
            }

            SaveContactButton.IsEnabled   = false;
            CancelContactButton.IsEnabled = false;
            _viewModel.IsBusy             = true;
            _viewModel.IsSaving           = true;

            Contact contact = new Contact();

            contact.ProgenyId   = progeny.Id;
            contact.AccessLevel = _viewModel.AccessLevel;
            string userEmail = await UserService.GetUserEmail();

            UserInfo userinfo = await UserService.GetUserInfo(userEmail);

            contact.Author          = userinfo.UserId;
            contact.FirstName       = FirstNameEntry?.Text ?? "";
            contact.MiddleName      = MiddleNameEntry?.Text ?? "";
            contact.LastName        = LastNameEntry?.Text ?? "";
            contact.DisplayName     = DisplayNameEntry?.Text ?? "";
            contact.AddressIdNumber = 0;
            contact.Email1          = Email1Entry?.Text ?? "";
            contact.Email2          = Email2Entry?.Text ?? "";
            contact.PhoneNumber     = PhoneNumberEntry?.Text ?? "";
            contact.MobileNumber    = MobileNumberEntry?.Text ?? "";
            contact.Website         = WebsiteEntry?.Text ?? "";
            contact.Context         = ContextEntry?.Text ?? "";
            contact.Notes           = NotesEditor?.Text ?? "";
            contact.Tags            = TagsEntry?.Text ?? "";
            contact.DateAdded       = ContactDatePicker.Date;
            contact.Active          = true;

            if (string.IsNullOrEmpty(_filePath) || !File.Exists(_filePath))
            {
                contact.PictureLink = Constants.DefaultPictureLink;
            }
            else
            {
                // Upload photo file, get a reference to the image.
                string pictureLink = await ProgenyService.UploadContactPicture(_filePath);

                if (pictureLink == "")
                {
                    SaveContactButton.IsEnabled   = true;
                    CancelContactButton.IsEnabled = true;
                    _viewModel.IsBusy             = false;
                    // Todo: Show error
                    return;
                }
                contact.PictureLink = pictureLink;
            }


            Address address = new Address();

            address.AddressLine1 = AddressLine1Entry.Text;
            address.AddressLine2 = AddressLine2Entry.Text;
            address.City         = CityEntry.Text;
            address.Country      = CountryEntry.Text;
            address.PostalCode   = PostalCodeEntry.Text;
            address.State        = StateEntry.Text;

            contact.Address = address;

            // Upload Contact object to add it to the database.
            Contact newContact = await ProgenyService.SaveContact(contact);

            _viewModel.IsBusy   = false;
            _viewModel.IsSaving = false;

            ErrorLabel.IsVisible = true;
            if (newContact.ContactId == 0)
            {
                var ci = CrossMultilingual.Current.CurrentCultureInfo;
                ErrorLabel.Text               = resmgr.Value.GetString("ErrorContactNotSaved", ci);
                ErrorLabel.BackgroundColor    = Color.Red;
                SaveContactButton.IsEnabled   = true;
                CancelContactButton.IsEnabled = true;
            }
            else
            {
                var ci = CrossMultilingual.Current.CurrentCultureInfo;
                ErrorLabel.Text                     = resmgr.Value.GetString("ContactSaved", ci) + newContact.ContactId;
                ErrorLabel.BackgroundColor          = Color.Green;
                SaveContactButton.IsVisible         = false;
                CancelContactButton.Text            = "Ok";
                CancelContactButton.BackgroundColor = Color.FromHex("#4caf50");
                CancelContactButton.IsEnabled       = true;
                await Shell.Current.Navigation.PopModalAsync();
            }
        }
Exemple #17
0
        public static async Task <List <MobileNotification> > GetNotificationsList(int count, int start, string language, bool readOnly)
        {
            bool online = ProgenyService.Online();

            if (online)
            {
                var client = new HttpClient();
                client.BaseAddress = new Uri(Constants.ProgenyApiUrl);

                string accessToken = await UserService.GetAuthAccessToken();

                if (String.IsNullOrEmpty(accessToken))
                {
                    return(new List <MobileNotification>());
                }
                else
                {
                    client.SetBearerToken(accessToken);

                    try
                    {
                        HttpResponseMessage result;
                        if (readOnly)
                        {
                            result = await client.GetAsync("api/notifications/unread/" + count + "/" + start + "/" + language).ConfigureAwait(false);
                        }
                        else
                        {
                            result = await client.GetAsync("api/notifications/latest/" + count + "/" + start + "/" + language).ConfigureAwait(false);
                        }

                        string userTimeZone = await GetUserTimezone();

                        if (result.IsSuccessStatusCode)
                        {
                            var notificationsString = await result.Content.ReadAsStringAsync();

                            List <MobileNotification> notificationsList = JsonConvert.DeserializeObject <List <MobileNotification> >(notificationsString);
                            if (notificationsList.Any())
                            {
                                foreach (MobileNotification notif in notificationsList)
                                {
                                    notif.Time = TimeZoneInfo.ConvertTimeFromUtc(notif.Time, TimeZoneInfo.FindSystemTimeZoneById(userTimeZone));
                                }
                            }

                            await SecureStorage.SetAsync("NotificationsList" + count + "start" + start + "lang" + language + "readonly" + readOnly, JsonConvert.SerializeObject(notificationsList));

                            return(notificationsList);
                        }
                        else
                        {
                            return(new List <MobileNotification>());
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                        return(new List <MobileNotification>());
                    }
                }
            }
            else
            {
                string notificationsString = await SecureStorage.GetAsync("NotificationsList" + count + "start" + start + "lang" + language + "readonly" + readOnly);

                if (string.IsNullOrEmpty(notificationsString))
                {
                    return(new List <MobileNotification>());
                }
                List <MobileNotification> notificationsList = JsonConvert.DeserializeObject <List <MobileNotification> >(notificationsString);
                return(notificationsList);
            }
        }
Exemple #18
0
        private async Task Reload()
        {
            _viewModel.IsBusy = true;
            await CheckAccount();

            List <Sleep> sleepList = await ProgenyService.GetSleepDetails(_viewModel.CurrentSleepId, _viewModel.UserAccessLevel, _userInfo.Timezone, 1);

            if (sleepList.Any())
            {
                _viewModel.CurrentSleep         = sleepList[0];
                _viewModel.AccessLevel          = _viewModel.CurrentSleep.AccessLevel;
                _viewModel.Rating               = _viewModel.CurrentSleep.SleepRating;
                _viewModel.CurrentSleep.Progeny = _viewModel.Progeny = await ProgenyService.GetProgeny(_viewModel.CurrentSleep.ProgenyId);

                _viewModel.Duration = _viewModel.CurrentSleep.SleepDuration;

                sleepList = sleepList.OrderByDescending(s => s.SleepStart).ToList();
                _viewModel.SleepItems.Add(sleepList[0]);
                _viewModel.SleepItems.Add(sleepList[1]);
                _viewModel.SleepItems.Add(sleepList[2]);

                _viewModel.StartYear    = _viewModel.CurrentSleep.SleepStart.Year;
                _viewModel.StartMonth   = _viewModel.CurrentSleep.SleepStart.Month;
                _viewModel.StartDay     = _viewModel.CurrentSleep.SleepStart.Day;
                _viewModel.StartHours   = _viewModel.CurrentSleep.SleepStart.Hour;
                _viewModel.StartMinutes = _viewModel.CurrentSleep.SleepStart.Minute;

                _viewModel.EndYear        = _viewModel.CurrentSleep.SleepEnd.Year;
                _viewModel.EndMonth       = _viewModel.CurrentSleep.SleepEnd.Month;
                _viewModel.EndDay         = _viewModel.CurrentSleep.SleepEnd.Day;
                _viewModel.EndHours       = _viewModel.CurrentSleep.SleepEnd.Hour;
                _viewModel.EndMinutes     = _viewModel.CurrentSleep.SleepEnd.Minute;
                SleepStartDatePicker.Date = new DateTime(_viewModel.CurrentSleep.SleepStart.Year, _viewModel.CurrentSleep.SleepStart.Month, _viewModel.CurrentSleep.SleepStart.Day);
                SleepStartTimePicker.Time = new TimeSpan(_viewModel.CurrentSleep.SleepStart.Hour, _viewModel.CurrentSleep.SleepStart.Minute, 0);
                SleepEndDatePicker.Date   = new DateTime(_viewModel.CurrentSleep.SleepEnd.Year, _viewModel.CurrentSleep.SleepEnd.Month, _viewModel.CurrentSleep.SleepEnd.Day);
                SleepEndTimePicker.Time   = new TimeSpan(_viewModel.CurrentSleep.SleepEnd.Hour, _viewModel.CurrentSleep.SleepEnd.Minute, 0);
            }

            _viewModel.UserAccessLevel = await ProgenyService.GetAccessLevel(_viewModel.CurrentSleep.ProgenyId);

            if (_viewModel.UserAccessLevel == 0)
            {
                _viewModel.CanUserEditItems = true;
            }
            else
            {
                _viewModel.CanUserEditItems = false;
            }

            var networkInfo = Connectivity.NetworkAccess;

            if (networkInfo == NetworkAccess.Internet)
            {
                // Connection to internet is available
                _online = true;
                OfflineStackLayout.IsVisible = false;
            }
            else
            {
                _online = false;
                OfflineStackLayout.IsVisible = true;
            }
            CalculateDuration();
            _viewModel.IsBusy = false;
        }
        private async void SaveNoteButton_OnClicked(object sender, EventArgs e)
        {
            if (ProgenyCollectionView.SelectedItem is Progeny progeny)
            {
                _viewModel.IsBusy   = true;
                _viewModel.IsSaving = true;
                Note saveNote = new Note();
                saveNote.ProgenyId   = progeny.Id;
                saveNote.AccessLevel = _viewModel.AccessLevel;
                saveNote.Progeny     = progeny;
                DateTime noteTime = new DateTime(NoteDatePicker.Date.Year, NoteDatePicker.Date.Month, NoteDatePicker.Date.Day, NoteTimePicker.Time.Hours, NoteTimePicker.Time.Minutes, 0);
                saveNote.CreatedDate = noteTime;

                string userEmail = await UserService.GetUserEmail();

                UserInfo userinfo = await UserService.GetUserInfo(userEmail);

                saveNote.Owner    = userinfo.UserId;
                saveNote.Title    = TitleEntry.Text;
                saveNote.Category = CategoryEntry.Text;
                string noteContent = await ContentWebView.EvaluateJavaScriptAsync("getContent()");

                noteContent      = noteContent.Replace(@"\u003C", "<"); // Todo: Proper string encoding/decoding.
                saveNote.Content = noteContent;
                // saveNote.Content = ContentEditor.Text;

                if (ProgenyService.Online())
                {
                    saveNote = await ProgenyService.SaveNote(saveNote);

                    _viewModel.IsBusy   = false;
                    _viewModel.IsSaving = false;
                    if (saveNote.NoteId == 0)
                    {
                        var ci = CrossMultilingual.Current.CurrentCultureInfo;
                        ErrorLabel.Text            = resmgr.Value.GetString("ErrorNoteNotSaved", ci);
                        ErrorLabel.BackgroundColor = Color.Red;
                    }
                    else
                    {
                        var ci = CrossMultilingual.Current.CurrentCultureInfo;
                        ErrorLabel.Text                  = resmgr.Value.GetString("NoteSaved", ci) + saveNote.NoteId;
                        ErrorLabel.BackgroundColor       = Color.Green;
                        SaveNoteButton.IsVisible         = false;
                        CancelNoteButton.Text            = "Ok";
                        CancelNoteButton.BackgroundColor = Color.FromHex("#4caf50");
                        await Shell.Current.Navigation.PopModalAsync();
                    }
                }
                else
                {
                    // Todo: Translate message.
                    ErrorLabel.Text            = $"Error: No internet connection. Measurement for {progeny.NickName} was not saved. Try again later.";
                    ErrorLabel.BackgroundColor = Color.Red;
                }

                _viewModel.IsBusy    = false;
                _viewModel.IsSaving  = false;
                ErrorLabel.IsVisible = true;
            }
        }
        private async Task Reload()
        {
            _viewModel.IsBusy = true;
            await CheckAccount();

            _viewModel.CurrentEvent =
                await ProgenyService.GetCalendarItem(_viewModel.CurrentEventId, _accessToken, _userInfo.Timezone);

            _viewModel.AccessLevel          = _viewModel.CurrentEvent.AccessLevel;
            _viewModel.CurrentEvent.Progeny = _viewModel.Progeny = await ProgenyService.GetProgeny(_viewModel.CurrentEvent.ProgenyId);

            if (_viewModel.CurrentEvent.StartTime.HasValue)
            {
                _viewModel.StartYear    = _viewModel.CurrentEvent.StartTime.Value.Year;
                _viewModel.StartMonth   = _viewModel.CurrentEvent.StartTime.Value.Month;
                _viewModel.StartDay     = _viewModel.CurrentEvent.StartTime.Value.Day;
                _viewModel.StartHours   = _viewModel.CurrentEvent.StartTime.Value.Hour;
                _viewModel.StartMinutes = _viewModel.CurrentEvent.StartTime.Value.Minute;

                if (_viewModel.CurrentEvent.EndTime.HasValue)
                {
                    _viewModel.EndYear        = _viewModel.CurrentEvent.EndTime.Value.Year;
                    _viewModel.EndMonth       = _viewModel.CurrentEvent.EndTime.Value.Month;
                    _viewModel.EndDay         = _viewModel.CurrentEvent.EndTime.Value.Day;
                    _viewModel.EndHours       = _viewModel.CurrentEvent.EndTime.Value.Hour;
                    _viewModel.EndMinutes     = _viewModel.CurrentEvent.EndTime.Value.Minute;
                    EventStartDatePicker.Date = new DateTime(_viewModel.StartYear, _viewModel.StartMonth, _viewModel.StartDay);
                    EventEndDatePicker.Date   = new DateTime(_viewModel.EndYear, _viewModel.EndMonth, _viewModel.EndDay);
                    EventStartTimePicker.Time = new TimeSpan(_viewModel.CurrentEvent.StartTime.Value.Hour, _viewModel.CurrentEvent.StartTime.Value.Minute, 0);
                    EventEndTimePicker.Time   = new TimeSpan(_viewModel.CurrentEvent.EndTime.Value.Hour, _viewModel.CurrentEvent.EndTime.Value.Minute, 0);
                }
            }

            _viewModel.UserAccessLevel = await ProgenyService.GetAccessLevel(_viewModel.CurrentEvent.ProgenyId);

            if (_viewModel.UserAccessLevel == 0)
            {
                _viewModel.CanUserEditItems = true;
            }
            else
            {
                _viewModel.CanUserEditItems = false;
            }

            _viewModel.AllDay     = _viewModel.CurrentEvent.AllDay;
            _viewModel.EventTitle = _viewModel.CurrentEvent.Title;
            _viewModel.Context    = _viewModel.CurrentEvent.Context;
            _viewModel.Location   = _viewModel.CurrentEvent.Location;
            _viewModel.Notes      = _viewModel.CurrentEvent.Notes;

            var networkInfo = Connectivity.NetworkAccess;

            if (networkInfo == NetworkAccess.Internet)
            {
                // Connection to internet is available
                _online = true;
                OfflineStackLayout.IsVisible = false;
            }
            else
            {
                _online = false;
                OfflineStackLayout.IsVisible = true;
            }

            _viewModel.IsBusy = false;
        }
        private async Task UpdateSleep()
        {
            _viewModel.IsBusy    = true;
            _viewModel.TodayDate = DateTime.Now;

            _viewModel.SleepStats =
                await ProgenyService.GetSleepStats(_viewModel.ViewChild, _viewModel.UserAccessLevel);

            if (_viewModel.SleepStats != null)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    _viewModel.SleepTotal       = _viewModel.SleepStats.SleepTotal;
                    _viewModel.TotalAverage     = _viewModel.SleepStats.TotalAverage;
                    _viewModel.SleepLastMonth   = _viewModel.SleepStats.SleepLastMonth;
                    _viewModel.LastMonthAverage = _viewModel.SleepStats.LastMonthAverage;
                    _viewModel.SleepLastYear    = _viewModel.SleepStats.SleepLastYear;
                    _viewModel.LastYearAverage  = _viewModel.SleepStats.LastYearAverage;
                });
            }


            List <Sleep> sleepList =
                await ProgenyService.GetSleepChartData(_viewModel.ViewChild, _viewModel.UserAccessLevel);

            _viewModel.SleepItems.ReplaceRange(sleepList);
            if (sleepList != null && sleepList.Count > 0)
            {
                LineSeries sleepLineSeries = new LineSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = this.Title
                };

                StairStepSeries sleepStairStepSeries = new StairStepSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = this.Title
                };

                StemSeries sleepStemSeries = new StemSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = this.Title
                };

                double   maxSleep       = 0;
                double   minSleep       = 24;
                DateTime firstSleepItem = _viewModel.EndDate;
                DateTime lastSleepItem  = _viewModel.StartDate;

                foreach (Sleep slp in _viewModel.SleepItems)
                {
                    if (slp.SleepStart >= StartDatePicker.Date && slp.SleepStart <= EndDatePicker.Date)
                    {
                        slp.SleepStart     = slp.SleepStart.Date;
                        slp.SleepDurDouble = slp.SleepDuration.TotalMinutes / 60.0;
                        double startDateDouble = DateTimeAxis.ToDouble(slp.SleepStart.Date);
                        sleepLineSeries.Points.Add(new DataPoint(startDateDouble, slp.SleepDurDouble));
                        sleepStairStepSeries.Points.Add(new DataPoint(startDateDouble, slp.SleepDurDouble));
                        sleepStemSeries.Points.Add(new DataPoint(startDateDouble, slp.SleepDurDouble));

                        if (slp.SleepDurDouble > maxSleep)
                        {
                            maxSleep = slp.SleepDurDouble;
                        }

                        if (slp.SleepDurDouble < minSleep)
                        {
                            minSleep = slp.SleepDurDouble;
                        }
                    }
                    if (slp.SleepStart < firstSleepItem)
                    {
                        firstSleepItem = slp.SleepStart;
                    }

                    if (slp.SleepStart > lastSleepItem)
                    {
                        lastSleepItem = slp.SleepStart;
                    }
                }

                if (sleepLineSeries.Points.Any())
                {
                    _viewModel.MinValue  = Math.Floor(minSleep);
                    _viewModel.MaxValue  = Math.Ceiling(maxSleep);
                    _viewModel.FirstDate = firstSleepItem;
                    _viewModel.LastDate  = lastSleepItem;

                    LinearAxis durationAxis = new LinearAxis();
                    durationAxis.Key                = "DurationAxis";
                    durationAxis.Minimum            = 0;                   //_viewModel.MinValue -1;
                    durationAxis.Maximum            = _viewModel.MaxValue; // + 1;
                    durationAxis.AbsoluteMinimum    = 0;                   //_viewModel.MinValue -1;
                    durationAxis.AbsoluteMaximum    = _viewModel.MaxValue; // + 1;
                    durationAxis.Position           = AxisPosition.Left;
                    durationAxis.MajorStep          = 1;
                    durationAxis.MinorStep          = 0.5;
                    durationAxis.MajorGridlineStyle = LineStyle.Solid;
                    durationAxis.MinorGridlineStyle = LineStyle.Solid;
                    durationAxis.MajorGridlineColor = OxyColor.FromRgb(200, 190, 170);
                    durationAxis.MinorGridlineColor = OxyColor.FromRgb(250, 225, 205);
                    durationAxis.AxislineColor      = OxyColor.FromRgb(0, 0, 0);

                    DateTimeAxis dateAxis = new DateTimeAxis();
                    dateAxis.Key                = "DateAxis";
                    dateAxis.Minimum            = DateTimeAxis.ToDouble(StartDatePicker.Date);
                    dateAxis.Maximum            = DateTimeAxis.ToDouble(EndDatePicker.Date);
                    dateAxis.AbsoluteMinimum    = DateTimeAxis.ToDouble(StartDatePicker.Date);
                    dateAxis.AbsoluteMaximum    = DateTimeAxis.ToDouble(EndDatePicker.Date);
                    dateAxis.Position           = AxisPosition.Bottom;
                    dateAxis.AxislineColor      = OxyColor.FromRgb(0, 0, 0);
                    dateAxis.StringFormat       = "dd-MMM-yyyy";
                    dateAxis.MajorGridlineStyle = LineStyle.Solid;
                    dateAxis.MajorGridlineColor = OxyColor.FromRgb(230, 190, 190);
                    dateAxis.IntervalType       = DateTimeIntervalType.Auto;
                    dateAxis.FirstDayOfWeek     = DayOfWeek.Monday;
                    dateAxis.MinorIntervalType  = DateTimeIntervalType.Auto;

                    _viewModel.SleepPlotModel            = new PlotModel();
                    _viewModel.SleepPlotModel.Background = OxyColors.White;
                    _viewModel.SleepPlotModel.Axes.Add(dateAxis);
                    _viewModel.SleepPlotModel.Axes.Add(durationAxis);

                    _viewModel.SleepPlotModel.LegendPosition   = LegendPosition.BottomCenter;
                    _viewModel.SleepPlotModel.LegendBackground = OxyColors.LightYellow;

                    Func <double, double> averageFunc = (x) => _viewModel.SleepStats.TotalAverage.TotalMinutes / 60.0;
                    _viewModel.SleepPlotModel.Series.Add(new FunctionSeries(averageFunc, dateAxis.Minimum, dateAxis.Maximum, (int)(dateAxis.Maximum - dateAxis.Minimum), AverageSleepTitle.Text));

                    Func <double, double> averageYearFunc = (x) => _viewModel.SleepStats.LastYearAverage.TotalMinutes / 60.0;
                    _viewModel.SleepPlotModel.Series.Add(new FunctionSeries(averageYearFunc, dateAxis.Minimum, dateAxis.Maximum, (int)(dateAxis.Maximum - dateAxis.Minimum), AverageSleepYearTitle.Text));

                    Func <double, double> averageMonthFunc = (x) => _viewModel.SleepStats.LastMonthAverage.TotalMinutes / 60.0;
                    _viewModel.SleepPlotModel.Series.Add(new FunctionSeries(averageMonthFunc, dateAxis.Minimum, dateAxis.Maximum, (int)(dateAxis.Maximum - dateAxis.Minimum), AverageSleepMonthTitle.Text));

                    if (ChartTypePicker.SelectedIndex == 0)
                    {
                        _viewModel.SleepPlotModel.Series.Add(sleepLineSeries);
                    }
                    if (ChartTypePicker.SelectedIndex == 1)
                    {
                        _viewModel.SleepPlotModel.Series.Add(sleepStairStepSeries);
                    }
                    if (ChartTypePicker.SelectedIndex == 2)
                    {
                        _viewModel.SleepPlotModel.Series.Add(sleepStemSeries);
                    }
                    _viewModel.SleepPlotModel.InvalidatePlot(true);
                }
            }

            _viewModel.IsBusy = false;
        }
Exemple #22
0
        private async void EditButton_OnClicked(object sender, EventArgs e)
        {
            if (_viewModel.EditMode)
            {
                _viewModel.EditMode = false;
                _viewModel.IsBusy   = true;
                _viewModel.IsSaving = true;

                _viewModel.CurrentContact.FirstName   = _viewModel.FirstName;
                _viewModel.CurrentContact.MiddleName  = _viewModel.MiddleName;
                _viewModel.CurrentContact.LastName    = _viewModel.LastName;
                _viewModel.CurrentContact.DisplayName = _viewModel.DisplayName;

                _viewModel.CurrentContact.AddressIdNumber = _viewModel.AddressIdNumber;
                Address address = new Address();
                address.AddressLine1 = _viewModel.AddressLine1;
                address.AddressLine2 = _viewModel.AddressLine2;
                address.City         = _viewModel.City;
                address.State        = _viewModel.State;
                address.PostalCode   = _viewModel.PostalCode;
                address.Country      = _viewModel.Country;
                address.AddressId    = _viewModel.AddressIdNumber;
                _viewModel.CurrentContact.Address = address;

                _viewModel.CurrentContact.Email1       = _viewModel.Email1;
                _viewModel.CurrentContact.Email2       = _viewModel.Email2;
                _viewModel.CurrentContact.PhoneNumber  = _viewModel.PhoneNumber;
                _viewModel.CurrentContact.MobileNumber = _viewModel.MobileNumber;
                _viewModel.CurrentContact.Website      = _viewModel.Website;
                _viewModel.CurrentContact.Notes        = _viewModel.Notes;

                _viewModel.CurrentContact.Context     = ContextEntry?.Text ?? "";
                _viewModel.CurrentContact.Tags        = TagsEntry?.Text ?? "";
                _viewModel.CurrentContact.AccessLevel = _viewModel.AccessLevel;
                _viewModel.CurrentContact.Active      = _viewModel.Active;

                DateTime contDate = new DateTime(_viewModel.DateYear, _viewModel.DateMonth, _viewModel.DateDay);
                _viewModel.CurrentContact.DateAdded = contDate;

                if (string.IsNullOrEmpty(_filePath) || !File.Exists(_filePath))
                {
                    _viewModel.CurrentContact.PictureLink = "[KeepExistingLink]";
                }
                else
                {
                    // Upload photo file, get a reference to the image.
                    string pictureLink = await ProgenyService.UploadContactPicture(_filePath);

                    if (pictureLink == "")
                    {
                        _viewModel.IsBusy = false;
                        // Todo: Show error
                        _viewModel.CurrentContact.PictureLink = "[KeepExistingLink]";
                        return;
                    }
                    _viewModel.CurrentContact.PictureLink = pictureLink;
                }
                // Save changes.
                Contact resultContact = await ProgenyService.UpdateContact(_viewModel.CurrentContact);

                _viewModel.IsBusy   = false;
                _viewModel.IsSaving = false;
                EditButton.Text     = IconFont.CalendarEdit;
                if (resultContact != null)  // Todo: Error message if update fails.
                {
                    await Reload();
                }
            }
            else
            {
                EditButton.Text = IconFont.ContentSave;

                _viewModel.EditMode            = true;
                _viewModel.TagsAutoSuggestList = await ProgenyService.GetTagsAutoSuggestList(_viewModel.CurrentContact.ProgenyId, 0);

                _viewModel.ContextAutoSuggestList = await ProgenyService.GetContextAutoSuggestList(_viewModel.CurrentContact.ProgenyId, 0);
            }
        }
        private async Task Reload()
        {
            _myChildrenViewModel.IsBusy   = true;
            _myChildrenViewModel.EditMode = false;
            _myChildrenViewModel.ProgenyAdminCollection.Clear();
            await CheckAccount();

            await ProgenyService.GetProgenyList(await UserService.GetUserEmail());

            List <Progeny> progenyList = await ProgenyService.GetProgenyAdminList();

            if (progenyList.Any())
            {
                _myChildrenViewModel.AnyChildren = true;
                foreach (Progeny progeny in progenyList)
                {
                    try
                    {
                        TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone);
                    }
                    catch (Exception)
                    {
                        progeny.TimeZone = TZConvert.WindowsToIana(progeny.TimeZone);
                    }
                    _myChildrenViewModel.ProgenyAdminCollection.Add(progeny);
                }

                if (_selectedProgenyId == 0)
                {
                    string userviewchild = await SecureStorage.GetAsync(Constants.UserViewChildKey);

                    bool    viewchildParsed = int.TryParse(userviewchild, out int viewChild);
                    Progeny viewProgeny     = new Progeny();
                    if (viewchildParsed)
                    {
                        viewProgeny = _myChildrenViewModel.ProgenyAdminCollection.SingleOrDefault(p => p.Id == viewChild);
                    }

                    if (viewProgeny != null)
                    {
                        ProgenyCollectionView.SelectedItem =
                            _myChildrenViewModel.ProgenyAdminCollection.SingleOrDefault(p => p.Id == viewChild);
                        ProgenyCollectionView.ScrollTo(ProgenyCollectionView.SelectedItem);
                    }
                    else
                    {
                        ProgenyCollectionView.SelectedItem = _myChildrenViewModel.ProgenyAdminCollection[0];
                    }
                }
                else
                {
                    ProgenyCollectionView.SelectedItem =
                        _myChildrenViewModel.ProgenyAdminCollection.SingleOrDefault(p => p.Id == _selectedProgenyId);
                    ProgenyCollectionView.ScrollTo(ProgenyCollectionView.SelectedItem);
                }

                _myChildrenViewModel.Progeny = (Progeny)ProgenyCollectionView.SelectedItem;
                if (_myChildrenViewModel.Progeny.BirthDay.HasValue)
                {
                    _myChildrenViewModel.ProgenyBirthDay = _myChildrenViewModel.Progeny.BirthDay.Value;
                    // BirthdayDatePicker.Date = _myChildrenViewModel.Progeny.BirthDay.Value.Date;
                    // BirthdayTimePicker.Time = _myChildrenViewModel.Progeny.BirthDay.Value.TimeOfDay;
                }

                _selectedProgenyId = _myChildrenViewModel.Progeny.Id;

                TimeZoneInfo progenyTimeZoneInfo = _myChildrenViewModel.TimeZoneList.SingleOrDefault(tz => tz.DisplayName == _myChildrenViewModel.Progeny.TimeZone);
                if (progenyTimeZoneInfo == null)
                {
                    progenyTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(_myChildrenViewModel.Progeny.TimeZone);
                }
                _myChildrenViewModel.SelectedTimeZone = progenyTimeZoneInfo;
                //int timeZoneIndex = _myChildrenViewModel.TimeZoneList.IndexOf(progenyTimeZoneInfo);
                //TimeZonePicker.SelectedIndex = timeZoneIndex;
            }
            else
            {
                _myChildrenViewModel.AnyChildren = false;
            }

            _filePath = "";

            _myChildrenViewModel.IsBusy = false;
        }
        private async Task UpdateVocabulary()
        {
            _viewModel.IsBusy    = true;
            _viewModel.TodayDate = DateTime.Now;


            List <VocabularyItem> vocabularyList =
                await ProgenyService.GetVocabularyList(_viewModel.ViewChild, _viewModel.UserAccessLevel, _viewModel.UserInfo.Timezone);

            _viewModel.VocabularyItems.ReplaceRange(vocabularyList);
            if (vocabularyList != null && vocabularyList.Count > 0)
            {
                vocabularyList = vocabularyList.OrderBy(v => v.Date).ToList();
                List <WordDateCount> dateTimesList = new List <WordDateCount>();
                int wordCount = 0;
                foreach (VocabularyItem vocabularyItem in vocabularyList)
                {
                    wordCount++;
                    if (vocabularyItem.Date != null)
                    {
                        if (dateTimesList.SingleOrDefault(d => d.WordDate.Date == vocabularyItem.Date.Value.Date) == null)
                        {
                            WordDateCount newDate = new WordDateCount();
                            newDate.WordDate  = vocabularyItem.Date.Value.Date;
                            newDate.WordCount = wordCount;
                            dateTimesList.Add(newDate);
                        }
                        else
                        {
                            WordDateCount wrdDateCount = dateTimesList.SingleOrDefault(d => d.WordDate.Date == vocabularyItem.Date.Value.Date);
                            if (wrdDateCount != null)
                            {
                                wrdDateCount.WordCount = wordCount;
                            }
                        }
                    }
                }

                LineSeries vocabularyLineSeries = new LineSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = this.Title
                };

                StairStepSeries vocabularyStairStepSeries = new StairStepSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = this.Title
                };

                StemSeries vocabularyStemSeries = new StemSeries()
                {
                    Color                 = OxyColors.DarkGreen,
                    MarkerType            = MarkerType.Circle,
                    MarkerSize            = 3,
                    MarkerStroke          = OxyColors.White,
                    MarkerFill            = OxyColors.Green,
                    MarkerStrokeThickness = 1.5,
                    Title                 = this.Title
                };

                double   maxCount      = 0;
                double   minCount      = 100000;
                DateTime firstWordDate = _viewModel.EndDate;
                DateTime lastWordDate  = _viewModel.StartDate;

                foreach (WordDateCount wordDateCount in dateTimesList)
                {
                    if (wordDateCount.WordDate >= StartDatePicker.Date && wordDateCount.WordDate <= EndDatePicker.Date)
                    {
                        double wordDateDouble = DateTimeAxis.ToDouble(wordDateCount.WordDate.Date);
                        vocabularyLineSeries.Points.Add(new DataPoint(wordDateDouble, wordDateCount.WordCount));
                        vocabularyStairStepSeries.Points.Add(new DataPoint(wordDateDouble, wordDateCount.WordCount));
                        vocabularyStemSeries.Points.Add(new DataPoint(wordDateDouble, wordDateCount.WordCount));

                        if (wordDateCount.WordCount > maxCount)
                        {
                            maxCount = wordDateCount.WordCount;
                        }

                        if (wordDateCount.WordCount < minCount)
                        {
                            minCount = wordDateCount.WordCount;
                        }
                    }
                    if (wordDateCount.WordDate < firstWordDate)
                    {
                        firstWordDate = wordDateCount.WordDate;
                    }

                    if (wordDateCount.WordDate > lastWordDate)
                    {
                        lastWordDate = wordDateCount.WordDate;
                    }
                }

                _viewModel.MinValue  = Math.Floor(minCount);
                _viewModel.MaxValue  = Math.Ceiling(maxCount);
                _viewModel.FirstDate = firstWordDate;
                _viewModel.LastDate  = lastWordDate;

                LinearAxis wordCountAxis = new LinearAxis();
                wordCountAxis.Key                = "WordCountAxis";
                wordCountAxis.Minimum            = 0;                   //_viewModel.MinValue -1;
                wordCountAxis.Maximum            = _viewModel.MaxValue; // + 1;
                wordCountAxis.Position           = AxisPosition.Left;
                wordCountAxis.MajorStep          = 10;
                wordCountAxis.MinorStep          = 5;
                wordCountAxis.MajorGridlineStyle = LineStyle.Solid;
                wordCountAxis.MinorGridlineStyle = LineStyle.Solid;
                wordCountAxis.MajorGridlineColor = OxyColor.FromRgb(200, 190, 170);
                wordCountAxis.MinorGridlineColor = OxyColor.FromRgb(250, 225, 205);
                wordCountAxis.AxislineColor      = OxyColor.FromRgb(0, 0, 0);

                DateTimeAxis dateAxis = new DateTimeAxis();
                dateAxis.Key                = "DateAxis";
                dateAxis.Minimum            = DateTimeAxis.ToDouble(StartDatePicker.Date);
                dateAxis.Maximum            = DateTimeAxis.ToDouble(EndDatePicker.Date);
                dateAxis.Position           = AxisPosition.Bottom;
                dateAxis.AxislineColor      = OxyColor.FromRgb(0, 0, 0);
                dateAxis.StringFormat       = "dd-MMM-yyyy";
                dateAxis.MajorGridlineStyle = LineStyle.Solid;
                dateAxis.MajorGridlineColor = OxyColor.FromRgb(230, 190, 190);
                dateAxis.IntervalType       = DateTimeIntervalType.Auto;
                dateAxis.FirstDayOfWeek     = DayOfWeek.Monday;
                dateAxis.MinorIntervalType  = DateTimeIntervalType.Auto;

                _viewModel.VocabularyPlotModel            = new PlotModel();
                _viewModel.VocabularyPlotModel.Background = OxyColors.White;
                _viewModel.VocabularyPlotModel.Axes.Add(wordCountAxis);
                _viewModel.VocabularyPlotModel.Axes.Add(dateAxis);
                _viewModel.VocabularyPlotModel.LegendPosition   = LegendPosition.TopLeft;
                _viewModel.VocabularyPlotModel.LegendBackground = OxyColors.LightYellow;

                if (ChartTypePicker.SelectedIndex == 0)
                {
                    _viewModel.VocabularyPlotModel.Series.Add(vocabularyLineSeries);
                }
                if (ChartTypePicker.SelectedIndex == 1)
                {
                    _viewModel.VocabularyPlotModel.Series.Add(vocabularyStairStepSeries);
                }
                if (ChartTypePicker.SelectedIndex == 2)
                {
                    _viewModel.VocabularyPlotModel.Series.Add(vocabularyStemSeries);
                }

                _viewModel.VocabularyPlotModel.InvalidatePlot(true);
            }


            _viewModel.IsBusy = false;
        }
        private async Task Reload()
        {
            _reload = false;
            var networkInfo = Connectivity.NetworkAccess;

            string userTimeZone = await UserService.GetUserTimezone();

            if (string.IsNullOrEmpty(userTimeZone))
            {
                userTimeZone = Constants.DefaultTimeZone;
            }

            try
            {
                TimeZoneInfo.FindSystemTimeZoneById(userTimeZone);
            }
            catch (Exception)
            {
                userTimeZone = TZConvert.WindowsToIana(userTimeZone);
            }

            TimeZoneInfo userTimeZoneInfo =
                _viewModel.TimeZoneList.SingleOrDefault(tz => tz.DisplayName == userTimeZone);

            if (userTimeZoneInfo == null)
            {
                userTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(userTimeZone);
            }

            int timeZoneIndex = _viewModel.TimeZoneList.IndexOf(userTimeZoneInfo);

            TimeZonePicker.SelectedIndex = timeZoneIndex;

            if (networkInfo == NetworkAccess.Internet)
            {
                // Connection to internet is available
                _online = true;
                OfflineStackLayout.IsVisible = false;
                LogInButton.IsEnabled        = true;
                LogOutButton.IsEnabled       = true;
                _viewModel.EditMode          = false;
                FullNameEntry.IsVisible      = true;
                _viewModel.Username          = await UserService.GetUsername();

                _viewModel.FullName = await UserService.GetFullname();

                _viewModel.Email = await UserService.GetUserEmail();

                _viewModel.Timezone = await UserService.GetUserTimezone();

                _viewModel.UserId = await UserService.GetUserId();

                UserInfo userInfo = await UserService.GetUserInfo(_viewModel.Email);

                if (!string.IsNullOrEmpty(userInfo.ProfilePicture))
                {
                    _viewModel.ProfilePicture = await UserService.GetUserPicture(userInfo.ProfilePicture);
                }
                else
                {
                    _viewModel.ProfilePicture = Constants.ProfilePicture;
                }

                ProfileImage.Source = _viewModel.ProfilePicture;

                _viewModel.FirstName  = userInfo.FirstName;
                _viewModel.MiddleName = userInfo.MiddleName;
                _viewModel.LastName   = userInfo.LastName;

                bool accessTokenCurrent = await UserService.IsAccessTokenCurrent();

                string accessToken = await UserService.GetAuthAccessToken();

                if (String.IsNullOrEmpty(accessToken) || !accessTokenCurrent)
                {
                    _viewModel.LoggedIn = false;
                }
                else
                {
                    _viewModel.LoggedIn = true;
                }

                List <Progeny> progenyList = await ProgenyService.GetProgenyList(_viewModel.Email);

                _viewModel.ProgenyCollection.Clear();
                foreach (Progeny prog in progenyList)
                {
                    _viewModel.ProgenyCollection.Add(prog);
                }
            }
            else
            {
                _online = false;
                OfflineStackLayout.IsVisible = true;
                LogInButton.IsEnabled        = false;
                LogOutButton.IsEnabled       = false;
            }
        }
Exemple #26
0
        private async void SaveFriendButton_OnClicked(object sender, EventArgs e)
        {
            Progeny progeny = ProgenyCollectionView.SelectedItem as Progeny;

            if (progeny == null)
            {
                return;
            }

            SaveFriendButton.IsEnabled   = false;
            CancelFriendButton.IsEnabled = false;
            _viewModel.IsBusy            = true;
            _viewModel.IsSaving          = true;


            Friend friend = new Friend();

            friend.ProgenyId   = progeny.Id;
            friend.AccessLevel = _viewModel.AccessLevel;
            string userEmail = await UserService.GetUserEmail();

            UserInfo userinfo = await UserService.GetUserInfo(userEmail);

            friend.Author          = userinfo.UserId;
            friend.Context         = ContextEntry?.Text ?? "";
            friend.Description     = DescriptionEditor?.Text ?? "";
            friend.FriendAddedDate = DateTime.Now;
            friend.FriendSince     = FriendSinceDatePicker.Date;
            friend.Name            = NameEntry.Text;
            friend.Notes           = NotesEditor?.Text ?? "";
            friend.Tags            = TagsEntry?.Text ?? "";
            friend.Type            = FriendTypePicker?.SelectedIndex ?? 0;

            if (string.IsNullOrEmpty(_filePath) || !File.Exists(_filePath))
            {
                friend.PictureLink = Constants.DefaultPictureLink;
            }
            else
            {
                // Upload photo file, get a reference to the image.
                string pictureLink = await ProgenyService.UploadFriendPicture(_filePath);

                if (pictureLink == "")
                {
                    SaveFriendButton.IsEnabled   = true;
                    CancelFriendButton.IsEnabled = true;
                    _viewModel.IsBusy            = false;
                    // Todo: Show error
                    return;
                }
                friend.PictureLink = pictureLink;
            }


            // Upload Friend object to add it to the database.

            Friend newFriend = await ProgenyService.SaveFriend(friend);

            _viewModel.IsBusy   = false;
            _viewModel.IsSaving = false;

            ErrorLabel.IsVisible = true;
            if (newFriend.FriendId == 0)
            {
                var ci = CrossMultilingual.Current.CurrentCultureInfo;
                ErrorLabel.Text              = resmgr.Value.GetString("ErrorFriendNotSaved", ci);
                ErrorLabel.BackgroundColor   = Color.Red;
                SaveFriendButton.IsEnabled   = true;
                CancelFriendButton.IsEnabled = true;
            }
            else
            {
                var ci = CrossMultilingual.Current.CurrentCultureInfo;
                ErrorLabel.Text                    = resmgr.Value.GetString("FriendSaved", ci) + newFriend.FriendId;
                ErrorLabel.BackgroundColor         = Color.Green;
                SaveFriendButton.IsVisible         = false;
                CancelFriendButton.Text            = "Ok";
                CancelFriendButton.BackgroundColor = Color.FromHex("#4caf50");
                CancelFriendButton.IsEnabled       = true;
                await Shell.Current.Navigation.PopModalAsync();
            }
        }
        private async Task CheckAccount()
        {
            string userEmail = await UserService.GetUserEmail();

            _accessToken = await UserService.GetAuthAccessToken();

            bool accessTokenCurrent = false;

            if (_accessToken != "")
            {
                accessTokenCurrent = await UserService.IsAccessTokenCurrent();

                if (!accessTokenCurrent)
                {
                    bool loginSuccess = await UserService.LoginIdsAsync();

                    if (loginSuccess)
                    {
                        _accessToken = await UserService.GetAuthAccessToken();

                        accessTokenCurrent = true;
                    }

                    await Reload();
                }
            }

            if (String.IsNullOrEmpty(_accessToken) || !accessTokenCurrent)
            {
                _myChildrenViewModel.IsLoggedIn = false;
                _myChildrenViewModel.LoggedOut  = true;
                EditButton.IsVisible            = false;
                _accessToken = "";
                _userInfo    = OfflineDefaultData.DefaultUserInfo;
            }
            else
            {
                _myChildrenViewModel.IsLoggedIn = true;
                _myChildrenViewModel.LoggedOut  = false;
                EditButton.IsVisible            = true;
                _userInfo = await UserService.GetUserInfo(userEmail);
            }

            string userviewchild = await SecureStorage.GetAsync(Constants.UserViewChildKey);

            bool viewchildParsed = int.TryParse(userviewchild, out _viewChild);

            if (!viewchildParsed)
            {
                _viewChild = _userInfo.ViewChild;
            }
            if (_viewChild == 0)
            {
                if (_userInfo.ViewChild != 0)
                {
                    _viewChild = _userInfo.ViewChild;
                }
                else
                {
                    _viewChild = Constants.DefaultChildId;
                }
            }

            if (String.IsNullOrEmpty(_userInfo.Timezone))
            {
                _userInfo.Timezone = Constants.DefaultTimeZone;
            }
            try
            {
                TimeZoneInfo.FindSystemTimeZoneById(_userInfo.Timezone);
            }
            catch (Exception)
            {
                _userInfo.Timezone = TZConvert.WindowsToIana(_userInfo.Timezone);
            }

            Progeny progeny = await ProgenyService.GetProgeny(_viewChild);

            try
            {
                TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone);
            }
            catch (Exception)
            {
                progeny.TimeZone = TZConvert.WindowsToIana(progeny.TimeZone);
            }
            _myChildrenViewModel.Progeny = progeny;

            List <Progeny> progenyList = await ProgenyService.GetProgenyList(userEmail);

            _myChildrenViewModel.ProgenyCollection.Clear();
            _myChildrenViewModel.CanUserAddItems = false;
            foreach (Progeny prog in progenyList)
            {
                _myChildrenViewModel.ProgenyCollection.Add(prog);
                if (prog.Admins.ToUpper().Contains(_userInfo.UserEmail.ToUpper()))
                {
                    _myChildrenViewModel.CanUserAddItems = true;
                }
            }

            _myChildrenViewModel.UserAccessLevel = await ProgenyService.GetAccessLevel(_viewChild);
        }
Exemple #28
0
        private async void SavePhotoButton_OnClicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_filePath) || !(ProgenyCollectionView.SelectedItem is Progeny progeny))
            {
                return;
            }

            if (!File.Exists(_filePath))
            {
                return;
            }

            SavePhotoButton.IsEnabled   = false;
            CancelPhotoButton.IsEnabled = false;
            _addPhotoViewModel.IsBusy   = true;
            _addPhotoViewModel.IsSaving = true;
            // Upload photo file, get a reference to the image.
            string pictureLink = await ProgenyService.UploadPictureFile(progeny.Id, _filePath);

            if (pictureLink == "")
            {
                SavePhotoButton.IsEnabled   = true;
                CancelPhotoButton.IsEnabled = true;
                _addPhotoViewModel.IsBusy   = false;
                return;
            }
            // Upload Picture object to add it to the database.
            Picture picture = new Picture();

            picture.PictureLink = pictureLink;
            picture.ProgenyId   = progeny.Id;
            picture.AccessLevel = _addPhotoViewModel.AccessLevel;
            string userEmail = await UserService.GetUserEmail();

            UserInfo userinfo = await UserService.GetUserInfo(userEmail);

            picture.Author   = userinfo.UserId;
            picture.Owners   = userEmail;
            picture.TimeZone = userinfo.Timezone;
            picture.Tags     = TagsEntry.Text;
            picture.Location = LocationEntry.Text;

            Picture newPicture = await ProgenyService.SavePicture(picture);

            if (newPicture.PictureId != 0)
            {
                TimeLineItem tItem = new TimeLineItem();
                tItem.ProgenyId   = newPicture.ProgenyId;
                tItem.AccessLevel = newPicture.AccessLevel;
                tItem.ItemType    = (int)KinaUnaTypes.TimeLineType.Photo;
                tItem.ItemId      = newPicture.PictureId.ToString();
                tItem.CreatedBy   = userinfo.UserId;
                tItem.CreatedTime = DateTime.UtcNow;
                if (newPicture.PictureTime.HasValue)
                {
                    tItem.ProgenyTime = newPicture.PictureTime.Value;
                }
                else
                {
                    tItem.ProgenyTime = DateTime.UtcNow;
                }

                await ProgenyService.SaveTimeLineItem(tItem);
            }
            _addPhotoViewModel.IsBusy   = false;
            _addPhotoViewModel.IsSaving = false;

            ErrorLabel.IsVisible = true;
            if (newPicture.PictureId == 0)
            {
                var ci = CrossMultilingual.Current.CurrentCultureInfo;
                ErrorLabel.Text             = resmgr.Value.GetString("ErrorPhotoNotSaved", ci);
                ErrorLabel.BackgroundColor  = Color.Red;
                SavePhotoButton.IsEnabled   = true;
                CancelPhotoButton.IsEnabled = true;
            }
            else
            {
                var ci = CrossMultilingual.Current.CurrentCultureInfo;
                ErrorLabel.Text                   = resmgr.Value.GetString("PhotoSaved", ci) + newPicture.PictureId;
                ErrorLabel.BackgroundColor        = Color.Green;
                SavePhotoButton.IsVisible         = false;
                CancelPhotoButton.Text            = "Ok";
                CancelPhotoButton.BackgroundColor = Color.FromHex("#4caf50");
                CancelPhotoButton.IsEnabled       = true;
                await Shell.Current.Navigation.PopModalAsync();
            }
        }
        private async void EditButton_OnClicked(object sender, EventArgs e)
        {
            if (_myChildrenViewModel.EditMode)
            {
                _myChildrenViewModel.EditMode = false;
                _myChildrenViewModel.IsBusy   = true;

                // Save changes.
                Progeny updatedProgeny = new Progeny();
                updatedProgeny.Id       = _myChildrenViewModel.Progeny.Id;
                updatedProgeny.Name     = NameEntry.Text;
                updatedProgeny.NickName = DisplayNameEntry.Text;
                TimeZoneInfo timeZoneInfo = (TimeZoneInfo)TimeZonePicker.SelectedItem;
                string       timeZoneName;
                if (TZConvert.TryIanaToWindows(timeZoneInfo.Id, out timeZoneName))
                {
                    updatedProgeny.TimeZone = timeZoneName;
                }
                else
                {
                    updatedProgeny.TimeZone = "Romance Standard Time";
                }

                if (!string.IsNullOrEmpty(_filePath))
                {
                    updatedProgeny.PictureLink = await ProgenyService.UploadProgenyPicture(_filePath);
                }

                string[] admins           = AdministratorsEntry.Text.Split(',');
                bool     validAdminEmails = true;
                foreach (string str in admins)
                {
                    if (!str.Trim().IsValidEmail())
                    {
                        validAdminEmails = false;
                    }
                }

                if (validAdminEmails)
                {
                    updatedProgeny.Admins = AdministratorsEntry.Text;
                }

                DateTime newBirthDay = new DateTime(BirthdayDatePicker.Date.Year, BirthdayDatePicker.Date.Month, BirthdayDatePicker.Date.Day, BirthdayTimePicker.Time.Hours, BirthdayTimePicker.Time.Minutes, 0);
                updatedProgeny.BirthDay = newBirthDay;

                Progeny resultProgeny = await ProgenyService.UpdateProgeny(updatedProgeny);

                _myChildrenViewModel.IsBusy = false;
                EditButton.Text             = IconFont.AccountEdit;
                if (resultProgeny != null)
                {
                    MessageLabel.Text      = "Profile saved.";
                    MessageLabel.IsVisible = true;
                    await Reload();
                }
            }
            else
            {
                EditButton.Text = IconFont.ContentSave;

                _myChildrenViewModel.EditMode = true;
            }
        }
Exemple #30
0
        private async Task Reload()
        {
            _viewModel.IsBusy = true;
            await CheckAccount();

            _viewModel.CurrentContact =
                await ProgenyService.GetContact(_viewModel.CurrentContactId, _accessToken);

            _viewModel.AccessLevel            = _viewModel.CurrentContact.AccessLevel;
            _viewModel.CurrentContact.Progeny = _viewModel.Progeny = await ProgenyService.GetProgeny(_viewModel.CurrentContact.ProgenyId);

            _viewModel.UserAccessLevel = await ProgenyService.GetAccessLevel(_viewModel.CurrentContact.ProgenyId);

            if (_viewModel.UserAccessLevel == 0)
            {
                _viewModel.CanUserEditItems = true;
            }
            else
            {
                _viewModel.CanUserEditItems = false;
            }

            _viewModel.Date = _viewModel.CurrentContact.DateAdded;
            if (_viewModel.Date.HasValue)
            {
                _viewModel.DateYear  = _viewModel.Date.Value.Year;
                _viewModel.DateMonth = _viewModel.Date.Value.Month;
                _viewModel.DateDay   = _viewModel.Date.Value.Day;
            }

            _viewModel.CurrentContactId = _viewModel.CurrentContact.ContactId;
            _viewModel.AccessLevel      = _viewModel.CurrentContact.AccessLevel;
            _viewModel.FirstName        = _viewModel.CurrentContact.FirstName;
            _viewModel.MiddleName       = _viewModel.CurrentContact.MiddleName;
            _viewModel.LastName         = _viewModel.CurrentContact.LastName;
            _viewModel.DisplayName      = _viewModel.CurrentContact.DisplayName;
            _viewModel.AddressIdNumber  = 0;
            if (_viewModel.CurrentContact.Address != null)
            {
                if (_viewModel.CurrentContact.AddressIdNumber != null)
                {
                    _viewModel.AddressIdNumber = _viewModel.CurrentContact.AddressIdNumber.Value;
                }
                _viewModel.AddressLine1 = _viewModel.CurrentContact.Address.AddressLine1;
                _viewModel.AddressLine2 = _viewModel.CurrentContact.Address.AddressLine2;
                _viewModel.City         = _viewModel.CurrentContact.Address.City;
                _viewModel.State        = _viewModel.CurrentContact.Address.State;
                _viewModel.PostalCode   = _viewModel.CurrentContact.Address.PostalCode;
                _viewModel.Country      = _viewModel.CurrentContact.Address.Country;
            }
            _viewModel.Email1       = _viewModel.CurrentContact.Email1;
            _viewModel.Email2       = _viewModel.CurrentContact.Email2;
            _viewModel.PhoneNumber  = _viewModel.CurrentContact.PhoneNumber;
            _viewModel.MobileNumber = _viewModel.CurrentContact.MobileNumber;
            _viewModel.Website      = _viewModel.CurrentContact.Website;
            _viewModel.Context      = _viewModel.CurrentContact.Context;
            _viewModel.Notes        = _viewModel.CurrentContact.Notes;
            _viewModel.Tags         = _viewModel.CurrentContact.Tags;
            _viewModel.Active       = _viewModel.CurrentContact.Active;
            ContactImage.Source     = _viewModel.CurrentContact.PictureLink;

            var networkInfo = Connectivity.NetworkAccess;

            if (networkInfo == NetworkAccess.Internet)
            {
                // Connection to internet is available
                _online = true;
                OfflineStackLayout.IsVisible = false;
            }
            else
            {
                _online = false;
                OfflineStackLayout.IsVisible = true;
            }

            _viewModel.IsBusy = false;
        }