修改错误上传逻辑,修改第一次启动判断字段
This commit is contained in:
@ -74,7 +74,11 @@ public class DataCollectionManager {
|
||||
|
||||
public static void onEvent(Context context, String type, Map<String, Object> map, boolean isUpload) {
|
||||
map.put("createdOn", Utils.getTime(context));
|
||||
onEvent(context, type, new JSONObject(map).toString(), isUpload);
|
||||
if (isUpload) {
|
||||
DataCollectionManager.getInstance(context).realTimeUpload(type, map);
|
||||
} else {
|
||||
onEvent(context, type, new JSONObject(map).toString(), false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void upsert(Context context, String type, Map<String, Object> map) {
|
||||
@ -114,7 +118,7 @@ public class DataCollectionManager {
|
||||
List<DataCollectionInfo> list = dao.getAll();
|
||||
if (list.size() >= 20) {
|
||||
try {
|
||||
upload(list);
|
||||
upload(list, false);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -153,9 +157,9 @@ public class DataCollectionManager {
|
||||
List<DataCollectionInfo> list = dao.getClickData();
|
||||
if (!list.isEmpty()) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
DataCollectionInfo dataCollectionEntity;
|
||||
List<Object> data = new ArrayList<>();
|
||||
try {
|
||||
DataCollectionInfo dataCollectionEntity;
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
dataCollectionEntity = list.get(i);
|
||||
ids.add(dataCollectionEntity.getId());
|
||||
@ -177,7 +181,7 @@ public class DataCollectionManager {
|
||||
List<DataCollectionInfo> list = dao.getAll();
|
||||
if (!list.isEmpty()) {
|
||||
try {
|
||||
upload(list);
|
||||
upload(list, true);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -187,7 +191,7 @@ public class DataCollectionManager {
|
||||
private boolean isUploading;
|
||||
|
||||
// 上传数据
|
||||
private void upload(List<DataCollectionInfo> list) throws JSONException {
|
||||
private void upload(List<DataCollectionInfo> list, boolean isForce) throws JSONException {
|
||||
if (isUploading) {
|
||||
return;
|
||||
}
|
||||
@ -214,6 +218,7 @@ public class DataCollectionManager {
|
||||
jsonArray = map.get(type);
|
||||
if (jsonArray == null) {
|
||||
jsonArray = new JSONArray();
|
||||
map.put(type, jsonArray);
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject(
|
||||
dataCollectionEntity.getData());
|
||||
@ -222,12 +227,11 @@ public class DataCollectionManager {
|
||||
jsonObject.put("device_id", TokenUtils.getDeviceId(mContext));
|
||||
jsonObject.put("channel", channel);
|
||||
jsonArray.put(jsonObject.toString());
|
||||
map.put(type, jsonArray);
|
||||
|
||||
ids.add(dataCollectionEntity.getId());
|
||||
}
|
||||
|
||||
if (ids.size() < 20) {
|
||||
if (!isForce && ids.size() < 20) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -260,10 +264,6 @@ public class DataCollectionManager {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
isUploading = false;
|
||||
// 上传失败,检查网络状态,继续上传
|
||||
if (error.networkResponse != null) {
|
||||
Utils.log(new String(error.networkResponse.data));
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request);
|
||||
|
||||
Reference in New Issue
Block a user