-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from AAkira/feature/divide-rx-java
Divide rx-java
- Loading branch information
Showing
13 changed files
with
197 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,24 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion COMPILE_SDK_VERSION as int | ||
buildToolsVersion BUILD_TOOLS_VERSION | ||
|
||
defaultConfig { | ||
minSdkVersion MIN_SDK_VERSION as int | ||
targetSdkVersion TARGET_SDK_VERSION as int | ||
versionName project.version | ||
|
||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile project(':binder') | ||
compile "io.reactivex.rxjava2:rxjava:$RX_JAVA_VERSION" | ||
} |
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,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Applications/android-sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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,4 @@ | ||
<manifest | ||
package="jp.satorufujiwara.binder.rx"> | ||
<application /> | ||
</manifest> |
96 changes: 96 additions & 0 deletions
96
binder-rx/src/main/java/jp/satorufujiwara/binder/rx/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,96 @@ | ||
package jp.satorufujiwara.binder.rx; | ||
|
||
import org.reactivestreams.Publisher; | ||
|
||
import java.util.concurrent.CancellationException; | ||
|
||
import io.reactivex.BackpressureStrategy; | ||
import io.reactivex.Completable; | ||
import io.reactivex.CompletableSource; | ||
import io.reactivex.CompletableTransformer; | ||
import io.reactivex.Flowable; | ||
import io.reactivex.FlowableTransformer; | ||
import io.reactivex.Maybe; | ||
import io.reactivex.MaybeSource; | ||
import io.reactivex.MaybeTransformer; | ||
import io.reactivex.Observable; | ||
import io.reactivex.ObservableSource; | ||
import io.reactivex.ObservableTransformer; | ||
import io.reactivex.Single; | ||
import io.reactivex.SingleSource; | ||
import io.reactivex.SingleTransformer; | ||
import io.reactivex.annotations.NonNull; | ||
import io.reactivex.functions.Function; | ||
|
||
/** | ||
* @see <a href="https://github.com/trello/RxLifecycle/">RxLifecycle#LifecycleTransformer</a> | ||
* <p> | ||
* Transformer that continues a subscription until a second Observable emits an event. | ||
*/ | ||
final class LifecycleTransformer<T> implements ObservableTransformer<T, T>, | ||
FlowableTransformer<T, T>, | ||
SingleTransformer<T, T>, | ||
MaybeTransformer<T, T>, | ||
CompletableTransformer { | ||
final Observable<?> observable; | ||
|
||
LifecycleTransformer(@NonNull Observable<?> observable) { | ||
this.observable = observable; | ||
} | ||
|
||
@Override | ||
public ObservableSource<T> apply(Observable<T> upstream) { | ||
return upstream.takeUntil(observable); | ||
} | ||
|
||
@Override | ||
public Publisher<T> apply(Flowable<T> upstream) { | ||
return upstream.takeUntil(observable.toFlowable(BackpressureStrategy.LATEST)); | ||
} | ||
|
||
@Override | ||
public SingleSource<T> apply(Single<T> upstream) { | ||
return upstream.takeUntil(observable.firstOrError()); | ||
} | ||
|
||
@Override | ||
public MaybeSource<T> apply(Maybe<T> upstream) { | ||
return upstream.takeUntil(observable.firstElement()); | ||
} | ||
|
||
@Override | ||
public CompletableSource apply(Completable upstream) { | ||
return Completable.ambArray(upstream, observable.flatMapCompletable(new Function<Object, Completable>() { | ||
@Override | ||
public Completable apply(Object ignore) throws Exception { | ||
return Completable.error(new CancellationException()); | ||
} | ||
})); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
LifecycleTransformer<?> that = (LifecycleTransformer<?>) o; | ||
|
||
return observable.equals(that.observable); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return observable.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LifecycleTransformer{" + | ||
"observable=" + observable + | ||
'}'; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
binder-rx/src/main/java/jp/satorufujiwara/binder/rx/RxRecyclerBinder.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,35 @@ | ||
package jp.satorufujiwara.binder.rx; | ||
|
||
|
||
import android.content.Context; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
import io.reactivex.subjects.PublishSubject; | ||
import jp.satorufujiwara.binder.ViewType; | ||
import jp.satorufujiwara.binder.recycler.RecyclerBinder; | ||
|
||
public abstract class RxRecyclerBinder<V extends ViewType> extends RecyclerBinder<V> { | ||
|
||
private static final Object SIGNAL = new Object(); | ||
private PublishSubject<Object> lifecycleSubject = PublishSubject.create(); | ||
|
||
protected RxRecyclerBinder(final Context context, final V viewType) { | ||
super(context, viewType); | ||
} | ||
|
||
@Override | ||
public void onRemoved() { | ||
super.onRemoved(); | ||
lifecycleSubject.onNext(SIGNAL); | ||
} | ||
|
||
@Override | ||
public void onViewRecycled(RecyclerView.ViewHolder holder) { | ||
super.onViewRecycled(holder); | ||
lifecycleSubject.onNext(SIGNAL); | ||
} | ||
|
||
public final <T> LifecycleTransformer<T> bindToLifecycle() { | ||
return new LifecycleTransformer<>(lifecycleSubject); | ||
} | ||
} |
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
54 changes: 0 additions & 54 deletions
54
binder/src/main/java/jp/satorufujiwara/binder/recycler/RxRecyclerBinder.java
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Wed Apr 10 15:27:10 PDT 2013 | ||
#Wed Jul 26 16:38:46 JST 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip |
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 +1 @@ | ||
include ':binder', ':binder-sample' | ||
include ':binder', ':binder-sample', ':binder-rx' |