Java Code Examples for com.facebook.internal.Utility#areObjectsEqual()

The following examples show how to use com.facebook.internal.Utility#areObjectsEqual() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessTokenManager.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
private void setCurrentAccessToken(AccessToken currentAccessToken, boolean saveToCache) {
    AccessToken oldAccessToken = this.currentAccessToken;
    this.currentAccessToken = currentAccessToken;
    tokenRefreshInProgress.set(false);
    this.lastAttemptedTokenExtendDate = new Date(0);

    if (saveToCache) {
        if (currentAccessToken != null) {
            accessTokenCache.save(currentAccessToken);
        } else {
            accessTokenCache.clear();
            Utility.clearFacebookCookies(FacebookSdk.getApplicationContext());
        }
    }

    if (!Utility.areObjectsEqual(oldAccessToken, currentAccessToken)) {
        sendCurrentAccessTokenChangedBroadcast(oldAccessToken, currentAccessToken);
    }
}
 
Example 2
Source File: LikeActionController.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
@Override
protected void processSuccess(GraphResponse response) {
    JSONArray dataSet = Utility.tryGetJSONArrayFromResponse(
            response.getJSONObject(),
            "data");
    if (dataSet != null) {
        for (int i = 0; i < dataSet.length(); i++) {
            JSONObject data = dataSet.optJSONObject(i);
            if (data != null) {
                objectIsLiked = true;
                JSONObject appData = data.optJSONObject("application");
                AccessToken accessToken = AccessToken.getCurrentAccessToken();
                if (appData != null &&
                        accessToken != null &&
                        Utility.areObjectsEqual(
                                accessToken.getApplicationId(),
                                appData.optString("id"))) {
                    unlikeToken = data.optString("id");
                }
            }
        }
    }
}
 
Example 3
Source File: VideoUploader.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
private static void registerAccessTokenTracker() {
    accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(
                AccessToken oldAccessToken,
                AccessToken currentAccessToken) {
            if (oldAccessToken == null) {
                // If we never had an access token, then there would be no pending uploads.
                return;
            }

            if (currentAccessToken == null ||
                    !Utility.areObjectsEqual(
                            currentAccessToken.getUserId(),
                            oldAccessToken.getUserId())) {
                // Cancel any pending uploads since the user changed.
                cancelAllRequests();
            }
        }
    };
}
 
Example 4
Source File: VideoUploader.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
@Override
protected void handleSuccess(JSONObject jsonObject)
        throws JSONException {
    String startOffset = jsonObject.getString(PARAM_START_OFFSET);
    String endOffset = jsonObject.getString(PARAM_END_OFFSET);

    if (Utility.areObjectsEqual(startOffset, endOffset)) {
        enqueueUploadFinish(
                uploadContext,
                0);
    } else {
        enqueueUploadChunk(
                uploadContext,
                startOffset,
                endOffset,
                0);
    }
}
 
Example 5
Source File: ProfileManager.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
private void setCurrentProfile(Profile currentProfile, boolean writeToCache) {
    Profile oldProfile = this.currentProfile;
    this.currentProfile = currentProfile;

    if (writeToCache) {
        if (currentProfile != null) {
            profileCache.save(currentProfile);
        } else {
            profileCache.clear();
        }
    }

    if (!Utility.areObjectsEqual(oldProfile, currentProfile)) {
        sendCurrentProfileChangedBroadcast(oldProfile, currentProfile);
    }
}
 
Example 6
Source File: AppEventsLogger.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (!(o instanceof AccessTokenAppIdPair)) {
        return false;
    }
    AccessTokenAppIdPair p = (AccessTokenAppIdPair) o;
    return Utility.areObjectsEqual(p.accessTokenString, accessTokenString) &&
            Utility.areObjectsEqual(p.applicationId, applicationId);
}
 
Example 7
Source File: AppEventsLogger.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (!(o instanceof AccessTokenAppIdPair)) {
        return false;
    }
    AccessTokenAppIdPair p = (AccessTokenAppIdPair) o;
    return Utility.areObjectsEqual(p.accessToken, accessToken) &&
            Utility.areObjectsEqual(p.applicationId, applicationId);
}
 
Example 8
Source File: AppEventsLogger.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (!(o instanceof AccessTokenAppIdPair)) {
        return false;
    }
    AccessTokenAppIdPair p = (AccessTokenAppIdPair) o;
    return Utility.areObjectsEqual(p.accessToken, accessToken) &&
            Utility.areObjectsEqual(p.applicationId, applicationId);
}
 
Example 9
Source File: LikeActionController.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
private void updateState(boolean isObjectLiked,
                         String likeCountStringWithLike,
                         String likeCountStringWithoutLike,
                         String socialSentenceWithLike,
                         String socialSentenceWithoutLike,
                         String unlikeToken) {
    // Normalize all empty strings to null, so that we don't have any problems with comparison.
    likeCountStringWithLike = Utility.coerceValueIfNullOrEmpty(likeCountStringWithLike, null);
    likeCountStringWithoutLike =
            Utility.coerceValueIfNullOrEmpty(likeCountStringWithoutLike, null);
    socialSentenceWithLike = Utility.coerceValueIfNullOrEmpty(socialSentenceWithLike, null);
    socialSentenceWithoutLike =
            Utility.coerceValueIfNullOrEmpty(socialSentenceWithoutLike, null);
    unlikeToken = Utility.coerceValueIfNullOrEmpty(unlikeToken, null);

    boolean stateChanged = isObjectLiked != this.isObjectLiked ||
            !Utility.areObjectsEqual(
                    likeCountStringWithLike,
                    this.likeCountStringWithLike) ||
            !Utility.areObjectsEqual(
                    likeCountStringWithoutLike,
                    this.likeCountStringWithoutLike) ||
            !Utility.areObjectsEqual(socialSentenceWithLike, this.socialSentenceWithLike) ||
            !Utility.areObjectsEqual(
                    socialSentenceWithoutLike,
                    this.socialSentenceWithoutLike) ||
            !Utility.areObjectsEqual(unlikeToken, this.unlikeToken);

    if (!stateChanged) {
        return;
    }

    this.isObjectLiked = isObjectLiked;
    this.likeCountStringWithLike = likeCountStringWithLike;
    this.likeCountStringWithoutLike = likeCountStringWithoutLike;
    this.socialSentenceWithLike = socialSentenceWithLike;
    this.socialSentenceWithoutLike = socialSentenceWithoutLike;
    this.unlikeToken = unlikeToken;

    serializeToDiskAsync(this);

    broadcastAction(this, ACTION_LIKE_ACTION_CONTROLLER_UPDATED);
}
 
Example 10
Source File: VideoUploader.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
private static byte[] getChunk(
        UploadContext uploadContext,
        String chunkStart,
        String chunkEnd)
        throws IOException {
    if (!Utility.areObjectsEqual(chunkStart, uploadContext.chunkStart)) {
        // Something went wrong in the book-keeping here.
        logError(
                null,
                "Error reading video chunk. Expected chunk '%s'. Requested chunk '%s'.",
                uploadContext.chunkStart,
                chunkStart);
        return null;
    }

    long chunkStartLong = Long.parseLong(chunkStart);
    long chunkEndLong = Long.parseLong(chunkEnd);
    int chunkSize = (int) (chunkEndLong - chunkStartLong);

    ByteArrayOutputStream byteBufferStream = new ByteArrayOutputStream();
    int bufferSize = Math.min(8192, chunkSize);
    byte[] buffer = new byte[bufferSize];

    int len = 0;
    while ((len = uploadContext.videoStream.read(buffer)) != -1) {
        byteBufferStream.write(buffer, 0, len);

        chunkSize -= len;
        if (chunkSize == 0) {
            // Done!
            break;
        } else if (chunkSize < 0) {
            // This should not happen. Signal an error.
            logError(
                    null,
                    "Error reading video chunk. Expected buffer length - '%d'. Actual - '%d'.",
                    chunkSize + len,
                    len);
            return null;
        }
    }

    uploadContext.chunkStart = chunkEnd;

    return byteBufferStream.toByteArray();
}