示例#1
0
        public static async Task <List <MalFriendRequest> > GetFriendRequests()
        {
            try
            {
                var client = await ResourceLocator.MalHttpContextProvider.GetHttpContextAsync();

                var response = await client.GetAsync("https://myanimelist.net/myfriends.php?go=pending");

                var doc = new HtmlDocument();
                doc.Load(await response.Content.ReadAsStreamAsync());


                var table = doc.DocumentNode.Descendants("table").First();
                var rows  = table.ChildNodes.Where(node => node.Name == "tr").ToList();

                var output = new List <MalFriendRequest>();

                for (int i = 0; i < rows.Count; i += 2)
                {
                    var current = new MalFriendRequest();
                    var tds     = rows[i + 1].Descendants("td").ToList();
                    current.User.ImgUrl = tds[0].Descendants("img").First().Attributes["src"].Value.Replace("/thumbs", "").Replace("_thumb", "");
                    current.User.Name   = WebUtility.HtmlDecode(tds[1].Descendants("strong").First().InnerText.Trim());
                    current.Message     = WebUtility.HtmlDecode(tds[1].FirstOrDefaultOfDescendantsWithClass("div", "spaceit")?.InnerText?.Substring(17)?.Trim());
                    current.Id          = rows[i].Descendants("td").First().Id.Substring(3);
                    output.Add(current);
                }

                return(output);
            }
            catch (Exception)
            {
                return(new List <MalFriendRequest>());
            }
        }
        private void DataTemplateBasic(View view, int i, MalFriendRequest model, FriendRequestViewHolder holder)
        {
            holder.Name.Text = model.User.Name;
            if (!string.IsNullOrEmpty(model.Message))
            {
                holder.Message.Text       = model.Message;
                holder.Message.Visibility = ViewStates.Visible;
            }
            else
            {
                holder.Message.Visibility = ViewStates.Gone;
            }


            holder.AcceptButton.Tag = holder.DenyButton.Tag = view.Tag;
        }
 private void DataTemplateFull(View view, int i, MalFriendRequest model, FriendRequestViewHolder holder)
 {
     holder.Image.Into(model.User.ImgUrl, new CircleTransformation());
     holder.Image.Visibility = ViewStates.Visible;
 }
 private void DataTemplateFling(View view, int i, MalFriendRequest model, FriendRequestViewHolder holder)
 {
     holder.Image.Visibility = holder.Image.IntoIfLoaded(model.User.ImgUrl, new CircleTransformation()) ? ViewStates.Visible : ViewStates.Gone;
 }