示例#1
0
        public UserViewModel(string username, IApplicationService applicationService = null)
        {
            applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();

            GoToFollowersCommand.Subscribe(_ => NavigateTo(new UserFollowersViewModel(username)));
            GoToFollowingCommand.Subscribe(_ => NavigateTo(new UserFollowingsViewModel(username)));
            GoToEventsCommand.Subscribe(_ => NavigateTo(new UserEventsViewModel(username)));
            GoToGroupsCommand.Subscribe(_ => NavigateTo(new GroupsViewModel(username)));
            GoToRepositoriesCommand.Subscribe(_ => NavigateTo(new UserRepositoriesViewModel(username)));

            this.WhenAnyValue(x => x.User.Website)
            .Select(x => !string.IsNullOrEmpty(x))
            .ToProperty(this, x => x.IsWebsiteAvailable, out _isWebsiteAvailable);

            this.WhenAnyValue(x => x.User.DisplayName)
            .Select(x => string.Equals(x, username) ? null : x)
            .ToProperty(this, x => x.DisplayName, out _displayName);

            GoToWebsiteCommand = ReactiveCommand.Create(
                () => NavigateTo(new WebBrowserViewModel(User.Website)),
                this.WhenAnyValue(x => x.IsWebsiteAvailable));

            ShouldShowGroups = string.Equals(username, applicationService.Account.Username, StringComparison.OrdinalIgnoreCase);

            Title = username;

            LoadCommand = ReactiveCommand.CreateFromTask(async t =>
            {
                if (!string.Equals(applicationService.Account.Username, username, StringComparison.OrdinalIgnoreCase))
                {
                    applicationService.Client.Groups.GetGroups(username)
                    .ToObservable()
                    .Select(_ => true)
                    .Catch(Observable.Return(false))
                    .ObserveOn(RxApp.MainThreadScheduler)
                    .Subscribe(x => ShouldShowGroups = x);
                }

                User = await applicationService.Client.Users.GetUser(username);
            });
        }
示例#2
0
        public TeamViewModel(
            string name,
            IApplicationService applicationService = null)
        {
            applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();

            Title = name;

            GoToFollowersCommand.Subscribe(_ => NavigateTo(new TeamFollowersViewModel(name)));
            GoToFollowingCommand.Subscribe(_ => NavigateTo(new TeamFollowingsViewModel(name)));
            GoToMembersCommand.Subscribe(_ => NavigateTo(new TeamMembersViewModel(name)));
            GoToGroupsCommand.Subscribe(_ => NavigateTo(new GroupsViewModel(name)));
            GoToEventsCommand.Subscribe(_ => NavigateTo(new UserEventsViewModel(name)));
            GoToRepositoriesCommand.Subscribe(_ => NavigateTo(new UserRepositoriesViewModel(name)));

            this.WhenAnyValue(x => x.Team.DisplayName)
            .Select(x => string.Equals(x, name) ? null : x)
            .ToProperty(this, x => x.DisplayName, out _displayName);

            LoadCommand = ReactiveCommand.CreateFromTask(async _ =>
            {
                Team = await applicationService.Client.Teams.Get(name);
            });
        }
示例#3
0
        public UserViewModel(IApplicationService applicationService)
        {
            _applicationService = applicationService;

            ToggleFollowingCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsFollowing).Select(x => x.HasValue), t => ToggleFollowing());

            GoToGistsCommand = ReactiveCommand.Create();
            GoToGistsCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserGistsViewModel>();
                vm.Username = Username;
                ShowViewModel(vm);
            });

            GoToRepositoriesCommand = ReactiveCommand.Create();
            GoToRepositoriesCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserRepositoriesViewModel>();
                vm.Username = Username;
                ShowViewModel(vm);
            });

            GoToOrganizationsCommand = ReactiveCommand.Create();
            GoToOrganizationsCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <OrganizationsViewModel>();
                vm.Username = Username;
                ShowViewModel(vm);
            });

            GoToEventsCommand = ReactiveCommand.Create();
            GoToEventsCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserEventsViewModel>();
                vm.Username = Username;
                ShowViewModel(vm);
            });

            GoToFollowingCommand = ReactiveCommand.Create();
            GoToFollowingCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserFollowingsViewModel>();
                vm.Username = Username;
                ShowViewModel(vm);
            });

            GoToFollowersCommand = ReactiveCommand.Create();
            GoToFollowersCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserFollowersViewModel>();
                vm.Username = Username;
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                this.RequestModel(applicationService.Client.AuthenticatedUser.IsFollowing(Username), t as bool?, x => IsFollowing = x.Data).FireAndForget();
                return(this.RequestModel(applicationService.Client.Users[Username].Get(), t as bool?, response => User = response.Data));
            });
        }
示例#4
0
        public OrganizationViewModel(ISessionService applicationService)
        {
            this.WhenAnyValue(x => x.Organization, x => x.Username,
                              (x, y) => x == null ? y : (string.IsNullOrEmpty(x.Name) ? x.Login : x.Name))
            .Select(x => x ?? "Organization")
            .Subscribe(x => Title = x);

            this.WhenAnyValue(x => x.Organization.AvatarUrl)
            .Select(x => new GitHubAvatar(x))
            .ToProperty(this, x => x.Avatar, out _avatar);

            GoToMembersCommand = ReactiveCommand.Create();
            GoToMembersCommand
            .Select(_ => this.CreateViewModel <OrganizationMembersViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToTeamsCommand = ReactiveCommand.Create();
            GoToTeamsCommand
            .Select(_ => this.CreateViewModel <TeamsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToFollowersCommand = ReactiveCommand.Create();
            GoToFollowersCommand
            .Select(_ => this.CreateViewModel <UserFollowersViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToFollowingCommand = ReactiveCommand.Create();
            GoToFollowingCommand
            .Select(_ => this.CreateViewModel <UserFollowingsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToEventsCommand = ReactiveCommand.Create();
            GoToEventsCommand
            .Select(_ => this.CreateViewModel <UserEventsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToGistsCommand = ReactiveCommand.Create();
            GoToGistsCommand
            .Select(_ => this.CreateViewModel <UserGistsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToRepositoriesCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm  = this.CreateViewModel <OrganizationRepositoriesViewModel>();
                vm.Name = Username;
                NavigateTo(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                applicationService.GitHubClient.Organization.Team.GetAll(Username)
                .ToBackground(x => CanViewTeams = true);

                Organization = await applicationService.GitHubClient.Organization.Get(Username);
            });
        }
示例#5
0
        public UserViewModel(ISessionService applicationService, IActionMenuFactory actionMenuService)
        {
            _applicationService = applicationService;

            ToggleFollowingCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsFollowing).Select(x => x.HasValue), t => ToggleFollowing());

            _hasBlog = this.WhenAnyValue(x => x.User.Blog)
                       .Select(x => !string.IsNullOrEmpty(x))
                       .ToProperty(this, x => x.HasBlog);

            _avatar = this.WhenAnyValue(x => x.User.AvatarUrl)
                      .Select(x => new GitHubAvatar(x))
                      .ToProperty(this, x => x.Avatar);

            GoToGistsCommand = ReactiveCommand.Create();
            GoToGistsCommand
            .Select(_ => this.CreateViewModel <UserGistsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToRepositoriesCommand = ReactiveCommand.Create();
            GoToRepositoriesCommand
            .Select(_ => this.CreateViewModel <UserRepositoriesViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToOrganizationsCommand = ReactiveCommand.Create();
            GoToOrganizationsCommand
            .Select(_ => this.CreateViewModel <OrganizationsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToEventsCommand = ReactiveCommand.Create();
            GoToEventsCommand
            .Select(_ => this.CreateViewModel <UserEventsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToFollowingCommand = ReactiveCommand.Create();
            GoToFollowingCommand
            .Select(_ => this.CreateViewModel <UserFollowingsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToFollowersCommand = ReactiveCommand.Create();
            GoToFollowersCommand
            .Select(_ => this.CreateViewModel <UserFollowersViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToWebsiteCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.HasBlog));
            GoToWebsiteCommand
            .Select(_ => this.CreateViewModel <WebBrowserViewModel>())
            .Select(x => x.Init(User.Blog))
            .Subscribe(NavigateTo);

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsFollowing).Select(x => x.HasValue),
                sender => {
                var menu = actionMenuService.Create();
                menu.AddButton(IsFollowing.Value ? "Unfollow" : "Follow", ToggleFollowingCommand);
                return(menu.Show(sender));
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                if (!IsLoggedInUser)
                {
                    applicationService.GitHubClient.User.Followers.IsFollowingForCurrent(Username)
                    .ToBackground(x => IsFollowing = x);
                }

                User = await applicationService.GitHubClient.User.Get(Username);
            });
        }