void RequestShare(Dictionary <string, object> paramsDictionary)
        {
            if (paramsDictionary.TryGetValue("content", out object shareContent) && shareContent is FacebookShareContent)
            {
                ShareContent content = null;
                if (shareContent is FacebookShareLinkContent)
                {
                    FacebookShareLinkContent linkContent        = shareContent as FacebookShareLinkContent;
                    ShareLinkContent.Builder linkContentBuilder = new ShareLinkContent.Builder();


                    if (linkContent.Quote != null)
                    {
                        linkContentBuilder.SetQuote(linkContent.Quote);
                    }

                    if (linkContent.ContentLink != null)
                    {
                        linkContentBuilder.SetContentUrl(Android.Net.Uri.Parse(linkContent.ContentLink.AbsoluteUri));
                    }

                    if (!string.IsNullOrEmpty(linkContent.Hashtag))
                    {
                        var shareHashTagBuilder = new ShareHashtag.Builder();
                        shareHashTagBuilder.SetHashtag(linkContent.Hashtag);
                        linkContentBuilder.SetShareHashtag(shareHashTagBuilder.Build().JavaCast <ShareHashtag>());
                    }

                    if (linkContent.PeopleIds != null && linkContent.PeopleIds.Length > 0)
                    {
                        linkContentBuilder.SetPeopleIds(linkContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(linkContent.PlaceId))
                    {
                        linkContentBuilder.SetPlaceId(linkContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(linkContent.Ref))
                    {
                        linkContentBuilder.SetRef(linkContent.Ref);
                    }

                    content = linkContentBuilder.Build();
                }
                else if (shareContent is FacebookSharePhotoContent)
                {
                    FacebookSharePhotoContent photoContent = shareContent as FacebookSharePhotoContent;

                    SharePhotoContent.Builder photoContentBuilder = new SharePhotoContent.Builder();

                    if (photoContent.Photos != null && photoContent.Photos.Length > 0)
                    {
                        foreach (var p in photoContent.Photos)
                        {
                            SharePhoto.Builder photoBuilder = new SharePhoto.Builder();

                            if (!string.IsNullOrEmpty(p.Caption))
                            {
                                photoBuilder.SetCaption(p.Caption);
                            }

                            if (p.ImageUrl != null && !string.IsNullOrEmpty(p.ImageUrl.AbsoluteUri))
                            {
                                photoBuilder.SetImageUrl(Android.Net.Uri.Parse(p.ImageUrl.AbsoluteUri));
                            }

                            if (p.Image != null)
                            {
                                Bitmap bmp = BitmapFactory.DecodeByteArray(p.Image, 0, p.Image.Length);

                                photoBuilder.SetBitmap(bmp);
                            }
                            photoContentBuilder.AddPhoto(photoBuilder.Build().JavaCast <SharePhoto>());
                        }
                    }

                    if (photoContent.ContentLink != null)
                    {
                        photoContentBuilder.SetContentUrl(Android.Net.Uri.Parse(photoContent.ContentLink.AbsoluteUri));
                    }

                    if (!string.IsNullOrEmpty(photoContent.Hashtag))
                    {
                        var shareHashTagBuilder = new ShareHashtag.Builder();
                        shareHashTagBuilder.SetHashtag(photoContent.Hashtag);
                        photoContentBuilder.SetShareHashtag(shareHashTagBuilder.Build().JavaCast <ShareHashtag>());
                    }

                    if (photoContent.PeopleIds != null && photoContent.PeopleIds.Length > 0)
                    {
                        photoContentBuilder.SetPeopleIds(photoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(photoContent.PlaceId))
                    {
                        photoContentBuilder.SetPlaceId(photoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(photoContent.Ref))
                    {
                        photoContentBuilder.SetRef(photoContent.Ref);
                    }

                    content = photoContentBuilder.Build();
                }
                else if (shareContent is FacebookShareVideoContent)
                {
                    FacebookShareVideoContent videoContent        = shareContent as FacebookShareVideoContent;
                    ShareVideoContent.Builder videoContentBuilder = new ShareVideoContent.Builder();


                    /*if (videoContent.PreviewPhoto != null)
                     * {
                     *   SharePhoto.Builder photoBuilder = new SharePhoto.Builder();
                     *
                     *   if (!string.IsNullOrEmpty(videoContent.PreviewPhoto.Caption))
                     *   {
                     *       photoBuilder.SetCaption(videoContent.PreviewPhoto.Caption);
                     *   }
                     *
                     *   if (videoContent.PreviewPhoto.ImageUrl != null && !string.IsNullOrEmpty(videoContent.PreviewPhoto.ImageUrl.AbsoluteUri))
                     *   {
                     *       photoBuilder.SetImageUrl(Android.Net.Uri.Parse(videoContent.PreviewPhoto.ImageUrl.AbsoluteUri));
                     *   }
                     *
                     *   if (videoContent.PreviewPhoto.Image != null)
                     *   {
                     *       Bitmap bmp = BitmapFactory.DecodeByteArray(videoContent.PreviewPhoto.Image, 0, videoContent.PreviewPhoto.Image.Length);
                     *
                     *       photoBuilder.SetBitmap(bmp);
                     *   }
                     *   videoContentBuilder.SetPreviewPhoto(photoBuilder.Build().JavaCast<SharePhoto>());
                     * }*/

                    if (videoContent.Video != null)
                    {
                        ShareVideo.Builder videoBuilder = new ShareVideo.Builder();

                        if (videoContent.Video.LocalUrl != null)
                        {
                            videoBuilder.SetLocalUrl(Android.Net.Uri.Parse(videoContent.Video.LocalUrl.AbsoluteUri));
                        }

                        videoContentBuilder.SetVideo(videoBuilder.Build().JavaCast <ShareVideo>());
                    }


                    if (videoContent.ContentLink != null)
                    {
                        videoContentBuilder.SetContentUrl(Android.Net.Uri.Parse(videoContent.ContentLink.AbsoluteUri));
                    }

                    if (!string.IsNullOrEmpty(videoContent.Hashtag))
                    {
                        var shareHashTagBuilder = new ShareHashtag.Builder();
                        shareHashTagBuilder.SetHashtag(videoContent.Hashtag);
                        videoContentBuilder.SetShareHashtag(shareHashTagBuilder.Build().JavaCast <ShareHashtag>());
                    }

                    if (videoContent.PeopleIds != null && videoContent.PeopleIds.Length > 0)
                    {
                        videoContentBuilder.SetPeopleIds(videoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(videoContent.PlaceId))
                    {
                        videoContentBuilder.SetPlaceId(videoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(videoContent.Ref))
                    {
                        videoContentBuilder.SetRef(videoContent.Ref);
                    }

                    content = videoContentBuilder.Build();
                }

                if (content != null)
                {
                    //ShareApi.Share(content, shareCallback);
                    ShareDialog dialog = new ShareDialog(CurrentActivity);
                    dialog.RegisterCallback(mCallbackManager, shareCallback);
                    dialog.ShouldFailOnDataError = true;
                    dialog.Show(content, ShareDialog.Mode.Automatic);
                }
            }
        }
Example #2
0
        void RequestShare(Dictionary <string, object> paramsDictionary)
        {
            if (paramsDictionary.TryGetValue("content", out object shareContent) && shareContent is FacebookShareContent)
            {
                ISharingContent content = null;
                if (shareContent is FacebookShareLinkContent)
                {
                    FacebookShareLinkContent linkContent  = shareContent as FacebookShareLinkContent;
                    ShareLinkContent         sLinkContent = new ShareLinkContent();


                    if (linkContent.Quote != null)
                    {
                        sLinkContent.Quote = linkContent.Quote;
                    }

                    if (linkContent.ContentLink != null)
                    {
                        sLinkContent.SetContentUrl(linkContent.ContentLink);
                    }

                    if (!string.IsNullOrEmpty(linkContent.Hashtag))
                    {
                        var shareHashTag = new Hashtag();
                        shareHashTag.StringRepresentation = linkContent.Hashtag;
                        sLinkContent.Hashtag = shareHashTag;
                    }

                    if (linkContent.PeopleIds != null && linkContent.PeopleIds.Length > 0)
                    {
                        sLinkContent.SetPeopleIds(linkContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(linkContent.PlaceId))
                    {
                        sLinkContent.SetPlaceId(linkContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(linkContent.Ref))
                    {
                        sLinkContent.SetRef(linkContent.Ref);
                    }

                    content = sLinkContent;
                }
                else if (shareContent is FacebookSharePhotoContent)
                {
                    FacebookSharePhotoContent photoContent = shareContent as FacebookSharePhotoContent;

                    SharePhotoContent sharePhotoContent = new SharePhotoContent();

                    if (photoContent.Photos != null && photoContent.Photos.Length > 0)
                    {
                        List <SharePhoto> photos = new List <SharePhoto>();
                        foreach (var p in photoContent.Photos)
                        {
                            if (p.ImageUrl != null && !string.IsNullOrEmpty(p.ImageUrl.AbsoluteUri))
                            {
                                SharePhoto photoFromUrl = SharePhoto.From(p.ImageUrl, true);

                                if (!string.IsNullOrEmpty(p.Caption))
                                {
                                    photoFromUrl.Caption = p.Caption;
                                }

                                photos.Add(photoFromUrl);
                            }

                            if (p.Image != null)
                            {
                                UIImage image = null;

                                var imageBytes = p.Image as byte[];

                                if (imageBytes != null)
                                {
                                    using (var data = NSData.FromArray(imageBytes))
                                        image = UIImage.LoadFromData(data);

                                    SharePhoto sPhoto = Facebook.ShareKit.SharePhoto.From(image, true);

                                    if (!string.IsNullOrEmpty(p.Caption))
                                    {
                                        sPhoto.Caption = p.Caption;
                                    }


                                    photos.Add(sPhoto);
                                }
                            }
                        }

                        if (photos.Count > 0)
                        {
                            sharePhotoContent.Photos = photos.ToArray();
                        }
                    }

                    if (photoContent.ContentLink != null)
                    {
                        sharePhotoContent.SetContentUrl(photoContent.ContentLink);
                    }

                    if (!string.IsNullOrEmpty(photoContent.Hashtag))
                    {
                        var shareHashTag = new Hashtag();
                        shareHashTag.StringRepresentation = photoContent.Hashtag;
                        sharePhotoContent.SetHashtag(shareHashTag);
                    }

                    if (photoContent.PeopleIds != null && photoContent.PeopleIds.Length > 0)
                    {
                        sharePhotoContent.SetPeopleIds(photoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(photoContent.PlaceId))
                    {
                        sharePhotoContent.SetPlaceId(photoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(photoContent.Ref))
                    {
                        sharePhotoContent.SetRef(photoContent.Ref);
                    }

                    content = sharePhotoContent;
                }
                else if (shareContent is FacebookShareVideoContent)
                {
                    FacebookShareVideoContent videoContent      = shareContent as FacebookShareVideoContent;
                    ShareVideoContent         shareVideoContent = new ShareVideoContent();


                    if (videoContent.PreviewPhoto != null)
                    {
                        if (videoContent.PreviewPhoto.ImageUrl != null && !string.IsNullOrEmpty(videoContent.PreviewPhoto.ImageUrl.AbsoluteUri))
                        {
                            SharePhoto photoFromUrl = Facebook.ShareKit.SharePhoto.From(videoContent.PreviewPhoto.ImageUrl, true);

                            if (!string.IsNullOrEmpty(videoContent.PreviewPhoto.Caption))
                            {
                                photoFromUrl.Caption = videoContent.PreviewPhoto.Caption;
                            }

                            shareVideoContent.PreviewPhoto = photoFromUrl;
                        }

                        if (videoContent.PreviewPhoto.Image != null)
                        {
                            UIImage image = null;

                            var imageBytes = videoContent.PreviewPhoto.Image as byte[];

                            if (imageBytes != null)
                            {
                                using (var data = NSData.FromArray(imageBytes))
                                    image = UIImage.LoadFromData(data);

                                SharePhoto photo = Facebook.ShareKit.SharePhoto.From(image, true);

                                if (!string.IsNullOrEmpty(videoContent.PreviewPhoto.Caption))
                                {
                                    photo.Caption = videoContent.PreviewPhoto.Caption;
                                }


                                shareVideoContent.PreviewPhoto = photo;
                            }
                        }
                    }

                    if (videoContent.Video != null)
                    {
                        if (videoContent.Video.LocalUrl != null)
                        {
                            shareVideoContent.Video = ShareVideo.From(videoContent.Video.LocalUrl);
                        }
                    }

                    if (videoContent.ContentLink != null)
                    {
                        shareVideoContent.SetContentUrl(videoContent.ContentLink);
                    }

                    if (!string.IsNullOrEmpty(videoContent.Hashtag))
                    {
                        var shareHashTag = new Hashtag();
                        shareHashTag.StringRepresentation = videoContent.Hashtag;
                        shareVideoContent.SetHashtag(shareHashTag);
                    }

                    if (videoContent.PeopleIds != null && videoContent.PeopleIds.Length > 0)
                    {
                        shareVideoContent.SetPeopleIds(videoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(videoContent.PlaceId))
                    {
                        shareVideoContent.SetPlaceId(videoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(videoContent.Ref))
                    {
                        shareVideoContent.SetRef(videoContent.Ref);
                    }

                    content = shareVideoContent;
                }

                if (content != null)
                {
                    ShareAPI.Share(content, this);
                }
            }
        }