Example #1
0
        public ReleaseViewModel(ISessionService applicationService,
            IUrlRouterService urlRouterService, IActionMenuFactory actionMenuService)
        {
            Title = "Release";

            this.WhenAnyValue(x => x.ReleaseModel)
                .Select(x => 
                {
                    if (x == null) return "Release";
                    var name = string.IsNullOrEmpty(x.Name) ? x.TagName : x.Name;
                    return name ?? "Release";
                })
                .Subscribe(x => Title = x);

            var shareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null));
            shareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, ReleaseModel.HtmlUrl));

            var gotoUrlCommand = new Action<string>(x =>
            {
                var vm = this.CreateViewModel<WebBrowserViewModel>();
                vm.Init(x);
                NavigateTo(vm);
            });

            var gotoGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null));
            gotoGitHubCommand.Select(_ => ReleaseModel.HtmlUrl).Subscribe(gotoUrlCommand);

            GoToLinkCommand = ReactiveCommand.Create();
            GoToLinkCommand.OfType<string>().Subscribe(x =>
            {
                var handledViewModel = urlRouterService.Handle(x);
                if (handledViewModel != null)
                    NavigateTo(handledViewModel);
                else
                    gotoUrlCommand(x);
            });

            var canShowMenu = this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null);
            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(canShowMenu, sender => {
                var menu = actionMenuService.Create();
                menu.AddButton("Share", shareCommand);
                menu.AddButton("Show in GitHub", gotoGitHubCommand);
                return menu.Show(sender);
            });

            _contentText = this.WhenAnyValue(x => x.ReleaseModel).IsNotNull()
                .Select(x => x.BodyHtml).ToProperty(this, x => x.ContentText);

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetRelease(ReleaseId);
                ReleaseModel = (await applicationService.Client.ExecuteAsync(request)).Data;
            });
        }
Example #2
0
        public ReleaseViewModel(IApplicationService applicationService, IShareService shareService,
                                IUrlRouterService urlRouterService, IActionMenuService actionMenuService)
        {
            this.WhenAnyValue(x => x.ReleaseModel)
            .Select(x => x == null ? "Release" : x.Name).Subscribe(x => Title = x);

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null));
            ShareCommand.Subscribe(_ => shareService.ShareUrl(ReleaseModel.HtmlUrl));

            var gotoUrlCommand = this.CreateUrlCommand();

            GoToGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null));
            GoToGitHubCommand.Select(_ => ReleaseModel.HtmlUrl).Subscribe(gotoUrlCommand.ExecuteIfCan);

            GoToLinkCommand = ReactiveCommand.Create();
            GoToLinkCommand.OfType <string>().Subscribe(x =>
            {
                var handledViewModel = urlRouterService.Handle(x);
                if (handledViewModel != null && applicationService.Account.OpenUrlsInApp)
                {
                    ShowViewModel(handledViewModel);
                }
                else
                {
                    gotoUrlCommand.ExecuteIfCan(x);
                }
            });

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null),
                _ =>
            {
                var menu = actionMenuService.Create(Title);
                menu.AddButton("Share", ShowMenuCommand);
                menu.AddButton("Show in GitHub", GoToGitHubCommand);
                return(menu.Show());
            });

            _contentText = this.WhenAnyValue(x => x.ReleaseModel).IsNotNull()
                           .Select(x => x.BodyHtml).ToProperty(this, x => x.ContentText);

            LoadCommand = ReactiveCommand.CreateAsyncTask(x =>
                                                          this.RequestModel(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetRelease(ReleaseId),
                                                                            x as bool?, r => ReleaseModel = r.Data));
        }
Example #3
0
        public ReleaseViewModel(ISessionService applicationService,
                                IUrlRouterService urlRouterService, IActionMenuFactory actionMenuService)
        {
            Title = "Release";

            this.WhenAnyValue(x => x.ReleaseModel)
            .Select(x =>
            {
                if (x == null)
                {
                    return("Release");
                }
                var name = string.IsNullOrEmpty(x.Name) ? x.TagName : x.Name;
                return(name ?? "Release");
            })
            .Subscribe(x => Title = x);

            var shareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null));

            shareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, ReleaseModel.HtmlUrl));

            var gotoUrlCommand = new Action <string>(x =>
            {
                var vm = this.CreateViewModel <WebBrowserViewModel>();
                vm.Init(x);
                NavigateTo(vm);
            });

            var gotoGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null));

            gotoGitHubCommand.Select(_ => ReleaseModel.HtmlUrl).Subscribe(gotoUrlCommand);

            GoToLinkCommand = ReactiveCommand.Create();
            GoToLinkCommand.OfType <string>().Subscribe(x =>
            {
                var handledViewModel = urlRouterService.Handle(x);
                if (handledViewModel != null)
                {
                    NavigateTo(handledViewModel);
                }
                else
                {
                    gotoUrlCommand(x);
                }
            });

            var canShowMenu = this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null);

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(canShowMenu, sender => {
                var menu = actionMenuService.Create();
                menu.AddButton("Share", shareCommand);
                menu.AddButton("Show in GitHub", gotoGitHubCommand);
                return(menu.Show(sender));
            });

            _contentText = this.WhenAnyValue(x => x.ReleaseModel).IsNotNull()
                           .Select(x => x.BodyHtml).ToProperty(this, x => x.ContentText);

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                var request  = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetRelease(ReleaseId);
                ReleaseModel = (await applicationService.Client.ExecuteAsync(request)).Data;
            });
        }