Search in sources :

Example 1 with AppCall

use of com.facebook.internal.AppCall in project facebook-android-sdk by facebook.

the class LikeActionController method getResultProcessor.

private ResultProcessor getResultProcessor(final Bundle analyticsParameters) {
    return new ResultProcessor(null) {

        @Override
        public void onSuccess(AppCall appCall, Bundle data) {
            if (data == null || !data.containsKey(LIKE_DIALOG_RESPONSE_OBJECT_IS_LIKED_KEY)) {
                // This is an empty result that we can't handle.
                return;
            }
            boolean isObjectLiked = data.getBoolean(LIKE_DIALOG_RESPONSE_OBJECT_IS_LIKED_KEY);
            // Default to known/cached state, if properties are missing.
            String likeCountStringWithLike = LikeActionController.this.likeCountStringWithLike;
            String likeCountStringWithoutLike = LikeActionController.this.likeCountStringWithoutLike;
            if (data.containsKey(LIKE_DIALOG_RESPONSE_LIKE_COUNT_STRING_KEY)) {
                likeCountStringWithLike = data.getString(LIKE_DIALOG_RESPONSE_LIKE_COUNT_STRING_KEY);
                likeCountStringWithoutLike = likeCountStringWithLike;
            }
            String socialSentenceWithLike = LikeActionController.this.socialSentenceWithLike;
            String socialSentenceWithoutWithoutLike = LikeActionController.this.socialSentenceWithoutLike;
            if (data.containsKey(LIKE_DIALOG_RESPONSE_SOCIAL_SENTENCE_KEY)) {
                socialSentenceWithLike = data.getString(LIKE_DIALOG_RESPONSE_SOCIAL_SENTENCE_KEY);
                socialSentenceWithoutWithoutLike = socialSentenceWithLike;
            }
            String unlikeToken = data.containsKey(LIKE_DIALOG_RESPONSE_OBJECT_IS_LIKED_KEY) ? data.getString(LIKE_DIALOG_RESPONSE_UNLIKE_TOKEN_KEY) : LikeActionController.this.unlikeToken;
            Bundle logParams = (analyticsParameters == null) ? new Bundle() : analyticsParameters;
            logParams.putString(AnalyticsEvents.PARAMETER_CALL_ID, appCall.getCallId().toString());
            getAppEventsLogger().logSdkEvent(AnalyticsEvents.EVENT_LIKE_VIEW_DIALOG_DID_SUCCEED, null, logParams);
            updateState(isObjectLiked, likeCountStringWithLike, likeCountStringWithoutLike, socialSentenceWithLike, socialSentenceWithoutWithoutLike, unlikeToken);
        }

        @Override
        public void onError(AppCall appCall, FacebookException error) {
            Logger.log(LoggingBehavior.REQUESTS, TAG, "Like Dialog failed with error : %s", error);
            Bundle logParams = analyticsParameters == null ? new Bundle() : analyticsParameters;
            logParams.putString(AnalyticsEvents.PARAMETER_CALL_ID, appCall.getCallId().toString());
            // Log the error and AppEvent
            logAppEventForError("present_dialog", logParams);
            broadcastAction(LikeActionController.this, ACTION_LIKE_ACTION_CONTROLLER_DID_ERROR, NativeProtocol.createBundleForException(error));
        }

        @Override
        public void onCancel(AppCall appCall) {
            onError(appCall, new FacebookOperationCanceledException());
        }
    };
}
Also used : AppCall(com.facebook.internal.AppCall) FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) Bundle(android.os.Bundle) FacebookException(com.facebook.FacebookException)

Example 2 with AppCall

use of com.facebook.internal.AppCall in project facebook-android-sdk by facebook.

the class ShareInternalUtility method handleActivityResult.

public static boolean handleActivityResult(int requestCode, int resultCode, Intent data, ResultProcessor resultProcessor) {
    AppCall appCall = getAppCallFromActivityResult(requestCode, resultCode, data);
    if (appCall == null) {
        return false;
    }
    NativeAppCallAttachmentStore.cleanupAttachmentsForCall(appCall.getCallId());
    if (resultProcessor == null) {
        return true;
    }
    FacebookException exception = NativeProtocol.getExceptionFromErrorData(NativeProtocol.getErrorDataFromResultIntent(data));
    if (exception != null) {
        if (exception instanceof FacebookOperationCanceledException) {
            resultProcessor.onCancel(appCall);
        } else {
            resultProcessor.onError(appCall, exception);
        }
    } else {
        // If here, we did not find an error in the result.
        Bundle results = NativeProtocol.getSuccessResultsFromIntent(data);
        resultProcessor.onSuccess(appCall, results);
    }
    return true;
}
Also used : AppCall(com.facebook.internal.AppCall) FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) FacebookException(com.facebook.FacebookException) Bundle(android.os.Bundle)

Example 3 with AppCall

use of com.facebook.internal.AppCall in project facebook-android-sdk by facebook.

the class CreateAppGroupDialog method registerCallbackImpl.

@Override
protected void registerCallbackImpl(final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) {
    final ResultProcessor resultProcessor = (callback == null) ? null : new ResultProcessor(callback) {

        @Override
        public void onSuccess(AppCall appCall, Bundle results) {
            callback.onSuccess(new Result(results.getString("id")));
        }
    };
    CallbackManagerImpl.Callback callbackManagerCallback = new CallbackManagerImpl.Callback() {

        @Override
        public boolean onActivityResult(int resultCode, Intent data) {
            return ShareInternalUtility.handleActivityResult(getRequestCode(), resultCode, data, resultProcessor);
        }
    };
    callbackManager.registerCallback(getRequestCode(), callbackManagerCallback);
}
Also used : AppCall(com.facebook.internal.AppCall) FacebookCallback(com.facebook.FacebookCallback) Bundle(android.os.Bundle) CallbackManagerImpl(com.facebook.internal.CallbackManagerImpl) Intent(android.content.Intent) ResultProcessor(com.facebook.share.internal.ResultProcessor)

Example 4 with AppCall

use of com.facebook.internal.AppCall in project facebook-android-sdk by facebook.

the class GameRequestDialog method registerCallbackImpl.

@Override
protected void registerCallbackImpl(final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) {
    final ResultProcessor resultProcessor = (callback == null) ? null : new ResultProcessor(callback) {

        @Override
        public void onSuccess(AppCall appCall, Bundle results) {
            if (results != null) {
                callback.onSuccess(new Result(results));
            } else {
                onCancel(appCall);
            }
        }
    };
    callbackManager.registerCallback(getRequestCode(), new CallbackManagerImpl.Callback() {

        @Override
        public boolean onActivityResult(int resultCode, Intent data) {
            return ShareInternalUtility.handleActivityResult(getRequestCode(), resultCode, data, resultProcessor);
        }
    });
}
Also used : AppCall(com.facebook.internal.AppCall) Bundle(android.os.Bundle) CallbackManagerImpl(com.facebook.internal.CallbackManagerImpl) Intent(android.content.Intent) ResultProcessor(com.facebook.share.internal.ResultProcessor)

Example 5 with AppCall

use of com.facebook.internal.AppCall in project facebook-android-sdk by facebook.

the class JoinAppGroupDialog method registerCallbackImpl.

@Override
protected void registerCallbackImpl(final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) {
    final ResultProcessor resultProcessor = (callback == null) ? null : new ResultProcessor(callback) {

        @Override
        public void onSuccess(AppCall appCall, Bundle results) {
            callback.onSuccess(new Result(results));
        }
    };
    CallbackManagerImpl.Callback callbackManagerCallback = new CallbackManagerImpl.Callback() {

        @Override
        public boolean onActivityResult(int resultCode, Intent data) {
            return ShareInternalUtility.handleActivityResult(getRequestCode(), resultCode, data, resultProcessor);
        }
    };
    callbackManager.registerCallback(getRequestCode(), callbackManagerCallback);
}
Also used : AppCall(com.facebook.internal.AppCall) FacebookCallback(com.facebook.FacebookCallback) Bundle(android.os.Bundle) CallbackManagerImpl(com.facebook.internal.CallbackManagerImpl) Intent(android.content.Intent) ResultProcessor(com.facebook.share.internal.ResultProcessor)

Aggregations

Bundle (android.os.Bundle)5 AppCall (com.facebook.internal.AppCall)5 Intent (android.content.Intent)3 CallbackManagerImpl (com.facebook.internal.CallbackManagerImpl)3 ResultProcessor (com.facebook.share.internal.ResultProcessor)3 FacebookCallback (com.facebook.FacebookCallback)2 FacebookException (com.facebook.FacebookException)2 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)2