Ejemplo n.º 1
0
        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            var parser = new InteractiveSourcesParser(Subtitles,
                                                      new ConsecutiveNumberAndConstantInteractiveSourceSubstitute
                                                          (1, GetString(Resource.String.source_substitute_counter)));

            var spannableTextBuilder = new SpannableTextBuilder();

            referencesFragment = new CaptionDialogReferencesFragment(GetString(Resource.String.audio_toolbar_references))
            {
                References = parser.Sources
            };
            referencesExisting = parser.Sources.Any();

            var interactiveSourceAction = new SwitchTabAndScrollToItemInteractiveSourceAction
            {
                GetRecyclerView   = referencesFragment.GetRecyclerView,
                GetTabsViewPagers = GetTabsViewPager,
                TargetTabIndex    = 1
            };
            var formattedSubtitles = spannableTextBuilder.CreateSubtitlesText(interactiveSourceAction, parser.TextWithSubstitutes, parser.Sources);

            subtitlesFragment = new CaptionDialogSubtitlesFragment(GetString(Resource.String.audio_toolbar_cc))
            {
                Subtitles = formattedSubtitles
            };
        }
        private void UpdateUi()
        {
            var srcList = referenceLink.Sources;
            var action  = referenceLink.Action;
            var spannableTextBuilder = new SpannableTextBuilder();

            ISpanned spannedText;

            string html = new HtmlTagHelper().FormatAdditionalTags(referenceLink.HtmlText);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
            {
                spannedText = Html.FromHtml(html, FromHtmlOptions.ModeLegacy);
            }
            else
            {
#pragma warning disable 618
                spannedText = Html.FromHtml(html);
#pragma warning restore 618
            }

            Control.TextFormatted = spannableTextBuilder.CreateSubtitlesText(action(), spannedText, srcList);

            // Make links clickable
            Control.MovementMethod = LinkMovementMethod.Instance;
            Control.AutoLinkMask   = MatchOptions.All;
            Control.Clickable      = true;
            Control.LinksClickable = true;
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Label> elementChangedEventArgs)
        {
            base.OnElementChanged(elementChangedEventArgs);

            if (elementChangedEventArgs.NewElement != null)
            {
                referenceLink = (ReferenceLink)elementChangedEventArgs.NewElement;
                if (referenceLink == null)
                {
                    return;
                }
                var srcList = referenceLink.Sources;
                var action  = referenceLink.Action;
                var spannableTextBuilder = new SpannableTextBuilder();

                ISpanned spannedText;

                string html = new HtmlTagHelper().FormatAdditionalTags(referenceLink.HtmlText);

                if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
                {
                    spannedText = Html.FromHtml(html, FromHtmlOptions.ModeLegacy);
                }
                else
                {
#pragma warning disable 618
                    spannedText = Html.FromHtml(html);
#pragma warning restore 618
                }

                Control.TextFormatted = spannableTextBuilder.CreateSubtitlesText(action(), spannedText, srcList);

                // Make links clickable
                Control.MovementMethod = LinkMovementMethod.Instance;
                Control.AutoLinkMask   = MatchOptions.All;
                Control.Clickable      = true;
                Control.LinksClickable = true;
            }
        }