private async Task <View> CreateProfileView(ProfileViewModel profile)
            {
                var parent = new LinearLayout(Activity)
                {
                    LayoutParameters = defaultLayoutParams, Orientation = Orientation.Vertical
                };
                var images  = Mvx.GetSingleton <IMvxImageCache <Bitmap> >();
                var inlines = new Dictionary <int, Bitmap>(profile.InlineImages.Count);

                foreach (var inline in profile.InlineImages)
                {
                    inlines.Add(inline.Key, await images.RequestImage(inline.Value.Url));
                }

                var text = await BBCodeBinding.GetFormatted(profile.Description, (node, builder) => AddProfile(builder, node, inlines, parent, 0));

                AddTextView(text, parent, 0);
                return(parent);
            }
            private async Task <bool> AddProfile(SpannableStringBuilder builder, TagNode node, IDictionary <int, Bitmap> inlines, LinearLayout parent, GravityFlags gravity)
            {
                if (!layoutTags.Contains(node.Tag.Name))
                {
                    return(false);
                }
                AddTextView(builder, parent, gravity);
                var          parameter = node.AttributeValues.Count > 0 ? node.AttributeValues.Values.First() : null;
                LinearLayout newParent;

                switch (node.Tag.Name)
                {
                case "collapse":
                    newParent = new CollapsingView(Activity)
                    {
                        LayoutParameters = defaultLayoutParams, Title = parameter
                    };
                    break;

                case "indent":
                    newParent = new LinearLayout(Activity)
                    {
                        LayoutParameters = defaultLayoutParams, Orientation = Orientation.Vertical
                    };
                    newParent.SetPaddingRelative(MLHelpers.DpToPixelsInt(10), 0, 0, 0);
                    break;

                case "left":
                case "center":
                case "right":
                    newParent = new LinearLayout(Activity)
                    {
                        LayoutParameters = defaultLayoutParams, Orientation = Orientation.Vertical
                    };
                    gravity = node.Tag.Name == "center" ? GravityFlags.Center : node.Tag.Name == "right" ? GravityFlags.End : GravityFlags.Start;
                    newParent.SetHorizontalGravity(gravity);
                    break;

                case "hr":
                    var value = new TypedValue();
                    Activity.Theme.ResolveAttribute(Resource.Attribute.colorAccent, value, true);
                    var hr = new View(Activity)
                    {
                        LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, MLHelpers.DpToPixelsInt(2))
                    };
                    hr.SetBackgroundColor(new Color(value.Data));
                    parent.AddView(hr);
                    return(true);

                case "heading":
                    var heading = new TextView(Activity)
                    {
                        LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
                        {
                            BottomMargin = MLHelpers.DpToPixelsInt(5)
                        },
                        Text = node.ToText()
                    };
                    heading.SetTextSize(ComplexUnitType.Sp, 22);
                    parent.AddView(heading);
                    return(true);

                case "img":
                    var image = new ImageView(Activity)
                    {
                        LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
                    };
                    image.SetImageBitmap(inlines[int.Parse(parameter)]);
                    parent.AddView(image);
                    return(true);

                case "quote":
                    newParent = new LinearLayout(Activity)
                    {
                        LayoutParameters = defaultLayoutParams, Orientation = Orientation.Vertical
                    };
                    var padding = MLHelpers.DpToPixelsInt(5);
                    newParent.SetPadding(padding, padding, padding, padding);
                    newParent.SetBackgroundResource(Resource.Drawable.background_quote);
                    var text = new TextView(Activity)
                    {
                        LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
                        {
                            BottomMargin = MLHelpers.DpToPixelsInt(5)
                        },
                        Text = Strings.Profile_Quote
                    };
                    text.SetTypeface(null, TypefaceStyle.Bold);
                    newParent.AddView(text);
                    return(true);

                default:
                    return(false);
                }
                parent.AddView(newParent);
                var remaining = await BBCodeBinding.GetFormatted(node, (n, b) => AddProfile(b, n, inlines, newParent, gravity));

                AddTextView(remaining, newParent, gravity);
                return(true);
            }
Esempio n. 3
0
        private async void ShowPreview()
        {
            var preview = await BBCodeBinding.GetFormatted(((ConversationViewModel)ViewModel.SelectedTab).GetPreview());

            new AlertDialog.Builder(Activity).SetMessage(preview).Show();
        }