去除volley
This commit is contained in:
@ -28,14 +28,8 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Request.Method;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DeviceUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
@ -73,19 +67,15 @@ import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.news.NewsFragment;
|
||||
import com.gh.gamecenter.personal.PersonalFragment;
|
||||
import com.gh.gamecenter.volley.extended.JsonArrayExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
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;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@ -98,6 +88,12 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -209,13 +205,15 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
// 统计下载
|
||||
private void uploadData(String id, String platform) {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("game", id);
|
||||
params.put("platform", platform);
|
||||
JSONObject jsonObject = new JSONObject(params);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(Method.POST,
|
||||
Config.HOST + "stat/download", jsonObject.toString(), null, null);
|
||||
AppController.addToRequestQueue(request);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getApi().postDownload(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
}
|
||||
|
||||
// 统计下载完成事件
|
||||
@ -292,20 +290,20 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
map.put("user", user);
|
||||
map.put("device_id", TokenUtils.getDeviceId(this));
|
||||
map.put("channel", channel);
|
||||
String url = Config.DATA_HOST + "api/v1d0/log";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "lunbotu");
|
||||
params.put("source", "GH-ASSIST-Client");
|
||||
params.put("time", String.valueOf(Utils.getTime(this)));
|
||||
params.put("content", new JSONObject(map).toString());
|
||||
StringExtendedRequest request = new StringExtendedRequest(Request.Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getData().postLog(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processHijack(DownloadEntity downloadEntity) {
|
||||
@ -335,16 +333,18 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
map.put("user", user);
|
||||
map.put("device_id", TokenUtils.getDeviceId(this));
|
||||
map.put("channel", channel);
|
||||
String url = Config.DATA_HOST + "api/v1d0/log";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "hijack");
|
||||
params.put("source", "GH-ASSIST-Client");
|
||||
params.put("time", String.valueOf(Utils.getTime(this)));
|
||||
params.put("content", new JSONObject(map).toString());
|
||||
StringExtendedRequest request = new StringExtendedRequest(Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getData().postLog(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
}
|
||||
|
||||
// 上传网络错误log
|
||||
@ -363,16 +363,18 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
map.put("device_id", TokenUtils.getDeviceId(this));
|
||||
map.put("channel", channel);
|
||||
map.put("error", downloadEntity.getError());
|
||||
String url = Config.DATA_HOST + "api/v1d0/log";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "neterror");
|
||||
params.put("source", "GH-ASSIST-Client");
|
||||
params.put("time", String.valueOf(Utils.getTime(this)));
|
||||
params.put("content", new JSONObject(map).toString());
|
||||
StringExtendedRequest request = new StringExtendedRequest(Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getData().postLog(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
}
|
||||
|
||||
/*
|
||||
@ -518,32 +520,17 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
|
||||
}
|
||||
|
||||
//初始化关注
|
||||
// 初始化关注
|
||||
private void initConcern() {
|
||||
final List<String> arrGameId = new ArrayList<>();
|
||||
final String getConcernUrl = Config.HOST + "device/" + TokenUtils.getDeviceId(MainActivity.this) + "/concern";
|
||||
ConcernUtils.loadConcernData(getConcernUrl, new ConcernUtils.DownJsonListener() {
|
||||
@Override
|
||||
public void downSucced(String str) {
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(str);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
String gameId = (String) jsonArray.get(i);
|
||||
arrGameId.add(gameId);
|
||||
RetrofitManager.getApi().getConcern(TokenUtils.getDeviceId(MainActivity.this))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<String>>() {
|
||||
@Override
|
||||
public void onResponse(List<String> response) {
|
||||
getConcernDigest(response);
|
||||
}
|
||||
|
||||
getConcernDigest(arrGameId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downFailed() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private int initConcernCount;
|
||||
@ -565,26 +552,22 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
initConcernCount = 0;
|
||||
for (String gameId : arrGameId) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "game/" + gameId + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
RetrofitManager.getApi().getGameDigest(gameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
concernDigest.add(gameEntity);
|
||||
}
|
||||
|
||||
public void onResponse(GameEntity response) {
|
||||
concernDigest.add(response);
|
||||
addInitConcernCount();
|
||||
if (size == initConcernCount && concernDigest.size() != 0) {
|
||||
concernManager.addByList(concernDigest);
|
||||
Utils.log("初始化关注成功==");
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
public void onFailure(Throwable e) {
|
||||
addInitConcernCount();
|
||||
if (size == initConcernCount && concernDigest.size() != 0) {
|
||||
concernManager.addByList(concernDigest);
|
||||
@ -592,7 +575,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
}
|
||||
@ -664,38 +646,34 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
iCount = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
final String packageName = list.get(i);
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "support/package/" + packageName + "/game/digest",
|
||||
new Response.Listener<JSONArray>() {
|
||||
RetrofitManager.getApi().getGameDigestByPackageName(packageName)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<GameDigestEntity>>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
if (response.length() != 0) {
|
||||
Type listType = new TypeToken<ArrayList<GameDigestEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<GameDigestEntity> list = gson.fromJson(response.toString(), listType);
|
||||
for (GameDigestEntity gameDigestEntity : list) {
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
gameInfo.setGameName(gameDigestEntity.getName());
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
}
|
||||
public void onResponse(List<GameDigestEntity> response) {
|
||||
for (GameDigestEntity gameDigestEntity : response) {
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
gameInfo.setGameName(gameDigestEntity.getName());
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
}
|
||||
|
||||
addInstalledCount();
|
||||
if (iCount == size) {
|
||||
updateConcern();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
public void onFailure(Throwable e) {
|
||||
addInstalledCount();
|
||||
if (iCount == size) {
|
||||
updateConcern();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}
|
||||
|
||||
@ -718,47 +696,44 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
final int size = concernIdList.size();
|
||||
cCount = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "game/" + concernIdList.get(i) + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
RetrofitManager.getApi().getGameDigest(concernIdList.get(i))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
ConcernInfo concernInfo = concernManager.findConcernById(gameEntity.getId());
|
||||
if (concernInfo != null && gameEntity.getApk() != null
|
||||
&& gameEntity.getApk().size() != 0) {
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
String packageName;
|
||||
for (int i = 0, size = gameEntity.getApk().size(); i < size; i++) {
|
||||
packageName = gameEntity.getApk().get(i).getPackageName();
|
||||
if (PackageManager.isInstalled(packageName)) {
|
||||
packageNames.put(packageName, true);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
public void onResponse(GameEntity response) {
|
||||
ConcernInfo concernInfo = concernManager.findConcernById(response.getId());
|
||||
if (concernInfo != null && response.getApk() != null
|
||||
&& response.getApk().size() != 0) {
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
String packageName;
|
||||
for (int i = 0, size = response.getApk().size(); i < size; i++) {
|
||||
packageName = response.getApk().get(i).getPackageName();
|
||||
if (PackageManager.isInstalled(packageName)) {
|
||||
packageNames.put(packageName, true);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
concernInfo.setTime(System.currentTimeMillis());
|
||||
concernInfo.setPackageNames(packageNames);
|
||||
concernManager.updateByConcern(concernInfo);
|
||||
}
|
||||
concernInfo.setTime(System.currentTimeMillis());
|
||||
concernInfo.setPackageNames(packageNames);
|
||||
concernManager.updateByConcern(concernInfo);
|
||||
}
|
||||
|
||||
addConcernCount();
|
||||
if (cCount == size) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
public void onFailure(Throwable e) {
|
||||
addConcernCount();
|
||||
if (cCount == size) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -872,28 +847,23 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
private void checkGameUpdate(String packageName) {
|
||||
Object gh_id = PackageUtils.getMetaData(this, packageName, "gh_id");
|
||||
String url;
|
||||
Observable<GameUpdateEntity> observable;
|
||||
if (gh_id == null) {
|
||||
url = Config.HOST + "update/package/" + packageName;
|
||||
observable = RetrofitManager.getApi().getGameUpdate(packageName);
|
||||
} else {
|
||||
url = Config.HOST + "update/game/" + gh_id + "/package/" + packageName;
|
||||
observable = RetrofitManager.getApi().getGameUpdate((String) gh_id, packageName);
|
||||
}
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(url,
|
||||
new Response.Listener<JSONObject>() {
|
||||
observable.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameUpdateEntity>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameUpdateEntity gameUpdateEntity = gson.fromJson(
|
||||
response.toString(), GameUpdateEntity.class);
|
||||
if (PackageUtils.isCanUpdate(MainActivity.this, gameUpdateEntity)) {
|
||||
PackageManager.addUpdate(gameUpdateEntity);
|
||||
EventBus.getDefault().post(new EBDownloadStatus("update"));
|
||||
}
|
||||
public void onResponse(GameUpdateEntity response) {
|
||||
if (PackageUtils.isCanUpdate(MainActivity.this, response)) {
|
||||
PackageManager.addUpdate(response);
|
||||
EventBus.getDefault().post(new EBDownloadStatus("update"));
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request);
|
||||
});
|
||||
}
|
||||
|
||||
private int count;
|
||||
@ -910,31 +880,28 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
final List<GameEntity> list = new ArrayList<>();
|
||||
count = 0;
|
||||
for (ConcernInfo info : infos) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "game/" + info.getId() + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
RetrofitManager.getApi().getGameDigest(info.getId())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
list.add(gameEntity);
|
||||
}
|
||||
public void onResponse(GameEntity response) {
|
||||
list.add(response);
|
||||
|
||||
addCount();
|
||||
if (count == size) {
|
||||
processPluginData(list);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
public void onFailure(Throwable e) {
|
||||
addCount();
|
||||
if (count == size) {
|
||||
processPluginData(list);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1004,9 +971,10 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
// 获取免责声明
|
||||
private void getDisclaimer(final boolean isFirst) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "disclaimer",
|
||||
new Response.Listener<JSONObject>() {
|
||||
RetrofitManager.getApi().getDisclaimer()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
@ -1025,8 +993,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request);
|
||||
});
|
||||
}
|
||||
|
||||
private Class<?> intentClass(String to) {
|
||||
@ -1125,86 +1092,77 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
};
|
||||
|
||||
private void getSearchHints() {
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "search/game/default",
|
||||
new Response.Listener<JSONArray>() {
|
||||
RetrofitManager.getApi().getSearchHints()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<String>>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
if (response.length() != 0) {
|
||||
Type listType = new TypeToken<ArrayList<String>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<String> searchHintList = gson.fromJson(response.toString(), listType);
|
||||
if (searchHintList != null && searchHintList.size() != 0) {
|
||||
if (searchHintList.size() == 1) {
|
||||
searchHint = searchHintList.get(0);
|
||||
} else {
|
||||
searchHint = searchHintList.get(RandomUtils.nextInt(searchHintList.size()));
|
||||
}
|
||||
if (gameFragment != null) {
|
||||
gameFragment.setHint(searchHint);
|
||||
}
|
||||
if (newsFragment != null) {
|
||||
newsFragment.setHint(searchHint);
|
||||
}
|
||||
public void onResponse(List<String> response) {
|
||||
if (response.size() != 0) {
|
||||
if (response.size() == 1) {
|
||||
searchHint = response.get(0);
|
||||
} else {
|
||||
searchHint = response.get(RandomUtils.nextInt(response.size()));
|
||||
}
|
||||
if (gameFragment != null) {
|
||||
gameFragment.setHint(searchHint);
|
||||
}
|
||||
if (newsFragment != null) {
|
||||
newsFragment.setHint(searchHint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request);
|
||||
});
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID");
|
||||
String url = Config.HOST + "support/upgrade?version=" + PackageUtils.getVersion(getApplicationContext())
|
||||
+ "&channel=" + TD_CHANNEL_ID;
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(url,
|
||||
new Response.Listener<JSONObject>() {
|
||||
RetrofitManager.getApi().getUpdate(PackageUtils.getVersion(getApplicationContext()), TD_CHANNEL_ID)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<AppEntity>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
appEntity = gson.fromJson(response.toString(), AppEntity.class);
|
||||
public void onResponse(AppEntity response) {
|
||||
appEntity = response;
|
||||
|
||||
float version = Float.valueOf(appEntity.getVersion());
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersion(getApplicationContext()));
|
||||
if (version > currentVersion) {
|
||||
// 光环助手 有更新
|
||||
GameUpdateEntity game = new GameUpdateEntity();
|
||||
game.setName("光环助手V" + appEntity.getVersion());
|
||||
game.setPackageName(getPackageName());
|
||||
game.setSize(appEntity.getSize());
|
||||
game.setVersion(appEntity.getVersion());
|
||||
game.setUrl(appEntity.getUrl());
|
||||
game.setPlatform("官方版");
|
||||
game.setId("5618b86e8ab49e17088b4575");
|
||||
PackageManager.addUpdate(0, game);
|
||||
float version = Float.valueOf(response.getVersion());
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersion(getApplicationContext()));
|
||||
if (version > currentVersion) {
|
||||
// 光环助手 有更新
|
||||
GameUpdateEntity game = new GameUpdateEntity();
|
||||
game.setName("光环助手V" + response.getVersion());
|
||||
game.setPackageName(getPackageName());
|
||||
game.setSize(response.getSize());
|
||||
game.setVersion(response.getVersion());
|
||||
game.setUrl(response.getUrl());
|
||||
game.setPlatform("官方版");
|
||||
game.setId("5618b86e8ab49e17088b4575");
|
||||
PackageManager.addUpdate(0, game);
|
||||
|
||||
String updateMD5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent());
|
||||
if (appEntity.isForce()) {
|
||||
// 强制更新
|
||||
String updateMD5 = MD5Utils.getUpdateMD5(response.getUrl(), response.getContent());
|
||||
if (response.isForce()) {
|
||||
// 强制更新
|
||||
showUpdateDialog(updateMD5);
|
||||
} else {
|
||||
// 非强制更新
|
||||
if ("EVERY_TIME_OPEN".equals(response.getAlert())) {
|
||||
// 每次都提示
|
||||
showUpdateDialog(updateMD5);
|
||||
} else {
|
||||
// 非强制更新
|
||||
if ("EVERY_TIME_OPEN".equals(appEntity.getAlert())) {
|
||||
// 每次都提示
|
||||
} else if (!"NEVER".equals(response.getAlert())){
|
||||
// 一天提示一次
|
||||
String showUpdateTime = sp.getString("show_update_tiem", null);
|
||||
SimpleDateFormat format = new SimpleDateFormat(
|
||||
"yyyy-MM-dd", Locale.getDefault());
|
||||
String today = format.format(new Date());
|
||||
if (!today.equals(showUpdateTime)) {
|
||||
sp.edit().putString("show_update_tiem", today).apply();
|
||||
showUpdateDialog(updateMD5);
|
||||
} else if (!"NEVER".equals(appEntity.getAlert())){
|
||||
// 一天提示一次
|
||||
String showUpdateTime = sp.getString("show_update_tiem", null);
|
||||
SimpleDateFormat format = new SimpleDateFormat(
|
||||
"yyyy-MM-dd", Locale.getDefault());
|
||||
String today = format.format(new Date());
|
||||
if (!today.equals(showUpdateTime)) {
|
||||
sp.edit().putString("show_update_tiem", today).apply();
|
||||
showUpdateDialog(updateMD5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request);
|
||||
});
|
||||
}
|
||||
|
||||
private void showUpdateDialog(final String md5) {
|
||||
@ -1339,17 +1297,18 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
map.put("user", user);
|
||||
map.put("device_id", TokenUtils.getDeviceId(this));
|
||||
map.put("channel", channel);
|
||||
String url = Config.DATA_HOST + "api/v1d0/log";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("topic", "upgrade");
|
||||
params.put("source", "GH-ASSIST-Client");
|
||||
params.put("time", String.valueOf(Utils.getTime(this)));
|
||||
params.put("content", new JSONObject(map).toString());
|
||||
StringExtendedRequest request = new StringExtendedRequest(Method.POST, url, null, null);
|
||||
request.setParams(params);
|
||||
request.setShouldCache(false);
|
||||
AppController.addToRequestQueue(request);
|
||||
Utils.log("提交更新数据" + new JSONObject(params).toString());
|
||||
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
RetrofitManager.getData().postLog(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
}
|
||||
|
||||
// 获取META-INF中的plugin_update 文件,判断是否从游戏插件中下载的app,是则获取游戏id,启动游戏更新,下载该游戏
|
||||
@ -1581,31 +1540,26 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
if ("安装".equals(busFour.getType()) && sp.getBoolean("concerngame", true)) {//设置页面控制是否安装后自动关注
|
||||
// 安装后关注游戏
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "support/package/" + packageName + "/game/digest",
|
||||
new Response.Listener<JSONArray>() {
|
||||
RetrofitManager.getApi().getGameDigestByPackageName(packageName)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<GameDigestEntity>>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
if (response.length() != 0) {
|
||||
Type listType = new TypeToken<ArrayList<GameDigestEntity>>() {}.getType();
|
||||
Gson gson = new Gson();
|
||||
List<GameDigestEntity> list = gson.fromJson(response.toString(), listType);
|
||||
for (GameDigestEntity gameDigestEntity : list) {
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
gameInfo.setGameName(gameDigestEntity.getName());
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
concernGame(gameDigestEntity.getId(), packageName);
|
||||
if (PackageUtils.getMetaData(getApplicationContext(),
|
||||
packageName, "gh_version") != null) {
|
||||
checkGameUpdate(packageName);
|
||||
}
|
||||
public void onResponse(List<GameDigestEntity> response) {
|
||||
for (GameDigestEntity gameDigestEntity : response) {
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
gameInfo.setGameName(gameDigestEntity.getName());
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
concernGame(gameDigestEntity.getId(), packageName);
|
||||
if (PackageUtils.getMetaData(getApplicationContext(),
|
||||
packageName, "gh_version") != null) {
|
||||
checkGameUpdate(packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request);
|
||||
});
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
@ -1615,36 +1569,32 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
|
||||
private void concernGame(final String id, final String packageName) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "game/" + id + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
RetrofitManager.getApi().getGameDigest(id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
GameManager manager = new GameManager(getApplicationContext());
|
||||
manager.addOrUpdate(gameEntity.getApk(), gameEntity.getId(), gameEntity.getName());
|
||||
if (!concernManager.isConcern(id)) {
|
||||
concernManager.addByEntity(gameEntity);
|
||||
}
|
||||
// 检查是否能插件化
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& gameEntity.getApk() != null) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(packageName)
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(getApplicationContext(), apkEntity.getPackageName())) {
|
||||
PackageManager.addUpdate(getGameUpdateEntity(gameEntity, apkEntity));
|
||||
EventBus.getDefault().post(new EBDownloadStatus("plugin"));
|
||||
break;
|
||||
}
|
||||
public void onResponse(GameEntity response) {
|
||||
GameManager manager = new GameManager(getApplicationContext());
|
||||
manager.addOrUpdate(response.getApk(), response.getId(), response.getName());
|
||||
if (!concernManager.isConcern(id)) {
|
||||
concernManager.addByEntity(response);
|
||||
}
|
||||
// 检查是否能插件化
|
||||
if (response.getTag() != null && response.getTag().size() != 0
|
||||
&& response.getApk() != null) {
|
||||
for (ApkEntity apkEntity : response.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(packageName)
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(getApplicationContext(), apkEntity.getPackageName())) {
|
||||
PackageManager.addUpdate(getGameUpdateEntity(response, apkEntity));
|
||||
EventBus.getDefault().post(new EBDownloadStatus("plugin"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
AppController.addToRequestQueue(request);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user