void SetImageViewHeight(IFeedCell cell, FeedItem item)
        {
            var parameters = cell.rlMedia.LayoutParameters as LinearLayout.LayoutParams;
            var height     = Application.Context.Resources.DisplayMetrics.WidthPixels * item.ImageAspectRatio;

            parameters.Height             = (int)height;
            cell.rlMedia.LayoutParameters = parameters;
        }
        void GetView(RecyclerView.ViewHolder holder, FeedItem item, int position, int viewType)
        {
            IFeedCell cell = holder as IFeedCell;

            if (viewType == (int)FeedViewType.AdvertisementItem)
            {
                var advertisment = holder as AdvertisementViewHolder;
                advertisment.ItemView.Tag    = position;
                advertisment.lblName.Text    = item.Username;
                advertisment.lblContent.Text = item.Content;
                if (string.IsNullOrEmpty(advertisment.lblContent.Text))
                {
                    advertisment.lblContent.Visibility = ViewStates.Gone;
                }
                else
                {
                    advertisment.lblContent.Visibility = ViewStates.Visible;
                }

                var parameters = advertisment.imgImage.LayoutParameters as LinearLayout.LayoutParams;
                var height     = Application.Context.Resources.DisplayMetrics.WidthPixels * item.ImageAspectRatio;
                parameters.Height = (int)height;
                advertisment.imgImage.LayoutParameters = parameters;

                advertisment.ProfileTask?.Cancel(item.ProfileUrl);
                if (!string.IsNullOrEmpty(item.ProfileUrl))
                {
                    advertisment.ProfileTask = new ImageLoaderHelper(ImageService.Instance.LoadUrl(item.ProfileUrl).SetSettings(advertisment.imgProfile, Resource.Drawable.DefProfPic, 60, new CircleTransformation()));
                }
                else
                {
                    advertisment.imgProfile.SetImageResource(Resource.Drawable.DefProfPic);
                }

                advertisment.ImageTask?.Cancel(item.ImageUrl);
                if (!string.IsNullOrEmpty(item.ImageUrl))
                {
                    advertisment.ImageTask = new ImageLoaderHelper(ImageService.Instance.LoadUrl(item.ImageUrl).SetSettings(advertisment.imgImage, Resource.Drawable.NoImageGraphic, 300));
                }
                else
                {
                    advertisment.imgImage.SetImageResource(Resource.Drawable.NoImageGraphic);
                }

                return;
            }
            else if (viewType == (int)FeedViewType.HeaderItem)
            {
                return;
            }

            if ((item.IsSharePost) && (!string.IsNullOrWhiteSpace(item.SharedUsername)))
            {
                var spanFromName = new SpannableString("Shared from" + " " + item.SharedUsername);
                spanFromName.SetSpan(new ForegroundColorSpan(Color.LightGray), 0, 11, 0);
                spanFromName.SetSpan(new RelativeSizeSpan(1.0f), 0, 11, 0);
                spanFromName.SetSpan(new StyleSpan(TypefaceStyle.Normal), 0, 11, 0);

                spanFromName.SetSpan(new ForegroundColorSpan(Color.Black), 12, item.SharedUsername.Length + 12, 0);
                spanFromName.SetSpan(new RelativeSizeSpan(1.0f), 12, item.SharedUsername.Length + 12, 0);
                spanFromName.SetSpan(new StyleSpan(TypefaceStyle.Bold), 12, item.SharedUsername.Length + 12, 0);



                cell.llSharePost.Visibility = ViewStates.Visible;
                cell.lblSharedFrom.SetText(spanFromName, TextView.BufferType.Spannable);
            }
            else
            {
                cell.llSharePost.Visibility = ViewStates.Gone;
            }


            cell.lblContent.Text = item.Content;
            //cell.lblContent.MovementMethod = LinkMovementMethod.Instance;

            DateTime date = DateTime.SpecifyKind(item.DateCreatedUtc, DateTimeKind.Utc);

            if (date > DateTime.UtcNow)
            {
                date = DateTime.UtcNow;
            }

            cell.lblTimeAgo.Text = TimeAgoHelper.GetTimeAgo(date);


            string[] separators = { "@" };
            string   value      = item.Username;

            string[] words      = value.Split(separators, StringSplitOptions.RemoveEmptyEntries);
            string   schoolName = string.Empty;
            string   sportsName = string.Empty;

            if (words.Count() > 1)
            {
                for (int i = 0; i < words.Length; i++)
                {
                    schoolName = words[0];
                    sportsName = words[1];
                }
            }
            else
            {
                schoolName = words[0];
            }

            var span = new SpannableString(schoolName + "\n" + sportsName);

            span.SetSpan(new ForegroundColorSpan(Color.Black), 0, schoolName.Length, 0);
            span.SetSpan(new RelativeSizeSpan(1.0f), 0, schoolName.Length, 0);
            span.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, schoolName.Length, 0);
            if (!string.IsNullOrEmpty(sportsName))
            {
                span.SetSpan(new ForegroundColorSpan(Color.LightGray), schoolName.Length + 1, schoolName.Length + sportsName.Length + 1, 0);
                span.SetSpan(new RelativeSizeSpan(1.0f), schoolName.Length + 1, schoolName.Length + sportsName.Length + 1, 0);
                span.SetSpan(new StyleSpan(TypefaceStyle.Normal), schoolName.Length + 1, schoolName.Length + sportsName.Length + 1, 0);
            }
            cell.lblName.SetText(span, TextView.BufferType.Spannable);

            cell.ProfileTask?.Cancel(item.ProfileUrl);
            if (!string.IsNullOrEmpty(item.ProfileUrl))
            {
                cell.ProfileTask = new ImageLoaderHelper(ImageService.Instance.LoadUrl(item.ProfileUrl).SetSettings(cell.imgProfile, Resource.Drawable.DefProfPic, 60, new CircleTransformation()));
            }
            else
            {
                cell.imgProfile.SetImageResource(Resource.Drawable.DefProfPic);
            }

            cell.lblLikes.Text    = item.LikeCount.ToString();
            cell.lblComments.Text = item.CommentCount.ToString();
            cell.lblTags.Text     = item.TagCount.ToString();
            cell.lblShares.Text   = item.ShareCount.ToString();

            cell.lblLikes.SetTextColor(item.IsLiked ? new Color(244, 62, 110) : new Color(136, 136, 136));
            cell.btnLike.SetImageResource(item.IsLiked ? Resource.Drawable.Liked : Resource.Drawable.Like);

            cell.lblComments.SetTextColor(item.IsCommented ? new Color(244, 62, 110) : new Color(136, 136, 136));
            cell.btnComment.SetImageResource(item.IsCommented ? Resource.Drawable.Commented : Resource.Drawable.Comment);

            cell.btnOptions.Visibility = user.Id == item.CreatedById ? ViewStates.Visible : ViewStates.Invisible;

            //cell.btnFacebook.Visibility = string.IsNullOrEmpty(item.FacebookUrl) ? ViewStates.Gone : ViewStates.Visible;
            //cell.btnTwitter.Visibility = string.IsNullOrEmpty(item.TwitterUrl) ? ViewStates.Gone : ViewStates.Visible;
            //cell.btnInstagram.Visibility = string.IsNullOrEmpty(item.InstagramUrl) ? ViewStates.Gone : ViewStates.Visible;

            if (string.IsNullOrEmpty(cell.lblContent.Text))
            {
                (cell.lblContent.Parent as ViewGroup).Visibility = ViewStates.Gone;
            }
            else
            {
                (cell.lblContent.Parent as ViewGroup).Visibility = ViewStates.Visible;
            }

            if (!string.IsNullOrEmpty(item.ImageUrl))
            {
                SetImageViewHeight(cell, item);

                cell.rlMedia.Visibility = ViewStates.Visible;
                cell.ImageTask?.Cancel(item.ImageUrl);
                if (!string.IsNullOrEmpty(item.ImageUrl))
                {
                    cell.ImageTask = new ImageLoaderHelper(ImageService.Instance.LoadUrl(item.ImageUrl).SetSettings(cell.imgImage, Resource.Drawable.NoImageGraphic, 300));
                }
                else
                {
                    cell.imgImage.SetImageResource(Resource.Drawable.NoImageGraphic);
                }
                cell.llLinkDetails.Visibility = ViewStates.Gone;
                cell.btnPlay.Visibility       = ViewStates.Gone;
            }
            else if (!string.IsNullOrEmpty(item.VideoUrl))
            {
                SetImageViewHeight(cell, item);
                cell.rlMedia.Visibility = ViewStates.Visible;
                cell.ImageTask?.Cancel(item.VideoImageUrl);
                if (!string.IsNullOrEmpty(item.VideoImageUrl))
                {
                    cell.ImageTask = new ImageLoaderHelper(ImageService.Instance.LoadUrl(item.VideoImageUrl).SetSettings(cell.imgImage, Resource.Drawable.NoImageGraphic, 300));
                }
                else
                {
                    cell.imgImage.SetImageResource(Resource.Drawable.NoImageGraphic);
                }
                cell.llLinkDetails.Visibility = ViewStates.Gone;
                cell.btnPlay.Visibility       = ViewStates.Visible;
            }
            else if (!string.IsNullOrEmpty(item.LinkUrl))
            {
                SetImageViewHeight(cell, item);
                cell.rlMedia.Visibility = ViewStates.Visible;
                cell.ImageTask?.Cancel(item.LinkImage);
                if (!string.IsNullOrEmpty(item.LinkImage))
                {
                    cell.ImageTask = new ImageLoaderHelper(ImageService.Instance.LoadUrl(item.LinkImage).SetSettings(cell.imgImage, Resource.Drawable.NoImageGraphic, 300));
                }
                else
                {
                    cell.imgImage.SetImageResource(Resource.Drawable.NoImageGraphic);
                }

                cell.lblLinkTitle.Text = item.LinkTitle;
                try
                {
                    var uri = new Uri(item.LinkUrl);
                    cell.lblLinkHost.Text = uri.Host;
                }
                catch
                {
                }

                cell.llLinkDetails.Visibility = ViewStates.Visible;
                cell.btnPlay.Visibility       = ViewStates.Gone;
            }
            else
            {
                cell.rlMedia.Visibility = ViewStates.Gone;
            }

            cell.ItemView.Tag = position;
        }
예제 #3
0
        public void SetNewsFeedCellCommon(IFeedCell cell, FeedItem item)
        {
            cell.PostId = item.Id;
            if (cell.IsCommonNew)
            {
                cell.BtnLike.TouchUpInside           += (sender, e) => LikeClicked(cell.Position, cell.BtnLike, cell.LblLikes);
                cell.BtnComment.TouchUpInside        += (sender, e) => PostDetailsClicked(cell.PostId, "Comments");
                cell.LblShares.UserInteractionEnabled = true;
                cell.LblShares.AddGestureRecognizer(new UITapGestureRecognizer((obj) => PostDetailsClicked(cell.PostId, "Shares")));
                cell.BtnShare.TouchUpInside += (sender, e) => ShareClicked(cell.PostId);
                cell.BtnTag.TouchUpInside   += (sender, e) => PostDetailsClicked(cell.PostId, "Tags");
                cell.LblComments.AddGestureRecognizer(new UITapGestureRecognizer(() => PostDetailsClicked(cell.PostId, "Comments")));
                cell.LblLikes.AddGestureRecognizer(new UITapGestureRecognizer(() => PostDetailsClicked(cell.PostId, "Likes")));
                cell.BtnOptions.TouchUpInside += (sender, e) => OptionsClicked(cell.PostId);
                cell.BtnPlay.TouchUpInside    += (sender, e) => PlayClicked(cell.PostId);
                cell.LblName.AddGestureRecognizer(new UITapGestureRecognizer(() => GoToProfile(cell.PostId)));
                cell.ImgProfile.UserInteractionEnabled = true;
                cell.ImgProfile.AddGestureRecognizer(new UITapGestureRecognizer(() => GoToProfile(cell.PostId)));
                cell.ImgImage.UserInteractionEnabled = true;
                cell.ImgImage.AddGestureRecognizer(new UITapGestureRecognizer((obj) => ImageClicked(cell.PostId)));
                // cell.BtnFacebook.TouchUpInside += (sender, e) => Links.OpenUrl(source.Items[cell.Position].FacebookUrl);
                //cell.BtnTwitter.TouchUpInside += (sender, e) => Links.OpenUrl(source.Items[cell.Position].TwitterUrl);
                // cell.BtnInstagram.TouchUpInside += (sender, e) => Links.OpenUrl(source.Items[cell.Position].InstagramUrl);
                cell.IsCommonNew = false;
            }



            if ((item.IsSharePost) && (!string.IsNullOrWhiteSpace(item.SharedUsername)))
            {
                NSMutableAttributedString shareName = null;

                shareName = new NSMutableAttributedString(

                    str: "Shared from ",
                    font: UIFont.SystemFontOfSize(12),
                    foregroundColor: UIColor.LightGray
                    );

                shareName.Append(new NSMutableAttributedString(

                                     str: item.SharedUsername,
                                     font: UIFont.BoldSystemFontOfSize(12),
                                     foregroundColor: UIColor.Black
                                     ));

                cell.VwShare.Hidden = false;
                cell.LblNameShares.AttributedText = shareName;
            }
            else
            {
                cell.VwShare.Hidden = true;
            }

            cell.ImgImage.RemoveConstraints(cell.ImgImage.Constraints);
            cell.ImgImage.AddConstraint(NSLayoutConstraint.Create(cell.ImgImage, NSLayoutAttribute.Height, NSLayoutRelation.Equal, cell.ImgImage, NSLayoutAttribute.Width, (nfloat)item.ImageAspectRatio, 0));

            cell.LblShares.Text   = item.ShareCount.ToString();
            cell.LblLikes.Text    = item.LikeCount.ToString();
            cell.LblComments.Text = item.CommentCount.ToString();
            cell.LblTags.Text     = item.TagCount.ToString();


            string[] separators = { "@" };
            string   value      = item.Username;

            string[] words      = value.Split(separators, StringSplitOptions.RemoveEmptyEntries);
            string   schoolName = string.Empty;
            string   sportsName = string.Empty;

            if (words.Count() > 1)
            {
                for (int i = 0; i < words.Length; i++)
                {
                    schoolName = words[0];
                    sportsName = words[1];
                }
            }
            else
            {
                schoolName = words[0];
            }

            NSMutableAttributedString username = null;

            username = new NSMutableAttributedString(

                str: schoolName,
                font: UIFont.BoldSystemFontOfSize(12),
                foregroundColor: UIColor.Black
                );

            username.Append(new NSMutableAttributedString(

                                str: "\n" + sportsName,
                                font: UIFont.SystemFontOfSize(12),
                                foregroundColor: UIColor.LightGray
                                ));

            cell.LblName.AttributedText = username;
            cell.TxtContent.Text        = item.Content;
            cell.VwContent.Hidden       = string.IsNullOrEmpty(cell.TxtContent.Text);

            cell.BtnOptions.Hidden = user.Id != item.CreatedById;

            cell.ProfileTask?.Cancel(item.ProfileUrl);
            if (!string.IsNullOrEmpty(item.ProfileUrl))
            {
                ImageService.Instance.LoadUrl(item.ProfileUrl).Into(cell.ImgProfile);
                cell.ProfileTask = new ImageLoaderHelper(item.ProfileUrl, cell.ImgProfile, AppDelegate.DefaultProfileString, 150, new CircleTransformation());
            }
            else
            {
                ImageService.Instance.LoadCompiledResource(AppDelegate.DefaultProfileString).Into(cell.ImgProfile);
            }

            DateTime date = DateTime.SpecifyKind(item.DateCreatedUtc, DateTimeKind.Utc);

            if (date > DateTime.UtcNow)
            {
                date = DateTime.UtcNow;
            }

            cell.LblTimeAgo.Text = TimeAgoHelper.GetTimeAgo(date);

            cell.LblLikes.TextColor = item.IsLiked ? UIColor.FromRGB(21, 21, 21) : UIColor.FromRGB(144, 144, 144);
            cell.BtnLike.SetImage(UIImage.FromBundle(item.IsLiked ? "IconIsLiked" : "IconLike"), UIControlState.Normal);

            cell.LblComments.TextColor = item.IsCommented ? UIColor.FromRGB(21, 21, 21) : UIColor.FromRGB(144, 144, 144);
            cell.BtnComment.SetImage(UIImage.FromBundle(item.IsCommented ? "IconCommented" : "IconComment"), UIControlState.Normal);


            //cell.BtnFacebook.Hidden = string.IsNullOrEmpty(item.FacebookUrl);
            //cell.BtnTwitter.Hidden = string.IsNullOrEmpty(item.TwitterUrl);
            //cell.BtnInstagram.Hidden = string.IsNullOrEmpty(item.InstagramUrl);

            cell.BtnFacebook.Hidden  = true;
            cell.BtnTwitter.Hidden   = true;
            cell.BtnInstagram.Hidden = true;

            if (!string.IsNullOrEmpty(item.ImageUrl))
            {
                cell.VwMedia.Hidden       = false;
                cell.VwLinkDetails.Hidden = true;
                cell.ImageTask?.Cancel(item.ImageUrl);
                ImageService.Instance.LoadUrl(item.ImageUrl).Into(cell.ImgImage);
                cell.ImageTask = new ImageLoaderHelper(item.ImageUrl, cell.ImgImage, "IconNoImage");

                cell.BtnPlay.Hidden = true;
            }
            else if (!string.IsNullOrEmpty(item.LinkUrl))
            {
                cell.VwMedia.Hidden       = false;
                cell.VwLinkDetails.Hidden = false;
                try
                {
                    cell.LblLinkHost.Text = new Uri(item.LinkUrl).Host;
                }
                catch {}

                cell.LblLinkTitle.Text = item.LinkTitle;

                cell.ImageTask?.Cancel(item.LinkImage);
                if (!string.IsNullOrEmpty(item.LinkImage))
                {
                    ImageService.Instance.LoadUrl(item.LinkImage).Into(cell.ImgImage);
                    cell.ImageTask = new ImageLoaderHelper(item.LinkImage, cell.ImgImage, "IconNoImage");
                }
                else
                {
                    ImageService.Instance.LoadCompiledResource("IconNoImage").Into(cell.ImgImage);
                }
                cell.BtnPlay.Hidden = true;
            }
            else if (!string.IsNullOrEmpty(item.VideoUrl))
            {
                cell.VwMedia.Hidden       = false;
                cell.VwLinkDetails.Hidden = true;
                cell.ImageTask?.Cancel(item.VideoImageUrl);
                if (!string.IsNullOrEmpty(item.VideoImageUrl))
                {
                    ImageService.Instance.LoadUrl(item.VideoImageUrl).Into(cell.ImgImage);
                    cell.ImageTask = new ImageLoaderHelper(item.VideoImageUrl, cell.ImgImage, "IconNoImage");
                }
                else
                {
                    ImageService.Instance.LoadCompiledResource("IconNoImage").Into(cell.ImgImage);
                }
                cell.BtnPlay.Hidden = false;
            }
            else
            {
                cell.VwMedia.Hidden = true;
            }
        }