示例#1
0
        private async Task <IReadOnlyList <Issue> > RetrieveIssues(int page = 1)
        {
            var connection = _sessionService.GitHubClient.Connection;
            var parameters = new Dictionary <string, string>();

            parameters["page"]     = page.ToString();
            parameters["per_page"] = 50.ToString();
            AddRequestParameters(parameters);

            parameters = parameters.Where(x => x.Value != null).ToDictionary(x => x.Key, x => x.Value);
            var ret = await connection.Get <IReadOnlyList <Issue> >(RequestUri, parameters, "application/json");

            if (ret.HttpResponse.ApiInfo.Links.ContainsKey("next"))
            {
                LoadMoreCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                    IssuesBacking.AddRange(await RetrieveIssues(page + 1));
                });
            }
            else
            {
                LoadMoreCommand = null;
            }

            return(ret.Body);
        }
 public static void Reset <T>(this IReactiveList <T> @this, IEnumerable <T> items)
 {
     using (@this.SuppressChangeNotifications())
     {
         @this.Clear();
         @this.AddRange(items);
     }
 }
 protected override Task Load(IApplicationService applicationService, IReactiveList <Repository> repositories)
 {
     return(applicationService.Client.ForAllItems(x => x.Repositories.GetAll("member"), repos =>
     {
         var shared = repos.Where(x => !string.Equals(x.Owner?.Username, _username, System.StringComparison.OrdinalIgnoreCase));
         repositories.AddRange(shared);
     }));
 }
        private void RemoveDuplicates <T, TKey>(IReactiveList <T> list, Func <T, TKey> keySelector)
        {
            var distinct = list.Distinct(keySelector).ToList();

            if (distinct.Count != list.Count)
            {
                list.Clear();
                list.AddRange(distinct);
            }
        }
示例#5
0
 public FaveGroupViewModel(
     Func <Article, FeedItemViewModel> factory,
     IGrouping <string, Article> grouping)
 {
     _factory  = factory;
     _grouping = grouping;
     _source   = new ReactiveList <FeedItemViewModel> {
         ChangeTrackingEnabled = true
     };
     Items = _source.CreateDerivedCollection(x => x, x => x.Fave);
     _source.AddRange(_grouping.Select(_factory));
 }
示例#6
0
 public Playlist(IEnumerable <Episode> collection)
     : this()
 {
     items.AddRange(collection.Select(_ =>
     {
         var item = new PlaylistItem(_)
         {
             Playlist = this
         };
         return(item);
     }));
 }
示例#7
0
        private async Task DoFetch()
        {
            var settings = await _settingManager.Read();

            var response = await _feedStoreService.Load(_category.Channels);

            var viewModels = response.Select(_factory).ToList();

            ShowRead = settings.Read;
            _source.Clear();
            _source.AddRange(viewModels);
        }
示例#8
0
 void SetupCollectionItems <T>(IReactiveList <T> src, IReactiveList <IHierarchicalLibraryItem> dst,
                               Func <T, bool> predicate = null) where T : Collection
 {
     lock (src) {
         var srcF = predicate == null ? src : src.Where(predicate);
         lock (dst)
             dst.AddRange(srcF.Select(CreateCustomModSet));
         _disposables.Add(src.TrackChanges(
                              x => dst.AddLocked(CreateCustomModSet(x)),
                              x => {
             lock (CollectionsGroup.Children)
                 dst.RemoveLocked(GetCollection(x));
         },
                              reset => {
             lock (dst) {
                 lock (CollectionsGroup.Children)
                     dst.RemoveAll(GetCollections().ToArray());
                 dst.AddRange(reset.Select(CreateCustomModSet));
             }
         }, predicate));
     }
 }
示例#9
0
        public static async Task SimpleCollectionLoad <T>(this IReactiveList <T> viewModel, GitHubRequest <List <T> > request, Action <Func <Task> > assignMore = null) where T : new()
        {
            if (assignMore == null)
            {
                assignMore = (x) => {}
            }
            ;

            var application = Locator.Current.GetService <ISessionService>();
            var response    = await application.Client.ExecuteAsync(request);

            viewModel.CreateMore(response, assignMore, x => viewModel.AddRange(x));
            viewModel.Reset(response.Data);
        }
    }
示例#10
0
        /// <summary>
        /// Adapts the specified changeset
        /// </summary>
        /// <param name="changes">The changes.</param>
        public void Adapt(IChangeSet <TObject, TKey> changes)
        {
            Clone(changes);

            if (changes.Count - changes.Refreshes > _resetThreshold || !_loaded)
            {
                _loaded = true;
                using (_target.SuppressChangeNotifications())
                {
                    _target.Clear();
                    _target.AddRange(_data.Values);
                }
            }
            else
            {
                DoUpdate(changes);
            }
        }
示例#11
0
        private async Task <IReadOnlyList <Gist> > RetrieveGists(int page = 1)
        {
            var connection = _sessionService.GitHubClient.Connection;
            var parameters = new Dictionary <string, string>();

            parameters["page"] = page.ToString();
            var ret = await connection.Get <IReadOnlyList <Gist> >(ApiUrls.PublicGists(), parameters, "application/json");

            if (ret.HttpResponse.ApiInfo.Links.ContainsKey("next"))
            {
                LoadMoreCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                    _gists.AddRange(await RetrieveGists(page + 1));
                });
            }
            else
            {
                LoadMoreCommand = null;
            }

            return(ret.Body);
        }
示例#12
0
        public static Task SimpleCollectionLoad <T>(this IReactiveList <T> viewModel, GitHubRequest <List <T> > request, bool?forceDataRefresh, Action <Func <Task> > assignMore = null) where T : new()
        {
            if (assignMore == null)
            {
                assignMore = (x) => {}
            }
            ;

            return(viewModel.RequestModel(request, forceDataRefresh, response =>
            {
                viewModel.CreateMore(response, assignMore, x =>
                {
                    // This is f*****g broken for iOS because it can't handle estimated rows and the insertions
                    // that ReactiveUI seems to be producing
                    using (viewModel.SuppressChangeNotifications())
                    {
                        viewModel.AddRange(x);
                    }
                });
                viewModel.Reset(response.Data);
            }));
        }
    }
示例#13
0
        private async Task <IReadOnlyList <GitHubCommit> > RetrieveCommits(int page = 1)
        {
            var connection = SessionService.GitHubClient.Connection;
            var parameters = new Dictionary <string, string>();

            parameters["page"] = page.ToString();
            AddRequestParameters(parameters);
            var ret = await connection.Get <IReadOnlyList <GitHubCommit> >(RequestUri, parameters, "application/json");

            if (ret.HttpResponse.ApiInfo.Links.ContainsKey("next"))
            {
                LoadMoreCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                    var loadMore = await RetrieveCommits(page + 1);
                    _commits.AddRange(loadMore.Select(x => new CommitItemViewModel(x, GoToCommit)));
                });
            }
            else
            {
                LoadMoreCommand = null;
            }

            return(ret.Body);
        }
示例#14
0
        private async Task <IReadOnlyList <PullRequest> > RetrievePullRequests(int page = 1)
        {
            var connection = _sessionService.GitHubClient.Connection;
            var parameters = new Dictionary <string, string>();

            parameters["page"]     = page.ToString();
            parameters["per_page"] = 50.ToString();
            parameters["state"]    = SelectedFilter == 0 ? "open" : "closed";
            var ret = await connection.Get <IReadOnlyList <PullRequest> >(ApiUrls.PullRequests(RepositoryOwner, RepositoryName), parameters, "application/json");

            if (ret.HttpResponse.ApiInfo.Links.ContainsKey("next"))
            {
                LoadMoreCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                    _pullRequests.AddRange(await RetrievePullRequests(page + 1));
                });
            }
            else
            {
                LoadMoreCommand = null;
            }

            return(ret.Body);
        }
示例#15
0
        protected override async Task Load(IApplicationService applicationService, IReactiveList <Repository> repositories)
        {
            var watchers = await applicationService.Client.Repositories.GetWatched();

            repositories.AddRange(watchers.Select(x =>
            {
                return(new Repository
                {
                    Name = x.Name,
                    CreatedOn = x.UtcCreatedOn,
                    Description = x.Description,
                    FullName = x.Owner + "/" + x.Slug,
                    UpdatedOn = x.UtcLastUpdated,
                    Owner = new User
                    {
                        Username = x.Owner,
                        Links = new User.UserLinks
                        {
                            Avatar = new Link(x.Logo)
                        }
                    }
                });
            }));
        }
 public static void Replace <T>(this IReactiveList <T> col, IEnumerable <T> replacement)
 {
     col.Clear();
     col.AddRange(replacement);
 }