示例#1
0
 public PublicGistsViewModel(IApplicationService applicationService)
 {
     Title       = "Public Gists";
     LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
                                                   GistsCollection.SimpleCollectionLoad(applicationService.Client.Gists.GetPublicGists(), t as bool?));
     LoadCommand.ExecuteIfCan();
 }
        public IssueMilestonesViewModel(
            Func<Task<IReadOnlyList<Milestone>>> loadMilestones,
            Func<Task<Milestone>> loadSelectedFunc,
            Func<Milestone, Task> saveFunc)
        {
            var milestones = new ReactiveList<Milestone>();
            Milestones = milestones.CreateDerivedCollection(x => CreateItemViewModel(x));

            this.WhenAnyValue(x => x.Selected)
                .Subscribe(x => {
                    foreach (var a in Milestones)
                        a.IsSelected = a.Number == x?.Number;
                });

            DismissCommand = ReactiveCommand.Create();

            SaveCommand = ReactiveCommand.CreateAsyncTask(_ => {
                DismissCommand.ExecuteIfCan();
                return _selected != _previouslySelected ? saveFunc(_selected) : Task.FromResult(0);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                _previouslySelected = Selected = await loadSelectedFunc();
                milestones.Reset(await loadMilestones());
            });
        }
示例#3
0
        public IssueAssigneeViewModel(
            Func<Task<IReadOnlyList<User>>> loadAssignees,
            Func<Task<User>> loadSelectedFunc,
            Func<User, Task> saveFunc)
        {
            var assignees = new ReactiveList<IssueAssigneeItemViewModel>();
            Assignees = assignees.CreateDerivedCollection(
                x => x,
                filter: x => x.Name.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            this.WhenAnyValue(x => x.Selected)
                .Subscribe(x => {
                    foreach (var a in Assignees)
                        a.IsSelected = string.Equals(a.User.Login, x?.Login);
                });

            DismissCommand = ReactiveCommand.Create();

            SaveCommand = ReactiveCommand.CreateAsyncTask(_ => {
                DismissCommand.ExecuteIfCan();
                return Selected != _previouslySelected ? saveFunc(_selected) : Task.FromResult(0);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                _previouslySelected = Selected = await loadSelectedFunc();
                assignees.Reset((await loadAssignees()).Select(CreateItemViewModel));
            });
        }
示例#4
0
        public static UIBarButtonItem ToBarButtonItem(this IReactiveCommand @this, UIBarButtonSystemItem item)
        {
            var button = new UIBarButtonItem(item, (s, e) => @this.ExecuteIfCan());

            button.EnableIfExecutable(@this);
            return(button);
        }
示例#5
0
        public IssueAssigneeViewModel(
            Func <Task <IReadOnlyList <User> > > loadAssignees,
            Func <Task <User> > loadSelectedFunc,
            Func <User, Task> saveFunc)
        {
            var assignees = new ReactiveList <IssueAssigneeItemViewModel>();

            Assignees = assignees.CreateDerivedCollection(
                x => x,
                filter: x => x.Name.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            this.WhenAnyValue(x => x.Selected)
            .Subscribe(x => {
                foreach (var a in Assignees)
                {
                    a.IsSelected = string.Equals(a.User.Login, x?.Login);
                }
            });

            DismissCommand = ReactiveCommand.Create();

            SaveCommand = ReactiveCommand.CreateAsyncTask(_ => {
                DismissCommand.ExecuteIfCan();
                return(Selected != _previouslySelected ? saveFunc(_selected) : Task.FromResult(0));
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                _previouslySelected = Selected = await loadSelectedFunc();
                assignees.Reset((await loadAssignees()).Select(CreateItemViewModel));
            });
        }
        public IssueMilestonesViewModel(
            Func <Task <IReadOnlyList <Milestone> > > loadMilestones,
            Func <Task <Milestone> > loadSelectedFunc,
            Func <Milestone, Task> saveFunc)
        {
            var milestones = new ReactiveList <Milestone>();

            Milestones = milestones.CreateDerivedCollection(x => CreateItemViewModel(x));

            this.WhenAnyValue(x => x.Selected)
            .Subscribe(x => {
                foreach (var a in Milestones)
                {
                    a.IsSelected = a.Number == x?.Number;
                }
            });

            DismissCommand = ReactiveCommand.Create();

            SaveCommand = ReactiveCommand.CreateAsyncTask(_ => {
                DismissCommand.ExecuteIfCan();
                return(_selected != _previouslySelected ? saveFunc(_selected) : Task.FromResult(0));
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                _previouslySelected = Selected = await loadSelectedFunc();
                milestones.Reset(await loadMilestones());
            });
        }
 internal PullRequestItemViewModel(PullRequestModel pullRequest, IReactiveCommand action)
 {
     PullRequest = pullRequest;
     Title       = pullRequest.Title ?? "No Title";
     ImageUrl    = pullRequest.User.AvatarUrl;
     Details     = string.Format("#{0} opened {1} by {2}", pullRequest.Number, pullRequest.CreatedAt.ToDaysAgo(), pullRequest.User.Login);
     GoToCommand = ReactiveCommand.Create().WithSubscription(_ => action.ExecuteIfCan(this));
 }
        public RepositoriesTrendingViewModel(IApplicationService applicationService,
                                             IJsonHttpClientService jsonHttpClient, INetworkActivityService networkActivityService)
        {
            _applicationService = applicationService;
            _jsonHttpClient     = jsonHttpClient;

            Title = "Trending";

            var defaultLanguage = LanguagesViewModel.DefaultLanguage;

            SelectedLanguage = new LanguageItemViewModel(defaultLanguage.Name, defaultLanguage.Slug);

            GoToLanguages = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = CreateViewModel <LanguagesViewModel>();
                vm.SelectedLanguage = SelectedLanguage;
                vm.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(x =>
                {
                    SelectedLanguage = x;
                    vm.DismissCommand.ExecuteIfCan();
                });
                ShowViewModel(vm);
            });

            var gotoRepository = new Action <RepositoryItemViewModel>(x =>
            {
                var vm             = CreateViewModel <RepositoryViewModel>();
                vm.RepositoryOwner = x.Owner;
                vm.RepositoryName  = x.Name;
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                var requests = _times.Select(t =>
                {
                    var query = "?since=" + t.Slug;
                    if (SelectedLanguage != null && SelectedLanguage.Slug != null)
                    {
                        query += string.Format("&language={0}", SelectedLanguage.Slug);
                    }
                    return(new { Time = t, Query = _jsonHttpClient.Get <List <TrendingRepositoryModel> >(TrendingUrl + query) });
                }).ToArray();

                await Task.WhenAll(requests.Select(x => x.Query));

                Repositories = requests.Select(r =>
                {
                    var transformedRepos = r.Query.Result.Select(x =>
                                                                 new RepositoryItemViewModel(x.Name, x.Owner, x.AvatarUrl, x.Description, x.Stars, x.Forks, true, gotoRepository));
                    return(new GroupedCollection <RepositoryItemViewModel>(r.Time.Name, new ReactiveList <RepositoryItemViewModel>(transformedRepos)));
                }).ToList();
            });

            LoadCommand.TriggerNetworkActivity(networkActivityService);
            this.WhenAnyValue(x => x.SelectedLanguage).Subscribe(_ => LoadCommand.ExecuteIfCan());
        }
        public RepositoriesTrendingViewModel(IApplicationService applicationService, TrendingRepository trendingRepository)
        {
            ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList;

            Title = "Trending";

            var defaultLanguage = LanguageRepository.DefaultLanguage;

            SelectedLanguage = new LanguageItemViewModel(defaultLanguage.Name, defaultLanguage.Slug);

            GoToLanguages = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = CreateViewModel <LanguagesViewModel>();
                vm.SelectedLanguage = SelectedLanguage;
                vm.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(x =>
                {
                    SelectedLanguage = x;
                    vm.DismissCommand.ExecuteIfCan();
                });
                ShowViewModel(vm);
            });

            var gotoRepository = new Action <RepositoryItemViewModel>(x =>
            {
                var vm             = CreateViewModel <RepositoryViewModel>();
                vm.RepositoryOwner = x.Owner;
                vm.RepositoryName  = x.Name;
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                Repositories = null;

                var requests = _times.Select(t =>
                {
                    var language = (SelectedLanguage != null && SelectedLanguage.Slug != null) ? SelectedLanguage.Slug : null;
                    return(new { Time = t, Query = trendingRepository.GetTrendingRepositories(t.Slug, language) });
                }).ToArray();

                await Task.WhenAll(requests.Select(x => x.Query));

                Repositories = requests.Select(r =>
                {
                    var transformedRepos = r.Query.Result.Select(x =>
                                                                 new RepositoryItemViewModel(x.Name, x.Owner.Login, x.Owner.AvatarUrl, x.Description, x.StargazersCount, x.ForksCount, true, gotoRepository));
                    return(new GroupedCollection <RepositoryItemViewModel>(r.Time.Name, new ReactiveList <RepositoryItemViewModel>(transformedRepos)));
                }).ToList();
            });

            this.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());
        }
示例#10
0
        public UserGistsViewModel(IApplicationService applicationService)
        {
            _applicationService = applicationService;
            Username = _applicationService.Account.Username;

            GoToCreateGistCommand = ReactiveCommand.Create();
            GoToCreateGistCommand.Subscribe(_ =>
            {
                var vm = CreateViewModel<GistCreateViewModel>();
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(t => 
                GistsCollection.SimpleCollectionLoad(applicationService.Client.Users[Username].Gists.GetGists(), t as bool?));
            LoadCommand.ExecuteIfCan();
        }
示例#11
0
        public UserGistsViewModel(IApplicationService applicationService)
        {
            _applicationService = applicationService;
            Username            = _applicationService.Account.Username;

            GoToCreateGistCommand = ReactiveCommand.Create();
            GoToCreateGistCommand.Subscribe(_ =>
            {
                var vm = CreateViewModel <GistCreateViewModel>();
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
                                                          GistsCollection.SimpleCollectionLoad(applicationService.Client.Users[Username].Gists.GetGists(), t as bool?));
            LoadCommand.ExecuteIfCan();
        }
示例#12
0
        public static UIRefreshControl ToRefreshControl(this IReactiveCommand @this)
        {
            var refreshControl = new UIRefreshControl();

            refreshControl.ValueChanged += (sender, e) => @this.ExecuteIfCan();
            @this.IsExecuting.Subscribe(x =>
            {
                if (x)
                {
                    refreshControl.BeginRefreshing();
                }
                else
                {
                    refreshControl.EndRefreshing();
                }
            });
            return(refreshControl);
        }
示例#13
0
        internal IssueItemViewModel(IssueModel issue, IReactiveCommand gotoCommand)
        {
            var isPullRequest = issue.PullRequest != null && !(string.IsNullOrEmpty(issue.PullRequest.HtmlUrl));
            var s1            = issue.Url.Substring(issue.Url.IndexOf("/repos/", StringComparison.Ordinal) + 7);
            var repoId        = new RepositoryIdentifier(s1.Substring(0, s1.IndexOf("/issues", StringComparison.Ordinal)));

            RepositoryFullName = repoId.Owner + "/" + repoId.Name;
            RepositoryName     = repoId.Name;
            RepositoryOwner    = repoId.Owner;
            IsPullRequest      = isPullRequest;
            Title       = issue.Title;
            Number      = (int)issue.Number;
            State       = issue.State;
            Comments    = issue.Comments;
            Assignee    = issue.Assignee != null ? issue.Assignee.Login : "******";
            UpdatedAt   = issue.UpdatedAt;
            GoToCommand = ReactiveCommand.Create(gotoCommand.CanExecuteObservable)
                          .WithSubscription(_ => gotoCommand.ExecuteIfCan(this));
        }
示例#14
0
        public IssueAssigneeViewModel(
            Func <Task <IReadOnlyList <User> > > loadAssignees,
            Func <Task <User> > loadCurrentlyAssigned,
            Func <User, Task> updateIssue
            )
        {
            DismissCommand = ReactiveCommand.Create();

            var derivedFunc = new Func <User, IssueAssigneeItemViewModel>(x =>
            {
                var vm = new IssueAssigneeItemViewModel(x);
                if (_selectedUser != null)
                {
                    vm.IsSelected = x.Id == _selectedUser.Id;
                }

                vm.GoToCommand
                .Select(_ => vm.IsSelected ? x : null)
                .Subscribe(user =>
                {
                    foreach (var a in Assignees.Where(y => y != vm))
                    {
                        a.IsSelected = false;
                    }
                    updateIssue(user).ToBackground();
                    DismissCommand.ExecuteIfCan();
                });
                return(vm);
            });

            var assignees = new ReactiveList <User>();

            Assignees = assignees.CreateDerivedCollection(
                derivedFunc,
                filter: x => x.Name.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                _selectedUser = (await loadCurrentlyAssigned());
                assignees.Reset(await loadAssignees());
            });
        }
        public RepositoriesTrendingViewModel(ISessionService applicationService, ITrendingRepository trendingRepository)
        {
            ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList;

            Title = "Trending";

            var defaultLanguage = LanguageRepository.DefaultLanguage;
            SelectedLanguage = new LanguageItemViewModel(defaultLanguage.Name, defaultLanguage.Slug);

            GoToLanguages = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = this.CreateViewModel<LanguagesViewModel>();
                vm.SelectedLanguage = SelectedLanguage;
                vm.WhenAnyValue(x => x.SelectedLanguage).Skip(1)
                    .Subscribe(x => SelectedLanguage = x);
                NavigateTo(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {

                var requests = _times.Select(t =>
                {
                    var language = (SelectedLanguage != null && SelectedLanguage.Slug != null) ? SelectedLanguage.Slug : null;
                    return new { Time = t, Query = trendingRepository.GetTrendingRepositories(t.Slug, language) };
                }).ToArray();

                await Task.WhenAll(requests.Select(x => x.Query));

                Repositories = requests.Select(r =>
                {
                    var transformedRepos = r.Query.Result.Select(x => new RepositoryItemViewModel(x, true, GoToRepository));
                    return new GroupedCollection<RepositoryItemViewModel>(r.Time.Name, new ReactiveList<RepositoryItemViewModel>(transformedRepos));
                }).ToList();
            });

            this.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(_ => 
            {
                Repositories = null;
                LoadCommand.ExecuteIfCan();
            });
        }
示例#16
0
        public RepositoriesTrendingViewModel(ISessionService applicationService, ITrendingRepository trendingRepository)
        {
            ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList;

            Title = "Trending";

            var defaultLanguage = LanguageRepository.DefaultLanguage;

            SelectedLanguage = new LanguageItemViewModel(defaultLanguage.Name, defaultLanguage.Slug);

            GoToLanguages = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = this.CreateViewModel <LanguagesViewModel>();
                vm.SelectedLanguage = SelectedLanguage;
                vm.WhenAnyValue(x => x.SelectedLanguage).Skip(1)
                .Subscribe(x => SelectedLanguage = x);
                NavigateTo(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                var requests = _times.Select(t =>
                {
                    var language = (SelectedLanguage != null && SelectedLanguage.Slug != null) ? SelectedLanguage.Slug : null;
                    return(new { Time = t, Query = trendingRepository.GetTrendingRepositories(t.Slug, language) });
                }).ToArray();

                await Task.WhenAll(requests.Select(x => x.Query));

                Repositories = requests.Select(r =>
                {
                    var transformedRepos = r.Query.Result.Select(x => new RepositoryItemViewModel(x, true, GoToRepository));
                    return(new GroupedCollection <RepositoryItemViewModel>(r.Time.Name, new ReactiveList <RepositoryItemViewModel>(transformedRepos)));
                }).ToList();
            });

            this.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(_ =>
            {
                Repositories = null;
                LoadCommand.ExecuteIfCan();
            });
        }
示例#17
0
        public IssueMilestonesViewModel(Func<Task<IReadOnlyList<Milestone>>> loadMilestones)
        {
            DismissCommand = ReactiveCommand.Create();

            var milestones = new ReactiveList<Milestone>();
            Milestones = milestones.CreateDerivedCollection(x => {
                var vm = new IssueMilestoneItemViewModel(x);
                vm.IsSelected = x.Number == Selected?.Number;
                vm.GoToCommand
                    .Select(_ => vm.IsSelected ? x : null)
                    .Subscribe(milestone =>  {
                        foreach (var a in Milestones.Where(y => y != vm))
                            a.IsSelected = false;
                        Selected = milestone;
                        DismissCommand.ExecuteIfCan();
                    });
                return vm;
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                milestones.Reset(await loadMilestones());
            });
        }
示例#18
0
        public IssueMilestonesViewModel(
            Func <Task <IReadOnlyList <Milestone> > > loadMilestones,
            Func <Task <Milestone> > currentMilestone,
            Func <Milestone, Task> updateIssue
            )
        {
            DismissCommand = ReactiveCommand.Create();

            var milestones = new ReactiveList <Milestone>();

            Milestones = milestones.CreateDerivedCollection(x =>
            {
                var vm = new IssueMilestoneItemViewModel(x);
                if (_selectedMilestone != null)
                {
                    vm.IsSelected = x.Number == _selectedMilestone.Number;
                }
                vm.GoToCommand
                .Select(_ => vm.IsSelected ? x : null)
                .Subscribe(milestone =>
                {
                    foreach (var a in Milestones.Where(y => y != vm))
                    {
                        a.IsSelected = false;
                    }
                    updateIssue(milestone).ToBackground();
                    DismissCommand.ExecuteIfCan();
                });
                return(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                _selectedMilestone = (await currentMilestone());
                milestones.Reset(await loadMilestones());
            });
        }
示例#19
0
 public SplitButton AddButton(string caption, string text, IReactiveCommand tapped)
 {
     return(AddButton(caption, text, () => tapped.ExecuteIfCan()));
 }
示例#20
0
 public SplitButton AddButton(string caption, string text, IReactiveCommand tapped)
 {
     return AddButton(caption, text, () => tapped.ExecuteIfCan());
 }
示例#21
0
 public StarredGistsViewModel(IApplicationService applicationService)
 {
     LoadCommand = ReactiveCommand.CreateAsyncTask(t => 
         GistsCollection.SimpleCollectionLoad(applicationService.Client.Gists.GetStarredGists(), t as bool?));
     LoadCommand.ExecuteIfCan();
 }
示例#22
0
 public static UIBarButtonItem WithCommand(this UIBarButtonItem @this, IReactiveCommand command)
 {
     @this.Clicked += (sender, e) => command.ExecuteIfCan();
     @this.EnableIfExecutable(command.CanExecuteObservable);
     return(@this);
 }
        public RepositoriesTrendingViewModel(IApplicationService applicationService, 
            IJsonHttpClientService jsonHttpClient, INetworkActivityService networkActivityService)
        {
            _applicationService = applicationService;
            _jsonHttpClient = jsonHttpClient;

            var defaultLanguage = LanguagesViewModel.DefaultLanguage;
            SelectedLanguage = new LanguageItemViewModel(defaultLanguage.Name, defaultLanguage.Slug);

            GoToLanguages = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = CreateViewModel<LanguagesViewModel>();
                vm.SelectedLanguage = SelectedLanguage;
                vm.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(x => 
                {
                    SelectedLanguage = x;
                    vm.DismissCommand.ExecuteIfCan();
                });
                ShowViewModel(vm);
            });

            var gotoRepository = new Action<RepositoryItemViewModel>(x =>
            {
                var vm = CreateViewModel<RepositoryViewModel>();
                vm.RepositoryOwner = x.Owner;
                vm.RepositoryName = x.Name;
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                var requests = _times.Select(t =>
                {
                    var query = "?since=" + t.Slug;
                    if (SelectedLanguage != null && SelectedLanguage.Slug != null)
                        query += string.Format("&language={0}", SelectedLanguage.Slug);
                    return new { Time = t, Query = _jsonHttpClient.Get<List<TrendingRepositoryModel>>(TrendingUrl + query) };
                }).ToArray();

                await Task.WhenAll(requests.Select(x => x.Query));

                Repositories = requests.Select(r =>
                {
                    var transformedRepos = r.Query.Result.Select(x => 
                        new RepositoryItemViewModel(x.Name, x.Owner, x.AvatarUrl, x.Description, x.Stars, x.Forks, true, gotoRepository));
                    return new GroupedCollection<RepositoryItemViewModel>(r.Time.Name, new ReactiveList<RepositoryItemViewModel>(transformedRepos));
                }).ToList();
            });

            LoadCommand.TriggerNetworkActivity(networkActivityService);
            this.WhenAnyValue(x => x.SelectedLanguage).Subscribe(_ => LoadCommand.ExecuteIfCan());
        }
 public static UIBarButtonItem WithCommand(this UIBarButtonItem @this, IReactiveCommand command)
 {
     @this.Clicked += (sender, e) => command.ExecuteIfCan();
     @this.EnableIfExecutable(command.CanExecuteObservable);
     return @this;
 }
示例#25
0
        private void DoTransition(IViewFor fromView, IViewFor toView)
        {
            var toViewController    = (UIViewController)toView;
            var toViewModel         = (IBaseViewModel)toView.ViewModel;
            var fromViewController  = (UIViewController)fromView;
            var routableToViewModel = toViewModel as IRoutingViewModel;
            IReactiveCommand <object> toViewDismissCommand = null;


            if (toViewController is AccountsView || toViewController is WebBrowserView || toViewController is GistCommentView ||
                toViewController is CommitCommentView || toViewController is GistCreateView || toViewController is FeedbackComposerView)
            {
                var appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;
                var rootNav     = (UINavigationController)appDelegate.Window.RootViewController;
                toViewDismissCommand = ReactiveCommand.Create().WithSubscription(_ => rootNav.DismissViewController(true, null));
                toViewController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(Images.Cancel, UIBarButtonItemStyle.Plain, (s, e) => toViewDismissCommand.ExecuteIfCan());
                var navController = new ThemedNavigationController(toViewController);
                rootNav.PresentViewController(navController, true, null);
            }
            else if (toViewController is MenuView)
            {
                var appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;
                var nav         = ((UINavigationController)appDelegate.Window.RootViewController);
                var slideout    = new SlideoutNavigationController();
                slideout.MenuViewController = new MenuNavigationController(toViewController, slideout);
                UIView.Transition(nav.View, 0.1, UIViewAnimationOptions.BeginFromCurrentState | UIViewAnimationOptions.TransitionCrossDissolve,
                                  () => nav.PushViewController(slideout, false), null);
            }
            else if (toViewController is NewAccountView && fromViewController is StartupView)
            {
                toViewDismissCommand = ReactiveCommand.Create().WithSubscription(_ => toViewController.DismissViewController(true, null));
                fromViewController.PresentViewController(new ThemedNavigationController(toViewController), true, null);
            }
            else if (fromViewController is MenuView)
            {
                fromViewController.NavigationController.PushViewController(toViewController, true);
            }
            else if (toViewController is LanguagesView && fromViewController is RepositoriesTrendingView)
            {
                toViewDismissCommand = ReactiveCommand.Create().WithSubscription(_ => fromViewController.DismissViewController(true, null));
                toViewController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, (s, e) => toViewDismissCommand.ExecuteIfCan());
                var ctrlToPresent = new ThemedNavigationController(toViewController);
                ctrlToPresent.TransitioningDelegate = new SlideDownTransition();
                fromViewController.PresentViewController(ctrlToPresent, true, null);
            }
            else if (toViewController is EditFileView || toViewController is CreateFileView)
            {
                toViewDismissCommand = ReactiveCommand.Create().WithSubscription(_ => fromViewController.DismissViewController(true, null));
                toViewController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(Images.Cancel, UIBarButtonItemStyle.Plain, (s, e) => toViewDismissCommand.ExecuteIfCan());
                fromViewController.PresentViewController(new ThemedNavigationController(toViewController), true, null);
            }
            else
            {
                toViewDismissCommand = ReactiveCommand.Create().WithSubscription(_ => toViewController.NavigationController.PopToViewController(fromViewController, true));
                fromViewController.NavigationController.PushViewController(toViewController, true);
            }

            if (toViewDismissCommand != null)
            {
                routableToViewModel.RequestDismiss.Subscribe(_ =>
                {
                    this.Log().Info("{0} is requesting dismissal", routableToViewModel.GetType().Name);
                    toViewDismissCommand.ExecuteIfCan();
                });
            }

            toViewModel.RequestNavigation.Subscribe(x =>
            {
                var viewType   = _viewModelViewService.GetViewFor(x.GetType());
                var view       = (IViewFor)_serviceConstructor.Construct(viewType);
                view.ViewModel = x;
                Transition(toView, view);
            });
        }
示例#26
0
        public PullRequestViewModel(IApplicationService applicationService,
                                    IMarkdownService markdownService, IActionMenuFactory actionMenuService)
        {
            _applicationService = applicationService;
            _markdownService    = markdownService;

            Comments = new ReactiveList <Octokit.IssueComment>();
            Events   = new ReactiveList <Octokit.IssueEvent>();

            this.WhenAnyValue(x => x.Id).Subscribe(x => Title = "Pull Request #" + x);

            _canMerge = this.WhenAnyValue(x => x.PullRequest)
                        .Select(x => x != null && !x.Merged)
                        .ToProperty(this, x => x.CanMerge);

            var canMergeObservable = this.WhenAnyValue(x => x.PullRequest).Select(x =>
                                                                                  x != null && !x.Merged && x.Mergeable.HasValue && x.Mergeable.Value);

            MergeCommand = ReactiveCommand.CreateAsyncTask(canMergeObservable, async t =>
            {
                var req      = new Octokit.MergePullRequest(null);
                var response = await _applicationService.GitHubClient.PullRequest.Merge(RepositoryOwner, RepositoryName, Id, req);
                if (!response.Merged)
                {
                    throw new Exception(string.Format("Unable to merge pull request: {0}", response.Message));
                }
                LoadCommand.ExecuteIfCan();
            });

            ToggleStateCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.PullRequest).Select(x => x != null),
                async t =>
            {
                var newState = PullRequest.State == Octokit.ItemState.Open ? Octokit.ItemState.Closed : Octokit.ItemState.Open;

                try
                {
                    var req = new Octokit.PullRequestUpdate {
                        State = newState
                    };
                    PullRequest = await _applicationService.GitHubClient.PullRequest.Update(RepositoryOwner, RepositoryName, Id, req);
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to " + (newState == Octokit.ItemState.Closed ? "close" : "open") + " the item. " + e.Message, e);
                }
            });

            GoToUrlCommand = ReactiveCommand.Create();
            GoToUrlCommand.OfType <string>().Subscribe(x =>
            {
                var vm = this.CreateViewModel <WebBrowserViewModel>();
                vm.Url = x;
                NavigateTo(vm);
            });

            GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null));
            GoToHtmlUrlCommand.Select(_ => PullRequest.HtmlUrl).Subscribe(x => GoToUrlCommand.ExecuteIfCan(x.AbsolutePath));

            GoToCommitsCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm             = this.CreateViewModel <PullRequestCommitsViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.PullRequestId   = Id;
                NavigateTo(vm);
            });

            GoToFilesCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm           = this.CreateViewModel <PullRequestFilesViewModel>();
                vm.Username      = RepositoryOwner;
                vm.Repository    = RepositoryName;
                vm.PullRequestId = Id;
                NavigateTo(vm);
            });
//
//            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl)))
//                .WithSubscription(_ => shareService.ShareUrl(PullRequest.HtmlUrl));

            GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm             = this.CreateViewModel <IssueEditViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.Id = Id;
                //vm.Issue = Issue;
//                vm.WhenAnyValue(x => x.Issue).Skip(1).Subscribe(x => Issue = x);
                NavigateTo(vm);
            });
//
//            GoToLabelsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ =>
//            {
//                var vm = this.CreateViewModel<IssueLabelsViewModel>();
//                vm.RepositoryOwner = RepositoryOwner;
//                vm.RepositoryName = RepositoryName;
//                vm.Id = Id;
//                vm.SaveOnSelect = true;
////                vm.SelectedLabels.Reset(Issue.Labels);
////                vm.WhenAnyValue(x => x.Labels).Skip(1).Subscribe(x =>
////                {
////                    Issue.Labels = x.ToList();
////                    this.RaisePropertyChanged("Issue");
////                });
//                NavigateTo(vm);
//            });

//            GoToMilestoneCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ =>
//            {
//                var vm = this.CreateViewModel<IssueMilestonesViewModel>();
//                vm.RepositoryOwner = RepositoryOwner;
//                vm.RepositoryName = RepositoryName;
//                vm.IssueId = Id;
//                vm.SaveOnSelect = true;
////                vm.SelectedMilestone = Issue.Milestone;
////                vm.WhenAnyValue(x => x.SelectedMilestone).Skip(1).Subscribe(x =>
////                {
////                    Issue.Milestone = x;
////                    this.RaisePropertyChanged("Issue");
////                });
//                NavigateTo(vm);
//            });
//
//            GoToAssigneeCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ =>
//            {
//                var vm = this.CreateViewModel<IssueAssignedToViewModel>();
//                vm.RepositoryOwner = RepositoryOwner;
//                vm.RepositoryName = RepositoryName;
//                vm.IssueId = Id;
//                //vm.SaveOnSelect = true;
////                vm.SelectedUser = Issue.Assignee;
////                vm.WhenAnyValue(x => x.SelectedUser).Skip(1).Subscribe(x =>
////                {
////                    Issue.Assignee = x;
////                    this.RaisePropertyChanged("Issue");
////                });
//                NavigateTo(vm);
//            });

            GoToAddCommentCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm             = this.CreateViewModel <IssueCommentViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.Id = Id;
                vm.SaveCommand.Subscribe(Comments.Add);
                NavigateTo(vm);
            });

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.PullRequest).Select(x => x != null),
                _ =>
            {
                var menu = actionMenuService.Create(Title);
                menu.AddButton("Edit", GoToEditCommand);
                menu.AddButton(PullRequest.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand);
                menu.AddButton("Comment", GoToAddCommentCommand);
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                return(menu.Show());
            });

            _markdownDescription = this.WhenAnyValue(x => x.PullRequest).IsNotNull()
                                   .Select(x => _markdownService.Convert(x.Body))
                                   .ToProperty(this, x => x.MarkdownDescription);

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                var pullRequest = _applicationService.GitHubClient.PullRequest.Get(RepositoryOwner, RepositoryName, Id);
                var comments    = _applicationService.GitHubClient.PullRequest.Comment.GetAll(RepositoryOwner, RepositoryName, Id);
                var events      = _applicationService.GitHubClient.Issue.Events.GetForIssue(RepositoryOwner, RepositoryName, Id);
                var issue       = _applicationService.GitHubClient.Issue.Get(RepositoryOwner, RepositoryName, Id);

                await Task.WhenAll(pullRequest, issue, comments, events);

                PullRequest = pullRequest.Result;
                Issue       = issue.Result;
            });
        }