/** * Fetch the current user profile * * @return profile of the given user */ public Task<UserProfile> getUserProfile() { return _stitchClient.executeRequest( Request.Method.GET, Paths.USER_PROFILE ).continueWith(new Continuation<String, UserProfile>() { @Override public UserProfile then(@NonNull Task<String> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } try { _userProfile = _objMapper.readValue(task.getResult(), UserProfile.class); } catch (final IOException e) { Log.e(TAG, "Error parsing user response", e); throw e; } return _userProfile; } }); }
/** * Create an api key associated with this user * @param name name of new api key * @return task with new api key */ public Task<APIKey> createApiKey(@NonNull final String name) { return _stitchClient.executeRequest( Request.Method.POST, Paths.USER_PROFILE_API_KEYS, new Document("name", name).toJson(), true, true ).continueWith(new Continuation<String, APIKey>() { @Override public APIKey then(@NonNull final Task<String> task) throws Exception { if (task.isSuccessful()) { return _objMapper.readValue(task.getResult(), APIKey.class); } else { Log.e(TAG, "Error while creating user api key", task.getException()); throw task.getException(); } } }); }
/** * Fetch an api key associated with this user by its id * @param id id of this user * @return api key for this id */ public Task<APIKey> fetchApiKey(@NonNull final String id) { return _stitchClient.executeRequest( Request.Method.GET, String.format( "%s/%s", Paths.USER_PROFILE_API_KEYS, id ), null, true, true ).continueWith(new Continuation<String, APIKey>() { @Override public APIKey then(@NonNull final Task<String> task) throws Exception { if (task.isSuccessful()) { return _objMapper.readValue(task.getResult(), APIKey.class); } else { Log.e(TAG, "Error while fetching user api keys", task.getException()); throw task.getException(); } } }); }
/** * Fetch all api keys associated with this user * @return list of api keys */ public Task<List<APIKey>> fetchApiKeys() { return _stitchClient.executeRequest( Request.Method.GET, Paths.USER_PROFILE_API_KEYS, null, true, true ).continueWith(new Continuation<String, List<APIKey>>() { @Override public List<APIKey> then(@NonNull final Task<String> task) throws Exception { if (task.isSuccessful()) { return Arrays.asList(_objMapper.readValue(task.getResult(), APIKey[].class)); } else { Log.e(TAG, "Error while fetching user api keys", task.getException()); throw task.getException(); } } }); }
/** * Delete an api key associated with this user * @param id id to delete * @return success boolean */ public Task<Boolean> deleteApiKey(@NonNull final String id) { return _stitchClient.executeRequest( Request.Method.DELETE, String.format( "%s/%s", Paths.USER_PROFILE_API_KEYS, id ), null, true, true ).continueWith(new Continuation<String, Boolean>() { @Override public Boolean then(@NonNull final Task<String> task) throws Exception { if (task.isSuccessful()) { return true; } else { Log.e(TAG, "Error while deleting user api key", task.getException()); throw task.getException(); } } }); }
/** * @return A task that can be resolved upon completion of registration to both GCM and Stitch. */ @Override public Task<Void> register() { final InstanceID instanceId = InstanceID.getInstance(getContext()); return getRegistrationToken(instanceId, _info.getSenderId()) .continueWithTask(new Continuation<String, Task<Void>>() { @Override public Task<Void> then(@NonNull final Task<String> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } return registerWithServer(task.getResult()); } }); }
/** * @return A task that can be resolved upon completion of deregistration from both GCM and Stitch. */ @Override public Task<Void> deregister() { final InstanceID instanceId = InstanceID.getInstance(getContext()); return deleteRegistrationToken(instanceId, _info.getSenderId()) .continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(@NonNull final Task<Void> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } return deregisterWithServer(); } }); }
/** * Register the registration token with Stitch. * * @param registrationToken The registration token generated for the sender. * @return A task that can be resolved upon registering the token with Stitch. */ private Task<Void> registerWithServer(final String registrationToken) { final Document parameters = getRegisterPushDeviceRequest(registrationToken); return getStitchClient().executeRequest( Request.Method.PUT, routes.getPushProvidersRegistrationRoute(this._info.getService()), parameters.toJson() ).continueWith(new Continuation<String, Void>() { @Override public Void then(@NonNull Task<String> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } return null; } }); }
/** * Updates a single document matching the query specifier. * * @param query The query specifier. * @param update The update specifier. * @param upsert Whether or not to upsert if the query matches no documents. * @return A task that can be resolved upon completion of the request. */ public Task<Document> updateOne(final Document query, final Document update, final boolean upsert) { Document doc = new Document(Parameters.QUERY, query); doc.put(Parameters.DATABASE, _database._dbName); doc.put(Parameters.COLLECTION, _collName); doc.put(Parameters.UPDATE, update); doc.put(Parameters.UPSERT, upsert); return _database._client._stitchClient.executeServiceFunction( "updateOne", _database._client._service, doc ).continueWith(new Continuation<Object, Document>() { @Override public Document then(@NonNull Task<Object> task) throws Exception { if (task.isSuccessful()) { return (Document) task.getResult(); } else { Log.e(TAG, "Error while executing function", task.getException()); throw task.getException(); } } }); }
/** * Updates many documents matching a query specifier. * * @param query The query specifier. * @param update The update specifier. * @param upsert Whether or not to upsert if the query matches no documents. * @return A task that can be resolved upon completion of the request. */ public Task<Document> updateMany(final Document query, final Document update, final boolean upsert) { Document doc = new Document(Parameters.QUERY, query); doc.put(Parameters.DATABASE, _database._dbName); doc.put(Parameters.COLLECTION, _collName); doc.put(Parameters.UPDATE, update); doc.put(Parameters.UPSERT, upsert); doc.put(Parameters.MULTI, true); return _database._client._stitchClient.executeServiceFunction( "updateMany", _database._client._service, doc ).continueWith(new Continuation<Object, Document>() { @Override public Document then(@NonNull Task<Object> task) throws Exception { if (task.isSuccessful()) { return (Document) task.getResult(); } else { Log.e(TAG, "Error while executing function", task.getException()); throw task.getException(); } } }); }
/** * Inserts a single document. * * @param document The document to insert. * @return A task that can be resolved upon completion of the request. */ public Task<Document> insertOne(final Document document) { final Document doc = new Document("document", document); doc.put(Parameters.DATABASE, _database._dbName); doc.put(Parameters.COLLECTION, _collName); return _database._client._stitchClient.executeServiceFunction( "insertOne", _database._client._service, doc ).continueWith(new Continuation<Object, Document>() { @Override public Document then(@NonNull Task<Object> task) throws Exception { if (task.isSuccessful()) { return (Document) task.getResult(); } else { Log.e(TAG, "Error while executing function", task.getException()); throw task.getException(); } } }); }
/** * Inserts many documents. * * @param documents The list of documents to insert. * @return A task that can be resolved upon completion of the request. */ public Task<Document> insertMany(final List<Document> documents) { Document doc = new Document("documents", documents); doc.put(Parameters.DATABASE, _database._dbName); doc.put(Parameters.COLLECTION, _collName); return _database._client._stitchClient.executeServiceFunction( "insertMany", _database._client._service, doc ).continueWith(new Continuation<Object, Document>() { @Override public Document then(@NonNull Task<Object> task) throws Exception { if (task.isSuccessful()) { return (Document) task.getResult(); } else { Log.e(TAG, "Error while executing function", task.getException()); throw task.getException(); } } }); }
/** * Deletes a single document matching a query specifier. * * @param query The query specifier. * @return A task that can be resolved upon completion of the request. */ public Task<Document> deleteOne(final Document query) { Document doc = new Document(Parameters.QUERY, query); doc.put(Parameters.DATABASE, _database._dbName); doc.put(Parameters.SINGLE_DOCUMENT, true); doc.put(Parameters.COLLECTION, _collName); return _database._client._stitchClient.executeServiceFunction( "deleteOne", _database._client._service, doc ).continueWith(new Continuation<Object, Document>() { @Override public Document then(@NonNull Task<Object> task) throws Exception { if (task.isSuccessful()) { return (Document) task.getResult(); } else { Log.e(TAG, "Error while executing function", task.getException()); throw task.getException(); } } }); }
/** * Deletes many document matching a query specifier. * * @param query The query specifier. * @return A task that can be resolved upon completion of the request. */ public Task<Document> deleteMany(final Document query) { final Document doc = new Document(Parameters.QUERY, query); doc.put(Parameters.DATABASE, _database._dbName); doc.put(Parameters.COLLECTION, _collName); doc.put(Parameters.SINGLE_DOCUMENT, false); return _database._client._stitchClient.executeServiceFunction( "deleteMany", _database._client._service, doc ).continueWith(new Continuation<Object, Document>() { @Override public Document then(@NonNull Task<Object> task) throws Exception { if (task.isSuccessful()) { return (Document) task.getResult(); } else { Log.e(TAG, "Error while executing function", task.getException()); throw task.getException(); } } }); }
/** * Logs out the current user. * * @return A task that can be resolved upon completion of logout. */ public Task<Void> logout() { if (!isAuthenticated()) { return Tasks.forResult(null); } return executeRequest(Request.Method.DELETE, routes.AUTH_SESSION, null, false, true).continueWith(new Continuation<String, Void>() { @Override public Void then(@NonNull final Task<String> task) throws Exception { if (task.isSuccessful()) { clearAuth(); return null; } throw task.getException(); } }); }
/** * Execute a named function associated with a service * @param name name of the function * @param serviceName name of your service * @param args extended JSON arguments associated with the function * @return return value of the associated function */ public Task<Object> executeServiceFunction(String name, String serviceName, Object... args) { ensureAuthenticated(); final Document doc = new Document("name", name); doc.put("arguments", asList(args)); if (serviceName != null) { doc.put("service", serviceName); } return executeRequest( Request.Method.POST, routes.FUNCTIONS, doc.toJson() ).continueWith(new Continuation<String, Object>() { @Override public Object then(@NonNull final Task<String> task) throws Exception { if (task.isSuccessful()) { return parseValue(task.getResult()); } else { Log.e(TAG, "Error while executing function", task.getException()); throw task.getException(); } } }); }
@SuppressWarnings("ConstantConditions") public RemoteConfig(boolean isDebug, final IAnalytics analytics) { firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(isDebug).build(); firebaseRemoteConfig.setConfigSettings(configSettings); firebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults); firebaseRemoteConfig.fetch().continueWith((Continuation<Void, Void>) task -> { if (task.isSuccessful()) { Log.e(TAG, "then: Success"); firebaseRemoteConfig.activateFetched(); analytics.setUserProperty(EXPERIMENT_ABOUT_MENU, getExperimentVariant(EXPERIMENT_ABOUT_MENU)); return null; } Log.e(TAG, "then: Failure"); throw task.getException(); }); }
private void taskChaining() { // [START task_chaining] Task<AuthResult> signInTask = FirebaseAuth.getInstance().signInAnonymously(); signInTask.continueWithTask(new Continuation<AuthResult, Task<String>>() { @Override public Task<String> then(@NonNull Task<AuthResult> task) throws Exception { // Take the result from the first task and start the second one AuthResult result = task.getResult(); return doSomething(result); } }).addOnSuccessListener(new OnSuccessListener<String>() { @Override public void onSuccess(String s) { // Chain of tasks completed successfully, got result from last task. // ... } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { // One of the tasks in the chain failed with an exception. // ... } }); // [END task_chaining] }
public Task<Void> createCounter(final DocumentReference ref, final int numShards) { // Initialize the counter document, then initialize each shard. return ref.set(new Counter(numShards)) .continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(@NonNull Task<Void> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } List<Task<Void>> tasks = new ArrayList<>(); // Initialize each shard with count=0 for (int i = 0; i < numShards; i++) { Task<Void> makeShard = ref.collection("shards") .document(String.valueOf(i)) .set(new Shard(0)); tasks.add(makeShard); } return Tasks.whenAll(tasks); } }); }
/** * Initializes the folder view after the given task completes. * * @return Task which resolves after the view has been initialized */ private Task<Void> initializeFolderView() { Task<DriveFolder> folderTask; if (mNavigationPath.isEmpty()) { folderTask = mDriveResourceClient.getRootFolder(); } else { folderTask = Tasks.forResult(mNavigationPath.peek().asDriveFolder()); } Task<Void> initFolderTask = folderTask.continueWith(new Continuation<DriveFolder, Void>() { @Override public Void then(@NonNull Task<DriveFolder> task) throws Exception { DriveId id = task.getResult().getDriveId(); if (mNavigationPath.isEmpty()) { mNavigationPath.push(id); } return null; } }); return updateUiAfterTask(initFolderTask); }
public Task<Map<DatabaseReference, DataSnapshot>> start() { // Create a Task<DataSnapshot> to trigger in response to each database listener. // final ArrayList<Task<DataSnapshot>> tasks = new ArrayList<>(refs.size()); for (final DatabaseReference ref : refs) { final TaskCompletionSource<DataSnapshot> source = new TaskCompletionSource<>(); final ValueEventListener listener = new MyValueEventListener(ref, source); ref.addListenerForSingleValueEvent(listener); listeners.put(ref, listener); tasks.add(source.getTask()); } // Return a single Task that triggers when all queries are complete. It contains // a map of all original DatabaseReferences originally given here to their resulting // DataSnapshot. // return Tasks.whenAll(tasks).continueWith(new Continuation<Void, Map<DatabaseReference, DataSnapshot>>() { @Override public Map<DatabaseReference, DataSnapshot> then(@NonNull Task<Void> task) throws Exception { task.getResult(); return new HashMap<>(snaps); } }); }
public static Task<String> fetchTopProvider(FirebaseAuth auth, @NonNull String email) { if (TextUtils.isEmpty(email)) { return Tasks.forException(new NullPointerException("Email cannot be empty")); } return auth.fetchProvidersForEmail(email) .continueWith(new Continuation<ProviderQueryResult, String>() { @Override public String then(@NonNull Task<ProviderQueryResult> task) { if (!task.isSuccessful()) return null; List<String> providers = task.getResult().getProviders(); return providers == null || providers.isEmpty() ? null : providers.get(providers.size() - 1); } }); }
@Override protected void onDriveClientReady() { getDriveClient() .requestSync() .continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(@NonNull Task<Void> task) throws Exception { return initializeGroceryList(); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.e(TAG, "Unexpected error", e); showMessage(getString(R.string.unexpected_error)); } }); }
private Task<Void> loadContents(DriveFile file) { mGroceryListFile = file; Task<DriveContents> loadTask = getDriveResourceClient().openFile(file, DriveFile.MODE_READ_ONLY); return loadTask.continueWith(new Continuation<DriveContents, Void>() { @Override public Void then(@NonNull Task<DriveContents> task) throws Exception { Log.d(TAG, "Reading file contents"); mDriveContents = task.getResult(); InputStream inputStream = mDriveContents.getInputStream(); String groceryListStr = ConflictUtil.getStringFromInputStream(inputStream); mEditText.setText(groceryListStr); return null; } }); }
private Task<DriveFile> createNewFile() { Log.d(TAG, "Creating new grocery list."); return getDriveResourceClient().getRootFolder().continueWithTask( new Continuation<DriveFolder, Task<DriveFile>>() { @Override public Task<DriveFile> then(@NonNull Task<DriveFolder> task) throws Exception { DriveFolder folder = task.getResult(); MetadataChangeSet changeSet = new MetadataChangeSet.Builder() .setTitle(getResources().getString( R.string.groceryListFileName)) .setMimeType("text/plain") .build(); return getDriveResourceClient().createFile(folder, changeSet, null); } }); }
/** * Invokes calls to query user's Google Drive root folder's children with * the currently selected query. */ private void refresh() { mResultsAdapter.clear(); getDriveResourceClient() .query(sQueries[mSelectedIndex]) .continueWith(new Continuation<MetadataBuffer, Void>() { @Override public Void then(@NonNull Task<MetadataBuffer> task) throws Exception { MetadataBuffer metadata = task.getResult(); Log.d(TAG, "Retrieved file count: " + metadata.getCount()); mResultsAdapter.append(metadata); return null; } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.e(TAG, "Error while retrieving files", e); showMessage(getString(R.string.msg_errorretrieval)); } }); }
/** * Enable or disable an api key associated with this user * @param id id of api key * @param shouldEnable whether or not the api key should be enabled * @return success boolean */ private Task<Boolean> _enableDisableApiKey(@NonNull final String id, final boolean shouldEnable) { return _stitchClient.executeRequest( Request.Method.PUT, String.format( "%s/%s/%s", Paths.USER_PROFILE_API_KEYS, id, shouldEnable ? "enable" : "disable" ), null, true, true ).continueWith(new Continuation<String, Boolean>() { @Override public Boolean then(@NonNull final Task<String> task) throws Exception { if (task.isSuccessful()) { return true; } else { Log.e( TAG, String.format( "Error while %s user api key", shouldEnable ? "enabling" : "disabling" ), task.getException() ); throw task.getException(); } } }); }
/** * Deregister the device associated with the registration token from Stitch. * * @return A task that can be resolved upon deregistering the device from Stitch. */ private Task<Void> deregisterWithServer() { return getStitchClient().executeRequest( Request.Method.DELETE, routes.getPushProvidersRegistrationRoute(this._info.getService()) ).continueWith(new Continuation<String, Void>() { @Override public Void then(@NonNull Task<String> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } return null; } }); }
/** * Finds and projects documents matching a query up to the specified limit. * * @param query The query specifier. * @param projection The projection document. * @param limit The maximum amount of matching documents to accept. * @return A task containing the matched and projected documents that can be resolved upon completion * of the request. */ public Task<List<Document>> find(final Document query, final Document projection, final Integer limit) { Document doc = new Document(Parameters.QUERY, query); doc.put(Parameters.DATABASE, _database._dbName); doc.put(Parameters.COLLECTION, _collName); doc.put(Parameters.LIMIT, limit); if (projection != null) { doc.put(Parameters.PROJECT, projection); } return _database._client._stitchClient.executeServiceFunction( "find", _database._client._service, doc ).continueWith(new Continuation<Object, List<Document>>() { @Override public List<Document> then(@NonNull Task<Object> task) throws Exception { if (task.isSuccessful()) { final List<Object> objects = (List<Object>) task.getResult(); final List<Document> docs = new ArrayList<>(objects.size()); for (final Object obj : objects) { docs.add((Document) obj); } return docs; } else { Log.e(TAG, "Error while executing function", task.getException()); throw task.getException(); } } }); }
/** * Counts the number of documents matching a query up to the specified limit. * * @param query The query specifier. * @return A task containing the number of matched documents that can be resolved upon completion * of the request. */ public Task<Long> count(final Document query, final Document projection) { Document doc = new Document(Parameters.QUERY, query); doc.put(Parameters.DATABASE, _database._dbName); doc.put(Parameters.COLLECTION, _collName); if (projection != null) { doc.put(Parameters.PROJECT, projection); } return _database._client._stitchClient.executeServiceFunction( "count", _database._client._service, doc ).continueWith(new Continuation<Object, Long>() { @Override public Long then(@NonNull Task<Object> task) throws Exception { if (task.isSuccessful()) { final Object result = task.getResult(); if (result instanceof Integer) { return Long.valueOf((Integer) result); } return (Long) result; } else { Log.e(TAG, "Error while executing function", task.getException()); throw task.getException(); } } }); }
/** * Gets all available push providers for the current app. * * @return A task containing {@link AvailablePushProviders} that can be resolved on completion * of the request. */ public Task<AvailablePushProviders> getPushProviders() { return executeRequest(Request.Method.GET, routes.PUSH).continueWith(new Continuation<String, AvailablePushProviders>() { @Override public AvailablePushProviders then(@NonNull final Task<String> task) throws Exception { return AvailablePushProviders.fromQuery(task.getResult()); } }); }
public Task<Integer> getCount(final DocumentReference ref) { // Sum the count of each shard in the subcollection return ref.collection("shards").get() .continueWith(new Continuation<QuerySnapshot, Integer>() { @Override public Integer then(@NonNull Task<QuerySnapshot> task) throws Exception { int count = 0; for (DocumentSnapshot snap : task.getResult()) { Shard shard = snap.toObject(Shard.class); count += shard.count; } return count; } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_streaming); StreamManager.initialize(MemberIdentity.ME) .continueWithTask(new Continuation<StreamManager, Task<CameraController>>() { @Override public Task<CameraController> then(@NonNull Task<StreamManager> task) throws Exception { if (!task.isSuccessful()) { Log.e(TAG, "init fail " + task.getException()); throw task.getException(); } mStreamManager = task.getResult(); mStreamManager.addEventListener(mEventListener); return preview(); } }); mTextureView = findViewById(R.id.preview); mTextureView.setKeepScreenOn(true); btn_trigger = findViewById(trigger); btn_switch = findViewById(switch_camera); btn_flash = findViewById(flash); btn_filter = findViewById(filter); mEditTitle = findViewById(R.id.edit_title); mEditSynopsis = findViewById(R.id.edit_synopsis); mStreamStats = findViewById(R.id.stream_stats); checkPermissions(); }
private void createNewDriveBackup() { final Task<DriveFolder> appFolderTask = getmDriveResourceClient().getAppFolder(); final Task<DriveContents> createContentsTask = getmDriveResourceClient().createContents(); Tasks.whenAll(appFolderTask, createContentsTask) .continueWithTask(new Continuation<Void, Task<DriveFile>>() { @Override public Task<DriveFile> then(@NonNull Task<Void> task) throws Exception { Log.d(TAG, "Creating drive file... "); DriveContents driveContents = createContentsTask.getResult(); writeBackupToOutputStream(driveContents.getOutputStream()); MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder() .setTitle(BACKUP_FILE_NAME_COMPRESSED) .setMimeType("application/zip") .setCustomProperty(DRIVE_KEY_APP_ID, mAppId) .setCustomProperty(DRIVE_KEY_DEVICE_NAME, DeviceName.getDeviceName()) .build(); return getmDriveResourceClient().createFile(appFolderTask.getResult(), metadataChangeSet, driveContents); } }) .addOnSuccessListener(new OnSuccessListener<DriveFile>() { @Override public void onSuccess(DriveFile driveFile) { mDriveId = driveFile.getDriveId().encodeToString(); Log.d(TAG, "Drive file created " + mDriveId); finishJob(true); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.e(TAG, "Error while trying to create file.", e); finishJob(); } }); }
private void modifyExistingDriveBackup() { final DriveId driveId = DriveId.decodeFromString(mDriveId); getmDriveResourceClient().openFile(driveId.asDriveFile(), DriveFile.MODE_WRITE_ONLY) .continueWithTask(new Continuation<DriveContents, Task<Void>>() { @Override public Task<Void> then(@NonNull Task<DriveContents> task) throws Exception { DriveContents driveContents = task.getResult(); writeBackupToOutputStream(driveContents.getOutputStream()); MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder() .setTitle(BACKUP_FILE_NAME_COMPRESSED) .setMimeType("application/zip") .setCustomProperty(DRIVE_KEY_APP_ID, mAppId) .setCustomProperty(DRIVE_KEY_DEVICE_NAME, DeviceName.getDeviceName()) .build(); return getmDriveResourceClient().commitContents(driveContents, metadataChangeSet); } }) .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { Log.d(TAG, "Drive file modified " + mDriveId); finishJob(true); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Couldn't open drive file. Maybe deleted by user."); mDriveId = null; // Create a new file createNewDriveBackup(); } }); }
/** * Inserts and verifies a session by chaining {@link Task} form {@link #insertSessionData} and * {@link #viewSessionData}. */ private void insertAndVerifySession() { insertSessionData().continueWithTask(new Continuation<Void, Task<SessionReadResponse>>() { @Override public Task<SessionReadResponse> then(@NonNull Task<Void> task) throws Exception { return viewSessionData(); } }); }
/** * Inserts and verifies a session by chaining {@link Task} form {@link #insertSteps} and * {@link #displayTodayData()}. */ private void insertAndDisplayToday() { insertSteps().continueWithTask(new Continuation<Void, Task<DataSet>>() { @Override public Task<DataSet> then(@NonNull Task<Void> task) throws Exception { return displayTodayData(); } }); }
private void UpdateAndDisplayWeek() { insertUpdateSteps().continueWithTask(new Continuation<Void, Task<DataReadResponse>>() { @Override public Task<DataReadResponse> then(@NonNull Task<Void> task) throws Exception { return displayLastWeeksData(); } }); }
/** * Update the UI with the current folder name * * @param folder currently selected folder */ private Task<Void> loadFolderName(DriveFolder folder) { Log.i(TAG, "Fetching folder metadata for " + folder.getDriveId().encodeToString()); Task<Metadata> getMetadataTask = mDriveResourceClient.getMetadata(folder); return getMetadataTask.continueWith(new Continuation<Metadata, Void>() { @Override public Void then(@NonNull Task<Metadata> task) throws Exception { mCurrentFolderNameTextView.setText(task.getResult().getTitle()); return null; } }); }
@NonNull @Override public <TContinuationResult> Task<TContinuationResult> continueWith( @NonNull Continuation<TResult, TContinuationResult> continuation) { try { return Tasks.forResult(continuation.then(Tasks.forResult(mResult))); } catch (Exception e) { throw new RuntimeException(e); } }