Esempio n. 1
0
        private async void ContentWebView_OnFocused(object sender, FocusEventArgs e)
        {
            string heightString = await ContentWebView.EvaluateJavaScriptAsync("getHeight()");

            bool heightParsed = double.TryParse(heightString, out _webViewHeight);

            if (heightParsed)
            {
                ContentWebView.HeightRequest = _webViewHeight + 25.0;
            }
        }
Esempio n. 2
0
        private async void ContentWebView_OnNavigating(object sender, WebNavigatingEventArgs e)
        {
            e.Cancel = true;
            string heightString = await ContentWebView.EvaluateJavaScriptAsync("getHeight()");

            bool heightParsed = double.TryParse(heightString, out _webViewHeight);

            if (heightParsed)
            {
                ContentWebView.HeightRequest = _webViewHeight + 25.0;
            }
        }
        private async void EditButton_OnClicked(object sender, EventArgs e)
        {
            if (_viewModel.EditMode)
            {
                _viewModel.EditMode = false;
                _viewModel.IsBusy   = true;
                _viewModel.IsSaving = true;

                DateTime noteDate = new DateTime(_viewModel.DateYear, _viewModel.DateMonth, _viewModel.DateDay, _viewModel.DateHours, _viewModel.DateMinutes, 0);
                _viewModel.CurrentNote.CreatedDate = noteDate;
                _viewModel.CurrentNote.Title       = _viewModel.NoteTitle;
                string noteContent = await ContentWebView.EvaluateJavaScriptAsync("getContent()");

                noteContent = noteContent.Replace(@"\u003C", "<"); // Todo: Proper string encoding/decoding.
                _viewModel.CurrentNote.Content     = noteContent;
                _viewModel.CurrentNote.Category    = CategoryEntry.Text;
                _viewModel.CurrentNote.AccessLevel = _viewModel.AccessLevel;

                // Save changes.
                Note resultNote = await ProgenyService.UpdateNote(_viewModel.CurrentNote);

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

                HtmlWebViewSource htmlSource = new HtmlWebViewSource();
                // htmlSource.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
                htmlSource.Html = DependencyService.Get <IBaseUrl>().GetQuillHtml().Replace("!!Content!!", _viewModel.Content);

                ContentWebView.Source = htmlSource;

                _viewModel.EditMode = true;
                _viewModel.CategoryAutoSuggestList = await ProgenyService.GetCategoryAutoSuggestList(_viewModel.CurrentNote.ProgenyId, 0);
            }
        }
Esempio n. 4
0
        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;
            }
        }