Skip to content

Commit

Permalink
Merge pull request #11 from AAkira/feature/divide-rx-java
Browse files Browse the repository at this point in the history
Divide rx-java
  • Loading branch information
satorufujiwara authored Aug 2, 2017
2 parents a7dce21 + 736a7c7 commit b9d7c61
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 66 deletions.
1 change: 1 addition & 0 deletions binder-rx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
24 changes: 24 additions & 0 deletions binder-rx/build.gradle
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"
}
25 changes: 25 additions & 0 deletions binder-rx/proguard-rules.pro
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
4 changes: 4 additions & 0 deletions binder-rx/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<manifest
package="jp.satorufujiwara.binder.rx">
<application />
</manifest>
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 +
'}';
}
}
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);
}
}
5 changes: 3 additions & 2 deletions binder-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':binder')
compile project(':binder-rx')

compile "com.android.support:appcompat-v7:$SUPPORT_APP_COMPAT_VERSION"
compile "com.android.support:recyclerview-v7:$SUPPORT_APP_COMPAT_VERSION"
compile "com.android.support:cardview-v7:$SUPPORT_APP_COMPAT_VERSION"
compile project(':binder')
compile "io.reactivex.rxjava2:rxjava:$RX_JAVA_VERSION"

compile 'com.jakewharton:butterknife:6.1.0'
}
2 changes: 0 additions & 2 deletions binder/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:$SUPPORT_APP_COMPAT_VERSION"
compile "com.android.support:recyclerview-v7:$SUPPORT_APP_COMPAT_VERSION"
provided 'io.reactivex:rxjava:1.1.0'
}

android.libraryVariants.all { variant ->
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
}
}
Expand Down
9 changes: 5 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
COMPILE_SDK_VERSION=23
BUILD_TOOLS_VERSION=23.0.1
COMPILE_SDK_VERSION=25
BUILD_TOOLS_VERSION=25.0.1
MIN_SDK_VERSION=11
TARGET_SDK_VERSION=23

SUPPORT_APP_COMPAT_VERSION=23.1.1
SUPPORT_APP_COMPAT_VERSION=25.3.1
RX_JAVA_VERSION=2.1.2

VERSION_NAME=1.3.3
VERSION_CODE=3
Expand All @@ -21,4 +22,4 @@ POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=satorufujiwara
POM_DEVELOPER_NAME=satorufujiwara
POM_DEVELOPER_EMAIL=holly.wist@gmail.com
ISSUE_URL=https://github.com/satorufujiwara/recyclerview-binder/issues
ISSUE_URL=https://github.com/satorufujiwara/recyclerview-binder/issues
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
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
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':binder', ':binder-sample'
include ':binder', ':binder-sample', ':binder-rx'

0 comments on commit b9d7c61

Please sign in to comment.