Skip to content

Commit 96e6a86

Browse files
authored
Merge pull request #29 from gswierczynski/master
Revert to Rx's Maybe for singleValueEvent as Rx's Single does not has…
2 parents c82bae7 + d146be3 commit 96e6a86

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ buildscript {
22
ext {
33
rx_version = "2.1.0"
44
rx_android_version = "2.0.1"
5-
firebase_version = "11.2.0"
5+
firebase_version = "11.2.2"
66
support_version = "26.0.1"
77
}
88
}

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import io.reactivex.FlowableEmitter;
2626
import io.reactivex.FlowableOnSubscribe;
2727
import io.reactivex.Maybe;
28+
import io.reactivex.MaybeEmitter;
29+
import io.reactivex.MaybeOnSubscribe;
30+
import io.reactivex.MaybeSource;
2831
import io.reactivex.Single;
2932
import io.reactivex.SingleEmitter;
3033
import io.reactivex.SingleOnSubscribe;
31-
import io.reactivex.SingleSource;
3234
import io.reactivex.functions.Cancellable;
3335
import io.reactivex.functions.Function;
3436
import io.reactivex.functions.Predicate;
@@ -58,8 +60,9 @@ public void subscribe(final FlowableEmitter<DataSnapshot> emitter) throws Except
5860
final ValueEventListener valueEventListener = new ValueEventListener() {
5961
@Override
6062
public void onDataChange(DataSnapshot dataSnapshot) {
61-
if (dataSnapshot.exists())
63+
if (dataSnapshot.exists()) {
6264
emitter.onNext(dataSnapshot);
65+
}
6366
}
6467

6568
@Override
@@ -86,15 +89,16 @@ public void cancel() throws Exception {
8689
* the given {@link DataSnapshot} exists.
8790
*/
8891
@NonNull
89-
public static Single<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) {
90-
return Single.create(new SingleOnSubscribe<DataSnapshot>() {
92+
public static Maybe<DataSnapshot> observeSingleValueEvent(@NonNull final Query query) {
93+
return Maybe.create(new MaybeOnSubscribe<DataSnapshot>() {
9194
@Override
92-
public void subscribe(final SingleEmitter<DataSnapshot> emitter) throws Exception {
95+
public void subscribe(final MaybeEmitter<DataSnapshot> emitter) throws Exception {
9396
query.addListenerForSingleValueEvent(new ValueEventListener() {
9497
@Override
9598
public void onDataChange(DataSnapshot dataSnapshot) {
96-
if (dataSnapshot.exists())
99+
if (dataSnapshot.exists()) {
97100
emitter.onSuccess(dataSnapshot);
101+
}
98102
emitter.onComplete();
99103
}
100104

@@ -267,10 +271,10 @@ public void cancel() throws Exception {
267271
*/
268272
@NonNull
269273
public static Flowable<DataSnapshot> observeMultipleSingleValueEvent(@NonNull DatabaseReference... whereRefs) {
270-
return Single.merge(Flowable.fromArray(whereRefs)
271-
.map(new Function<DatabaseReference, SingleSource<? extends DataSnapshot>>() {
274+
return Maybe.merge(Flowable.fromArray(whereRefs)
275+
.map(new Function<DatabaseReference, MaybeSource<? extends DataSnapshot>>() {
272276
@Override
273-
public SingleSource<? extends DataSnapshot> apply(@io.reactivex.annotations.NonNull DatabaseReference databaseReference) throws
277+
public MaybeSource<? extends DataSnapshot> apply(@io.reactivex.annotations.NonNull DatabaseReference databaseReference) throws
274278
Exception {
275279
return observeSingleValueEvent(databaseReference);
276280
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.2.2'
8+
classpath 'com.android.tools.build:gradle:2.3.0'
99
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Dec 28 10:00:20 PST 2015
1+
#Tue Sep 19 19:36:52 CEST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

0 commit comments

Comments
 (0)