Search in sources :

Example 1 with SharePhoto

use of com.facebook.share.model.SharePhoto in project facebook-android-sdk by facebook.

the class ShareInternalUtility method toJSONObjectForCall.

public static JSONObject toJSONObjectForCall(final UUID callId, final ShareOpenGraphContent content) throws JSONException {
    final ShareOpenGraphAction action = content.getAction();
    final ArrayList<NativeAppCallAttachmentStore.Attachment> attachments = new ArrayList<>();
    JSONObject actionJSON = OpenGraphJSONUtility.toJSONObject(action, new OpenGraphJSONUtility.PhotoJSONProcessor() {

        @Override
        public JSONObject toJSONObject(SharePhoto photo) {
            NativeAppCallAttachmentStore.Attachment attachment = getAttachment(callId, photo);
            if (attachment == null) {
                return null;
            }
            attachments.add(attachment);
            JSONObject photoJSONObject = new JSONObject();
            try {
                photoJSONObject.put(NativeProtocol.IMAGE_URL_KEY, attachment.getAttachmentUrl());
                if (photo.getUserGenerated()) {
                    photoJSONObject.put(NativeProtocol.IMAGE_USER_GENERATED_KEY, true);
                }
            } catch (JSONException e) {
                throw new FacebookException("Unable to attach images", e);
            }
            return photoJSONObject;
        }
    });
    NativeAppCallAttachmentStore.addAttachments(attachments);
    // People and place tags must be moved from the share content to the open graph action
    if (content.getPlaceId() != null) {
        String placeTag = actionJSON.optString("place");
        // share content
        if (Utility.isNullOrEmpty(placeTag)) {
            actionJSON.put("place", content.getPlaceId());
        }
    }
    if (content.getPeopleIds() != null) {
        JSONArray peopleTags = actionJSON.optJSONArray("tags");
        Set<String> peopleIdSet = peopleTags == null ? new HashSet<String>() : Utility.jsonArrayToSet(peopleTags);
        for (String peopleId : content.getPeopleIds()) {
            peopleIdSet.add(peopleId);
        }
        actionJSON.put("tags", new JSONArray(peopleIdSet));
    }
    return actionJSON;
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) SharePhoto(com.facebook.share.model.SharePhoto) FacebookException(com.facebook.FacebookException)

Example 2 with SharePhoto

use of com.facebook.share.model.SharePhoto in project facebook-android-sdk by facebook.

the class WebDialogParameters method create.

public static Bundle create(SharePhotoContent sharePhotoContent) {
    final Bundle params = createBaseParameters(sharePhotoContent);
    final String[] urls = new String[sharePhotoContent.getPhotos().size()];
    Utility.map(sharePhotoContent.getPhotos(), new Utility.Mapper<SharePhoto, String>() {

        @Override
        public String apply(SharePhoto item) {
            return item.getImageUrl().toString();
        }
    }).toArray(urls);
    params.putStringArray(ShareConstants.WEB_DIALOG_PARAM_MEDIA, urls);
    return params;
}
Also used : SharePhoto(com.facebook.share.model.SharePhoto) Bundle(android.os.Bundle)

Example 3 with SharePhoto

use of com.facebook.share.model.SharePhoto in project facebook-android-sdk by facebook.

the class ShareContentValidation method validateVideoContent.

private static void validateVideoContent(ShareVideoContent videoContent, Validator validator) {
    validator.validate(videoContent.getVideo());
    SharePhoto previewPhoto = videoContent.getPreviewPhoto();
    if (previewPhoto != null) {
        validator.validate(previewPhoto);
    }
}
Also used : SharePhoto(com.facebook.share.model.SharePhoto)

Example 4 with SharePhoto

use of com.facebook.share.model.SharePhoto in project react-native-fbsdk by facebook.

the class Utility method reactArrayToPhotoList.

public static List<SharePhoto> reactArrayToPhotoList(ReadableArray photos) {
    List<SharePhoto> list = new ArrayList<>(photos.size());
    for (int i = 0; i < photos.size(); i++) {
        ReadableMap photoDetail = photos.getMap(i);
        list.add(buildSharePhoto(photoDetail));
    }
    return list;
}
Also used : SharePhoto(com.facebook.share.model.SharePhoto) ArrayList(java.util.ArrayList) ReadableMap(com.facebook.react.bridge.ReadableMap)

Example 5 with SharePhoto

use of com.facebook.share.model.SharePhoto in project facebook-android-sdk by facebook.

the class ShareContentValidationTest method testItDoesNotAcceptShareVideoContentByWeb.

@Test(expected = FacebookException.class)
public void testItDoesNotAcceptShareVideoContentByWeb() {
    SharePhoto previewPhoto = buildSharePhoto("https://facebook.com/awesome.gif");
    ShareVideoContent shareVideoContent = new ShareVideoContent.Builder().setPreviewPhoto(previewPhoto).build();
    ShareContentValidation.validateForWebShare(shareVideoContent);
}
Also used : SharePhoto(com.facebook.share.model.SharePhoto) ShareVideoContent(com.facebook.share.model.ShareVideoContent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SharePhoto (com.facebook.share.model.SharePhoto)17 Bitmap (android.graphics.Bitmap)6 SharePhotoContent (com.facebook.share.model.SharePhotoContent)5 ShareOpenGraphAction (com.facebook.share.model.ShareOpenGraphAction)4 ArrayList (java.util.ArrayList)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Uri (android.net.Uri)3 LargeTest (android.test.suitebuilder.annotation.LargeTest)3 ShareOpenGraphObject (com.facebook.share.model.ShareOpenGraphObject)3 Bundle (android.os.Bundle)2 Sharer (com.facebook.share.Sharer)2 ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 JSONArray (org.json.JSONArray)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 FacebookException (com.facebook.FacebookException)1