Exemple #1
0
        public async void Refresh(bool showRead)
        {
            var errorCondition = Result.NoError;

            try
            {
                var backendItems = await NextcloudNewsInterface.NextcloudNewsInterface.getInstance().getItems();

                var feeds = await NextcloudNewsInterface.NextcloudNewsInterface.getInstance().getFeeds();

                foreach (var item in backendItems.items)
                {
                    var existingItem = (from ItemModel selitem in _list where selitem.id == item.id select selitem).FirstOrDefault <ItemModel>();
                    if (existingItem == null)
                    {
                        if (showRead == false && item.unread == false)
                        {
                            continue;
                        }

                        var newItem = ItemModel.FromItem(item);
                        var feed    = feeds.getFeedForId(item.feedId);

                        if (feed != null)
                        {
                            if (feed.faviconLink != null && feed.faviconLink != String.Empty)
                            {
                                Uri validatedUri;
                                //TODO: Need to also verify that the protocol part of the url is http or https
                                if (Uri.TryCreate(feed.faviconLink, UriKind.RelativeOrAbsolute, out validatedUri))
                                {
                                    newItem.favicon = feed.faviconLink;
                                }
                                else
                                {
                                    newItem.favicon = "https://boingboing.net/favicon.ico";
                                }
                            }
                            else
                            {
                                newItem.favicon = "https://boingboing.net/favicon.ico";
                            }
                        }
                        _list.Insert(0, newItem);
                    }
                }
            }
            catch
            {
                //TODO: Catch the right exception
                errorCondition = Result.ConnectionError;
            }
            finally
            {
                RefreshComplete?.Invoke(this, errorCondition);
            }
        }