LikeActionController controllerForObject = getControllerFromInMemoryCache(objectId); if (controllerForObject != null) { verifyControllerAndInvokeCallback(controllerForObject, objectType, callback); return; controllerForObject = deserializeFromDiskSynchronously(objectId); controllerForObject = new LikeActionController(objectId, objectType); serializeToDiskAsync(controllerForObject); putControllerInMemoryCache(objectId, controllerForObject); invokeCallbackWithController(callback, controllerToRefresh, null);
/** * Only to be called after an OG-publish was attempted and something went wrong. The Button * state is reverted and an error is returned to the LikeViews */ private void publishDidError(boolean oldLikeState) { updateLikeState(oldLikeState); Bundle errorBundle = new Bundle(); errorBundle.putString( NativeProtocol.STATUS_ERROR_DESCRIPTION, ERROR_PUBLISH_ERROR); broadcastAction( LikeActionController.this, ACTION_LIKE_ACTION_CONTROLLER_DID_ERROR, errorBundle); }
/** * @deprecated * LikeView is deprecated */ @Deprecated public void toggleLike( Activity activity, FragmentWrapper fragment, Bundle analyticsParameters) { boolean shouldLikeObject = !this.isObjectLiked; if (canUseOGPublish()) { // Update UI Like state optimistically updateLikeState(shouldLikeObject); if (isPendingLikeOrUnlike) { // If the user toggled the button quickly, and there is still a publish underway, // don't fire off another request. Also log this behavior. getAppEventsLogger().logSdkEvent( AnalyticsEvents.EVENT_LIKE_VIEW_DID_UNDO_QUICKLY, null, analyticsParameters); } else if (!publishLikeOrUnlikeAsync(shouldLikeObject, analyticsParameters)) { // We were not able to send a graph request to unlike or like the object // Undo the optimistic state-update and show the dialog instead updateLikeState(!shouldLikeObject); presentLikeDialog(activity, fragment, analyticsParameters); } } else { presentLikeDialog(activity, fragment, analyticsParameters); } }
private boolean publishLikeOrUnlikeAsync( boolean shouldLikeObject, Bundle analyticsParameters) { boolean requested = false; if (canUseOGPublish()) { if (shouldLikeObject) { requested = true; publishLikeAsync(analyticsParameters); } else if (!Utility.isNullOrEmpty(this.unlikeToken)) { requested = true; publishUnlikeAsync(analyticsParameters); } } return requested; }
} else { logAppEventForError("present_dialog", analyticsParameters); Utility.logd(TAG, "Cannot show the Like Dialog on this device."); broadcastAction(null, ACTION_LIKE_ACTION_CONTROLLER_UPDATED); saveState(analyticsParameters); getAppEventsLogger().logSdkEvent( AnalyticsEvents.EVENT_LIKE_VIEW_DID_PRESENT_DIALOG, null,
private void onActivityResult( int requestCode, int resultCode, Intent data) { // Look for results ShareInternalUtility.handleActivityResult( requestCode, resultCode, data, getResultProcessor(facebookDialogAnalyticsBundle)); // The handlers from above will run synchronously. So by the time we get here, it should be // safe to stop tracking this call and also serialize the controller to disk clearState(); }
refreshStatusViaService(); return; fetchVerifiedObjectId(new RequestCompletionCallback() { @Override public void onComplete() {
private static void broadcastAction( LikeActionController controller, String action, Bundle data) { Intent broadcastIntent = new Intent(action); if (controller != null) { if (data == null) { data = new Bundle(); } data.putString(ACTION_OBJECT_ID_KEY, controller.getObjectId()); } if (data != null) { broadcastIntent.putExtras(data); } LocalBroadcastManager.getInstance(FacebookSdk.getApplicationContext()) .sendBroadcast(broadcastIntent); }
private static void serializeToDiskAsync(LikeActionController controller) { String controllerJson = serializeToJson(controller); String cacheKey = getCacheKeyForObjectId(controller.objectId); if (!Utility.isNullOrEmpty(controllerJson) && !Utility.isNullOrEmpty(cacheKey)) { diskIOWorkQueue.addActiveWorkItem( new SerializeToDiskWorkItem(cacheKey, controllerJson)); } }
/** * NOTE: This MUST be called ONLY via the CreateLikeActionControllerWorkItem class to ensure * that it happens on the right thread, at the right time. */ private static LikeActionController deserializeFromDiskSynchronously(String objectId) { LikeActionController controller = null; InputStream inputStream = null; try { String cacheKey = getCacheKeyForObjectId(objectId); inputStream = controllerDiskCache.get(cacheKey); if (inputStream != null) { String controllerJsonString = Utility.readStreamToString(inputStream); if (!Utility.isNullOrEmpty(controllerJsonString)) { controller = deserializeFromJson(controllerJsonString); } } } catch (IOException e) { Log.e(TAG, "Unable to deserialize controller from disk", e); controller = null; } finally { if (inputStream != null) { Utility.closeQuietly(inputStream); } } return controller; }
this.unlikeToken = unlikeToken; serializeToDiskAsync(this); broadcastAction(this, ACTION_LIKE_ACTION_CONTROLLER_UPDATED);
private static LikeActionController getControllerFromInMemoryCache(String objectId) { String cacheKey = getCacheKeyForObjectId(objectId); LikeActionController controller = cache.get(cacheKey); if (controller != null) { // Move this object to the front mruCacheWorkQueue.addActiveWorkItem(new MRUCacheWorkItem(cacheKey, false)); } return controller; }
getControllerForObjectId( objectIdForPendingController, LikeView.ObjectType.UNKNOWN,
private void publishLikeAsync(final Bundle analyticsParameters) { isPendingLikeOrUnlike = true; fetchVerifiedObjectId(new RequestCompletionCallback() { @Override public void onComplete() {
private void logAppEventForError(String action, Bundle parameters) { Bundle logParams = new Bundle(parameters); logParams.putString(AnalyticsEvents.PARAMETER_LIKE_VIEW_OBJECT_ID, objectId); logParams.putString(AnalyticsEvents.PARAMETER_LIKE_VIEW_OBJECT_TYPE, objectType.toString()); logParams.putString(AnalyticsEvents.PARAMETER_LIKE_VIEW_CURRENT_ACTION, action); getAppEventsLogger().logSdkEvent(AnalyticsEvents.EVENT_LIKE_VIEW_ERROR, null, logParams); }
LikeView.ObjectType.UNKNOWN.getValue()); controller = new LikeActionController( objectId, LikeView.ObjectType.fromInt(objectTypeInt));
private static void putControllerInMemoryCache( String objectId, LikeActionController controllerForObject) { String cacheKey = getCacheKeyForObjectId(objectId); // Move this object to the front. Also trim cache if necessary mruCacheWorkQueue.addActiveWorkItem(new MRUCacheWorkItem(cacheKey, true)); cache.put(cacheKey, controllerForObject); }
private void setObjectIdAndTypeForced(String newObjectId, ObjectType newObjectType) { tearDownObjectAssociations(); objectId = newObjectId; objectType = newObjectType; if (Utility.isNullOrEmpty(newObjectId)) { return; } creationCallback = new LikeActionControllerCreationCallback(); if (!isInEditMode()) { LikeActionController.getControllerForObjectId( newObjectId, newObjectType, creationCallback); } }