修改数据收集接口,去掉点击加载更多,新闻和下载数据实时上传

This commit is contained in:
huangzhuanghua
2016-06-21 11:56:55 +08:00
parent 3c6dae28f3
commit c97db56a74
31 changed files with 744 additions and 365 deletions

View File

@ -1,7 +1,6 @@
package com.gh.gamecenter.manager;
import android.content.Context;
import android.util.Log;
import com.android.volley.Request.Method;
import com.android.volley.Response;
@ -34,6 +33,7 @@ public class DataCollectionManager {
private DataCollectionManager(Context context) {
mContext = context;
dao = new DataCollectionDao(mContext);
isUploading = false;
}
public static DataCollectionManager getInstance(Context context) {
@ -64,8 +64,11 @@ public class DataCollectionManager {
onEvent(context, entity, isUpload);
}
public static void onEvent(Context context, String type,
Map<String, Object> map) {
public static void onEvent(Context context, String type, Map<String, Object> map) {
if ("news".equals(type) || "download".equals(type)) {
DataCollectionManager.getInstance(context).realTimeUpload(type, map);
return;
}
onEvent(context, type, new JSONObject(map).toString(), true);
}
@ -119,6 +122,43 @@ public class DataCollectionManager {
}
}
/*
* 实时上传
*/
private void realTimeUpload(String type, Map<String, Object> map) {
String version = PackageUtils.getVersion(mContext);
String user = DeviceUtils.getDeviceID(mContext);
String channel = (String) PackageUtils.getMetaData(mContext,
mContext.getPackageName(), "TD_CHANNEL_ID");
map.put("version", version);
map.put("user", user);
map.put("channel", channel);
Map<String, String> params = new HashMap<String, String>();
params.put("type", type);
params.put("data", new JSONObject(map).toString());
String url = "http://data.ghzhushou.com/collection/upload2";
JSONObject body = new JSONObject(params);
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
Method.POST, url, body.toString(),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Utils.log("realTimeUpload = " + response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// 上传失败,检查网络状态,继续上传
Utils.log("realTimeUpload = " + error);
if (error.networkResponse != null) {
Utils.log(new String(error.networkResponse.data));
}
}
});
AppController.addToRequestQueue(request, DataCollectionManager.class);
}
/*
* 统计点击数据
*/
@ -158,10 +198,15 @@ public class DataCollectionManager {
}
}
private boolean isUploading;
// 上传数据
private void upload(List<DataCollectionInfo> list)
throws JSONException {
String url = "http://114.215.139.210/data/collection/upload";
private void upload(List<DataCollectionInfo> list) throws JSONException {
if (isUploading) {
return;
}
isUploading = true;
String url = "http://data.ghzhushou.com/collection/upload";
final List<String> ids = new ArrayList<String>();
@ -214,7 +259,7 @@ public class DataCollectionManager {
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
isUploading = false;
Utils.log(response);
try {
if ("success".equals(response.getString("status"))) {
@ -222,14 +267,13 @@ public class DataCollectionManager {
dao.delete(ids);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
isUploading = false;
// 上传失败,检查网络状态,继续上传
Utils.log(error);
if (error.networkResponse != null) {
@ -237,7 +281,6 @@ public class DataCollectionManager {
}
}
});
Log.e("result", new String(request.getBody()));
AppController.addToRequestQueue(request, DataCollectionManager.class);
}