private void DataTemplateFling(View view, int i, DirectRecommendationData animeRecomData) { var img = view.FindViewById <ImageViewAsync>(Resource.Id.AnimeRecomItemImage); if (!img.IntoIfLoaded(animeRecomData.ImageUrl)) { img.Visibility = ViewStates.Invisible; } }
private void DataTemplateBasic(View view, int i, DirectRecommendationData animeRecomData) { view.FindViewById <TextView>(Resource.Id.AnimeRecomItemShowTitle).Text = animeRecomData.Title; view.FindViewById <TextView>(Resource.Id.AnimeRecomItemShowType).Text = animeRecomData.Type.ToString(); //var spannableString = new SpannableString(animeRecomData.Description); //spannableString.SetSpan(new LeadingSpannableString(12, DimensionsHelper.DpToPx(140)), 0, spannableString.Length(), SpanTypes.Paragraph); //view.FindViewById<TextView>(Resource.Id.AnimeRecomItemRecomContent).SetText(spannableString.SubSequenceFormatted(0, spannableString.Length()), TextView.BufferType.Spannable); var txt = view.FindViewById <TextView>(Resource.Id.AnimeRecomItemRecomContent); var txtOverflow = view.FindViewById <TextView>(Resource.Id.AnimeRecomItemRecomContentOverflow); txtOverflow.Text = string.Empty; txt.Text = animeRecomData.Description; txt.Post(() => { try { if (txt.LineCount < 11) { return; } var ellipsis = txt.Layout.GetEllipsisStart(10); if (ellipsis != -1) { var chars = txt.Layout.GetLineEnd(9) + ellipsis; int lastSpaceIndex = 0; for (int j = chars - 5; j > 0; j--) { if (animeRecomData.Description[j] == ' ') { lastSpaceIndex = j; break; } } if (lastSpaceIndex == 0) { return; } txt.Text = animeRecomData.Description.Substring(0, lastSpaceIndex); txtOverflow.Text = animeRecomData.Description.Substring(lastSpaceIndex + 1); } } catch (Exception) { //TODO Grab the thing from hockey //ResourceLocator.TelemetryProvider.LogEvent($"Recoms wrpping crash on {ViewModel.Title} - recom {animeRecomData.Title}"); } }); }
private void DataTemplateFull(View view, int i, DirectRecommendationData animeRecomData) { var img = view.FindViewById <ImageViewAsync>(Resource.Id.AnimeRecomItemImage); if (img.Tag == null || (string)img.Tag != animeRecomData.ImageUrl) { Debug.WriteLine(animeRecomData.ImageUrl); img.Into(animeRecomData.ImageUrl); } else { img.Visibility = ViewStates.Visible; } view.FindViewById(Resource.Id.AnimeRecomItemImagePlaceholder).Visibility = ViewStates.Gone; }
private void DataTemplateFull(View view, int i, DirectRecommendationData animeRecomData) { var img = view.FindViewById <ImageViewAsync>(Resource.Id.AnimeRecomItemImage); img.Into(animeRecomData.ImageUrl); }
public async Task <List <DirectRecommendationData> > GetDirectRecommendations(bool force = false) { var output = force ? new List <DirectRecommendationData>() : await DataCache.RetrieveDirectRecommendationData(_animeId, _animeMode) ?? new List <DirectRecommendationData>(); if (output.Count != 0) { return(output); } var raw = await GetRequestResponse(false); if (string.IsNullOrEmpty(raw)) { return(null); } var doc = new HtmlDocument(); doc.LoadHtml(raw); var recommNodes = doc.DocumentNode.Descendants("div") .Where( node => node.Attributes.Contains("class") && node.Attributes["class"].Value == HtmlClassMgr.ClassDefs["#DirectRecomm:recommNode:class"]).Take(Settings.RecommsToPull); foreach (var recommNode in recommNodes) { try { var current = new DirectRecommendationData(); var tds = recommNode.Descendants("td").Take(2).ToList(); current.ImageUrl = tds[0].Descendants("img").First().Attributes["src"].Value; var pos = current.ImageUrl.LastIndexOf('t'); // we want to remove last "t" from url as this is much smaller image than we would want if (pos != -1) { current.ImageUrl = current.ImageUrl.Remove(pos, 1); } current.Description = WebUtility.HtmlDecode(tds[1].Descendants("div").First( node => node.Attributes.Contains("class") && node.Attributes["class"].Value == HtmlClassMgr.ClassDefs["#DirectRecomm:recommNode:descClass"]) .Descendants("div") .First().InnerText.Trim().Replace(" ", "").Replace("read more", "")); var titleNode = tds[1].ChildNodes[3].Descendants("a").First(); current.Title = titleNode.Descendants("strong").First().InnerText.Trim(); var link = titleNode.Attributes["href"].Value.Split('/'); current.Id = Convert.ToInt32(link[2]); current.Type = link[1] == "anime" ? RelatedItemType.Anime : link[1] == "manga" ? RelatedItemType.Manga : RelatedItemType.Unknown; output.Add(current); } catch (Exception) { //who knows...raw html is scary } } DataCache.SaveDirectRecommendationsData(_animeId, output, _animeMode); return(output); }
public async Task <List <DirectRecommendationData> > GetDirectRecommendations(bool force = false) { var output = force ? new List <DirectRecommendationData>() : await DataCache.RetrieveDirectRecommendationData(_animeId, _animeMode) ?? new List <DirectRecommendationData>(); if (output.Count != 0) { return(output); } var raw = await GetRequestResponse(); if (string.IsNullOrEmpty(raw)) { return(null); } var doc = new HtmlDocument(); doc.LoadHtml(raw); try { var recommNodes = doc.DocumentNode.Descendants("div") .Where( node => node.Attributes.Contains("class") && node.Attributes["class"].Value == "borderClass").Take(Settings.RecommsToPull); foreach (var recommNode in recommNodes) { try { var current = new DirectRecommendationData(); var tds = recommNode.Descendants("td").Take(2).ToList(); var img = tds[0].Descendants("img").First().Attributes["data-src"].Value; if (!img.Contains("questionmark")) { img = Regex.Replace(img, @"\/r\/\d+x\d+", ""); current.ImageUrl = img.Substring(0, img.IndexOf('?')); } current.Description = WebUtility.HtmlDecode(tds[1].Descendants("div").First( node => node.Attributes.Contains("class") && node.Attributes["class"].Value == "borderClass bgColor1") .Descendants("div") .First().InnerText.Trim().Replace(" ", "").Replace("read more", "")); current.Description = current.Description.Substring(0, current.Description.Length - 1); var titleNode = tds[1].ChildNodes[3].Descendants("a").First(); current.Title = titleNode.Descendants("strong").First().InnerText.Trim(); var link = titleNode.Attributes["href"].Value.Split('/'); current.Id = Convert.ToInt32(link[4]); current.Type = link[3] == "anime" ? RelatedItemType.Anime : link[3] == "manga" ? RelatedItemType.Manga : RelatedItemType.Unknown; output.Add(current); } catch (Exception) { //who knows...raw html is scary } } } catch (Exception) { //something we wrong } DataCache.SaveDirectRecommendationsData(_animeId, output, _animeMode); return(output); }