Skip to content

Commit 6bf0a73

Browse files
committed
Increase version and move no snapshot predicate to Mapper
1 parent 96e6a86 commit 6bf0a73

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ android {
2222
defaultConfig {
2323
minSdkVersion 14
2424
targetSdkVersion 26
25-
versionCode 4
26-
versionName "1.0"
25+
versionCode 5
26+
versionName "1.3"
2727
}
2828
buildTypes {
2929
release {

app/src/main/java/durdinapps/rxfirebase2/DataSnapshotMapper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package durdinapps.rxfirebase2;
22

3+
import android.support.annotation.NonNull;
4+
35
import com.google.firebase.database.DataSnapshot;
46
import com.google.firebase.database.GenericTypeIndicator;
57

@@ -10,6 +12,7 @@
1012
import durdinapps.rxfirebase2.exceptions.RxFirebaseDataCastException;
1113
import io.reactivex.exceptions.Exceptions;
1214
import io.reactivex.functions.Function;
15+
import io.reactivex.functions.Predicate;
1316

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

@@ -149,4 +152,11 @@ public RxFirebaseChildEvent<U> apply(final RxFirebaseChildEvent<DataSnapshot> rx
149152
}
150153
}
151154
}
155+
156+
static final Predicate<DataSnapshot> DATA_SNAPSHOT_EXISTENCE_PREDICATE = new Predicate<DataSnapshot>() {
157+
@Override
158+
public boolean test(@NonNull DataSnapshot dataSnapshot) throws Exception {
159+
return dataSnapshot.exists();
160+
}
161+
};
152162
}

app/src/main/java/durdinapps/rxfirebase2/RxFirebaseDatabase.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,10 @@
3333
import io.reactivex.SingleOnSubscribe;
3434
import io.reactivex.functions.Cancellable;
3535
import io.reactivex.functions.Function;
36-
import io.reactivex.functions.Predicate;
3736

38-
public class RxFirebaseDatabase {
37+
import static durdinapps.rxfirebase2.DataSnapshotMapper.DATA_SNAPSHOT_EXISTENCE_PREDICATE;
3938

40-
public static final Predicate<DataSnapshot> DATA_SNAPSHOT_EXISTENCE_PREDICATE = new Predicate<DataSnapshot>() {
41-
@Override
42-
public boolean test(@io.reactivex.annotations.NonNull DataSnapshot dataSnapshot) throws Exception {
43-
return dataSnapshot.exists();
44-
}
45-
};
39+
public class RxFirebaseDatabase {
4640

4741
/**
4842
* Listener for changes in te data at the given query location.
@@ -163,7 +157,7 @@ public static Completable setValue(@NonNull final DatabaseReference ref,
163157
final Object value) {
164158
return Completable.create(new CompletableOnSubscribe() {
165159
@Override
166-
public void subscribe(@io.reactivex.annotations.NonNull final CompletableEmitter e) throws Exception {
160+
public void subscribe(@NonNull final CompletableEmitter e) throws Exception {
167161
ref.setValue(value).addOnSuccessListener(new OnSuccessListener<Void>() {
168162
@Override public void onSuccess(Void aVoid) {
169163
e.onComplete();
@@ -274,7 +268,7 @@ public static Flowable<DataSnapshot> observeMultipleSingleValueEvent(@NonNull Da
274268
return Maybe.merge(Flowable.fromArray(whereRefs)
275269
.map(new Function<DatabaseReference, MaybeSource<? extends DataSnapshot>>() {
276270
@Override
277-
public MaybeSource<? extends DataSnapshot> apply(@io.reactivex.annotations.NonNull DatabaseReference databaseReference) throws
271+
public MaybeSource<? extends DataSnapshot> apply(@NonNull DatabaseReference databaseReference) throws
278272
Exception {
279273
return observeSingleValueEvent(databaseReference);
280274
}
@@ -304,7 +298,7 @@ public static Maybe<DatabaseReference[]> requestFilteredReferenceKeys(@NonNull f
304298
@NonNull Query whereRef) {
305299
return observeSingleValueEvent(whereRef, new Function<DataSnapshot, DatabaseReference[]>() {
306300
@Override
307-
public DatabaseReference[] apply(@io.reactivex.annotations.NonNull DataSnapshot dataSnapshot) throws Exception {
301+
public DatabaseReference[] apply(@NonNull DataSnapshot dataSnapshot) throws Exception {
308302
int childrenCount = (int) dataSnapshot.getChildrenCount();
309303
DatabaseReference[] filterRefs = new DatabaseReference[childrenCount];
310304
final Iterator<DataSnapshot> iterator = dataSnapshot.getChildren().iterator();

0 commit comments

Comments
 (0)