-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added LifecycleTransformer for access to Single Transformers
- Loading branch information
Showing
9 changed files
with
267 additions
and
26 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
rxlifecycle/src/main/java/com/trello/rxlifecycle/LifecycleTransformer.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,10 @@ | ||
package com.trello.rxlifecycle; | ||
|
||
import rx.Observable; | ||
import rx.Single; | ||
|
||
public interface LifecycleTransformer<T> extends Observable.Transformer<T, T> { | ||
|
||
Single.Transformer<T, T> forSingle(); | ||
|
||
} |
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
33 changes: 31 additions & 2 deletions
33
rxlifecycle/src/main/java/com/trello/rxlifecycle/UntilLifecycleObservableTransformer.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 |
---|---|---|
@@ -1,20 +1,49 @@ | ||
package com.trello.rxlifecycle; | ||
|
||
import android.support.annotation.NonNull; | ||
import rx.Observable; | ||
import rx.Single; | ||
|
||
/** | ||
* Continues a subscription until it sees *any* lifecycle event. | ||
*/ | ||
class UntilLifecycleObservableTransformer<T, R> implements Observable.Transformer<T, T> { | ||
final class UntilLifecycleObservableTransformer<T, R> implements LifecycleTransformer<T> { | ||
|
||
final Observable<R> lifecycle; | ||
|
||
public UntilLifecycleObservableTransformer(Observable<R> lifecycle) { | ||
public UntilLifecycleObservableTransformer(@NonNull Observable<R> lifecycle) { | ||
this.lifecycle = lifecycle; | ||
} | ||
|
||
@Override | ||
public Observable<T> call(Observable<T> source) { | ||
return source.takeUntil(lifecycle); | ||
} | ||
|
||
@Override | ||
public Single.Transformer<T, T> forSingle() { | ||
return new UntilLifecycleSingleTransformer<>(lifecycle); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { return true; } | ||
if (o == null || getClass() != o.getClass()) { return false; } | ||
|
||
UntilLifecycleObservableTransformer<?, ?> that = (UntilLifecycleObservableTransformer<?, ?>) o; | ||
|
||
return lifecycle.equals(that.lifecycle); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return lifecycle.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "UntilLifecycleObservableTransformer{" + | ||
"lifecycle=" + lifecycle + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.