214 lines
8.4 KiB
Java
214 lines
8.4 KiB
Java
package com.gh.common.util;
|
|
|
|
import android.app.Application;
|
|
import android.content.Context;
|
|
import android.os.Build;
|
|
import android.provider.Settings;
|
|
import android.text.TextUtils;
|
|
|
|
import com.gh.gamecenter.BuildConfig;
|
|
import com.gh.gamecenter.entity.CommunityEntity;
|
|
import com.gh.gamecenter.entity.SpecialColumn;
|
|
import com.gh.gamecenter.manager.UserManager;
|
|
import com.gh.gamecenter.qa.entity.Questions;
|
|
import com.gh.loghub.LogHubUtils;
|
|
import com.halo.assistant.HaloApp;
|
|
import com.lightgame.utils.Util_System_Phone_State;
|
|
import com.lightgame.utils.Utils;
|
|
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/**
|
|
* Created by khy on 2/01/18.
|
|
*/
|
|
public class LogUtils {
|
|
|
|
public static void uploadCommunityArticle(String tracers,
|
|
String articleId,
|
|
String articleTitle,
|
|
int readTime,
|
|
CommunityEntity community,
|
|
SpecialColumn specialColumn) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("subject", "community_article");
|
|
object.put("community_id", community.getId());
|
|
object.put("community_name", community.getName());
|
|
object.put("article_id", articleId);
|
|
object.put("article_name", articleTitle);
|
|
object.put("tracers", tracers);
|
|
object.put("read", readTime);
|
|
JSONObject columnObject = new JSONObject();
|
|
if (specialColumn != null) {
|
|
columnObject.put("type", specialColumn.getType());
|
|
columnObject.put("name", specialColumn.getName());
|
|
columnObject.put("tab", specialColumn.getTab());
|
|
} else {
|
|
columnObject.put("type", "");
|
|
columnObject.put("name", "");
|
|
columnObject.put("tab", "");
|
|
}
|
|
object.put("special_column", columnObject);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
upload(object);
|
|
}
|
|
|
|
public static void uploadDevice(LunchType launchType) {
|
|
JSONObject object = new JSONObject();
|
|
Application application = HaloApp.getInstance().getApplication();
|
|
try {
|
|
object.put("subject", "halo_device");
|
|
object.put("launch_time", Utils.getTime(application));
|
|
object.put("launch_type", launchType.name());
|
|
object.put("manufacture", Build.MANUFACTURER);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
upload(object);
|
|
}
|
|
|
|
public static void uploadAnswerReadTime(String tracers,
|
|
int readTime,
|
|
String answerId,
|
|
Questions questions,
|
|
String communityId,
|
|
String CommunityName,
|
|
SpecialColumn specialColumn) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("subject", "answer");
|
|
object.put("community_id", communityId);
|
|
object.put("community_name", CommunityName);
|
|
object.put("question_id", questions.getId());
|
|
object.put("question_name", questions.getTitle());
|
|
object.put("tracers", tracers);
|
|
object.put("answer_id", answerId);
|
|
object.put("read", readTime);
|
|
JSONObject columnObject = new JSONObject();
|
|
if (specialColumn != null) {
|
|
columnObject.put("type", specialColumn.getType());
|
|
columnObject.put("name", specialColumn.getName());
|
|
columnObject.put("tab", specialColumn.getTab());
|
|
} else {
|
|
columnObject.put("type", "");
|
|
columnObject.put("name", "");
|
|
columnObject.put("tab", "");
|
|
}
|
|
object.put("special_column", columnObject);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
upload(object);
|
|
}
|
|
|
|
public static void uploadQuestionReadTime(String tracers,
|
|
int readTime,
|
|
Questions questions,
|
|
String communityId,
|
|
String communityName,
|
|
SpecialColumn specialColumn) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("subject", "question");
|
|
object.put("community_id", communityId);
|
|
object.put("community_name", communityName);
|
|
object.put("question_id", questions.getId());
|
|
object.put("question_name", questions.getTitle());
|
|
object.put("tracers", tracers);
|
|
object.put("read", readTime);
|
|
JSONObject columnObject = new JSONObject();
|
|
if (specialColumn != null) {
|
|
columnObject.put("type", specialColumn.getType());
|
|
columnObject.put("name", specialColumn.getName());
|
|
columnObject.put("tab", specialColumn.getTab());
|
|
} else {
|
|
columnObject.put("type", "");
|
|
columnObject.put("name", "");
|
|
columnObject.put("tab", "");
|
|
}
|
|
object.put("special_column", columnObject);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
upload(object);
|
|
}
|
|
|
|
public static void uploadSearch(String searchKey) {
|
|
if (TextUtils.isEmpty(searchKey)) return;
|
|
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("community_id", UserManager.getInstance().getCommunity().getId());
|
|
object.put("community_name", UserManager.getInstance().getCommunity().getName());
|
|
object.put("keyword", searchKey);
|
|
object.put("subject", "search");
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
upload(object);
|
|
}
|
|
|
|
|
|
public static void communityRefresh(int dataCount, boolean manualRefresh) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("subject", "community_refresh");
|
|
object.put("community_id", UserManager.getInstance().getCommunity().getId());
|
|
object.put("refresh_type", "recommend");
|
|
object.put("refresh_way", manualRefresh ? "manual" : "auto");
|
|
object.put("data_count", dataCount);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
upload(object);
|
|
}
|
|
|
|
public static void login(String loginStep, String loginType, String entrance) {
|
|
JSONObject object = new JSONObject();
|
|
try {
|
|
object.put("entrance", entrance);
|
|
object.put("subject", "login");
|
|
object.put("step", loginStep);
|
|
object.put("login_type", loginType);
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
upload(object);
|
|
}
|
|
|
|
private static void upload(JSONObject object) {
|
|
if (BuildConfig.DEBUG) {
|
|
Utils.log("LogUtils->" + object.toString());
|
|
}
|
|
|
|
Context context = HaloApp.getInstance().getApplication();
|
|
try {
|
|
object.put("version", PackageUtils.getVersionName());
|
|
object.put("channel", HaloApp.getInstance().getChannel());
|
|
object.put("android_id", Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
|
|
object.put("time", Utils.getTime(context));
|
|
object.put("network", DeviceUtils.getNetwork(context));
|
|
object.put("user_id", UserManager.getInstance().getUserId());
|
|
object.put("device_system", android.os.Build.VERSION.RELEASE);
|
|
object.put("device_model", android.os.Build.MODEL);
|
|
object.put("imei", Util_System_Phone_State.getImei(HaloApp.getInstance().getApplication()));
|
|
object.put("G_ID", UserManager.getInstance().getDeviceId());
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// 暂时除了曝光外的数据都是扔到 community 这个库的,要是不是这个这个库的话这里要改一下
|
|
LogHubUtils.uploadLog(DeviceUtils.getIPAddress(context), object, "community");
|
|
}
|
|
}
|