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, 
            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 RepositoriesTrendingViewModel(IApplicationService applicationService, IJsonHttpClientService jsonHttpClient)
        {
            _applicationService = applicationService;
            _jsonHttpClient     = jsonHttpClient;

            Languages    = new ReactiveList <LanguageModel>();
            Repositories = new ReactiveList <RepositoryModel>();

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

            SelectedTime     = Times[0];
            SelectedLanguage = _defaultLanguage;
            GetLanguages().FireAndForget();

            this.WhenAnyValue(x => x.SelectedTime, x => x.SelectedLanguage, (x, y) => Unit.Default)
            .Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                var query = "?";
                if (SelectedLanguage != null && SelectedLanguage.Slug != null)
                {
                    query += string.Format("language={0}&", SelectedLanguage.Slug);
                }
                if (SelectedTime != null && SelectedTime.Slug != null)
                {
                    query += string.Format("since={0}", SelectedTime.Slug);
                }

                var repos = await _jsonHttpClient.Get <List <RepositoryModel> >(TrendingUrl + query);
                Repositories.Reset(repos);
            });
        }
        public RepositoriesTrendingViewModel(IApplicationService applicationService, IJsonHttpClientService jsonHttpClient)
        {
            _applicationService = applicationService;
            _jsonHttpClient = jsonHttpClient;

            Languages = new ReactiveList<LanguageModel>();
            Repositories = new ReactiveCollection<RepositoryModel>();

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

            SelectedTime = Times[0];
            SelectedLanguage = _defaultLanguage;
            GetLanguages().FireAndForget();

            this.WhenAnyValue(x => x.SelectedTime, x => x.SelectedLanguage, (x, y) => Unit.Default)
                .Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());

            LoadCommand.RegisterAsyncTask(async t =>
            {
                var query = "?";
                if (SelectedLanguage != null && SelectedLanguage.Slug != null)
                    query += string.Format("language={0}&", SelectedLanguage.Slug);
                if (SelectedTime != null && SelectedTime.Slug != null)
                    query += string.Format("since={0}", SelectedTime.Slug);

                var repos = await _jsonHttpClient.Get<List<RepositoryModel>>(TrendingUrl + query);
                Repositories.Reset(repos);
            });
        }
Esempio n. 5
0
 public GistCommentViewModel(IStatusIndicatorService status, IAlertDialogService alert, IJsonHttpClientService jsonClient, IApplicationService applicationService)
     : base(status, alert, jsonClient)
 {
     _applicationService = applicationService;
 }
 public RepositoriesTrendingViewModel(IJsonHttpClientService jsonHttpClient)
 {
     _jsonHttpClient = jsonHttpClient;
 }
 public RepositoriesTrendingViewModel(IJsonHttpClientService jsonHttpClient)
 {
     _jsonHttpClient = jsonHttpClient;
 }
Esempio n. 8
0
        protected MarkdownComposerViewModel(IStatusIndicatorService status, IAlertDialogService alert, IJsonHttpClientService jsonClient)
        {
            var saveCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)),
                t => Save());

            saveCommand.IsExecuting.Where(x => x).Subscribe(_ => status.Show("Saving..."));
            saveCommand.IsExecuting.Where(x => !x).Subscribe(_ => status.Hide());
            saveCommand.Subscribe(x => DismissCommand.ExecuteIfCan());
            SaveCommand = saveCommand;

            PostToImgurCommand =
                ReactiveCommand.CreateAsyncTask(async data =>
            {
                var uploadData = data as byte[];
                if (uploadData == null)
                {
                    throw new Exception("There is no data to upload!");
                }

                return(await jsonClient.Post <ImgurModel>("https://api.imgur.com/3/image",
                                                          new { image = Convert.ToBase64String(uploadData) },
                                                          new Dictionary <string, string> {
                    { "Authorization", "Client-ID " + AuthorizationClientId }
                }));
            });

            PostToImgurCommand.IsExecuting.Where(x => x).Subscribe(_ => status.Show("Uploading..."));
            PostToImgurCommand.IsExecuting.Where(x => !x).Subscribe(_ => status.Hide());
            PostToImgurCommand.ThrownExceptions.SubscribeSafe(e => alert.Alert("Error", "Unable to upload image: " + e.Message));
        }