private SpannableString SpannableText(string text, string word, CustomClickableSpan clickableSpan) { var spannableText = new SpannableString(text); var index = text.IndexOf(word, StringComparison.Ordinal); spannableText.SetSpan(new ForegroundColorSpan(Resources.GetColor(Resource.Color.rgb255_34_5)), index, index + word.Length, 0); spannableText.SetSpan(clickableSpan, index, index + word.Length, SpanTypes.ExclusiveExclusive); return(spannableText); }
public override void OnViewCreated(View view, Bundle savedInstanceState) { if (IsInitialized) { return; } base.OnViewCreated(view, savedInstanceState); _pageTitle.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.PlagiarismTitle); _guidelines.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.GuidelinesForPlagiarism); _cancelPublishing.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.CancelPublishing); _continuePublishing.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.ContinuePublishing); _pageTitle.Typeface = Style.Semibold; _guidelines.Typeface = Style.Semibold; _plagiarismTitle.Typeface = Style.Regular; _plagiarismDescription.Typeface = Style.Regular; _cancelPublishing.Typeface = Style.Semibold; _continuePublishing.Typeface = Style.Semibold; guidelinesUri = Android.Net.Uri.Parse(Constants.Guide); _topPanel.BringToFront(); _backButton.Click += (sender, e) => { ((BaseActivity)Activity).OnBackPressed(); }; _rootLayout.Click += (sender, e) => { ((BaseActivity)Activity).HideKeyboard(); }; _guidelines.Click += OpenGuidelines; _cancelPublishing.Click += CancelPublishing; _continuePublishing.Click += ContinuePublishing; if (media.Count > 1) { _photos.Visibility = ViewStates.Visible; _previewContainer.Visibility = ViewStates.Gone; _photos.SetLayoutManager(new LinearLayoutManager(Activity, LinearLayoutManager.Horizontal, false)); _photos.SetAdapter(adapter); _photos.AddItemDecoration(new ListItemDecoration((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, Resources.DisplayMetrics))); } else { _photos.Visibility = ViewStates.Gone; _previewContainer.Visibility = ViewStates.Visible; _preview.ClipToOutline = true; var margin = (int)BitmapUtils.DpToPixel(15, Resources); if (media[0].PreparedBitmap != null) { var previewSize = BitmapUtils.CalculateImagePreviewSize(media[0].Parameters, Style.ScreenWidth - margin * 2); var layoutParams = new RelativeLayout.LayoutParams(previewSize.Width, previewSize.Height); layoutParams.SetMargins(margin, 0, margin, margin); _previewContainer.LayoutParameters = layoutParams; _preview.SetImageBitmap(media[0].PreparedBitmap); } } var similarText = AppSettings.LocalizationManager.GetText(LocalizationKeys.SimilarPhoto).ToLower(); var photoText = AppSettings.LocalizationManager.GetText(LocalizationKeys.Photo).ToLower(); var plagiarismText = string.Empty; CustomClickableSpan clickableSpan; SpannableString spannableTitle; if (model.PlagiarismUsername == AppSettings.User.Login) { plagiarismText = AppSettings.LocalizationManager.GetText(LocalizationKeys.SelfPlagiarism, similarText); clickableSpan = new CustomClickableSpan(); clickableSpan.Click += OpenSimilar; spannableTitle = SpannableText(plagiarismText, similarText, clickableSpan); _plagiarismTitle.SetText(spannableTitle, TextView.BufferType.Spannable); _plagiarismDescription.Visibility = ViewStates.Gone; } else { var author = $"@{model.PlagiarismUsername}"; plagiarismText = AppSettings.LocalizationManager.GetText(LocalizationKeys.PhotoPlagiarism, similarText, author); spannableTitle = new SpannableString(plagiarismText); var similarIndex = plagiarismText.IndexOf(similarText, StringComparison.Ordinal); clickableSpan = new CustomClickableSpan(); var authorIndex = plagiarismText.IndexOf(author, StringComparison.Ordinal); var clickableAuthor = new CustomClickableSpan(); clickableSpan.Click += OpenSimilar; clickableAuthor.Click += OpenProfile; spannableTitle.SetSpan(new ForegroundColorSpan(Resources.GetColor(Resource.Color.rgb255_34_5)), similarIndex, similarIndex + similarText.Length, 0); spannableTitle.SetSpan(clickableSpan, similarIndex, similarIndex + similarText.Length, SpanTypes.ExclusiveExclusive); spannableTitle.SetSpan(new ForegroundColorSpan(Resources.GetColor(Resource.Color.rgb255_34_5)), authorIndex, authorIndex + author.Length, 0); spannableTitle.SetSpan(clickableAuthor, authorIndex, authorIndex + author.Length, SpanTypes.ExclusiveExclusive); _plagiarismTitle.SetText(spannableTitle, TextView.BufferType.Spannable); var descriptionText = AppSettings.LocalizationManager.GetText(LocalizationKeys.PlagiarismDescription, photoText); var clickablePhoto = new CustomClickableSpan(); clickablePhoto.Click += OpenSimilar; var spannableDescription = SpannableText(descriptionText, photoText, clickablePhoto); _plagiarismDescription.Visibility = ViewStates.Visible; _plagiarismDescription.SetText(spannableDescription, TextView.BufferType.Spannable); _plagiarismDescription.MovementMethod = new LinkMovementMethod(); } _plagiarismTitle.MovementMethod = new LinkMovementMethod(); }