/** * Saves the file to the Parse cloud in a background thread. * * @return A Task that will be resolved when the save completes. */ public Task<Void> saveInBackground() { return saveInBackground((ProgressCallback) null); }
/** * Saves the file to the Parse cloud in a background thread. * `progressCallback` is guaranteed to be called with 100 before saveCallback is called. * * @param saveCallback A SaveCallback that gets called when the save completes. * @param progressCallback A ProgressCallback that is called periodically with progress updates. */ public void saveInBackground(final SaveCallback saveCallback, ProgressCallback progressCallback) { ParseTaskUtils.callbackOnMainThreadAsync(saveInBackground(progressCallback), saveCallback); }
/** * Saves the file to the Parse cloud synchronously. */ public void save() throws ParseException { ParseTaskUtils.wait(saveInBackground()); }
/** * Saves the file to the Parse cloud in a background thread. * * @param callback A SaveCallback that gets called when the save completes. */ public void saveInBackground(SaveCallback callback) { ParseTaskUtils.callbackOnMainThreadAsync(saveInBackground(), callback); }
@Test public void testCancel() { ParseFile file = new ParseFile(new ParseFile.State.Builder().build()); TaskQueueTestHelper queueHelper = new TaskQueueTestHelper(file.taskQueue); queueHelper.enqueue(); List<Task<Void>> saveTasks = Arrays.asList( file.saveInBackground(), file.saveInBackground(), file.saveInBackground()); List<Task<byte[]>> getDataTasks = Arrays.asList( file.getDataInBackground(), file.getDataInBackground(), file.getDataInBackground()); file.cancel(); queueHelper.dequeue(); for (int i = 0; i < saveTasks.size(); i++) { assertTrue("Task #" + i + " was not cancelled", saveTasks.get(i).isCancelled()); } for (int i = 0; i < getDataTasks.size(); i++) { assertTrue("Task #" + i + " was not cancelled", getDataTasks.get(i).isCancelled()); } }
@NonNull public static Completable save(@NonNull final ParseFile file) { return RxTask.completable(() -> file.saveInBackground()); }
imgFile.saveInBackground(); userProfile.setPhotoFile(imgFile);
@NonNull public static Completable save(@NonNull final ParseFile file, @NonNull final ProgressCallback uploadProgressCallback) { return RxTask.completable(() -> file.saveInBackground(uploadProgressCallback)); }
private void addPost(String postBody, Bitmap finalImg) { final Post post = new Post(); post.setDescription(postBody); ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (finalImg != null) { finalImg.compress(Bitmap.CompressFormat.JPEG, 100, stream); // get byte array here byte[] bytearray = stream.toByteArray(); ParseFile imgFile = new ParseFile("profileImg.png", bytearray); imgFile.saveInBackground(); post.setPostPicFile(imgFile); } post.setUser(currentUser); post.setFeature(feature); post.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { // notify fragment FeaturePostsFragment pf = (FeaturePostsFragment) getSupportFragmentManager().getFragments().get(0); // make sure it will aways be that 0! posts are zero in view pager if (null != pf) { pf.setReceivedPost(post); } } }); }
imgFile.saveInBackground(); post.setPostPicFile(imgFile);
@Test public void testParseObservableSaveFileProgress() { rx.parse2.ParseObservable.save(mocker(ParseFile.class) .when(it -> it.saveInBackground(any(ProgressCallback.class))) .thenReturn(it -> Task.<Void>forResult(null)) .mock(), mock(ProgressCallback.class)) .test() .assertNoErrors() .assertComplete(); }
@Test public void testParseObservableSaveFile() { rx.parse2.ParseObservable.save(mocker(ParseFile.class) .when(it -> it.saveInBackground()) .thenReturn(it -> Task.<Void>forResult(null)) .mock()) .test() .assertNoErrors() .assertComplete(); }