Ejemplo n.º 1
0
        void LoadFeeds()
        {
            List <UserFeed> feeds = null;

            using (var repo = new Repo()) {
                feeds = repo.GetFeeds(Service);

                feeds.Sort((x, y) => x.Category.CompareTo(y.Category));
            }

            DialogSection feedSection = null;

            foreach (var f in feeds)
            {
                if (feedSection == null || feedSection.Header != f.Category)
                {
                    feedSection = new DialogSection(f.Category);
                    Sections.Add(feedSection);
                }

                var e = new FeedElement(Service, f, UITableViewCellAccessory.None);
                e.Selected += delegate {
                    if (FeedSelected != null)
                    {
                        FeedSelected(e.Feed);
                    }
                };
                feedSection.Add(e);
            }
        }
        void LoadData(bool forceFeeds)
        {
            //
            // Load the data
            //
            List <UserQuery> queries = null;
            List <UserFeed>  feeds   = null;

            using (var repo = new Repo()) {
                queries = repo.GetQueries(Service);

                feeds = repo.GetFeeds(Service);

                feeds.Sort((x, y) => x.Category.CompareTo(y.Category));

                if (feeds.Count == 0 || Service.ShouldUpdateFeeds || forceFeeds)
                {
                    BeginDownloadFeeds();
                }
            }

            //
            // Update the UI
            //
            if (feeds.Count > 0)
            {
                RemoveLoading();
                foreach (var f in _feeds)
                {
                    Sections.Remove(f);
                }

                DialogSection feedSection = null;

                foreach (var f in feeds)
                {
                    if (feedSection == null || feedSection.Header != f.Category)
                    {
                        feedSection = new DialogSection(f.Category);
                        _feeds.Add(feedSection);
                        Sections.Add(feedSection);
                    }

                    var e = new FeedElement(Service, f, UITableViewCellAccessory.DisclosureIndicator);
                    e.Selected += delegate { PushDataViewController(e.Feed); };
                    feedSection.Add(e);
                }
            }

            _queries.Clear();
            foreach (var q in queries)
            {
                var e = new QueryElement(q);
                _queries.Add(e);
            }
            if (queries.Count > 0 && !Sections.Contains(_queries))
            {
                Sections.Insert(0, _queries);
            }

            TableView.ReloadData();
        }