Skip to content

Commit

Permalink
增加log
Browse files Browse the repository at this point in the history
  • Loading branch information
wecodexyz committed Oct 18, 2017
1 parent 022882b commit 0dfeeb2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
8 changes: 6 additions & 2 deletions core/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-renamesourcefileattribute SourceFile

-keepclassmembers net.angrycode.core.network.*
-keepclassmembers net.angrycode.mvp.*
-keepclassmembers net.angrycode.toolkit.*
27 changes: 27 additions & 0 deletions core/src/main/java/net/angrycode/core/network/BaseTextRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

/**
* Network request using rxjava2
Expand Down Expand Up @@ -43,6 +46,23 @@ public Publisher<T> apply(@NonNull Pair<Integer, String> pair) throws Exception

}

public void request(final OnRequestCallback<T> callback) {
request().observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new Consumer<T>() {
@Override
public void accept(@NonNull T t) throws Exception {
callback.callback(t);
}
}, new Consumer<Throwable>() {
@Override
public void accept(@NonNull Throwable throwable) throws Exception {
callback.onError(new Exception(throwable));
}
});
}


@Override
public boolean isSupportCache() {
return true;
Expand All @@ -51,4 +71,11 @@ public boolean isSupportCache() {
protected abstract T onRequestFinish(String result);

protected abstract T onRequestError(int code, String message);

public interface OnRequestCallback<T> {
void callback(T t);

void onError(Exception e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public RequestWrapper(Context context) {

@Override
public Pair<Integer, String> doRequest() {
Pair<Integer, String> result = new Pair<>(ERROR_NETWORK, "");
Pair<Integer, String> result = new Pair<>(ERROR_NETWORK, "network is not connect!");
okhttp3.Request request = null;

if (getHttpMethod() == HttpMethod.POST) {
Expand All @@ -72,6 +72,8 @@ public Pair<Integer, String> doRequest() {
} else {
result = new Pair<>(response.code(), response.message());
}
Log.d("Network", "request url - " + getUrlWithParams());
Log.d("Network", "response json - " + result.second);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
Expand Down Expand Up @@ -103,7 +105,9 @@ public void setProxy(String host, int port) {
mProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
}

public @Nullable Context getContext() {
public
@Nullable
Context getContext() {
return mContextRef.get();
}

Expand Down

0 comments on commit 0dfeeb2

Please sign in to comment.