Skip to content

Commit

Permalink
rxjava2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
张涛 committed Dec 22, 2016
1 parent 7cdd4f0 commit 7320c59
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 329 deletions.
4 changes: 2 additions & 2 deletions RxVolley/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.kymjs.rxvolley.demo"
Expand All @@ -22,7 +22,7 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:appcompat-v7:23.2.0'
compile project(':bitmapcore')
compile project(':okhttp3')
compile project(':rxvolley')
Expand Down
21 changes: 0 additions & 21 deletions RxVolley/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,6 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!--<activity android:name=".ParamsTestActivity">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN"/>-->

<!--<category android:name="android.intent.category.LAUNCHER"/>-->
<!--</intent-filter>-->
<!--</activity>-->
<!--<activity android:name=".RxImageRequestTest">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN"/>-->

<!--<category android:name="android.intent.category.LAUNCHER"/>-->
<!--</intent-filter>-->
<!--</activity>-->
<!--<activity android:name=".ImageLoadTestActivity">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN"/>-->

<!--<category android:name="android.intent.category.LAUNCHER"/>-->
<!--</intent-filter>-->
<!--</activity>-->
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,19 @@
import java.io.File;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;

public class MainActivity extends AppCompatActivity {

private Subscription subscription;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -143,29 +141,28 @@ public void onFinish() {
.callback(callback)
.getResult();

subscription = observable
.subscribeOn(Schedulers.io())
observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Result>() {
@Override
public void onStart() {
Log.i("kymjs", "======网络请求开始");
}

.subscribe(new Observer<Result>() {
@Override
public void onCompleted() {
public void onComplete() {
Log.i("kymjs", "======网络请求结束");
}

@Override
public void onError(Throwable e) {
Log.i("kymjs", "======网络请求失败" + e.getMessage());
public void onSubscribe(Disposable d) {
Log.i("kymjs", "======网络请求开始");
}

@Override
public void onNext(Result s) {
Log.i("kymjs", "======网络请求" + new String(s.data));
}

@Override
public void onError(Throwable e) {
Log.i("kymjs", "======网络请求失败" + e.getMessage());
}
});
}

Expand All @@ -191,12 +188,4 @@ public void onFailure(int errorNo, String strMsg) {
}
});
}

@Override
protected void onDestroy() {
super.onDestroy();
if (subscription != null && subscription.isUnsubscribed()) {
subscription.unsubscribe();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import rx.Observable;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
import io.reactivex.Observable;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

/**
* 入口类
Expand Down Expand Up @@ -324,9 +324,9 @@ public void onSuccess(Map<String, String> headers, Bitmap bitmap) {
public Observable<Bitmap> getResult() {
doTask();
return config.mSubject
.map(new Func1<Result, Bitmap>() {
.map(new Function<Result, Bitmap>() {
@Override
public Bitmap call(Result result) {
public Bitmap apply(Result result) throws Exception {
return CreateBitmap.create(result.data, config.maxWidth, config.maxHeight);
}
})
Expand Down
Loading

0 comments on commit 7320c59

Please sign in to comment.