Example #1
0
            private void LoadPhoto(MediaModel mediaModel, CardView photoCard)
            {
                if (mediaModel != null)
                {
                    var photo = (ImageView)photoCard.GetChildAt(0);
                    var url   = mediaModel.Thumbnails.Mini;
                    Picasso.With(_context).Load(url).NoFade()
                    .Resize(_context.Resources.DisplayMetrics.WidthPixels, 0).Priority(Picasso.Priority.High)
                    .Into(photo, null, () =>
                    {
                        Picasso.With(_context).Load(url).NoFade().Priority(Picasso.Priority.High).Into(photo);
                    });

                    if (_type == PostPagerType.PostScreen)
                    {
                        photoCard.Radius = (int)BitmapUtils.DpToPixel(7, _context.Resources);
                    }

                    var size = new Size {
                        Height = mediaModel.Size.Height / Style.Density, Width = mediaModel.Size.Width / Style.Density
                    };
                    var height = (int)(OptimalPhotoSize.Get(size, Style.ScreenWidthInDp, 130, Style.MaxPostHeight) * Style.Density);
                    photoCard.LayoutParameters.Height = height;
                    ((View)photoCard.Parent).LayoutParameters.Height = height;
                    photo.LayoutParameters.Height = height;
                }
            }
        public static CellSizeHelper Calculate(Post post)
        {
            var photoHeight = (int)(OptimalPhotoSize.Get(new Size()
            {
                Height = post.Media[0].Size.Height, Width = post.Media[0].Size.Width
            },
                                                         (float)UIScreen.MainScreen.Bounds.Width, 180, (float)UIScreen.MainScreen.Bounds.Width + 50));

            var attributedLabel = new TTTAttributedLabel();
            var at = new NSMutableAttributedString();

            at.Append(new NSAttributedString(post.Title, _noLinkAttribute));
            if (!string.IsNullOrEmpty(post.Description))
            {
                at.Append(new NSAttributedString(Environment.NewLine));
                at.Append(new NSAttributedString(Environment.NewLine));
                at.Append(new NSAttributedString(post.Description, _noLinkAttribute));
            }

            foreach (var tag in post.Tags)
            {
                if (tag == "steepshot")
                {
                    continue;
                }
                NSUrl tagUrlWithoutWhitespaces = null;
                try
                {
                    tagUrlWithoutWhitespaces = new NSUrl(tag.Replace(' ', '#'));
                }
                catch (Exception ex)
                {
                    AppSettings.Reporter.SendCrash(ex);
                }
                var linkAttribute = new UIStringAttributes
                {
                    Link            = tagUrlWithoutWhitespaces,
                    Font            = Constants.Regular14,
                    ForegroundColor = Constants.R231G72B0,
                };
                at.Append(new NSAttributedString($" #{tag}", linkAttribute));
            }

            attributedLabel.Lines = 0;
            attributedLabel.SetText(at);

            var textHeight = attributedLabel.SizeThatFits(new CGSize(UIScreen.MainScreen.Bounds.Width - 15 * 2, 0)).Height;

            return(new CellSizeHelper(photoHeight, textHeight, at));
        }
Example #3
0
            private void LoadPhoto(MediaModel mediaModel, ImageView photo)
            {
                if (mediaModel != null)
                {
                    var url = mediaModel.Thumbnails.Mini;
                    Picasso.With(_context).Load(url).Placeholder(new ColorDrawable(Style.R245G245B245)).NoFade()
                    .Resize(_context.Resources.DisplayMetrics.WidthPixels, 0).Priority(Picasso.Priority.High)
                    .Into(photo, null, () =>
                    {
                        Picasso.With(_context).Load(url).Placeholder(new ColorDrawable(Style.R245G245B245)).NoFade().Priority(Picasso.Priority.High).Into(photo);
                    });

                    var size = new Size {
                        Height = mediaModel.Size.Height / Style.Density, Width = mediaModel.Size.Width / Style.Density
                    };
                    var height = (int)(OptimalPhotoSize.Get(size, Style.ScreenWidthInDp, 130, Style.MaxPostHeight) * Style.Density);
                    ((View)photo.Parent).LayoutParameters.Height = height;
                    photo.LayoutParameters.Height = height;
                }
            }
        public void UpdateData(Post post, Context context)
        {
            Post = post;
            if (post.NetLikes > 0)
            {
                _likes.Visibility = ViewStates.Visible;
                _likes.Text       = AppSettings.LocalizationManager.GetText(Post.NetLikes == 1 ? LocalizationKeys.Like : LocalizationKeys.Likes, post.NetLikes);
            }
            else
            {
                _likes.Visibility = ViewStates.Gone;
            }
            if (post.NetFlags > 0)
            {
                _flags.Visibility = _flagsIcon.Visibility = ViewStates.Visible;
                _flags.Text       = $"{post.NetFlags}";
            }
            else
            {
                _flags.Visibility = _flagsIcon.Visibility = ViewStates.Gone;
            }
            if (post.TotalPayoutReward > 0)
            {
                _cost.Visibility = ViewStates.Visible;
                _cost.Text       = BasePresenter.ToFormatedCurrencyString(post.TotalPayoutReward);
            }
            else
            {
                _cost.Visibility = ViewStates.Gone;
            }
            _time.Text   = post.Created.ToPostTime();
            _author.Text = post.Author;

            if (!string.IsNullOrEmpty(Post.Avatar))
            {
                Picasso.With(Context).Load(Post.Avatar).Placeholder(Resource.Drawable.ic_holder).Resize(300, 0).Priority(Picasso.Priority.Low).Into(_avatar, null, OnPicassoError);
            }
            else
            {
                Picasso.With(context).Load(Resource.Drawable.ic_holder).Into(_avatar);
            }

            var size = new Size {
                Height = post.Media[0].Size.Height / Style.Density, Width = post.Media[0].Size.Width / Style.Density
            };
            var height = (int)(OptimalPhotoSize.Get(size, Style.ScreenWidthInDp, 130, Style.MaxPostHeight) * Style.Density);

            PhotosViewPager.LayoutParameters.Height = height;
            ((PostPhotosPagerAdapter)PhotosViewPager.Adapter).UpdateData(Post);

            _title.UpdateText(Post, TagToExclude, TagFormat, MaxLines, Post.IsExpanded || PhotoPagerType == PostPagerType.PostScreen);

            _topLikers.RemoveAllViews();
            var topLikersSize   = (int)BitmapUtils.DpToPixel(24, Context.Resources);
            var topLikersMargin = (int)BitmapUtils.DpToPixel(6, Context.Resources);

            for (int i = 0; i < Post.TopLikersAvatars.Length; i++)
            {
                var topLikersAvatar = new CircleImageView(Context)
                {
                    BorderColor = Color.White, BorderWidth = 3, FillColor = Color.White
                };
                var layoutParams = new LinearLayout.LayoutParams(topLikersSize, topLikersSize);
                if (i != 0)
                {
                    layoutParams.LeftMargin = -topLikersMargin;
                }
                _topLikers.AddView(topLikersAvatar, layoutParams);
                var avatarUrl = Post.TopLikersAvatars[i];
                if (!string.IsNullOrEmpty(avatarUrl))
                {
                    Picasso.With(Context).Load(avatarUrl).Placeholder(Resource.Drawable.ic_holder).Resize(240, 0).Priority(Picasso.Priority.Low).Into(topLikersAvatar, null,
                                                                                                                                                      () =>
                    {
                        Picasso.With(context).Load(Resource.Drawable.ic_holder).Into(topLikersAvatar);
                    });
                }
                else
                {
                    Picasso.With(context).Load(Resource.Drawable.ic_holder).Into(topLikersAvatar);
                }
            }

            _title.UpdateText(Post, TagToExclude, TagFormat, MaxLines, Post.IsExpanded || PhotoPagerType == PostPagerType.PostScreen);

            _commentSubtitle.Text = post.Children == 0
                ? AppSettings.LocalizationManager.GetText(LocalizationKeys.PostFirstComment)
                : post.Children == 1
                    ? AppSettings.LocalizationManager.GetText(LocalizationKeys.SeeComment)
                    : AppSettings.LocalizationManager.GetText(LocalizationKeys.ViewComments, post.Children);

            if (_isAnimationRuning && !post.VoteChanging)
            {
                _isAnimationRuning = false;
                _likeOrFlag.ScaleX = 1f;
                _likeOrFlag.ScaleY = 1f;
            }
            if (!BasePostPresenter.IsEnableVote)
            {
                if (post.VoteChanging && !_isAnimationRuning)
                {
                    LikeSet(false);
                }
                else if (post.FlagChanging)
                {
                    LikeSet(true);
                }
                else if (post.Vote || !post.Flag)
                {
                    _likeOrFlag.SetImageResource(post.Vote
                        ? Resource.Drawable.ic_new_like_disabled
                        : Resource.Drawable.ic_new_like);
                }
            }
            else
            {
                if (post.Vote || !post.Flag)
                {
                    _likeOrFlag.SetImageResource(post.Vote
                        ? Resource.Drawable.ic_new_like_filled
                        : Resource.Drawable.ic_new_like_selected);
                }
                else
                {
                    _likeOrFlag.SetImageResource(Resource.Drawable.ic_flag_active);
                }
            }

            _pagerTabLayout.Visibility = post.Media.Length > 1 ? ViewStates.Visible : ViewStates.Gone;

            SetNsfwMaskLayout();

            if (Post.Flag && !Post.FlagNotificationWasShown)
            {
                NsfwMask.Visibility             = ViewStates.Visible;
                _nsfwMaskCloseButton.Visibility = ViewStates.Visible;
                _nsfwMaskMessage.Text           = AppSettings.LocalizationManager.GetText(LocalizationKeys.FlagMessage);
                NsfwMaskSubMessage.Text         = AppSettings.LocalizationManager.GetText(LocalizationKeys.FlagSubMessage);
                _nsfwMaskActionButton.Text      = AppSettings.LocalizationManager.GetText(LocalizationKeys.UnFlagPost);
            }
            else if (Post.ShowMask && (Post.IsLowRated || Post.IsNsfw))
            {
                NsfwMask.Visibility        = ViewStates.Visible;
                _nsfwMaskMessage.Text      = AppSettings.LocalizationManager.GetText(Post.IsLowRated ? LocalizationKeys.LowRatedContent : LocalizationKeys.NsfwContent);
                NsfwMaskSubMessage.Text    = AppSettings.LocalizationManager.GetText(Post.IsLowRated ? LocalizationKeys.LowRatedContentExplanation : LocalizationKeys.NsfwContentExplanation);
                _nsfwMaskActionButton.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.NsfwShow);
            }
            else
            {
                NsfwMask.Visibility = _nsfwMaskCloseButton.Visibility = ViewStates.Gone;
            }
        }