com.google.android.gms.games.snapshot.SnapshotContents Java Examples

The following examples show how to use com.google.android.gms.games.snapshot.SnapshotContents. 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: GoogleCloudSave.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
private void processOpenSnapshotResult(OpenSnapshotResult result, final UserData userData, IConflictResolver resolver) {
    final Snapshot snapshot = result.getSnapshot();
    if (result.getStatus().isSuccess()) {
        final SnapshotContents contents = snapshot.getSnapshotContents();
        final Map server = fromBytes(contents);
        if (server != null && server.containsKey("uuid") && !server.get("uuid").equals(userData.uuid())) {
            performUserResolve(server, resolver, new IConflictResolverCallback() {
                @Override public void onResolved(boolean useLocal) {
                    contents.writeBytes(useLocal ? toBytes(userData) : toBytes(server));
                    Games.Snapshots.commitAndClose(client, snapshot, EMPTY_CHANGE);
                }
            });
        } else {
            contents.writeBytes(toBytes(userData));
            Games.Snapshots.commitAndClose(client, snapshot, EMPTY_CHANGE);
        }
    } else if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) {
        Snapshot conflictingSnapshot = result.getConflictingSnapshot();
        startResolving(userData, conflictingSnapshot, result.getConflictId(), resolver);
    }
}
 
Example #2
Source File: GoogleCloudSave.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
private void startResolving(final UserData userData, final Snapshot conflictingSnapshot, final String conflictId, final IConflictResolver resolver) {
    final SnapshotContents contents = conflictingSnapshot.getSnapshotContents();
    final Map server = fromBytes(contents);
    if (server == null) {
        contents.writeBytes(toBytes(userData));
        Games.Snapshots.resolveConflict(client, conflictId, SNAPSHOT_ID, EMPTY_CHANGE, contents);
        return;
    }
    performUserResolve(server, resolver, new IConflictResolverCallback() {
        @SuppressWarnings("unchecked")
        @Override public void onResolved(boolean useLocal) {
            contents.writeBytes(useLocal ? toBytes(userData) : toBytes(server));
            Games.Snapshots
                .resolveConflict(client, conflictId, SNAPSHOT_ID, EMPTY_CHANGE, contents)
                .setResultCallback(new ResultCallback<OpenSnapshotResult>() {
                    @Override public void onResult(OpenSnapshotResult result) {
                        if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) {
                            startResolving(userData, result.getConflictingSnapshot(), result.getConflictId(), resolver);
                        }
                    }
                });
        }
    });
}
 
Example #3
Source File: SnapshotCoordinator.java    From Asteroid with Apache License 2.0 5 votes vote down vote up
@Override
public PendingResult<OpenSnapshotResult> resolveConflict(GoogleApiClient googleApiClient,
                                                         String conflictId, String snapshotId,
                                                         SnapshotMetadataChange snapshotMetadataChange,
                                                         SnapshotContents snapshotContents) {

    // Since the unique name of the snapshot is unknown, this resolution method cannot be safely
    // used.  Please use another method of resolution.
    throw new IllegalStateException("resolving conflicts with ids is not supported.");
}
 
Example #4
Source File: SnapshotCoordinator.java    From Trivia-Knowledge with Apache License 2.0 5 votes vote down vote up
@Override
public PendingResult<OpenSnapshotResult> resolveConflict(GoogleApiClient googleApiClient,
                                                         String conflictId, String snapshotId,
                                                         SnapshotMetadataChange snapshotMetadataChange,
                                                         SnapshotContents snapshotContents) {

    // Since the unique name of the snapshot is unknown, this resolution method cannot be safely
    // used.  Please use another method of resolution.
    throw new IllegalStateException("resolving conflicts with ids is not supported.");
}
 
Example #5
Source File: SnapshotCoordinator.java    From android-basic-samples with Apache License 2.0 5 votes vote down vote up
public Task<SnapshotsClient.DataOrConflict<Snapshot>> resolveConflict(SnapshotsClient snapshotsClient,
                                                                      String conflictId, String snapshotId,
                                                                      SnapshotMetadataChange snapshotMetadataChange,
                                                                      SnapshotContents snapshotContents) {
  // Since the unique name of the snapshot is unknown, this resolution method cannot be safely
  // used.  Please use another method of resolution.
  throw new IllegalStateException("resolving conflicts with ids is not supported.");
}