use of com.facebook.internal.Mutable in project facebook-android-sdk by facebook.
the class ShareApi method stageArrayList.
private void stageArrayList(final ArrayList arrayList, final CollectionMapper.OnMapValueCompleteListener onArrayListStagedListener) {
final JSONArray stagedObject = new JSONArray();
final CollectionMapper.Collection<Integer> collection = new CollectionMapper.Collection<Integer>() {
@Override
public Iterator<Integer> keyIterator() {
final int size = arrayList.size();
final Mutable<Integer> current = new Mutable<Integer>(0);
return new Iterator<Integer>() {
@Override
public boolean hasNext() {
return current.value < size;
}
@Override
public Integer next() {
return current.value++;
}
@Override
public void remove() {
}
};
}
@Override
public Object get(Integer key) {
return arrayList.get(key);
}
@Override
public void set(Integer key, Object value, CollectionMapper.OnErrorListener onErrorListener) {
try {
stagedObject.put(key, value);
} catch (final JSONException ex) {
String message = ex.getLocalizedMessage();
if (message == null) {
message = "Error staging object.";
}
onErrorListener.onError(new FacebookException(message));
}
}
};
final CollectionMapper.OnMapperCompleteListener onStagedArrayMapperCompleteListener = new CollectionMapper.OnMapperCompleteListener() {
@Override
public void onComplete() {
onArrayListStagedListener.onComplete(stagedObject);
}
@Override
public void onError(FacebookException exception) {
onArrayListStagedListener.onError(exception);
}
};
stageCollectionValues(collection, onStagedArrayMapperCompleteListener);
}
use of com.facebook.internal.Mutable in project facebook-android-sdk by facebook.
the class ShareApi method sharePhotoContent.
private void sharePhotoContent(final SharePhotoContent photoContent, final FacebookCallback<Sharer.Result> callback) {
final Mutable<Integer> requestCount = new Mutable<Integer>(0);
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
final ArrayList<GraphRequest> requests = new ArrayList<GraphRequest>();
final ArrayList<JSONObject> results = new ArrayList<JSONObject>();
final ArrayList<GraphResponse> errorResponses = new ArrayList<GraphResponse>();
final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
final JSONObject result = response.getJSONObject();
if (result != null) {
results.add(result);
}
if (response.getError() != null) {
errorResponses.add(response);
}
requestCount.value -= 1;
if (requestCount.value == 0) {
if (!errorResponses.isEmpty()) {
ShareInternalUtility.invokeCallbackWithResults(callback, null, errorResponses.get(0));
} else if (!results.isEmpty()) {
final String postId = results.get(0).optString("id");
ShareInternalUtility.invokeCallbackWithResults(callback, postId, response);
}
}
}
};
try {
for (SharePhoto photo : photoContent.getPhotos()) {
Bundle params;
try {
params = getSharePhotoCommonParameters(photo, photoContent);
} catch (JSONException e) {
ShareInternalUtility.invokeCallbackWithException(callback, e);
return;
}
final Bitmap bitmap = photo.getBitmap();
final Uri photoUri = photo.getImageUrl();
String caption = photo.getCaption();
if (caption == null) {
caption = this.getMessage();
}
if (bitmap != null) {
requests.add(GraphRequest.newUploadPhotoRequest(accessToken, getGraphPath(PHOTOS_EDGE), bitmap, caption, params, requestCallback));
} else if (photoUri != null) {
requests.add(GraphRequest.newUploadPhotoRequest(accessToken, getGraphPath(PHOTOS_EDGE), photoUri, caption, params, requestCallback));
}
}
requestCount.value += requests.size();
for (GraphRequest request : requests) {
request.executeAsync();
}
} catch (final FileNotFoundException ex) {
ShareInternalUtility.invokeCallbackWithException(callback, ex);
}
}
Aggregations