Skip to content

Commit

Permalink
Increase version and move no snapshot predicate to Mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
FrangSierra committed Sep 21, 2017
1 parent 96e6a86 commit 6bf0a73
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 4
versionName "1.0"
versionCode 5
versionName "1.3"
}
buildTypes {
release {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/durdinapps/rxfirebase2/DataSnapshotMapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package durdinapps.rxfirebase2;

import android.support.annotation.NonNull;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.GenericTypeIndicator;

Expand All @@ -10,6 +12,7 @@
import durdinapps.rxfirebase2.exceptions.RxFirebaseDataCastException;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;

public abstract class DataSnapshotMapper<T, U> implements Function<T, U> {

Expand Down Expand Up @@ -149,4 +152,11 @@ public RxFirebaseChildEvent<U> apply(final RxFirebaseChildEvent<DataSnapshot> rx
}
}
}

static final Predicate<DataSnapshot> DATA_SNAPSHOT_EXISTENCE_PREDICATE = new Predicate<DataSnapshot>() {
@Override
public boolean test(@NonNull DataSnapshot dataSnapshot) throws Exception {
return dataSnapshot.exists();
}
};
}
16 changes: 5 additions & 11 deletions app/src/main/java/durdinapps/rxfirebase2/RxFirebaseDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,10 @@
import io.reactivex.SingleOnSubscribe;
import io.reactivex.functions.Cancellable;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;

public class RxFirebaseDatabase {
import static durdinapps.rxfirebase2.DataSnapshotMapper.DATA_SNAPSHOT_EXISTENCE_PREDICATE;

public static final Predicate<DataSnapshot> DATA_SNAPSHOT_EXISTENCE_PREDICATE = new Predicate<DataSnapshot>() {
@Override
public boolean test(@io.reactivex.annotations.NonNull DataSnapshot dataSnapshot) throws Exception {
return dataSnapshot.exists();
}
};
public class RxFirebaseDatabase {

/**
* Listener for changes in te data at the given query location.
Expand Down Expand Up @@ -163,7 +157,7 @@ public static Completable setValue(@NonNull final DatabaseReference ref,
final Object value) {
return Completable.create(new CompletableOnSubscribe() {
@Override
public void subscribe(@io.reactivex.annotations.NonNull final CompletableEmitter e) throws Exception {
public void subscribe(@NonNull final CompletableEmitter e) throws Exception {
ref.setValue(value).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override public void onSuccess(Void aVoid) {
e.onComplete();
Expand Down Expand Up @@ -274,7 +268,7 @@ public static Flowable<DataSnapshot> observeMultipleSingleValueEvent(@NonNull Da
return Maybe.merge(Flowable.fromArray(whereRefs)
.map(new Function<DatabaseReference, MaybeSource<? extends DataSnapshot>>() {
@Override
public MaybeSource<? extends DataSnapshot> apply(@io.reactivex.annotations.NonNull DatabaseReference databaseReference) throws
public MaybeSource<? extends DataSnapshot> apply(@NonNull DatabaseReference databaseReference) throws
Exception {
return observeSingleValueEvent(databaseReference);
}
Expand Down Expand Up @@ -304,7 +298,7 @@ public static Maybe<DatabaseReference[]> requestFilteredReferenceKeys(@NonNull f
@NonNull Query whereRef) {
return observeSingleValueEvent(whereRef, new Function<DataSnapshot, DatabaseReference[]>() {
@Override
public DatabaseReference[] apply(@io.reactivex.annotations.NonNull DataSnapshot dataSnapshot) throws Exception {
public DatabaseReference[] apply(@NonNull DataSnapshot dataSnapshot) throws Exception {
int childrenCount = (int) dataSnapshot.getChildrenCount();
DatabaseReference[] filterRefs = new DatabaseReference[childrenCount];
final Iterator<DataSnapshot> iterator = dataSnapshot.getChildren().iterator();
Expand Down

0 comments on commit 6bf0a73

Please sign in to comment.