Example #1
0
        private async void DataCacheServiceOnDataChanged(object sender, EventArgs eventArgs)
        {
            var feeds = (await _dataCacheService.GetNewsFeeds(it => it.UnreadCount > 0)).OrderBy(ob => ob.Title).ToList();

            // Add items
            foreach (var feed in feeds)
            {
                var item = FeedItemSource.FirstOrDefault(x => x.Id == feed.Id);
                if (item == null)
                {
                    FeedItemSource.Add(feed);
                }
            }

            // Remove items
            foreach (var feed in FeedItemSource.ToList())
            {
                var item = feeds.FirstOrDefault(x => x.Id == feed.Id);
                if (item == null)
                {
                    FeedItemSource.Remove(feed);
                }
            }
        }
Example #2
0
        private async Task ProcessFeedUpdates(NewsFeedResponse results)
        {
            _dataCacheService.BeginWrite();

            foreach (var item in results.Feeds)
            //foreach (var item in results.feeds.FeedItems.Where(t => t.properties.feed_title == "AnandTech"))
            {
                //TODO: dependency inject the realmness
                var thisFeed = (await _dataCacheService.GetNewsFeeds(fe => fe.Id == item.Id)).FirstOrDefault();
                if (thisFeed == null)
                {
                    try
                    {
                        Debug.WriteLine(item.LastStoryDate);
                        thisFeed = new NewsFeed()
                        {
                            Id      = item.Id,
                            FeedUri = item.FeedAddress,
                            Title   = item.FeedTitle,
                            IconUri = item.FaviconUrl,
                            Active  = item.Active,
                            LastStoryDateFromService = !string.IsNullOrEmpty(item.LastStoryDate) ? DateTimeOffset.Parse(item.LastStoryDate) : DateTimeOffset.MinValue
                        };

                        _dataCacheService.AddFeed(thisFeed);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
                else
                {
                    if (item.LastStoryDate != null)
                    {
                        thisFeed.LastStoryDateFromService = DateTimeOffset.Parse(item.LastStoryDate);
                    }
                }

                //thisFeed.UnreadCount = DataModelManager.RealmInstance.All<Story>().Where(st => st.ReadStatus == 0 && st.FeedId == thisFeed.Id).Count();
            }

            _dataCacheService.Commit();
        }