Пример #1
0
        public async Task Load(Tuple <Repository, Issue> tuple)
        {
            Issue      = tuple.Item2;
            Repository = tuple.Item1;

            if (!GlobalHelper.IsInternet())
            {
                //Sending NoInternet message to all viewModels
                Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType {
                    Message = "No Internet", Glyph = "\uE704"
                });
            }
            else
            {
                isLoading = true;
                Comments  = await IssueUtility.GetAllCommentsForIssue(Repository.Id, Issue.Number);

                isLoading = false;

                if (Repository.Owner == null)
                {
                    Repository = await RepositoryUtility.GetRepository(Repository.Id);
                }

                if (Repository.Owner.Login == GlobalHelper.UserLogin || Issue.User.Login == GlobalHelper.UserLogin)
                {
                    CanEditIssue = true;
                }
                if (Repository.Owner.Login == GlobalHelper.UserLogin)
                {
                    IsMyRepo = true;
                }
            }
        }
        private static async Task <NotificationModel> ProcessNotification(this Octokit.Notification notification)
        {
            NotificationModel result = null;
            var isIssue = notification.Subject.Type.ToLower() == "issue";
            var isPR    = notification.Subject.Type.ToLower() == "pullrequest";

            if (int.TryParse(notification.Subject.Url.Split('/').Last().Split('#').First(), out int number))
            {
                var subtitle = "";
                var repo     = notification.Repository;
                var repoName = repo.FullName ?? repo.Name;
                if (isIssue)
                {
                    var issue = await IssueUtility.GetIssue(repo.Id, number);

                    subtitle = $"Issue {number}";
                    result   = new NotificationModel(repo.Id, issue, subtitle);
                }
                else if (isPR)
                {
                    var pr = await PullRequestUtility.GetPullRequest(repo.Id, number);

                    subtitle = $"PR {number}";
                    result   = new NotificationModel(repo.Id, pr, subtitle);
                }
                subtitle = !StringHelper.IsNullOrEmptyOrWhiteSpace(subtitle)
                          ? $"{subtitle} in {repoName}"
                          : repoName;
                result.SetSubtitle(subtitle);
            }

            return(result ?? throw new NullReferenceException(nameof(result)));
        }
Пример #3
0
        public async Task EditIssue()
        {
            IssueUpdate updatedIssue = new IssueUpdate();

            updatedIssue.Title = NewIssueTitleText;
            updatedIssue.Body  = NewIssueBodyText;
            isLoading          = true;
            Issue issue = await IssueUtility.EditIssue(Repository.Id, Issue.Number, updatedIssue);

            isLoading = false;
            if (issue != null)
            {
                Issue = issue;
            }
        }
Пример #4
0
        public async Task Load(Tuple <Repository, PullRequest> tuple)
        {
            PullRequest = tuple.Item2;
            Repository  = tuple.Item1;

            if (GlobalHelper.IsInternet())
            {
                isLoading   = true;
                PullRequest = await PullRequestUtility.GetPullRequest(Repository.Id, PullRequest.Number);

                Comments = await IssueUtility.GetAllCommentsForIssue(Repository.Id, PullRequest.Number);

                isLoading = false;
            }
        }
        public async void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Pivot p = sender as Pivot;

            if (p.SelectedIndex == 0)
            {
                isLoading = true;
                Comments  = await IssueUtility.GetAllCommentsForIssue(Repository.Id, PullRequest.Number);

                isLoading = false;
            }
            else if (p.SelectedIndex == 1)
            {
                IsLoadingCommits = true;
                Commits          = await PullRequestUtility.GetAllCommitsForPullRequest(Repository.Id, PullRequest.Number);

                IsLoadingCommits = false;
            }
        }
Пример #6
0
        public async Task Load(object param)
        {
            if (param as Tuple <Repository, Issue> != null)
            {
                var tuple = param as Tuple <Repository, Issue>;
                Issue      = tuple.Item2;
                Repository = tuple.Item1;
            }
            else
            {
                var tuple = (param as Tuple <string, string, Issue>);
                if (tuple != null)
                {
                    Issue      = tuple.Item3;
                    Repository = await RepositoryUtility.GetRepository(tuple.Item1, tuple.Item2);
                }
            }

            if (GlobalHelper.IsInternet())
            {
                if (Repository != null)
                {
                    isLoading = true;
                    Comments  = await IssueUtility.GetAllCommentsForIssue(Repository.Id, Issue.Number);

                    isLoading = false;

                    if (Repository.Owner == null)
                    {
                        Repository = await RepositoryUtility.GetRepository(Repository.Id);
                    }

                    if (Repository.Owner.Login == GlobalHelper.UserLogin || Issue.User.Login == GlobalHelper.UserLogin)
                    {
                        CanEditIssue = true;
                    }
                    if (Repository.Owner.Login == GlobalHelper.UserLogin)
                    {
                        IsMyRepo = true;
                    }
                }
            }
        }
        public async Task Load(Tuple <Repository, PullRequest> tuple)
        {
            PullRequest = tuple.Item2;
            Repository  = tuple.Item1;

            if (!GlobalHelper.IsInternet())
            {
                //Sending NoInternet message to all viewModels
                Messenger.Default.Send(new GlobalHelper.LocalNotificationMessageType {
                    Message = "No Internet", Glyph = "\uE704"
                });
            }
            else
            {
                isLoading   = true;
                PullRequest = await PullRequestUtility.GetPullRequest(Repository.Id, PullRequest.Number);

                Comments = await IssueUtility.GetAllCommentsForIssue(Repository.Id, PullRequest.Number);

                isLoading = false;
            }
        }
Пример #8
0
        public async void NotificationsListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            Notification notif = e.ClickedItem as Notification;

            if (int.TryParse(notif.Subject.Url.Split('/').Last().Split('?')[0], out int id))
            {
                if (notif.Subject.Type.ToLower().Equals("issue"))
                {
                    await SimpleIoc.Default.GetInstance <IAsyncNavigationService>().NavigateAsync(typeof(IssueDetailView), new Tuple <Repository, Issue>(notif.Repository, await IssueUtility.GetIssue(notif.Repository.Id, id)));
                }
                else if (notif.Subject.Type.ToLower().Equals("pullrequest"))
                {
                    await SimpleIoc.Default.GetInstance <IAsyncNavigationService>().NavigateAsync(typeof(PullRequestDetailView), new Tuple <Repository, PullRequest>(notif.Repository, await PullRequestUtility.GetPullRequest(notif.Repository.Id, id)));
                }
            }
            if (notif.Unread)
            {
                await NotificationsService.MarkNotificationAsRead(notif.Id);
            }
        }
Пример #9
0
        private async void OnLaunchedOrActivated(IActivatedEventArgs args)
        {
            // Set the right theme-depending color for the alternating rows
            if (SettingsService.Get <bool>(SettingsKeys.AppLightThemeEnabled))
            {
                XAMLHelper.AssignValueToXAMLResource("OddAlternatingRowsBrush", new SolidColorBrush {
                    Color = Color.FromArgb(0x08, 0, 0, 0)
                });
            }
            if (args is LaunchActivatedEventArgs launchArgs)
            {
                if (!launchArgs.PrelaunchActivated)
                {
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(null);
                        (Window.Current.Content as Page).OpenFromSplashScreen(launchArgs.SplashScreen.ImageLocation);
                    }
                }
                Activate();
                Window.Current.Activate();
                BackgroundTaskService.RegisterAppTriggerBackgroundTasks();
            }
            else if (args is ToastNotificationActivatedEventArgs toastActivatedEventArgs)
            {
                if (args.Kind == ActivationKind.Protocol)
                {
                    if (args.PreviousExecutionState == ApplicationExecutionState.Running)
                    {
                        await HandleProtocolActivationArguments(args);
                    }
                    else
                    {
                        if (Window.Current.Content == null)
                        {
                            Window.Current.Content = new MainPage(args);
                        }
                        Activate();
                    }
                }
                else if (args.Kind == ActivationKind.ToastNotification)
                {
                    var mainPageType = typeof(FeedView);
                    var backPageType = typeof(NotificationsView);
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(args);
                    }
                    else
                    {
                        var svc = SimpleIoc
                                  .Default
                                  .GetInstance <IAsyncNavigationService>();
                        try
                        {
                            var toastArgs      = QueryString.Parse(toastActivatedEventArgs.Argument);
                            var notificationId = toastArgs["notificationId"] as string;
                            var repoId         = long.Parse(toastArgs["repoId"]);

                            string group = null,
                                   tag   = $"N{notificationId}+R{repoId}";

                            var repo = await RepositoryUtility.GetRepository(repoId);

                            switch (toastArgs["action"])
                            {
                            case "showIssue":
                                var issueNumber = int.Parse(toastArgs["issueNumber"]);

                                var issue = await IssueUtility.GetIssue(repo.Id, issueNumber);

                                tag  += $"+I{issueNumber}";
                                group = "Issues";
                                await svc.NavigateAsync(typeof(IssueDetailView), new Tuple <Repository, Issue>(repo, issue), backPageType : backPageType);

                                break;

                            case "showPr":
                                var prNumber = int.Parse(toastArgs["prNumber"]);
                                var pr       = await PullRequestUtility.GetPullRequest(repoId, prNumber);

                                tag  += $"+P{pr.Number}";
                                group = "PullRequests";
                                await svc.NavigateAsync(typeof(PullRequestDetailView), new Tuple <Repository, PullRequest>(repo, pr), backPageType : backPageType);

                                break;
                            }
                            if (!StringHelper.IsNullOrEmptyOrWhiteSpace(tag) && !StringHelper.IsNullOrEmptyOrWhiteSpace(group))
                            {
                                ToastNotificationManager.History.Remove(tag, group);
                            }
                            if (!StringHelper.IsNullOrEmptyOrWhiteSpace(notificationId))
                            {
                                await NotificationsService.MarkNotificationAsRead(notificationId);
                            }
                        }
                        catch
                        {
                            await svc.NavigateAsync(mainPageType);
                        }
                    }

                    Activate();
                    Window.Current.Activate();
                }
            }
            else if (args is StartupTaskActivatedEventArgs startupTaskActivatedEventArgs)
            {
                if (args.Kind == ActivationKind.StartupTask)
                {
                    var payload = ActivationKind.StartupTask.ToString();
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(args);
                    }
                    (Window.Current.Content as Frame).Navigate(typeof(NotificationsView));
                }
            }
        }