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; }
@Override public Builder readFrom(final SharePhotoContent model) { if (model == null) { return this; } return super. readFrom(model) .addPhotos(model.getPhotos()); }
private static void validatePhotoContent( SharePhotoContent photoContent, Validator validator) { List<SharePhoto> photos = photoContent.getPhotos(); if (photos == null || photos.isEmpty()) { throw new FacebookException("Must specify at least one Photo in SharePhotoContent."); } if (photos.size() > ShareConstants.MAXIMUM_PHOTO_COUNT) { throw new FacebookException( String.format( Locale.ROOT, "Cannot add more than %d photos.", ShareConstants.MAXIMUM_PHOTO_COUNT)); } for (SharePhoto photo : photos) { validator.validate(photo); } }
public static List<String> getPhotoUrls( final SharePhotoContent photoContent, final UUID appCallId) { List<SharePhoto> photos; if (photoContent == null || (photos = photoContent.getPhotos()) == null) { return null; } List<NativeAppCallAttachmentStore.Attachment> attachments = Utility.map( photos, new Utility.Mapper<SharePhoto, NativeAppCallAttachmentStore.Attachment>() { @Override public NativeAppCallAttachmentStore.Attachment apply(SharePhoto item) { return getAttachment(appCallId, item); } }); List<String> attachmentUrls = Utility.map( attachments, new Utility.Mapper<NativeAppCallAttachmentStore.Attachment, String>() { @Override public String apply(NativeAppCallAttachmentStore.Attachment item) { return item.getAttachmentUrl(); } }); NativeAppCallAttachmentStore.addAttachments(attachments); return attachmentUrls; }
private SharePhotoContent createAndMapAttachments( final SharePhotoContent content, final UUID callId) { final SharePhotoContent.Builder contentBuilder = new SharePhotoContent.Builder().readFrom(content); final List<SharePhoto> photos = new ArrayList<>(); final List<NativeAppCallAttachmentStore.Attachment> attachments = new ArrayList<>(); for (int i = 0; i < content.getPhotos().size(); i++) { SharePhoto sharePhoto = content.getPhotos().get(i); final Bitmap photoBitmap = sharePhoto.getBitmap(); if (photoBitmap != null) { NativeAppCallAttachmentStore.Attachment attachment = NativeAppCallAttachmentStore.createAttachment(callId, photoBitmap); sharePhoto = new SharePhoto.Builder() .readFrom(sharePhoto) .setImageUrl(Uri.parse(attachment.getAttachmentUrl())) .setBitmap(null) .build(); attachments.add(attachment); } photos.add(sharePhoto); } contentBuilder.setPhotos(photos); NativeAppCallAttachmentStore.addAttachments(attachments); return contentBuilder.build(); } }
for (SharePhoto photo : photoContent.getPhotos()) { Bundle params; try {
@Test public void testPhotoBuilder() { final SharePhotoContent content = ShareModelTestUtility.getPhotoContentBuilder().build(); ShareModelTestUtility.assertEquals( ShareModelTestUtility.PHOTO_CONTENT_PHOTOS, content.getPhotos()); ShareModelTestUtility.assertEquals(content, TestUtils.parcelAndUnparcel(content)); } }