Skip to content

Commit ad92a7e

Browse files
committed
support rxjava2 and release to v2.0
1 parent 2939bce commit ad92a7e

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
lines changed

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ dependencies {
2626
compile fileTree(include: ['*.jar'], dir: 'libs')
2727
testCompile 'junit:junit:4.12'
2828
compile 'com.android.support:appcompat-v7:25.1.1'
29-
compile 'me.jessyan:rxerrorhandler:1.0.1'
29+
// compile 'me.jessyan:rxerrorhandler:1.0.1'
30+
compile project(':rxerrorhandler')
3031
}

app/src/main/java/me/jessyan/rxerrorhandler/demo/MainActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import android.support.v7.app.AppCompatActivity;
66
import android.util.Log;
77

8+
import io.reactivex.Observable;
89
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
910
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
1011
import me.jessyan.rxerrorhandler.handler.RetryWithDelay;
1112
import me.jessyan.rxerrorhandler.handler.listener.ResponseErroListener;
12-
import rx.Observable;
1313

1414
public class MainActivity extends AppCompatActivity {
1515
private final String TAG = getClass().getSimpleName();
@@ -38,7 +38,6 @@ public void handleResponseError(Context context, Exception e) {
3838
public void onNext(Object o) {
3939

4040
}
41-
4241
});
4342
}
4443
}

rxerrorhandler/bintray.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ publish {
1919
userOrg = 'jessyancoding' //bintray注册的用户名
2020
groupId = 'me.jessyan' //compile引用时的第1部分groupId
2121
artifactId = 'rxerrorhandler' //compile引用时的第2部分项目名
22-
publishVersion = '1.0.1' //compile引用时的第3部分版本号
22+
publishVersion = '2.0' //compile引用时的第3部分版本号
2323
desc = 'Error Handle Of Rxjava'
2424
website = siteUrl
2525
}

rxerrorhandler/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 15
99
targetSdkVersion 25
10-
versionCode 2
11-
versionName "1.0.1"
10+
versionCode 1
11+
versionName "2.0"
1212
}
1313
buildTypes {
1414
release {
@@ -21,8 +21,9 @@ android {
2121
dependencies {
2222
compile fileTree(dir: 'libs', include: ['*.jar'])
2323
testCompile 'junit:junit:4.12'
24-
compile 'com.android.support:appcompat-v7:25.1.1'
25-
compile 'io.reactivex:rxjava:1.2.6'
24+
compile 'com.android.support:appcompat-v7:25.3.1'
25+
compile 'io.reactivex.rxjava2:rxjava:2.1.0'
26+
2627
}
2728

2829

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
package me.jessyan.rxerrorhandler.handler;
22

3+
import io.reactivex.Observer;
4+
import io.reactivex.annotations.NonNull;
5+
import io.reactivex.disposables.Disposable;
36
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
4-
import rx.Subscriber;
57

68
/**
79
* Created by jess on 9/2/16 14:41
810
* Contact with jess.yan.effort@gmail.com
911
*/
1012

11-
public abstract class ErrorHandleSubscriber<T> extends Subscriber<T> {
13+
public abstract class ErrorHandleSubscriber<T> implements Observer<T> {
1214
private ErrorHandlerFactory mHandlerFactory;
1315

1416
public ErrorHandleSubscriber(RxErrorHandler rxErrorHandler){
1517
this.mHandlerFactory = rxErrorHandler.getHandlerFactory();
1618
}
1719

20+
21+
@Override
22+
public void onSubscribe(@NonNull Disposable d) {
23+
24+
}
25+
26+
1827
@Override
19-
public void onCompleted() {
28+
public void onComplete() {
2029

2130
}
2231

32+
2333
@Override
24-
public void onError(Throwable e) {
34+
public void onError(@NonNull Throwable e) {
2535
e.printStackTrace();
2636
mHandlerFactory.handleError(e);
2737
}
28-
2938
}
3039

rxerrorhandler/src/main/java/me/jessyan/rxerrorhandler/handler/RetryWithDelay.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
import java.util.concurrent.TimeUnit;
66

7-
import rx.Observable;
8-
import rx.functions.Func1;
7+
import io.reactivex.Observable;
8+
import io.reactivex.ObservableSource;
9+
import io.reactivex.annotations.NonNull;
10+
import io.reactivex.functions.Function;
911

1012
/**
1113
* Created by jess on 9/2/16 14:32
1214
* Contact with jess.yan.effort@gmail.com
1315
*/
1416
public class RetryWithDelay implements
15-
Func1<Observable<? extends Throwable>, Observable<?>> {
17+
Function<Observable<Throwable>, ObservableSource<?>> {
18+
1619
public final String TAG = this.getClass().getSimpleName();
1720
private final int maxRetries;
1821
private final int retryDelaySecond;
@@ -24,11 +27,12 @@ public RetryWithDelay(int maxRetries, int retryDelaySecond) {
2427
}
2528

2629
@Override
27-
public Observable<?> call(Observable<? extends Throwable> attempts) {
28-
return attempts
29-
.flatMap(new Func1<Throwable, Observable<?>>() {
30+
public ObservableSource<?> apply(@NonNull Observable<Throwable> throwableObservable) throws Exception {
31+
32+
return throwableObservable
33+
.flatMap(new Function<Throwable, ObservableSource<?>>() {
3034
@Override
31-
public Observable<?> call(Throwable throwable) {
35+
public ObservableSource<?> apply(@NonNull Throwable throwable) throws Exception {
3236
if (++retryCount <= maxRetries) {
3337
// When this Observable calls onNext, the original Observable will be retried (i.e. re-subscribed).
3438
Log.d(TAG, "get error, it will try after " + retryDelaySecond

0 commit comments

Comments
 (0)