Пример #1
0
        public DetailNewsPageViewModel()
        {
            Task.Run(() =>
            {
                NewsDetailResponse newsDetailResponse = null;

                _cache.TryGetValue(Helpers.Helper.Instance().news.slug, out newsDetailResponse);

                if (newsDetailResponse == null)
                {
                    newsDetailResponse = PingPongNews.GetNewsDetail(Helpers.Helper.Instance().news.slug);

                    _cache.Add(Helpers.Helper.Instance().news.slug, newsDetailResponse);
                }
                var data    = newsDetailResponse.data.content;
                imageSource = Helpers.Helper.Instance().news.image;
                string html =
                    "<html><head><style>img{max-width: 100%; width:auto; max-height: 250;}h1{color:blue;font-size: 100%}</style></head>" +
                    "<body>" +
                    "<img src=\"" + imageSource + "\">" +
                    data +
                    "<h1>Nguồn Sporttv.vn<h1>" +
                    "</body></html>";
                Device.BeginInvokeOnMainThread(() =>
                {
                    DetailNews = html;
                });
            });
        }
Пример #2
0
        private void GetNewsDetail()
        {
            NewsDetailResponse newsDetailResponse = null;

            _cache.TryGetValue(_news.slug, out newsDetailResponse);

            if (newsDetailResponse == null)
            {
                newsDetailResponse = PingPongNews.GetNewsDetail(_news.slug);

                _cache.Add(_news.slug, newsDetailResponse);
            }


            if (newsDetailResponse.success)
            {
                var data = newsDetailResponse.data.content;
                //lblContent.Text = "<!DOCTYPE><html><body>" + data + "</body></html>";
                //lblContent.Text = "<html><body><h1>Xamarin.Forms</h1><p>Welcome to WebView.</p></body></html>";
                // var htmlDoc = new HtmlAgilityPack.HtmlDocument();
                // htmlDoc.LoadHtml(data);
                //var header = htmlDoc.DocumentNode.Descendants("header")
                //               .Where(e => e.GetAttributeValue("class", "") == "article__title");
                //var contentNews = htmlDoc.DocumentNode.Descendants("section")
                //    .Where(e => e.GetAttributeValue("class", "") == "article__text type");
                //var htmlNodes = contentNews as HtmlNode[] ?? contentNews.ToArray();
                //var contentNode = htmlNodes.First().Descendants("ul")
                //    .Where(e => e.GetAttributeValue("class", "") == "related_post");
                //var enumerable = contentNode as HtmlNode[] ?? contentNode.ToArray();
                //if (enumerable.Count() != 0)
                //{
                //    htmlNodes.First().RemoveChild(enumerable.First());
                //}
                //   string content = header.First().InnerHtml;
                // string content = htmlNodes.First().InnerHtml;
                string html =
                    "<html><head><style>img{max-width: 100%; width:auto; max-height: 250;}h1{color:blue;font-size: 100%}</style></head><body>" +
                    data +
                    "<h1>Nguồn gametv.vn<h1></body></html>";

                //lblContent = new HtmlFormattedLabel()
                //{
                //    FontSize = 12,
                //    Text = data
                //};
                //contentLayout.Children.Add(lblContent);
                htmlSource.Html = html;
                webview.Source  = htmlSource;
            }
            else
            {
                Debug.WriteLine("CategoryItemDetail: " + newsDetailResponse.message);
            }
        }