Ejemplo n.º 1
0
        private async void InitializePowerFrame()
        {
            do
            {
                var error = await _presenter.TryGetUserInfo(AppSettings.User.Login);

                if (error == null || error is CanceledError)
                {
                    _powerFrame.ChangePercents((int)_presenter.UserProfileResponse.VotingPower);
                    ImageService.Instance.LoadUrl(_presenter.UserProfileResponse.ProfileImage, TimeSpan.FromDays(30))
                    .FadeAnimation(false, false, 0)
                    .DownSample(width: (int)100)
                    .Into(_avatar);
                    break;
                }
                await Task.Delay(5000);
            } while (true);
        }
Ejemplo n.º 2
0
        private async void InitializePowerFrame()
        {
            do
            {
                var exception = await _presenter.TryGetUserInfo(AppSettings.User.Login);

                if (exception == null || exception is OperationCanceledException)
                {
                    _powerFrame.ChangePercents((int)_presenter.UserProfileResponse.VotingPower);
                    if (!string.IsNullOrEmpty(_presenter.UserProfileResponse.ProfileImage))
                    {
                        ImageLoader.Load(_presenter.UserProfileResponse.ProfileImage, _avatar, size: new CGSize(300, 300));
                    }
                    else
                    {
                        _avatar.Image = UIImage.FromBundle("ic_noavatar");
                    }
                    break;
                }
                await Task.Delay(5000);
            } while (true);
        }
        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
        }