Esempio n. 1
0
 public override void DidSelectLinkWithURL(Xamarin.TTTAttributedLabel.TTTAttributedLabel label, NSUrl url)
 {
     try
     {
         if (!url.ToString().StartsWith("http", StringComparison.Ordinal))
         {
             var i = int.Parse(url.ToString());
             _links[i].Callback();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Unable to callback on TTTAttributedLabel: {0}", e.Message);
     }
 }
        private void CreateView()
        {
            GetPostSize();
            SetImage();

            var photoTitleSeparator = new UIView();

            photoTitleSeparator.BackgroundColor = Constants.R245G245B245;

            var noLinkTitleAttribute = new UIStringAttributes
            {
                Font            = Constants.Semibold20,
                ForegroundColor = Constants.R15G24B30,
            };

            var similarAttribute = new UIStringAttributes
            {
                Link            = new NSUrl(PlagiarismLinkType.Similar.ToString()),
                Font            = Constants.Semibold20,
                ForegroundColor = Constants.R255G34B5,
            };

            var authorAttribute = new UIStringAttributes
            {
                Link            = new NSUrl(PlagiarismLinkType.Author.ToString()),
                Font            = Constants.Semibold20,
                ForegroundColor = Constants.R255G34B5,
            };

            _plagiarismAttributedLabel = new Xamarin.TTTAttributedLabel.TTTAttributedLabel();
            _plagiarismAttributedLabel.EnabledTextCheckingTypes = NSTextCheckingType.Link;
            _plagiarismAttributedLabel.Lines = 0;

            var prop = new NSDictionary();

            _plagiarismAttributedLabel.LinkAttributes       = prop;
            _plagiarismAttributedLabel.ActiveLinkAttributes = prop;

            _plagiarismAttributedLabel.UserInteractionEnabled = true;
            _plagiarismAttributedLabel.Enabled  = true;
            _plagiarismAttributedLabel.Delegate = new TTTAttributedLabelActionDelegate(TextLinkAction);

            _cancelButton = new UIButton();
            _cancelButton.SetTitle(AppSettings.LocalizationManager.GetText(LocalizationKeys.CancelPublishing).ToUpper(), UIControlState.Normal);
            _cancelButton.Layer.CornerRadius   = 25;
            _cancelButton.TitleLabel.Font      = Constants.Bold14;
            _cancelButton.TitleLabel.TextColor = Constants.R255G255B255;

            _continueButton = new UIButton();
            _continueButton.SetTitle(AppSettings.LocalizationManager.GetText(LocalizationKeys.ContinuePublishing).ToUpper(), UIControlState.Normal);
            _continueButton.Layer.CornerRadius   = 25;
            _continueButton.TitleLabel.Font      = Constants.Bold14;
            _continueButton.TitleLabel.TextColor = Constants.R255G255B255;

            mainScroll.AddSubview(photoTitleSeparator);
            mainScroll.AddSubview(_plagiarismAttributedLabel);
            mainScroll.AddSubview(_cancelButton);
            mainScroll.AddSubview(_continueButton);

            _cancelButton.TouchDown += (sender, e) =>
            {
                plagiarismResult.Continue = false;
                NavigationController.PopViewController(true);
            };

            _continueButton.TouchDown += (sender, e) =>
            {
                plagiarismResult.Continue = true;
                NavigationController.PopViewController(true);
            };

            var at = new NSMutableAttributedString();

            if (_model.PlagiarismUsername == AppSettings.User.Login)
            {
                at.Append(new NSAttributedString("We have found a ", noLinkTitleAttribute));
                at.Append(new NSAttributedString(AppSettings.LocalizationManager.GetText(LocalizationKeys.SimilarPhoto).ToLower(), similarAttribute));
                at.Append(new NSAttributedString(" in Steepshot, uploaded by you. We do not recommend you to re-upload photos as it may result in low payouts and reputation loss.", noLinkTitleAttribute));
            }
            else
            {
                at.Append(new NSAttributedString("We have found a ", noLinkTitleAttribute));
                at.Append(new NSAttributedString(AppSettings.LocalizationManager.GetText(LocalizationKeys.SimilarPhoto).ToLower(), similarAttribute));
                at.Append(new NSAttributedString(" in Steepshot, uploaded by ", noLinkTitleAttribute));
                at.Append(new NSAttributedString($"@{_model.PlagiarismUsername}", authorAttribute));
                at.Append(new NSAttributedString(". We do not recommend you to upload other users' photos as it may result in low payouts and reputation loss.", noLinkTitleAttribute));
                at.Append(new NSAttributedString(Environment.NewLine));
                at.Append(new NSAttributedString(Environment.NewLine));
                at.Append(new NSAttributedString(Environment.NewLine));

                noLinkTitleAttribute.Font = Constants.Semibold14;
                similarAttribute.Font     = Constants.Semibold14;

                at.Append(new NSAttributedString("If you're sure that you are the author of the photo, please flag and/or leave a comment under the ", noLinkTitleAttribute));
                at.Append(new NSAttributedString(AppSettings.LocalizationManager.GetText(LocalizationKeys.Photo).ToLower(), similarAttribute));
                at.Append(new NSAttributedString(" to let other people know they should flag this post.", noLinkTitleAttribute));
            }

            _plagiarismAttributedLabel.SetText(at);

            if (photoView != null)
            {
                photoTitleSeparator.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, photoView, 24f);
            }
            else
            {
                photoTitleSeparator.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, photoCollection, 24f);
            }

            photoTitleSeparator.AutoPinEdgeToSuperviewEdge(ALEdge.Left, _separatorMargin);
            photoTitleSeparator.AutoPinEdgeToSuperviewEdge(ALEdge.Right, _separatorMargin);
            photoTitleSeparator.AutoSetDimension(ALDimension.Height, 1f);
            photoTitleSeparator.AutoSetDimension(ALDimension.Width, UIScreen.MainScreen.Bounds.Width - _separatorMargin * 2);

            _plagiarismAttributedLabel.AutoPinEdgeToSuperviewEdge(ALEdge.Left, _separatorMargin);
            _plagiarismAttributedLabel.AutoPinEdgeToSuperviewEdge(ALEdge.Right, _separatorMargin);
            _plagiarismAttributedLabel.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, photoTitleSeparator, 24);

            _cancelButton.AutoPinEdgeToSuperviewEdge(ALEdge.Left, _separatorMargin);
            _cancelButton.AutoPinEdgeToSuperviewEdge(ALEdge.Right, _separatorMargin);
            _cancelButton.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, _plagiarismAttributedLabel, 34);
            _cancelButton.AutoSetDimension(ALDimension.Height, 50);

            _continueButton.AutoPinEdgeToSuperviewEdge(ALEdge.Left, _separatorMargin);
            _continueButton.AutoPinEdgeToSuperviewEdge(ALEdge.Right, _separatorMargin);
            _continueButton.AutoPinEdgeToSuperviewEdge(ALEdge.Bottom, 34);
            _continueButton.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, _cancelButton, 10);
            _continueButton.AutoSetDimension(ALDimension.Height, 50);
        }