Exemplo n.º 1
0
        private async Task RegisterPushNotifications(bool enabled)
        {
            if (!_featuresService.IsProEnabled)
            {
                var response = await _alertDialogService.PromptYesNo(
                    "Requires Activation",
                    "Push notifications require activation. Would you like to go there now to activate push notifications?");

                if (response)
                {
                    UpgradeViewController.Present(this);
                }

                return;
            }

            if (enabled)
            {
                await _pushNotificationsService.Register();
            }
            else
            {
                await _pushNotificationsService.Deregister();
            }

            _applicationService.Account.IsPushNotificationsEnabled = enabled;
            await _applicationService.UpdateActiveAccount();
        }
Exemplo n.º 2
0
        public NewCommentViewModel(
            Func <string, Task> doneAction,
            IAlertDialogService alertDialogService = null)
        {
            alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>();

            DoneCommand = ReactiveCommand.CreateFromTask(async _ =>
            {
                await doneAction(Text);
                DismissCommand.ExecuteNow();
                Text = string.Empty;
            }, this.WhenAnyValue(x => x.Text).Select(x => x?.Length > 0));

            DiscardCommand = ReactiveCommand.CreateFromTask(async _ =>
            {
                if (Text?.Length > 0)
                {
                    var result = await alertDialogService.PromptYesNo(
                        "Discard Comment", "Are you sure you want to discard this comment?");
                    if (!result)
                    {
                        return;
                    }
                }

                Text = string.Empty;
                DismissCommand.ExecuteNow();
            });
        }
Exemplo n.º 3
0
        public FeedbackComposerViewModel(
            IApplicationService applicationService = null,
            IAlertDialogService alertDialogService = null)
        {
            applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>();

            this.WhenAnyValue(x => x.IsFeature)
            .Subscribe(x => Title = x ? "New Feature" : "Bug Report");

            SubmitCommand = ReactiveCommand.CreateFromTask(async _ =>
            {
                if (string.IsNullOrEmpty(Subject))
                {
                    throw new ArgumentException(string.Format("You must provide a title for this {0}!", IsFeature ? "feature" : "bug"));
                }

                var labels    = await applicationService.GitHubClient.Issue.Labels.GetAllForRepository(CodeHubOwner, CodeHubName);
                var labelName = IsFeature ? "enhancement" : "bug";

                var createLabels = labels
                                   .Where(x => string.Equals(x.Name, labelName, StringComparison.OrdinalIgnoreCase))
                                   .Select(x => x.Name)
                                   .Distinct();

                var createIssueRequest = new Octokit.NewIssue(Subject)
                {
                    Body = Description
                };

                foreach (var label in createLabels)
                {
                    createIssueRequest.Labels.Add(label);
                }

                await applicationService.GitHubClient.Issue.Create(CodeHubOwner, CodeHubName, createIssueRequest);
            }, this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x)));

            SubmitCommand
            .ThrownExceptions
            .Select(x => new UserError("There was a problem trying to post your feedback: " + x.Message))
            .SelectMany(Interactions.Errors.Handle)
            .Subscribe();

            DismissCommand = ReactiveCommand.CreateFromTask(async t =>
            {
                if (string.IsNullOrEmpty(Description) && string.IsNullOrEmpty(Subject))
                {
                    return(true);
                }

                var itemType = IsFeature ? "feature" : "bug";

                return(await alertDialogService.PromptYesNo(
                           "Discard " + itemType.Transform(To.TitleCase) + "?",
                           "Are you sure you want to discard this " + itemType + "?"));
            });
        }
        public FeedbackComposerViewModel(
            IApplicationService applicationService = null,
            IAlertDialogService alertDialogService = null)
        {
            applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>();

            SubmitCommand = ReactiveCommand.CreateFromTask(async _ =>
            {
                if (string.IsNullOrEmpty(Subject))
                {
                    throw new ArgumentException("You must provide a title for this issue!");
                }

                var createIssueRequest = new Octokit.NewIssue(Subject)
                {
                    Body = Description
                };

                await applicationService.GitHubClient.Issue.Create(CodeHubOwner, CodeHubName, createIssueRequest);
            }, this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x)));

            SubmitCommand
            .ThrownExceptions
            .Select(ex => new UserError("There was a problem trying to post your feedback.", ex))
            .SelectMany(Interactions.Errors.Handle)
            .Subscribe();

            DismissCommand = ReactiveCommand.CreateFromTask(async t =>
            {
                if (string.IsNullOrEmpty(Description) && string.IsNullOrEmpty(Subject))
                {
                    return(true);
                }

                return(await alertDialogService.PromptYesNo(
                           "Discard Issue?",
                           "Are you sure you want to discard this issue?"));
            });
        }
Exemplo n.º 5
0
        public IssueViewModel(
            string username, string repository, int issueId,
            IApplicationService applicationService = null, IMarkdownService markdownService       = null,
            IMessageService messageService         = null, IAlertDialogService alertDialogService = null,
            IActionMenuService actionMenuService   = null)
        {
            _applicationService = applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            messageService      = messageService ?? Locator.Current.GetService <IMessageService>();
            markdownService     = markdownService ?? Locator.Current.GetService <IMarkdownService>();
            alertDialogService  = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>();
            actionMenuService   = actionMenuService ?? Locator.Current.GetService <IActionMenuService>();

            Title      = "Issue #" + issueId;
            Username   = username;
            Repository = repository;
            IssueId    = issueId;

            GoToWebCommand = ReactiveCommand.Create <string>(
                url => NavigateTo(new WebBrowserViewModel(url)));

            GoToReporterCommand = ReactiveCommand.Create(
                () => NavigateTo(new UserViewModel(Issue.ReportedBy.Username)),
                this.WhenAnyValue(x => x.Issue.ReportedBy.Username).Select(x => x != null));

            GoToAssigneeCommand = ReactiveCommand.Create(
                () => NavigateTo(new UserViewModel(Issue.Responsible.Username)),
                this.WhenAnyValue(x => x.Issue.Responsible.Username).Select(x => x != null));

            GoToEditCommand = ReactiveCommand.Create(
                () => NavigateTo(new IssueEditViewModel(username, repository, Issue)),
                this.WhenAnyValue(x => x.Issue).Select(x => x != null));

            this.WhenAnyValue(x => x.Issue)
            .Select(x => x?.Responsible?.Username ?? "Unassigned")
            .ToProperty(this, x => x.Assigned, out _assigned, "Unassigned");

            this.WhenAnyValue(x => x.Issue.Content)
            .Select(x => string.IsNullOrEmpty(x) ? null : markdownService.ConvertMarkdown(x))
            .ToProperty(this, x => x.Description, out _description);

            this.WhenAnyValue(x => x.Description)
            .Select(x => !string.IsNullOrEmpty(x))
            .ToProperty(this, x => x.ShowDescription, out _showDescription);

            Comments = _comments.CreateDerivedCollection(x =>
                                                         new CommentItemViewModel(x.AuthorInfo.Username,
                                                                                  new Utils.Avatar(x.AuthorInfo.Avatar),
                                                                                  x.UtcCreatedOn.Humanize(),
                                                                                  markdownService.ConvertMarkdown(x.Content)));

            LoadCommand = ReactiveCommand.CreateFromTask(async t => {
                var issueTask = applicationService.Client.Issues.Get(username, repository, issueId);
                applicationService.Client.Issues.GetComments(username, repository, issueId)
                .ToBackground(x => _comments.Reset(x.Where(y => !string.IsNullOrEmpty(y.Content))));
                Issue = await issueTask;
            });

            DeleteCommand = ReactiveCommand.CreateFromTask(async _ =>
            {
                try
                {
                    var prompt = await alertDialogService.PromptYesNo(
                        "Are you sure?", "You are about to permanently delete issue #" + Issue.LocalId + ".");

                    if (prompt)
                    {
                        await applicationService.Client.Issues.Delete(username, repository, Issue.LocalId);
                        messageService.Send(new IssueDeleteMessage(Issue));
                        DismissCommand.ExecuteNow();
                    }
                }
                catch (Exception e)
                {
                    this.Log().ErrorException("Error deleting issue", e);
                }
            });

            ShowMenuCommand = ReactiveCommand.CreateFromTask(sender =>
            {
                var menu = actionMenuService.Create();
                menu.AddButton("Edit", _ => GoToEditCommand.ExecuteNow());
                menu.AddButton("Delete", _ => DeleteCommand.ExecuteNow());
                return(menu.Show(sender));
            });

            _issueMessageBus = messageService.Listen <IssueUpdateMessage>(x =>
            {
                if (x.Issue.LocalId == issueId)
                {
                    Issue = x.Issue;
                }
            });
        }