Exemplo n.º 1
0
        private void BottomNavigation_NavigationItemSelected(object sender, BottomNavigationView.NavigationItemSelectedEventArgs e)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine($"Bottom navigation menu is selected: {e.Item.ItemId}");

                if (e.Item.ItemId == Resource.Id.menu_settings)
                {
                    if (GoToSettingsCommand != null && GoToSettingsCommand.CanExecute(null))
                    {
                        GoToSettingsCommand.Execute(null);
                    }
                }
                if (e.Item.ItemId == Resource.Id.menu_list)
                {
                    if (GoToFavoritesCommand != null && GoToFavoritesCommand.CanExecute(null))
                    {
                        GoToFavoritesCommand.Execute(null);
                    }
                }
                if (e.Item.ItemId == Resource.Id.menu_home)
                {
                    if (GoToHomeCommand != null && GoToHomeCommand.CanExecute(null))
                    {
                        GoToHomeCommand.Execute(null);
                    }
                }
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine($"Exception: {exception.Message}");
                Crashes.TrackError(exception);
            }
        }
Exemplo n.º 2
0
        public ProfileViewModel(IApplicationService applicationService, INetworkActivityService networkActivity, IFeaturesService featuresService)
        {
            StumbleHistory       = new ReactiveList <StumbledRepository>();
            GoToInterestsCommand = ReactiveCommand.Create();
            Username             = applicationService.Account.Username;

            Action updateStumbled = () =>
            {
                var stumbledRepositories = applicationService.Account.StumbledRepositories.Count();
                Interests      = applicationService.Account.Interests.Count();
                Likes          = applicationService.Account.StumbledRepositories.LikedRepositories();
                Dislikes       = applicationService.Account.StumbledRepositories.DislikedRepositories();
                HasMoreHistory = stumbledRepositories > 30;
                if (stumbledRepositories != StumbledRepositories)
                {
                    StumbledRepositories = stumbledRepositories;
                    StumbleHistory.Reset(applicationService.Account.StumbledRepositories.Query.OrderByDescending(x => x.CreatedAt).Take(30));
                }
            };

            this.WhenActivated(d =>
            {
                if (applicationService.Account != null)
                {
                    updateStumbled();

                    d(applicationService.RepositoryAdded
                      .Buffer(TimeSpan.FromSeconds(5))
                      .Where(x => x.Count > 0)
                      .ObserveOn(SynchronizationContext.Current)
                      .Subscribe(x => updateStumbled()));
                }

                CanPurchase = !featuresService.ProEditionEnabled;
            });

            GoToRepositoryCommand = ReactiveCommand.Create();
            GoToRepositoryCommand.OfType <StumbledRepository>().Subscribe(x =>
            {
                var vm = CreateViewModel <RepositoryViewModel>();
                vm.RepositoryIdentifier = new BaseRepositoryViewModel.RepositoryIdentifierModel(x.Owner, x.Name);
                ShowViewModel(vm);
            });

            GoToPurchaseCommand = ReactiveCommand.Create();
            GoToPurchaseCommand.Subscribe(_ => CreateAndShowViewModel <PurchaseProViewModel>());

            GoToHistoryCommand = ReactiveCommand.Create();
            GoToHistoryCommand.Subscribe(_ => CreateAndShowViewModel <HistoryViewModel>());

            GoToLikesCommand = ReactiveCommand.Create();
            GoToLikesCommand.Subscribe(_ => CreateAndShowViewModel <LikedRepositoriesViewModel>());

            GoToDislikesCommand = ReactiveCommand.Create();
            GoToDislikesCommand.Subscribe(_ => CreateAndShowViewModel <DislikedRepositoriesViewModel>());

            GoToSettingsCommand = ReactiveCommand.Create();
            GoToSettingsCommand.Subscribe(_ => CreateAndShowViewModel <SettingsViewModel>());


            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                User = await applicationService.Client.User.Current();
            });

            LoadCommand.TriggerNetworkActivity(networkActivity);
        }
Exemplo n.º 3
0
        public MenuViewModel(IApplicationService applicationService, IAccountsService accountsService)
            : base(accountsService)
        {
            _applicationService = applicationService;

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

            GoToAccountsCommand = ReactiveCommand.Create();
            GoToAccountsCommand.Subscribe(_ => CreateAndShowViewModel <AccountsViewModel>());

            GoToProfileCommand = ReactiveCommand.Create();
            GoToProfileCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserViewModel>();
                vm.Username = Account.Username;
                ShowViewModel(vm);
            });

            GoToMyIssuesCommand = ReactiveCommand.Create();
            GoToMyIssuesCommand.Subscribe(_ => CreateAndShowViewModel <MyIssuesViewModel>());

            GoToUpgradesCommand = ReactiveCommand.Create();
            GoToUpgradesCommand.Subscribe(_ => CreateAndShowViewModel <UpgradesViewModel>());

            GoToAboutCommand = ReactiveCommand.Create();
            GoToAboutCommand.Subscribe(_ => CreateAndShowViewModel <AboutViewModel>());

            GoToRepositoryCommand = ReactiveCommand.Create();
            GoToRepositoryCommand.OfType <RepositoryIdentifier>().Subscribe(x =>
            {
                var vm             = CreateViewModel <RepositoryViewModel>();
                vm.RepositoryOwner = x.Owner;
                vm.RepositoryName  = x.Name;
                ShowViewModel(vm);
            });

            GoToSettingsCommand = ReactiveCommand.Create();
            GoToSettingsCommand.Subscribe(_ => CreateAndShowViewModel <SettingsViewModel>());

            GoToNewsCommand = ReactiveCommand.Create();
            GoToNewsCommand.Subscribe(_ => CreateAndShowViewModel <NewsViewModel>());

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

            GoToTrendingRepositoriesCommand = ReactiveCommand.Create();
            GoToTrendingRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel <RepositoriesTrendingViewModel>());

            GoToExploreRepositoriesCommand = ReactiveCommand.Create();
            GoToExploreRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel <RepositoriesExploreViewModel>());

            GoToOrganizationEventsCommand = ReactiveCommand.Create();
            GoToOrganizationEventsCommand.OfType <string>().Subscribe(name =>
            {
                var vm      = CreateViewModel <UserEventsViewModel>();
                vm.Username = name;
                ShowViewModel(vm);
            });

            GoToOrganizationCommand = ReactiveCommand.Create();
            GoToOrganizationCommand.OfType <string>().Subscribe(name =>
            {
                var vm      = CreateViewModel <OrganizationViewModel>();
                vm.Username = name;
                ShowViewModel(vm);
            });

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

            GoToStarredRepositoriesCommand = ReactiveCommand.Create().WithSubscription(
                _ => CreateAndShowViewModel <RepositoriesStarredViewModel>());

            GoToPublicGistsCommand = ReactiveCommand.Create().WithSubscription(
                _ => CreateAndShowViewModel <PublicGistsViewModel>());

            GoToStarredGistsCommand = ReactiveCommand.Create().WithSubscription(
                _ => CreateAndShowViewModel <StarredGistsViewModel>());

            GoToMyGistsCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm      = CreateViewModel <UserGistsViewModel>();
                vm.Username = Account.Username;
                ShowViewModel(vm);
            });

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

            LoadCommand = ReactiveCommand.CreateAsyncTask(_ =>
            {
                var notificationRequest = applicationService.Client.Notifications.GetAll();
                notificationRequest.RequestFromCache = false;
                notificationRequest.CheckIfModified  = false;

                var task2 = applicationService.Client.ExecuteAsync(notificationRequest)
                            .ContinueWith(t => Notifications = t.Result.Data.Count, TaskScheduler.FromCurrentSynchronizationContext());

                var task3 = applicationService.Client.ExecuteAsync(applicationService.Client.AuthenticatedUser.GetOrganizations())
                            .ContinueWith(t => Organizations = t.Result.Data.Select(y => y.Login).ToList(), TaskScheduler.FromCurrentSynchronizationContext());

                return(Task.WhenAll(task2, task3));
            });
        }
Exemplo n.º 4
0
        public MenuViewModel(
            IApplicationService applicationService = null,
            IAccountsService accountsService       = null)
        {
            _applicationService = applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            accountsService     = accountsService ?? Locator.Current.GetService <IAccountsService>();

            var account = applicationService.Account;

            Avatar   = new Avatar(account.AvatarUrl);
            Username = account.Username;
            var username = Username;

            Title = username;

            var repos = new ReactiveList <PinnedRepository>();

            PinnedRepositories = repos.CreateDerivedCollection(x =>
            {
                var vm = new PinnedRepositoryItemViewModel(x.Name, new Avatar(x.ImageUri));
                vm.DeleteCommand
                .Do(_ => account.PinnedRepositories.RemoveAll(y => y.Id == x.Id))
                .Subscribe(_ => repos.Remove(x));
                vm.GoToCommand
                .Select(_ => new RepositoryViewModel(x.Owner, x.Slug))
                .Subscribe(NavigateTo);
                return(vm);
            });

            RefreshCommand = ReactiveCommand.CreateFromTask(_ =>
            {
                repos.Reset(applicationService.Account.PinnedRepositories);
                return(Task.FromResult(Unit.Default));
            });

            var teams = new ReactiveList <User>();

            Teams = teams.CreateDerivedCollection(x =>
            {
                var viewModel = new TeamItemViewModel(x.Username);
                viewModel.GoToCommand
                .Select(_ => new TeamViewModel(x))
                .Subscribe(NavigateTo);
                return(viewModel);
            });

            TeamEvents = teams.CreateDerivedCollection(x =>
            {
                var viewModel = new TeamItemViewModel(x.Username);
                viewModel.GoToCommand
                .Select(_ => new UserEventsViewModel(x.Username))
                .Subscribe(NavigateTo);
                return(viewModel);
            });

            LoadCommand = ReactiveCommand.CreateFromTask(t =>
            {
                applicationService.Client
                .AllItems(x => x.Teams.GetAll())
                .ToBackground(teams.Reset);

                applicationService.Client.Groups
                .GetGroups(username)
                .ToBackground(groups => Groups.Reset(groups.Select(ToViewModel)));

                return(Task.FromResult(Unit.Default));
            });

            GoToProfileCommand
            .Select(_ => new UserViewModel(username))
            .Subscribe(NavigateTo);

            GoToMyEvents
            .Select(_ => new UserEventsViewModel(username))
            .Subscribe(NavigateTo);

            GoToStarredRepositoriesCommand
            .Select(_ => new RepositoriesStarredViewModel())
            .Subscribe(NavigateTo);

            GoToOwnedRepositoriesCommand
            .Select(_ => new UserRepositoriesViewModel(username))
            .Subscribe(NavigateTo);

            GoToSharedRepositoriesCommand
            .Select(_ => new RepositoriesSharedViewModel())
            .Subscribe(NavigateTo);

            GoToTeamsCommand
            .Select(_ => new TeamsViewModel())
            .Subscribe(NavigateTo);

            GoToSettingsCommand
            .Select(_ => new SettingsViewModel())
            .Subscribe(NavigateTo);

            GoToFeedbackCommand
            .Select(_ => new IssuesViewModel("thedillonb", "codebucket"))
            .Subscribe(NavigateTo);

            GoToGroupsCommand
            .Select(_ => new GroupsViewModel(username))
            .Subscribe(NavigateTo);

            GoToExploreRepositoriesCommand
            .Select(_ => new RepositoriesExploreViewModel())
            .Subscribe(NavigateTo);

            GoToDefaultTopView.Subscribe(_ =>
            {
                var startupViewName = applicationService.Account.DefaultStartupView;
                if (!string.IsNullOrEmpty(startupViewName))
                {
                    var props                       = from p in GetType().GetProperties()
                                           let attr = p.GetCustomAttributes(typeof(PotentialStartupViewAttribute), true)
                                                      where attr.Length == 1
                                                      select new { Property = p, Attribute = attr[0] as PotentialStartupViewAttribute };


                    var match = props.FirstOrDefault(x => string.Equals(startupViewName, x.Attribute.Name));
                    var cmd   = match?.Property.GetValue(this) as ReactiveCommand <Unit, Unit>;
                    if (cmd != null)
                    {
                        cmd.ExecuteNow();
                        return;
                    }
                }

                //Oh no... Look for the last resort DefaultStartupViewAttribute
                var deprop = (from p in GetType().GetProperties()
                              let attr = p.GetCustomAttributes(typeof(DefaultStartupViewAttribute), true)
                                         where attr.Length == 1
                                         select new { Property = p, Attribute = attr[0] as DefaultStartupViewAttribute }).FirstOrDefault();

                //That shouldn't happen...
                var bCmd = deprop?.Property.GetValue(this) as ReactiveCommand <Unit, Unit>;
                if (bCmd != null)
                {
                    bCmd.ExecuteNow();
                }
            });
        }