/// <summary>
        /// Deletes a contribution.
        /// </summary>
        async Task DeleteContribution()
        {
            try
            {
                // Shouldn't be getting here anyway, so no need for a message.
                if (!CanBeEdited)
                {
                    return;
                }

                if (!await VerifyInternetConnection())
                {
                    return;
                }
                // Ask for confirmation before deletion.
                var confirm = await DialogService.ConfirmAsync(Translations.contributiondetail_deleteconfirmation, Translations.warning_title, Translations.ok, Translations.cancel).ConfigureAwait(false);

                if (!confirm)
                {
                    return;
                }

                State = LayoutState.Loading;

                var isDeleted = await MvpApiService.DeleteContributionAsync(Contribution);

                if (isDeleted)
                {
                    // TODO: Pass back true to indicate it needs to refresh.
                    // TODO: Be a bit more sensible with muh threads plz.
                    MainThread.BeginInvokeOnMainThread(() => HapticFeedback.Perform(HapticFeedbackType.LongPress));
                    AnalyticsService.Track("Contribution Deleted");
                    await MainThread.InvokeOnMainThreadAsync(() => BackAsync());

                    //MessagingService.Current.SendMessage(MessageKeys.HardRefreshNeeded);
                    MessagingService.Current.SendMessage(MessageKeys.HardRefreshNeeded);
                }
                else
                {
                    await DialogService.AlertAsync(Translations.contributiondetail_notdeleted, Translations.error_title, Translations.ok).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                AnalyticsService.Report(ex);
                await DialogService.AlertAsync(Translations.error_unexpected, Translations.error_title, Translations.ok).ConfigureAwait(false);
            }
            finally
            {
                State = LayoutState.None;
            }
        }
示例#2
0
        /// <summary>
        /// Checks if the clipboard contains a URL to use for prefilling.
        /// </summary>
        async Task CheckForClipboardUrl()
        {
            if (Connectivity.NetworkAccess != NetworkAccess.Internet)
            {
                return;
            }

            if (!Settings.UseClipboardUrls)
            {
                return;
            }

            var clipboardText = string.Empty;

            try
            {
                if (!Clipboard.HasText)
                {
                    return;
                }

                clipboardText = await Clipboard.GetTextAsync();

                var result = Uri.TryCreate(clipboardText, UriKind.Absolute, out var uriResult) &&
                             (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

                if (!result)
                {
                    return;
                }

                var shouldCreateActivity = await DialogService.ConfirmAsync(Translations.clipboard_description, Translations.clipboard_title, Translations.yes, Translations.no);

                if (!shouldCreateActivity)
                {
                    return;
                }

                GetOpenGraphData(clipboardText).SafeFireAndForget();
            }
            catch (Exception ex)
            {
                AnalyticsService.Report(ex, new Dictionary <string, string> {
                    { nameof(clipboardText), clipboardText }
                });
                return;
            }
        }
示例#3
0
        private async void CitySelected(EventModel selectedEvent)
        {
            if (ViewModelLocator.Instance.UseMockService && (selectedEvent.CityId != GlobalSetting.DefaultMockCityId))
            {
                if (!await DialogService.ConfirmAsync("Your current selection will disable mock mode, Are you sure?", "Mock Enabled"))
                {
                    return;
                }
                else
                {
                    ViewModelLocator.Instance.UseMockService = false;
                }
            }

            Settings.SelectedCity       = selectedEvent.CityId;
            Settings.UserLatitude       = selectedEvent.Latitude;
            Settings.UserLongitude      = selectedEvent.Longitude;
            Settings.AmbulanceLatitude  = selectedEvent.AmbulancePosition.Latitude;
            Settings.AmbulanceLongitude = selectedEvent.AmbulancePosition.Longitude;
            await NavigationService.NavigateToAsync <LoginViewModel>(selectedEvent);

            await NavigationService.RemoveBackStackAsync();
        }
示例#4
0
        async Task DeleteContribution()
        {
            try
            {
                // Shouldn't be getting here anyway, so no need for a message.
                if (!Contribution.StartDate.IsWithinCurrentAwardPeriod())
                {
                    return;
                }

                // Ask for confirmation before deletion.
                var confirm = await DialogService.ConfirmAsync("Are you sure you want to delete this contribution? You cannot undo this.", Alerts.HoldOn, Alerts.OK, Alerts.Cancel);

                if (!confirm)
                {
                    return;
                }

                var isDeleted = await MvpApiService.DeleteContributionAsync(Contribution);

                if (isDeleted)
                {
                    // TODO: Pass back true to indicate it needs to refresh.
                    await NavigationHelper.BackAsync().ConfigureAwait(false);
                }
                else
                {
                    await DialogService.AlertAsync("Your contribution could not be deleted. Perhaps it was already deleted, or it took place in the previous award period?", Alerts.Error, Alerts.OK);
                }
            }
            catch (Exception ex)
            {
                AnalyticsService.Report(ex);
                await DialogService.AlertAsync(Alerts.UnexpectedError, Alerts.Error, Alerts.OK).ConfigureAwait(false);
            }
        }
示例#5
0
        async Task <bool> CheckForClipboardUrl()
        {
            var text = string.Empty;

            try
            {
                if (!Clipboard.HasText)
                {
                    return(false);
                }

                text = await Clipboard.GetTextAsync();

                if (string.IsNullOrEmpty(text) || (!text.StartsWith("http://") && !text.StartsWith("https://")))
                {
                    return(false);
                }

                var shouldCreateActivity = await DialogService.ConfirmAsync(
                    "We notice a URL on your clipboard. Do you want us to pre-fill an activity out of that?",
                    "That looks cool!",
                    "Yes",
                    "No"
                    );

                if (!shouldCreateActivity)
                {
                    return(false);
                }

                var ogData = await OpenGraph.ParseUrlAsync(text);

                if (ogData == null)
                {
                    return(false);
                }

                DateTime?dateTime = null;

                if (ogData.Metadata.ContainsKey("article:published_time") &&
                    DateTime.TryParse(ogData.Metadata["article:published_time"].Value(), out var activityDate))
                {
                    dateTime = activityDate;
                }

                var contrib = new Contribution
                {
                    Title        = HttpUtility.HtmlDecode(ogData.Title),
                    ReferenceUrl = ogData.Url.AbsoluteUri,
                    Description  = ogData.Metadata.ContainsKey("og:description")
                        ? HttpUtility.HtmlDecode(ogData.Metadata["og:description"].Value())
                        : string.Empty,
                    StartDate = dateTime
                };

                await NavigationHelper.OpenModalAsync(nameof(WizardActivityTypePage), contrib, true).ConfigureAwait(false);

                return(true);
            }
            catch (Exception ex)
            {
                AnalyticsService.Report(ex, new Dictionary <string, string> {
                    { "clipboard_value", text }
                });
                return(false);
            }
        }