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)); }
public static CellSizeHelper Calculate(Post post) { var attributedLabel = new TTTAttributedLabel(); var at = new NSMutableAttributedString(); var photoHeight = PhotoHeight.Get(post.Media[0].Size); 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; } var linkAttribute = new UIStringAttributes { Link = new NSUrl(tag), 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)); }
public nfloat UpdateProfile(UserProfileResponse userData) { if (userData == null && _userData == null) { return(0); } descriptionY = topViewHeight + mainMargin + verticalSpacing; if (userData != null) { _userData = userData; } if (!string.IsNullOrEmpty(_userData.ProfileImage)) { ImageLoader.Load(_userData.ProfileImage, avatar, size: new CGSize(300, 300)); } else { avatar.Image = UIImage.FromBundle("ic_noavatar"); } if (_userData.Username == AppSettings.User.Login) { powerFrame.ChangePercents((int)_userData.VotingPower); } else { powerFrame.ChangePercents(0); } if (string.IsNullOrEmpty(_userData.Name)) { userName.Hidden = true; } else { userName.Hidden = false; userName.Text = _userData.Name; } if (string.IsNullOrEmpty(_userData.Location)) { userLocation.Hidden = true; } else { userLocation.Hidden = false; userLocation.Text = _userData.Location; } if (AppSettings.User.HasPostingPermission && _userData.Username != AppSettings.User.Login) { followButton.Frame = new CGRect(new CGPoint(mainMargin, descriptionY), new CGSize(UIScreen.MainScreen.Bounds.Width - mainMargin * 2, 40)); descriptionY += verticalSpacing + 40; DecorateFollowButton(); } else { followButton.Hidden = true; followProgress.Hidden = true; } at.SetString(new NSAttributedString(string.Empty)); var noLinkAttribute = new UIStringAttributes { Font = Helpers.Constants.Regular14, ForegroundColor = Helpers.Constants.R15G24B30 }; if (!string.IsNullOrEmpty(_userData.About)) { at.Append(new NSAttributedString(_userData.About, noLinkAttribute)); } if (!string.IsNullOrEmpty(_userData.Website)) { var linkAttribute = new UIStringAttributes { Link = new NSUrl(_userData.Website.Replace(" ", string.Empty)), Font = Helpers.Constants.Semibold14, ForegroundColor = Helpers.Constants.R255G34B5 }; at.Append(new NSAttributedString(Environment.NewLine)); at.Append(new NSAttributedString(Environment.NewLine)); at.Append(new NSAttributedString(_userData.Website, linkAttribute)); } attributedLabel.SetText(at); var textHeight = attributedLabel.SizeThatFits(new CGSize(UIScreen.MainScreen.Bounds.Width - mainMargin * 2, 0)).Height; attributedLabel.Frame = new CGRect(new CGPoint(mainMargin, descriptionY), new CGSize(UIScreen.MainScreen.Bounds.Width - mainMargin * 2, textHeight)); AddSubview(attributedLabel); //originalityContainer.Frame = new CGRect(new CGPoint(extraMargin, attributedLabel.Frame.Bottom + verticalSpacing), //new CGSize(UIScreen.MainScreen.Bounds.Width - extraMargin * 2, 50)); statsContainer.Frame = new CGRect(new CGPoint(mainMargin, attributedLabel.Frame.Bottom + verticalSpacing),//originalityContainer.Frame.Bottom + verticalSpacing), new CGSize(UIScreen.MainScreen.Bounds.Width - mainMargin * 2, 45)); SetupStats(); //#if DEBUG balanceContainer.Frame = new CGRect(new CGPoint(0, statsContainer.Frame.Bottom + verticalSpacing), new CGSize(UIScreen.MainScreen.Bounds.Width, 70)); balance.Text = $"$ {_userData.EstimatedBalance}"; Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, balanceContainer.Frame.Bottom); return(balanceContainer.Frame.Bottom); //#else //Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, statsContainer.Frame.Bottom + verticalSpacing); //return statsContainer.Frame.Bottom + verticalSpacing; //#endif }
public nfloat UpdateCell(Post post, CellSizeHelper variables, nfloat direction) { _currentPost = post; if (direction == 0) { leftMargin = 0; } else if (direction > 0) { leftMargin = 5; } else { leftMargin = -5; } likesMargin = leftMargin; _avatarImage?.RemoveFromSuperview(); _avatarImage = new UIImageView(new CGRect(leftMargin, 20, 30, 30)); _avatarImage.Layer.CornerRadius = _avatarImage.Frame.Size.Width / 2; _avatarImage.ClipsToBounds = true; _avatarImage.ContentMode = UIViewContentMode.ScaleAspectFill; _contentView.AddSubview(_avatarImage); _scheduledWorkAvatar?.Cancel(); if (!string.IsNullOrEmpty(_currentPost.Avatar)) { _scheduledWorkAvatar = ImageService.Instance.LoadUrl(_currentPost.Avatar, TimeSpan.FromDays(30)) .WithCache(FFImageLoading.Cache.CacheType.All) .FadeAnimation(false) .DownSample(200) .LoadingPlaceholder("ic_noavatar.png") .ErrorPlaceholder("ic_noavatar.png") .WithPriority(LoadingPriority.Normal) .Into(_avatarImage); } else { _avatarImage.Image = UIImage.FromBundle("ic_noavatar"); } _author.Text = _currentPost.Author; _timestamp.Text = _currentPost.Created.ToPostTime(); _contentScroll.SetContentOffset(new CGPoint(0, 0), false); _photoScroll.Frame = new CGRect(0, 0, _contentScroll.Frame.Width, variables.PhotoHeight); _photoScroll.ContentSize = new CGSize(_contentScroll.Frame.Width /* * _currentPost.Media.Length*/, variables.PhotoHeight); _photoScroll.SetContentOffset(new CGPoint(0, 0), false); foreach (var subview in _photoScroll.Subviews) { subview.RemoveFromSuperview(); } for (int i = 0; i < _scheduledWorkBody.Length; i++) { _scheduledWorkBody[i]?.Cancel(); } _scheduledWorkBody = new IScheduledWork[1 /*_currentPost.Media.Length*/]; _bodyImage = new UIImageView[1 /*_currentPost.Media.Length*/]; for (int i = 0; i < 1 /*_currentPost.Media.Length*/; i++) { _bodyImage[i] = new UIImageView(); _bodyImage[i].Layer.CornerRadius = 10; _bodyImage[i].ClipsToBounds = true; _bodyImage[i].UserInteractionEnabled = true; _bodyImage[i].ContentMode = UIViewContentMode.ScaleAspectFill; _bodyImage[i].Frame = new CGRect(_contentScroll.Frame.Width * i, 0, _contentScroll.Frame.Width, variables.PhotoHeight); _photoScroll.AddSubview(_bodyImage[i]); _scheduledWorkBody[i] = ImageService.Instance.LoadUrl(_currentPost.Media[0].Url) .Retry(2) .FadeAnimation(false) .WithCache(FFImageLoading.Cache.CacheType.All) .WithPriority(LoadingPriority.Highest) //.DownloadProgress((f)=> //{ //}) .Into(_bodyImage[i]); } if (_currentPost.TopLikersAvatars.Any() && !string.IsNullOrEmpty(_currentPost.TopLikersAvatars[0])) { _firstLikerImage?.RemoveFromSuperview(); _firstLikerImage = new UIImageView(); _contentScroll.AddSubview(_firstLikerImage); _firstLikerImage.BackgroundColor = UIColor.White; _firstLikerImage.Layer.CornerRadius = likersCornerRadius; _firstLikerImage.ClipsToBounds = true; _firstLikerImage.ContentMode = UIViewContentMode.ScaleAspectFill; _firstLikerImage.Frame = new CGRect(leftMargin, _photoScroll.Frame.Bottom + likersY, likersImageSide, likersImageSide); _scheduledWorkfirst?.Cancel(); _scheduledWorkfirst = ImageService.Instance.LoadUrl(_currentPost.TopLikersAvatars[0], TimeSpan.FromDays(30)) .WithCache(FFImageLoading.Cache.CacheType.All) .LoadingPlaceholder("ic_noavatar.png") .ErrorPlaceholder("ic_noavatar.png") .DownSample(width: 100) .FadeAnimation(false) .WithPriority(LoadingPriority.Lowest) .Into(_firstLikerImage); likesMargin = _firstLikerImage.Frame.Right + likesMarginConst; } else if (_firstLikerImage != null) { _firstLikerImage.Hidden = true; } if (_currentPost.TopLikersAvatars.Count() >= 2 && !string.IsNullOrEmpty(_currentPost.TopLikersAvatars[1])) { _secondLikerImage?.RemoveFromSuperview(); _secondLikerImage = new UIImageView(); _contentScroll.AddSubview(_secondLikerImage); _secondLikerImage.BackgroundColor = UIColor.White; _secondLikerImage.Layer.CornerRadius = likersCornerRadius; _secondLikerImage.ClipsToBounds = true; _secondLikerImage.ContentMode = UIViewContentMode.ScaleAspectFill; _secondLikerImage.Frame = new CGRect(_firstLikerImage.Frame.Right - likersMargin, _photoScroll.Frame.Bottom + likersY, likersImageSide, likersImageSide); _scheduledWorksecond?.Cancel(); _scheduledWorksecond = ImageService.Instance.LoadUrl(_currentPost.TopLikersAvatars[1], TimeSpan.FromDays(30)) .WithCache(FFImageLoading.Cache.CacheType.All) .LoadingPlaceholder("ic_noavatar.png") .ErrorPlaceholder("ic_noavatar.png") .WithPriority(LoadingPriority.Lowest) .DownSample(width: 100) .FadeAnimation(false) .Into(_secondLikerImage); likesMargin = _secondLikerImage.Frame.Right + likesMarginConst; } else if (_secondLikerImage != null) { _secondLikerImage.Hidden = true; } if (_currentPost.TopLikersAvatars.Count() >= 3 && !string.IsNullOrEmpty(_currentPost.TopLikersAvatars[2])) { _thirdLikerImage?.RemoveFromSuperview(); _thirdLikerImage = new UIImageView(); _contentScroll.AddSubview(_thirdLikerImage); _thirdLikerImage.BackgroundColor = UIColor.White; _thirdLikerImage.Layer.CornerRadius = likersCornerRadius; _thirdLikerImage.ClipsToBounds = true; _thirdLikerImage.ContentMode = UIViewContentMode.ScaleAspectFill; _thirdLikerImage.Frame = new CGRect(_secondLikerImage.Frame.Right - likersMargin, _photoScroll.Frame.Bottom + likersY, likersImageSide, likersImageSide); _scheduledWorkthird?.Cancel(); _scheduledWorkthird = ImageService.Instance.LoadUrl(_currentPost.TopLikersAvatars[2], TimeSpan.FromDays(30)) .WithCache(FFImageLoading.Cache.CacheType.All) .LoadingPlaceholder("ic_noavatar.png") .ErrorPlaceholder("ic_noavatar.png") .WithPriority(LoadingPriority.Lowest) .DownSample(width: 100) .FadeAnimation(false) .Into(_thirdLikerImage); likesMargin = _thirdLikerImage.Frame.Right + likesMarginConst; } else if (_thirdLikerImage != null) { _thirdLikerImage.Hidden = true; } nfloat flagMargin = 0; if (_currentPost.NetLikes != 0) { _likes.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.Likes, _currentPost.NetLikes); var likesWidth = _likes.SizeThatFits(new CGSize(0, underPhotoPanelHeight)); _likes.Frame = new CGRect(likesMargin, _photoScroll.Frame.Bottom, likesWidth.Width, underPhotoPanelHeight); flagMargin = flagsMarginConst; } else { _likes.Frame = new CGRect(likesMargin, _photoScroll.Frame.Bottom, 0, 0); } _likersTapView.Frame = new CGRect(leftMargin, _photoScroll.Frame.Bottom, _likes.Frame.Right - leftMargin, _likes.Frame.Height); if (_currentPost.NetFlags != 0) { _flags.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.Flags, _currentPost.NetFlags); var flagsWidth = _flags.SizeThatFits(new CGSize(0, underPhotoPanelHeight)); _flags.Frame = new CGRect(likesMargin + _likes.Frame.Width + flagMargin, _photoScroll.Frame.Bottom, flagsWidth.Width, underPhotoPanelHeight); } else { _flags.Frame = new CGRect(likesMargin, _photoScroll.Frame.Bottom, 0, 0); } _like.Frame = new CGRect(_contentView.Frame.Width - likeButtonWidthConst, _photoScroll.Frame.Bottom, likeButtonWidthConst, underPhotoPanelHeight); _like.Transform = CGAffineTransform.MakeScale(1f, 1f); if (_currentPost.VoteChanging) { Animate(); } else { _like.Layer.RemoveAllAnimations(); _like.LayoutIfNeeded(); _like.Image = _currentPost.Vote ? UIImage.FromBundle("ic_like_active") : UIImage.FromBundle("ic_like"); _like.UserInteractionEnabled = true; } _verticalSeparator.Frame = new CGRect(_contentView.Frame.Width - likeButtonWidthConst - 1, _photoScroll.Frame.Bottom + underPhotoPanelHeight / 2 - verticalSeparatorHeight / 2, 1, verticalSeparatorHeight); /* * _rewards.Text = BaseViewController.ToFormatedCurrencyString(_currentPost.TotalPayoutReward); * var rewardWidth = _rewards.SizeThatFits(new CGSize(0, underPhotoPanelHeight)); * _rewards.Frame = new CGRect(_verticalSeparator.Frame.Left - rewardWidth.Width, _photoScroll.Frame.Bottom, rewardWidth.Width, underPhotoPanelHeight); */ _topSeparator.Frame = new CGRect(0, _photoScroll.Frame.Bottom + underPhotoPanelHeight, _contentScroll.Frame.Width, 1); var at = new NSMutableAttributedString(); var _noLinkAttribute = new UIStringAttributes { Font = Constants.Regular14, ForegroundColor = Constants.R15G24B30, }; at.Append(new NSAttributedString(_currentPost.Title, _noLinkAttribute)); if (!string.IsNullOrEmpty(_currentPost.Description)) { at.Append(new NSAttributedString(Environment.NewLine)); at.Append(new NSAttributedString(Environment.NewLine)); at.Append(new NSAttributedString(post.Description, _noLinkAttribute)); } foreach (var tag in _currentPost.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($" ", _noLinkAttribute)); at.Append(new NSAttributedString($"#{tag}", linkAttribute)); } _attributedLabel?.RemoveFromSuperview(); _attributedLabel = new TTTAttributedLabel(); _attributedLabel.EnabledTextCheckingTypes = NSTextCheckingType.Link; var prop = new NSDictionary(); _attributedLabel.LinkAttributes = prop; _attributedLabel.ActiveLinkAttributes = prop; _attributedLabel.Font = Constants.Regular14; _attributedLabel.Lines = 0; _attributedLabel.UserInteractionEnabled = true; _attributedLabel.Enabled = true; //_attributedLabel.BackgroundColor = UIColor.Blue; _contentScroll.AddSubview(_attributedLabel); _attributedLabel.Delegate = new TTTAttributedLabelFeedDelegate(_tagAction); _attributedLabel.SetText(at); var textHeight = _attributedLabel.SizeThatFits(new CGSize(_contentScroll.Frame.Width, 0)).Height; _attributedLabel.Frame = new CGRect(new CGPoint(leftMargin, _topSeparator.Frame.Bottom + 15), new CGSize(_contentScroll.Frame.Width, textHeight)); _comments.Text = _currentPost.Children == 0 ? AppSettings.LocalizationManager.GetText(LocalizationKeys.PostFirstComment) : AppSettings.LocalizationManager.GetText(LocalizationKeys.ViewComments, _currentPost.Children); _comments.Frame = new CGRect(leftMargin - 5, _attributedLabel.Frame.Bottom + 5, _comments.SizeThatFits(new CGSize(10, 20)).Width + 10, 20 + 10); _bottomSeparator.Frame = new CGRect(0, _comments.Frame.Bottom + 10, _contentScroll.Frame.Width, 1); _contentScroll.ContentSize = new CGSize(_contentScroll.Frame.Width, _bottomSeparator.Frame.Bottom); return(_bottomSeparator.Frame.Bottom); //for constant size checking //var constantsSize = _bottomSeparator.Frame.Bottom - _attributedLabel.Frame.Height - _bodyImage.Frame.Height; }