细节修复、部分bug修复
This commit is contained in:
@ -8,15 +8,19 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@ -49,6 +53,7 @@ import com.gh.common.util.RunningUtils;
|
||||
import com.gh.common.util.SpeedUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.TrafficUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntity;
|
||||
@ -69,7 +74,6 @@ import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.eventbus.EBTopStatus;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.game.Game1Fragment;
|
||||
import com.gh.gamecenter.game.GameFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
@ -84,6 +88,7 @@ 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.tencent.stat.StatConfig;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -127,6 +132,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
private TextView home1Title, home2Title, home3Title;
|
||||
|
||||
private SharedPreferences sp;
|
||||
private ConcernManager concernManager;
|
||||
|
||||
private ArrayMap<String, String> entryMap;
|
||||
|
||||
@ -134,6 +140,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
|
||||
private boolean isDestroy = false;
|
||||
private boolean isShowDownload = false;
|
||||
private boolean isNewFirstLaunch;
|
||||
|
||||
private Dialog dialog;
|
||||
private ProgressBar app_pb_progress;
|
||||
@ -410,64 +417,291 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
getSearchHints();
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
concernManager = new ConcernManager(getApplicationContext());
|
||||
|
||||
if (!sp.getBoolean("isNewFirstLaunch", true)
|
||||
&& sp.getBoolean("autoupdate", true)) {
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunch", true);
|
||||
|
||||
if (!isNewFirstLaunch && sp.getBoolean("autoupdate", true)) {
|
||||
checkUpdate();
|
||||
}
|
||||
|
||||
if (sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
if (isNewFirstLaunch) {
|
||||
getPluginUpdate();
|
||||
getDisclaimer(true);
|
||||
// 注册设备
|
||||
TokenUtils.register(this);
|
||||
sp.edit().putBoolean("isNewFirstLaunch", false).apply();
|
||||
} else {
|
||||
getDisclaimer(false);
|
||||
handler.postDelayed(runnable, 500);
|
||||
}
|
||||
|
||||
getDisclaimer(isNewFirstLaunch);
|
||||
|
||||
// 初始化PlatformUtils
|
||||
PlatformUtils.getInstance(getApplicationContext());
|
||||
|
||||
// 添加观察者
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ArrayList<String> concernList = new ArrayList<>();
|
||||
ConcernManager concernManager = new ConcernManager(MainActivity.this);
|
||||
for (ConcernInfo entity : concernManager.getAllConcern()) {
|
||||
if (entity.isConcern()) {
|
||||
concernList.add(entity.getGameName());
|
||||
}
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("type", Build.MODEL);
|
||||
map.put("system", Build.VERSION.SDK_INT + "=" + Build.VERSION.RELEASE);
|
||||
map.put("install", PackageManager.getInstalledList());
|
||||
map.put("concern", concernList);
|
||||
DataCollectionManager.upsert(MainActivity.this, "user", map);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// //检查是否存在更新的dex包
|
||||
// checkHotfix();
|
||||
|
||||
// 检查游戏更新
|
||||
checkGameUpdate();
|
||||
// 检查是否有权限读取应用列表
|
||||
checkPermission();
|
||||
|
||||
// 检查可插件化游戏
|
||||
checkGamePlugin();
|
||||
if (isNewFirstLaunch
|
||||
|| TokenUtils.getDeviceId(this) == null) {
|
||||
// 注册设备
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
TokenUtils.register(MainActivity.this);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
|
||||
}
|
||||
|
||||
private void checkPermission() {
|
||||
ArrayList<String> list = PackageUtils.getAllPackageName(getApplicationContext());
|
||||
if (list.isEmpty()) {
|
||||
// 无权限获取应用列表
|
||||
Spanned content = Html.fromHtml("请前往系统权限设置,把“" +
|
||||
"<font color='#ff0000'>读取应用列表</font>”选择为打开" +
|
||||
"“<font color='#ff0000'>允许</font>”,否则光环助手将无法帮您安装插件加速版的游戏");
|
||||
DialogUtils.showWarningDialog(this, "提示", content, "忽略", "去开启",
|
||||
new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
// 跳转应用信息界面
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
startActivityForResult(intent, 0x123);
|
||||
}
|
||||
}, null);
|
||||
} else {
|
||||
getInstalledListFromServer(list);
|
||||
}
|
||||
}
|
||||
|
||||
private int iCount;
|
||||
|
||||
private void addInstalledCount() {
|
||||
synchronized (MainActivity.class) {
|
||||
iCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取已安装游戏
|
||||
private void getInstalledListFromServer(ArrayList<String> list) {
|
||||
PackageManager manager = new PackageManager(getApplicationContext());
|
||||
manager.initInstalledMap(list);
|
||||
|
||||
final int size = list.size();
|
||||
iCount = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
final String packageName = list.get(i);
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/" + packageName + "/game/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
GameDigestEntity gameDigestEntity = gson.fromJson(
|
||||
response.toString(), GameDigestEntity.class);
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
}
|
||||
addInstalledCount();
|
||||
if (iCount == size) {
|
||||
updateConcern();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addInstalledCount();
|
||||
if (iCount == size) {
|
||||
updateConcern();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, MainActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
private int cCount;
|
||||
|
||||
private void addConcernCount() {
|
||||
synchronized (MainActivity.class) {
|
||||
cCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConcern() {
|
||||
// 移除疑似游戏数据库中所有数据
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(
|
||||
getApplicationContext());
|
||||
suspectedGameManager.deleteAll();
|
||||
|
||||
ArrayList<String> concernIdList = new ArrayList<>();
|
||||
for (ConcernInfo entity : concernManager.getAllConcern()) {
|
||||
concernIdList.add(entity.getId());
|
||||
}
|
||||
if (concernIdList.isEmpty()) {
|
||||
update();
|
||||
} else {
|
||||
final int size = concernIdList.size();
|
||||
cCount = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + concernIdList.get(i) + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
concernInfo.setTime(System.currentTimeMillis());
|
||||
concernInfo.setPackageNames(packageNames);
|
||||
concernManager.updateByConcern(concernInfo);
|
||||
}
|
||||
if (isNewFirstLaunch) {
|
||||
//默认安装即为关注
|
||||
if (!concernManager.isConcern(gameEntity.getId())) {
|
||||
concernManager.addByEntity(gameEntity);
|
||||
}
|
||||
}
|
||||
addConcernCount();
|
||||
if (cCount == size) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addConcernCount();
|
||||
if (cCount == size) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, MainActivity.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 更新关注列表数据
|
||||
*/
|
||||
private void update() {
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
TrafficUtils spy = TrafficUtils.getInstance(getApplicationContext(), true);
|
||||
List<ConcernInfo> concernList = concernManager.getAllConcern();
|
||||
for (ConcernInfo concernEntity : concernList) {
|
||||
concernEntity.setTime(System.currentTimeMillis());
|
||||
int quantity = 0;
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
for (String packageName : concernEntity.getPackageNames().keySet()) {
|
||||
if (PackageManager.isInstalled(packageName)) {
|
||||
quantity++;
|
||||
packageNames.put(packageName, true);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
}
|
||||
concernEntity.setPackageNames(packageNames);
|
||||
concernEntity.setInstalled(quantity > 0);
|
||||
concernEntity.setInstalledQuantity(quantity);
|
||||
String tag = null;
|
||||
int weight = 0;
|
||||
if (concernEntity.isConcern() && concernEntity.isInstalled()) {
|
||||
tag = "已关注,已安装";
|
||||
weight = 2;
|
||||
} else if (concernEntity.isConcern()
|
||||
&& !concernEntity.isInstalled()) {
|
||||
tag = "已关注";
|
||||
weight = 1;
|
||||
} else if (!concernEntity.isConcern()
|
||||
&& concernEntity.isInstalled()) {
|
||||
tag = "已安装";
|
||||
weight = 1;
|
||||
}
|
||||
concernEntity.setTag(tag);
|
||||
long traffic = spy.getTraffic(new ArrayList<>(concernEntity
|
||||
.getPackageNames().keySet()));
|
||||
concernEntity.setTraffic(traffic);
|
||||
if (traffic > 0) {
|
||||
weight++;
|
||||
}
|
||||
concernEntity.setWeight(weight);
|
||||
if (weight == 0) {
|
||||
concernManager.deleteConcern(concernEntity.getId());
|
||||
} else {
|
||||
concernManager.updateByConcern(concernEntity);
|
||||
}
|
||||
}
|
||||
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ArrayList<String> concernList = new ArrayList<>();
|
||||
for (ConcernInfo entity : concernManager.getAllConcern()) {
|
||||
if (entity.isConcern()) {
|
||||
concernList.add(entity.getGameName());
|
||||
}
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("type", Build.MODEL);
|
||||
map.put("system", Build.VERSION.SDK_INT + "=" + Build.VERSION.RELEASE);
|
||||
map.put("install", PackageManager.getInstalledList());
|
||||
map.put("concern", concernList);
|
||||
DataCollectionManager.upsert(MainActivity.this, "user", map);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// 检查游戏更新
|
||||
checkGameUpdate();
|
||||
|
||||
// 检查可插件化游戏
|
||||
checkGamePlugin();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == 0x123) {
|
||||
ArrayList<String> list = PackageUtils.getAllPackageName(getApplicationContext());
|
||||
if (list.isEmpty()) {
|
||||
toast("读取应用列表失败");
|
||||
} else {
|
||||
getInstalledListFromServer(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkGameUpdate() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
|
||||
ConcernManager concernManager = new ConcernManager(this);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
for (ConcernInfo info : infos) {
|
||||
for (String packageName : info.getPackageNames().keySet()) {
|
||||
@ -554,7 +788,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
|
||||
private void checkGamePlugin() {
|
||||
ConcernManager concernManager = new ConcernManager(this);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
final int size = infos.size();
|
||||
final List<GameEntity> list = new ArrayList<>();
|
||||
@ -584,7 +817,7 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, Game1Fragment.class);
|
||||
AppController.addToRequestQueue(request, MainActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -592,7 +825,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ConcernManager concernManager = new ConcernManager(this);
|
||||
PackageManager mPackageManager = new PackageManager(this);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
HashMap<String, Boolean> map;
|
||||
@ -1313,8 +1545,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
GameManager gameManager = new GameManager(getApplicationContext());
|
||||
GameInfo gameEntity = gameManager.findGame(packageName);
|
||||
if (gameEntity != null) {
|
||||
ConcernManager concernManager = new ConcernManager(
|
||||
getApplicationContext());
|
||||
concernManager.updateByEntity(gameEntity);
|
||||
} else {
|
||||
FilterManager filterManager = new FilterManager(
|
||||
@ -1334,8 +1564,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
getApplicationContext());
|
||||
suspectedGameManager.deleteSuspectedGame(packageName);
|
||||
|
||||
ConcernManager concernManager = new ConcernManager(
|
||||
getApplicationContext());
|
||||
concernManager.updateByPackageName(packageName);
|
||||
}
|
||||
}
|
||||
@ -1383,7 +1611,6 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
|
||||
}
|
||||
|
||||
private void concernGame(String id) {
|
||||
final ConcernManager concernManager = new ConcernManager(getApplicationContext());
|
||||
if (!concernManager.isConcern(id)) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + id + "/digest",
|
||||
|
||||
Reference in New Issue
Block a user