Skip to content

Commit

Permalink
升级OkHttp
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoKaiQiang committed Jan 4, 2016
1 parent 4de5eea commit 9ffbe1d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -250,7 +250,7 @@ OkHttpProxy.post()
##JCenter

```
compile 'com.github.zhaokaiqiang.okhttpplus:library:0.4.0'
compile 'com.github.zhaokaiqiang.okhttpplus:library:1.0.0'
```


Expand Down
5 changes: 2 additions & 3 deletions library/build.gradle
Expand Up @@ -21,12 +21,11 @@ android {

dependencies {
compile 'com.squareup.okhttp3:okhttp:3.0.0-RC1'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.okio:okio:1.5.0'
compile 'com.github.zhaokaiqiang.klog:library:1.1.0'
}

version = "0.4.0"
version = "1.0.0"
def siteUrl = 'https://github.com/ZhaoKaiQiang/OkHttpPlus'
def gitUrl = 'https://github.com/ZhaoKaiQiang/OkHttpPlus.git'
group = "com.github.zhaokaiqiang.okhttpplus"
Expand Down
2 changes: 0 additions & 2 deletions library/src/main/java/com/socks/okhttp/plus/OkHttpProxy.java
Expand Up @@ -6,8 +6,6 @@
import com.socks.okhttp.plus.builder.UploadRequestBuilder;
import com.socks.okhttp.plus.listener.DownloadListener;

import java.util.List;

import okhttp3.Call;
import okhttp3.Dispatcher;
import okhttp3.OkHttpClient;
Expand Down
Expand Up @@ -4,12 +4,13 @@
import android.os.Looper;

import com.socks.okhttp.plus.parser.OkBaseParser;

import java.io.IOException;

import okhttp3.Callback;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

/**
* Created by zhaokaiqiang on 15/11/22.
*/
Expand Down
10 changes: 5 additions & 5 deletions sample/build.gradle
Expand Up @@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "com.socks.sample.okhttpplus"
minSdkVersion 9
targetSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
Expand All @@ -20,8 +20,8 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.github.zhaokaiqiang.klog:library:1.1.0'
// compile 'com.github.zhaokaiqiang.okhttpplus:library:0.4.0'
compile project(':library')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.github.zhaokaiqiang.klog:library:1.3.0'
compile 'com.github.zhaokaiqiang.okhttpplus:library:1.0.0'
// compile project(':library')
}
Expand Up @@ -25,7 +25,6 @@
import com.socks.sample.okhttp.model.User;
import com.socks.sample.okhttp.parser.JokeParser;
import com.socks.sample.okhttp.util.TestUrls;
import okhttp3.Response;

import java.io.File;
import java.io.IOException;
Expand All @@ -34,6 +33,8 @@
import java.util.List;
import java.util.Map;

import okhttp3.Response;

public class MainActivity extends AppCompatActivity implements TestUrls {

private TextView tv_response;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void onFailure(Throwable e) {
public void getJokes(View view) {
OkHttpProxy.get()
.url(Joke.getRequestUrl(1))
.tag(this).enqueue(new OkCallback<List<Joke>>(new JokeParser()) {
.tag(this).enqueue(new OkCallback<List<Joke>>(new JokeParser<List<Joke>>()) {
@Override
public void onSuccess(int code, List<Joke> jokes) {
tv_response.setText(jokes.toString());
Expand Down
@@ -1,18 +1,20 @@
package com.socks.sample.okhttp.parser;

import android.support.annotation.Nullable;
import android.util.Log;

import com.google.gson.reflect.TypeToken;
import com.socks.okhttp.plus.parser.OkJsonParser;
import com.socks.sample.okhttp.model.Joke;
import okhttp3.Response;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;

import okhttp3.Response;

/**
* Created by zhaokaiqiang on 15/11/23.
*/
Expand All @@ -23,6 +25,7 @@ public class JokeParser<T> extends OkJsonParser<T> {
public T parse(Response response) throws IOException {
String jsonStr = response.body().string();
try {
Log.d("OkCallback",Thread.currentThread().getName());
jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();
return mGson.fromJson(jsonStr, new TypeToken<ArrayList<Joke>>() {
}.getType());
Expand Down

0 comments on commit 9ffbe1d

Please sign in to comment.