-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed tests, added LifecycleRxJavaBinder, added leak canary, code cle…
…an up and bug fixes
- Loading branch information
Showing
13 changed files
with
155 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
sampleApp/src/main/java/com/zeyad/usecases/app/components/LifecycleRxJavaBinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.zeyad.usecases.app.components; | ||
|
||
import android.arch.lifecycle.LifecycleOwner; | ||
import android.arch.lifecycle.LiveData; | ||
import android.arch.lifecycle.LiveDataReactiveStreams; | ||
|
||
import io.reactivex.BackpressureStrategy; | ||
import io.reactivex.Flowable; | ||
import io.reactivex.FlowableTransformer; | ||
import io.reactivex.MaybeTransformer; | ||
import io.reactivex.ObservableTransformer; | ||
import io.reactivex.SingleTransformer; | ||
|
||
/** | ||
* @author by ZIaDo on 6/14/17. | ||
*/ | ||
public class LifecycleRxJavaBinder { | ||
public static <T> FlowableTransformer<T, T> applyFlowable(LifecycleOwner lifecycleOwner) { | ||
return flowable -> { | ||
LiveData<T> liveData = LiveDataReactiveStreams.fromPublisher(flowable); | ||
return Flowable.fromPublisher(LiveDataReactiveStreams.toPublisher(lifecycleOwner, liveData)); | ||
}; | ||
} | ||
|
||
public static <T> ObservableTransformer<T, T> applyObservable(LifecycleOwner lifecycleOwner, | ||
BackpressureStrategy strategy) { | ||
return observable -> { | ||
LiveData<T> liveData = LiveDataReactiveStreams.fromPublisher(observable.toFlowable(strategy)); | ||
return Flowable.fromPublisher(LiveDataReactiveStreams | ||
.toPublisher(lifecycleOwner, liveData)).toObservable(); | ||
}; | ||
} | ||
|
||
public static <T> ObservableTransformer<T, T> applyObservable(LifecycleOwner lifecycleOwner) { | ||
return observable -> { | ||
LiveData<T> liveData = LiveDataReactiveStreams.fromPublisher(observable | ||
.toFlowable(BackpressureStrategy.BUFFER)); | ||
return Flowable.fromPublisher(LiveDataReactiveStreams | ||
.toPublisher(lifecycleOwner, liveData)).toObservable(); | ||
}; | ||
} | ||
|
||
public static <T> SingleTransformer<T, T> applySingle(LifecycleOwner lifecycleOwner) { | ||
return single -> { | ||
LiveData<T> liveData = LiveDataReactiveStreams.fromPublisher(single.toFlowable()); | ||
return Flowable.fromPublisher(LiveDataReactiveStreams | ||
.toPublisher(lifecycleOwner, liveData)).singleOrError(); | ||
}; | ||
} | ||
|
||
public static <T> MaybeTransformer<T, T> applyMaybe(LifecycleOwner lifecycleOwner) { | ||
return maybe -> { | ||
LiveData<T> liveData = LiveDataReactiveStreams.fromPublisher(maybe.toFlowable()); | ||
return Flowable.fromPublisher(LiveDataReactiveStreams | ||
.toPublisher(lifecycleOwner, liveData)).firstElement(); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.