去除volley
This commit is contained in:
@ -2,18 +2,15 @@ package com.gh.gamecenter.manager;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.volley.Request.Method;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DeviceUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.db.DataCollectionDao;
|
||||
import com.gh.gamecenter.db.info.DataCollectionInfo;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -25,6 +22,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public class DataCollectionManager {
|
||||
|
||||
private static DataCollectionManager mInstance;
|
||||
@ -142,13 +145,13 @@ public class DataCollectionManager {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("type", type);
|
||||
params.put("data", new JSONObject(map).toString());
|
||||
String url = Config.DATA_HOST + "collection/upload2";
|
||||
JSONObject body = new JSONObject(params);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Method.POST, url, body.toString(),
|
||||
null, null);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getData().postRealData(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
}
|
||||
|
||||
/*
|
||||
@ -197,7 +200,6 @@ public class DataCollectionManager {
|
||||
return;
|
||||
}
|
||||
isUploading = true;
|
||||
String url = Config.DATA_HOST + "collection/upload";
|
||||
|
||||
final List<String> ids = new ArrayList<>();
|
||||
|
||||
@ -244,30 +246,34 @@ public class DataCollectionManager {
|
||||
JSONObject jsonObject = new JSONObject(hashMap);
|
||||
params.add(jsonObject);
|
||||
}
|
||||
JSONArray body = new JSONArray(params);
|
||||
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Method.POST, url, body.toString(),
|
||||
new Response.Listener<JSONObject>() {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONArray(params).toString());
|
||||
RetrofitManager.getData().postData(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
isUploading = false;
|
||||
try {
|
||||
if ("success".equals(response.getString("status"))) {
|
||||
// 上传成功,删除本地数据
|
||||
dao.delete(ids);
|
||||
|
||||
if (response.length() != 0) {
|
||||
try {
|
||||
if ("success".equals(response.getString("status"))) {
|
||||
// 上传成功,删除本地数据
|
||||
dao.delete(ids);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
public void onFailure(Throwable e) {
|
||||
isUploading = false;
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user