Skip to content

Commit

Permalink
Update dependencies, add null control for Firestore tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
FrangSierra committed Jan 3, 2019
1 parent 4eef4a9 commit 464f511
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ buildscript {
ext {
rx_version = "2.1.10"
rx_android_version = "2.0.2"
firebase_auth_version='16.0.5'
firebase_database_version='16.0.4'
firebase_storage_version='16.0.4'
firebase_firestore_version='17.1.3'
firebase_auth_version='16.1.0'
firebase_database_version='16.0.5'
firebase_storage_version='16.0.5'
firebase_firestore_version='17.1.5'
firebase_functions_version='16.1.3'
firebase_remote_version='16.1.0'
firebase_remote_version='16.1.2'
support_version = "28.0.3"
}
}
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/durdinapps/rxfirebase2/RxFirestore.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Map;
import java.util.concurrent.Executor;

import durdinapps.rxfirebase2.exceptions.RxFirebaseNullDataException;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Completable;
import io.reactivex.CompletableEmitter;
Expand Down Expand Up @@ -133,6 +134,10 @@ public void subscribe(final SingleEmitter<DocumentReference> emitter) {
ref.add(data).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
@Override
public void onComplete(@NonNull Task<DocumentReference> task) {
if (task.getResult() == null){
emitter.onError(new RxFirebaseNullDataException(task.getException()));
return;
}
emitter.onSuccess(task.getResult());
}
}).addOnFailureListener(new OnFailureListener() {
Expand Down Expand Up @@ -162,6 +167,10 @@ public void subscribe(final SingleEmitter<DocumentReference> emitter) {
ref.add(pojo).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
@Override
public void onComplete(@NonNull Task<DocumentReference> task) {
if (task.getResult() == null){
emitter.onError(new RxFirebaseNullDataException(task.getException()));
return;
}
emitter.onSuccess(task.getResult());
}
}).addOnFailureListener(new OnFailureListener() {
Expand All @@ -186,7 +195,7 @@ public void onFailure(@NonNull Exception e) {
* @return a Single which emits the {@link DocumentReference} of the added Document.
*/
@NonNull
private static Completable addDocumentOffline(@NonNull final CollectionReference ref,
public static Completable addDocumentOffline(@NonNull final CollectionReference ref,
@NonNull final Map<String, Object> data) {
return Completable.create(new CompletableOnSubscribe() {
@Override
Expand All @@ -212,7 +221,7 @@ public void subscribe(CompletableEmitter emitter) {
* @return a Single which emits the {@link DocumentReference} of the added Document.
*/
@NonNull
private static Completable addDocumentOffline(@NonNull final CollectionReference ref,
public static Completable addDocumentOffline(@NonNull final CollectionReference ref,
@NonNull final Object pojo) {
return Completable.create(new CompletableOnSubscribe() {
@Override
Expand Down Expand Up @@ -1232,7 +1241,7 @@ public static <T> Maybe<List<T>> getCollection(@NonNull final CollectionReferenc
* @param mapper specific function to map the dispatched events.
*/
@NonNull
private static <T> Maybe<List<T>> getCollection(CollectionReference ref,
public static <T> Maybe<List<T>> getCollection(CollectionReference ref,
DocumentSnapshotMapper<QuerySnapshot,
List<T>> mapper) {
return getCollection(ref)
Expand All @@ -1259,7 +1268,7 @@ public static <T> Maybe<List<T>> getCollection(@NonNull final Query query,
* @param mapper specific function to map the dispatched events.
*/
@NonNull
private static <T> Maybe<List<T>> getCollection(@NonNull Query query,
public static <T> Maybe<List<T>> getCollection(@NonNull Query query,
@NonNull DocumentSnapshotMapper<QuerySnapshot,
List<T>> mapper) {
return getCollection(query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@


import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

public class RxFirebaseNullDataException extends NullPointerException {
private final static String DEFAULT_MESSAGE = "Task result was successfully but data was empty";

public RxFirebaseNullDataException() {
}
Expand All @@ -12,4 +14,7 @@ public RxFirebaseNullDataException(@NonNull String detailMessage) {
super(detailMessage);
}

public RxFirebaseNullDataException(@Nullable Exception resultException) {
super(resultException != null ? resultException.getMessage() : DEFAULT_MESSAGE);
}
}

0 comments on commit 464f511

Please sign in to comment.