Exemplo n.º 1
0
        public LanguagesViewModel(INetworkActivityService networkActivity, LanguageRepository languageRepository)
        {
            ExtraLanguages = new List <Language>();

            Languages = _languages.CreateDerivedCollection(
                x => x,
                x => x.Name.StartsWith(SearchKeyword ?? string.Empty, StringComparison.OrdinalIgnoreCase),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                var langs = await languageRepository.GetLanguages();
                langs.InsertRange(0, ExtraLanguages);
                _languages.Reset(langs);
            });

            LoadCommand.TriggerNetworkActivity(networkActivity);
        }
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);
        }