去除volley
This commit is contained in:
@ -20,9 +20,6 @@ import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
@ -44,9 +41,8 @@ import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
||||
import com.gh.gamecenter.volley.extended.StringExtendedRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.kyleduo.switchbutton.SwitchButton;
|
||||
|
||||
import org.json.JSONObject;
|
||||
@ -56,6 +52,12 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* 游戏设置页面
|
||||
@ -388,66 +390,62 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
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) {
|
||||
|
||||
public void onResponse(AppEntity response) {
|
||||
isChecking = false;
|
||||
if (loadingDialog != null) {
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
|
||||
if (response.length() == 0) {
|
||||
toast("您的光环助手已是最新版本");
|
||||
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);
|
||||
|
||||
String updateMD5 = MD5Utils.getUpdateMD5(
|
||||
appEntity.getUrl(),
|
||||
appEntity.getContent());
|
||||
|
||||
showUpdateDialog(updateMD5);
|
||||
} else {
|
||||
Gson gson = new Gson();
|
||||
appEntity = gson.fromJson(response.toString(),
|
||||
AppEntity.class);
|
||||
|
||||
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);
|
||||
|
||||
String updateMD5 = MD5Utils.getUpdateMD5(
|
||||
appEntity.getUrl(),
|
||||
appEntity.getContent());
|
||||
|
||||
showUpdateDialog(updateMD5);
|
||||
} else {
|
||||
toast("已是最新版本");
|
||||
}
|
||||
|
||||
toast("已是最新版本");
|
||||
}
|
||||
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
public void onFailure(Throwable e) {
|
||||
isChecking = false;
|
||||
if (loadingDialog != null) {
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
|
||||
Utils.log("error = " + error.toString());
|
||||
if (e instanceof HttpException) {
|
||||
HttpException exception = (HttpException) e;
|
||||
if (exception.code() == 304) {
|
||||
toast("您的光环助手已是最新版本");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
toast("检查更新失败");
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request);
|
||||
}
|
||||
|
||||
private void showUpdateDialog(final String md5) {
|
||||
@ -568,17 +566,18 @@ public class SettingActivity extends BaseActivity implements OnClickListener {
|
||||
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(Request.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>());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user