Exemple #1
0
 public CollectionViewRssPage()
 {
     InitializeComponent();
     rssItem        = new RSSFeedItem();
     viewModel      = new RssItemViewModel();
     BindingContext = viewModel;
 }
        public MainPageCustom()
        {
            InitializeComponent();
            rssItem = new RSSFeedItem();
            var setting       = new SettingPage();
            var settingTabbar = new SettingTabView();

            viewModel.Url = "https://cdn.24h.com.vn/upload/rss/trangchu24h.rss";
            viewModel.LoadRssFeed();
            BindingContext = viewModel;
            setting.UpdateStyleItem();
            settingTabbar.UpdateSettingItem();
            if (Xamarin.Forms.Application.Current.Properties.ContainsKey("TabItem"))
            {
                if (Convert.ToBoolean(Xamarin.Forms.Application.Current.Properties["TabItem"].ToString()))
                {
                    TabBar.IsVisible = false;
                }
                else
                {
                    TabBar.IsVisible = true;
                }
            }
            TabBar.OnTabBarClicked += TabBar_OnTabItemClicked;
        }
Exemple #3
0
        public DetailViewController(RSSFeedItem item)
            : base(UITableViewStyle.Grouped, null, true)
        {
            var attributes = new NSAttributedStringDocumentAttributes();

            attributes.DocumentType   = NSDocumentType.HTML;
            attributes.StringEncoding = NSStringEncoding.UTF8;
            var error      = new NSError();
            var htmlString = new NSAttributedString(item.Description, attributes, ref error);


            Root = new RootElement(item.Title)
            {
                new Section {
                    new StringElement(item.Author),
                    new StringElement(item.PublishDate),
                    new StyledMultilineElement(htmlString),
                    new HtmlElement("Full Article", item.Link)
                }
            };

            NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, async delegate
            {
                var message = item.Title + " " + item.Link + " #PlanetXamarin";
                var social  = new UIActivityViewController(new NSObject[] { new NSString(message) },
                                                           new UIActivity[] { new UIActivity() });
                PresentViewController(social, true, null);
            });
        }
        void BeginDownloadingImage(RSSFeedItem app, NSIndexPath path)
        {
            // Queue the image to be downloaded. This task will execute
            // as soon as the existing ones have finished.
            byte[] data = null;
            DownloadTask = DownloadTask.ContinueWith(prevTask => {
                try {
                    UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
                    using (var c = new GzipWebClient())
                        data = c.DownloadData(app.Image);
                } finally {
                    UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
                }
            });

            // When the download task is finished, queue another task to update the UI.
            // Note that this task will run only if the download is successful and it
            // uses the CurrentSyncronisationContext, which on MonoTouch causes the task
            // to be run on the main UI thread. This allows us to safely access the UI.
            DownloadTask = DownloadTask.ContinueWith(t => {
                // Load the image from the byte array.
                app.TheImage = UIImage.LoadFromData(NSData.FromArray(data));

                // Retrieve the cell which corresponds to the current App. If the cell is null, it means the user
                // has already scrolled that app off-screen.
                var cell = TableView.VisibleCells.Where(c => c.Tag == viewModel.FeedItems.IndexOf(app)).FirstOrDefault();
                if (cell != null)
                {
                    cell.ImageView.Image = app.TheImage;
                }
            }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext());
        }
 public RssFeedItemPage()
 {
     InitializeComponent();
     rssItem       = new RSSFeedItem();
     viewModel     = new RssItemViewModel();
     viewModel.Url = "https://tinhte.vn/rss/";
     //viewModel.Url = Url;
     BindingContext = viewModel;
 }
Exemple #6
0
 protected virtual void AddFeedToOutput(HtmlTextWriter output, RSSFeedItem feed)
 {
     output.AddAttribute(HtmlTextWriterAttribute.Rel, "alternate");
     output.AddAttribute(HtmlTextWriterAttribute.Title, feed.Title.Text);
     output.AddAttribute(HtmlTextWriterAttribute.Type, "application/rss+xml");
     output.AddAttribute(HtmlTextWriterAttribute.Href, feed.Url);
     output.RenderBeginTag(HtmlTextWriterTag.Link);
     output.RenderEndTag();
 }
Exemple #7
0
 public MainPageCustom()
 {
     InitializeComponent();
     rssItem        = new RSSFeedItem();
     BindingContext = viewModel;
     if (!string.IsNullOrEmpty(Url))
     {
         viewModel.Url = Url;
         viewModel.LoadRssFeed();
     }
     TabBar.OnTabBarClicked += TabBar_OnTabItemClicked;
 }
        public MainPageCustom()
        {
            InitializeComponent();
            rssItem = new RSSFeedItem();
            var setting = new SettingPage();

            viewModel.Url = "https://cdn.24h.com.vn/upload/rss/trangchu24h.rss";
            viewModel.LoadRssFeed();
            BindingContext = viewModel;
            setting.UpdateStyleItem();
            viewModel.heightImages  = 40;
            TabBar.OnTabBarClicked += TabBar_OnTabItemClicked;
        }
Exemple #9
0
            private string _EventRssToString()
            {
                try
                {
                    int    count     = 0;
                    string xmlString = String.Empty;

                    if (this._rss == null)
                    {
                        return(String.Empty);
                    }
                    lock (this._lockRss)
                    {
                        foreach (DataRow row in this._data.Rows)
                        {
                            RSSFeedItem itm = this._RssItemAdd(row, (count++), this._parent._ci);
                            if (itm != null)
                            {
                                this._rss.Add(itm);
                            }
                        }

                        xmlString = this._rss.WriteString(this._parent._ilog);

                        if (!string.IsNullOrWhiteSpace(xmlString))
                        {
                            return(xmlString);
                        }
                    }
                }
#if DEBUG
                catch (Exception e)
                {
                    if (this._parent.isLogEnable)
                    {
                        this._parent._ilog.LogError(
                            string.Format(
                                Properties.Resources.CoCNotifyProcessError,
                                Properties.Resources.CoCNotifyDataRss,
                                Properties.Resources.CoCNotifyDataOtherError,
                                e.Message
                                )
                            );
                    }
#else
                catch (Exception)
                {
#endif
                }
                return(String.Empty);
            }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Detail);

            webView = FindViewById <WebView>(Resource.Id.webview);
            var id = Intent.GetIntExtra("id", 0);

            feedItem = MasterActivity.ViewModel.GetFeedItem(id);
            webView.LoadData(feedItem.Description, "text/html", "charset=UTF-8");
            webView.Settings.JavaScriptEnabled = true;

            ActionBar.Title = feedItem.Title;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var idString = string.Empty;

            //parse out id and get feed item from cache
            if (NavigationContext.QueryString.TryGetValue("id", out idString))
            {
                var id = 0;
                int.TryParse(idString, out id);
                item        = MasterPage.ViewModel.GetFeedItem(id);
                DataContext = item;
                var fullHtml = WebBrowserHelper.WrapHtml(item.Description, Browser.ActualWidth);
                Browser.NavigateToString(fullHtml);
            }
        }
Exemple #12
0
        void ShowRSSFeedItemDetails(object sender, EventArgs e)
        {
            if (lstBoxFeed.Items.Count < 1)
            {
                return;
            }
            RSSFeed rssFeed = GetSelectedFeed();

            int selectedIndex = lstBoxFeedItems.SelectedIndex;

            RSSFeedItem rssFeedItem = _currentRssFeedItems[selectedIndex];

            lstBoxFeedItems.Items[selectedIndex] = rssFeedItem.Title;

            rssFeed.ActionIdentifiers.Add(rssFeedItem.Id);
            rssFeed.Save();
            wbRssFeed.DocumentText = rssFeedItem.GetHtmlRepresentation();
        }
Exemple #13
0
            private string _EventRssToString(CoCNotifyHost host)
            {
                int count = 0;

                stRSS.RSSWriter rssRoot = null;
                CultureInfo     ci      = stNet.stWebServerUtil.HttpUtil.GetHttpClientLanguage(host.Language, this._parent._ci);

                try
                {
                    if ((rssRoot = this._RssRootAdd(ci)) == null)
                    {
                        throw new ArgumentNullException();
                    }
                    foreach (DataRow row in this._data.Rows)
                    {
                        RSSFeedItem itm = this._RssItemAdd(row, (count++), ci);
                        if (itm != null)
                        {
                            rssRoot.Add(itm);
                        }
                    }
                    return(rssRoot.WriteString(this._parent._ilog));
                }
#if DEBUG
                catch (Exception e)
                {
                    if (this._parent.isLogEnable)
                    {
                        this._parent._ilog.LogError(
                            string.Format(
                                Properties.Resources.CoCNotifyProcessError,
                                Properties.Resources.CoCNotifyDataRss,
                                Properties.Resources.CoCNotifyDataOtherError,
                                e.Message
                                )
                            );
                    }
#else
                catch (Exception)
                {
#endif
                }
                return(this._rssString);
            }
Exemple #14
0
        void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs args)
        {
            if (args.SelectedItem != null)
            {
                // Deselect item.
                ((Xamarin.Forms.ListView)sender).SelectedItem = null;

                // Set WebView source to RSS item
                rssItem = (RSSFeedItem)args.SelectedItem;

                // For iOS 9, a NSAppTransportSecurity key was added to
                //  Info.plist to allow accesses to EarthObservatory.nasa.gov sites.
                webView.Source = rssItem.Link;

                // Hide and make visible.
                rssLayout.IsVisible = false;
                webLayout.IsVisible = true;
            }
        }
        public static List <RSSFeedItem> GetRSSFeedItems(string rssFeedXml)
        {
            List <RSSFeedItem> rssFeedItems = new List <RSSFeedItem>();

            TextReader      tr        = new StringReader(rssFeedXml);
            XmlReader       xmlReader = XmlReader.Create(tr);
            SyndicationFeed feed      = SyndicationFeed.Load(xmlReader);

            foreach (SyndicationItem item in feed.Items)
            {
                string title   = item.Title.Text;
                string summary = item.Summary.Text;
                List <SyndicationLink> links = item.Links.ToList();
                string      id          = item.Id;
                RSSFeedItem rssFeedItem = new RSSFeedItem(title, summary, id, links);
                rssFeedItems.Add(rssFeedItem);
            }

            return(rssFeedItems);
        }
        private async void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs args)
        {
            if (args.SelectedItem != null)
            {
                // Deselect item.
                ((Xamarin.Forms.ListView)sender).SelectedItem = null;

                // Set WebView source to RSS item
                rssItem = (RSSFeedItem)args.SelectedItem;

                // For iOS 9, a NSAppTransportSecurity key was added to
                //  Info.plist to allow accesses to EarthObservatory.nasa.gov sites.
                //webView.Source = rssItem.Link;

                await Navigation.PushAsync(new RssDetailsPage(rssItem.Link));

                // Hide and make visible.
                //ShowData.IsVisible = false;
                //webLayout.IsVisible = true;
            }
        }
        public DetailViewController(RSSFeedItem item)
            : base(UITableViewStyle.Grouped, null, true)
        {
            var attributes = new NSAttributedStringDocumentAttributes();

            attributes.DocumentType   = NSDocumentType.HTML;
            attributes.StringEncoding = NSStringEncoding.UTF8;
            var error      = new NSError();
            var htmlString = new NSAttributedString(item.Description, attributes, ref error);


            Root = new RootElement(item.Title)
            {
                new Section {
                    new StringElement(item.Author),
                    new StringElement(item.PublishDate),
                    new StyledMultilineElement(htmlString),
                    new HtmlElement("Full Article", item.Link)
                }
            };
        }
Exemple #18
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Detail);

            webView = FindViewById <WebView>(Resource.Id.webview);
            var id = Intent.GetIntExtra("id", 0);

            feedItem = MasterActivity.ViewModel.GetFeedItem(id);
            webView.LoadData(feedItem.Description, "text/html", "charset=UTF-8");
            webView.Settings.JavaScriptEnabled = true;

            ActionBar.Title = feedItem.Title;

            readFullButton        = FindViewById <Button>(Resource.Id.button_read_full);
            readFullButton.Click += (sender, args) =>
            {
                webView.LoadUrl(feedItem.Link);
                readFullButton.Visibility = ViewStates.Gone;
            };
        }
Exemple #19
0
        private List <RSSFeedItem> GetRSSFeedItems(List <string> feedList)
        {
            var RSSItems = new List <RSSFeedItem>();

            foreach (var url in feedList)
            {
                XmlReader       reader = XmlReader.Create(url);
                SyndicationFeed feed   = SyndicationFeed.Load(reader);
                reader.Close();
                foreach (var item in feed.Items)
                {
                    var RSSItem = new RSSFeedItem();
                    RSSItem.ImageSrc    = feed.ImageUrl;
                    RSSItem.ItemSrc     = item.Links.FirstOrDefault().Uri;
                    RSSItem.PublishDate = item.PublishDate.DateTime;
                    RSSItem.Title       = item.Title.Text;
                    RSSItem.Description = item.Summary.Text;

                    RSSItems.Add(RSSItem);
                }
            }
            return(RSSItems);
        }
Exemple #20
0
 public ItemDetailViewModel(RSSFeedItem item = null)
 {
     Title   = item?.Link;
     RssItem = item;
 }
        public void LoadRssFeed()
        {
            if (!string.IsNullOrEmpty(Url))
            {
                WebRequest request = WebRequest.Create(Url);
                request.BeginGetResponse((args) =>
                {
                    try
                    {
                        // Download XML.
                        Stream stream = request.EndGetResponse(args).GetResponseStream();
                        StreamReader reader = new StreamReader(stream);
                        string xml = reader.ReadToEnd();

                        // Parse XML to extract data from RSS feed.
                        XDocument doc = XDocument.Parse(xml);
                        XElement rss = doc.Element(XName.Get("rss"));
                        XElement channel = rss.Element(XName.Get("channel"));

                        // Set Title property.
                        Title = channel.Element(XName.Get("title")).Value;

                        // Set Items property.
                        List<RSSFeedItem> list =
                        channel.Elements(XName.Get("item")).Select((XElement element) =>
                        {
                            var desciption = element.Element(XName.Get("description"));
                            //var image = desciption.Element(XName.Get("img")).Attribute("src").Value.ToString();
                            var result = new RSSFeedItem();
                            result.Title = element.Element(XName.Get("title")).Value;
                            result.Description = desciption.Value;
                            result.Link = element.Element(XName.Get("link")).Value;
                            result.PubDate = element.Element(XName.Get("pubDate")).Value;
                            #region get images form description
                            Regex regx = new Regex("http(s?)://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?.(?:jpg|bmp|gif|png)", RegexOptions.IgnoreCase);
                            MatchCollection mactches = regx.Matches(desciption.ToString());
                            if (mactches.Count > 0)
                            {
                                foreach (var urlImage in mactches)
                                {
                                    result.Thumbnail = urlImage.ToString();
                                }
                            }
                            else
                            {
                                result.Thumbnail = "";
                            }
                            #endregion
                            return result;

                        }).ToList();
                        var lstItem = list.OrderByDescending(s => s.PubDateTime).ToList();
                        try
                        {
                            if (!string.IsNullOrEmpty(searchText))
                            {
                                Items = lstItem.Where(s => s.Title.ToLower().Contains(searchText.ToLower())).ToList().ToObservableCollection();
                            }
                            else
                            {
                                Items = lstItem.ToObservableCollection();
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }

                        // Set IsRefreshing to false to stop the 'wait' icon.
                        IsRefreshing = false;
                    }
                    catch (Exception)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            Application.Current.MainPage.DisplayAlert("Server Error", "Not Connected", "OK");
                        });
                    }
                }, null);
            }
            else
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Application.Current.MainPage.DisplayAlert("Error", "Please check url no empty", "OK");
                });
            }


        }
Exemple #22
0
 public RssTriThucPage()
 {
     InitializeComponent();
     rssItem        = new RSSFeedItem();
     BindingContext = viewModel;
 }