细节修复、部分bug修复
This commit is contained in:
@ -7,6 +7,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
@ -75,13 +76,18 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
private String from;
|
||||
|
||||
private long start;
|
||||
|
||||
private boolean isFirst;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
isFirst = true;
|
||||
|
||||
sp = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
@ -185,8 +191,8 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
FilterManager filterManager = new FilterManager(getApplicationContext());
|
||||
filterManager.addAllFilter(list);
|
||||
sp.edit().putBoolean("isLoadFilter", true).apply();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,6 +209,8 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
if (!today.equals(time)) {
|
||||
FilterManager manager = new FilterManager(getApplicationContext());
|
||||
manager.getFilterFromServer(today);
|
||||
|
||||
// 获取版本代码、名称
|
||||
getPlatform();
|
||||
}
|
||||
|
||||
@ -218,13 +226,28 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
*/
|
||||
DataCollectionManager.getInstance(getApplicationContext()).upload();
|
||||
|
||||
/*
|
||||
* 初始化已安装软件map,获取游戏更新列表和已安装列表
|
||||
*/
|
||||
PackageManager manager = new PackageManager(getApplicationContext());
|
||||
manager.getInstalledMapFromLocal();
|
||||
// 不是第一次启动
|
||||
if (!sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
int height = sp.getInt("actionbar_height", 0);
|
||||
if (height == 0) {
|
||||
final ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
sp.edit().putInt("actionbar_height", actionBar.getHeight()).apply();
|
||||
}
|
||||
}
|
||||
|
||||
getInstalledListFromServer(sp.getBoolean("isNewFirstLaunch", true));
|
||||
long end = System.currentTimeMillis() - start;
|
||||
if (end < 3000) {
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launch();
|
||||
}
|
||||
}, 3000 - end);
|
||||
} else {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,7 +378,6 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
editor.putStringSet("platform", pset);
|
||||
editor.apply();
|
||||
} catch (JSONException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -363,217 +385,6 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
}
|
||||
|
||||
private int iCount;
|
||||
|
||||
private void addInstalledCount() {
|
||||
synchronized (SplashScreenActivity.class) {
|
||||
iCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void getInstalledListFromServer(final boolean isFirst) {
|
||||
List<String> list = PackageManager.getLocalPackageName(getApplicationContext());
|
||||
if (list.isEmpty()) {
|
||||
// 跳转应用信息界面
|
||||
// Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
// Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
// intent.setData(uri);
|
||||
// startActivity(intent);
|
||||
update();
|
||||
return;
|
||||
}
|
||||
final int count = list.size();
|
||||
final List<JSONObject> data = new ArrayList<>();
|
||||
final List<String> useParams = new ArrayList<>();
|
||||
iCount = 0;
|
||||
for (int i = 0, size = list.size(); 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) {
|
||||
data.add(response);
|
||||
useParams.add(packageName);
|
||||
}
|
||||
addInstalledCount();
|
||||
if (iCount == count) {
|
||||
processingInstalledData(data, useParams, isFirst);
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addInstalledCount();
|
||||
if (iCount == count) {
|
||||
processingInstalledData(data, useParams, isFirst);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processingInstalledData(List<JSONObject> data, List<String> useParams, boolean isFirst) {
|
||||
Gson gson = new Gson();
|
||||
for (int i = 0, size = data.size(); i < size; i++) {
|
||||
GameDigestEntity gameDigestEntity = gson.fromJson(data.get(i)
|
||||
.toString(), GameDigestEntity.class);
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(useParams.get(i));
|
||||
concernManager.updateByEntity(gameInfo);
|
||||
}
|
||||
|
||||
// 移除疑似游戏数据库中所有数据
|
||||
SuspectedGameManager suspectedGameManager = new SuspectedGameManager(
|
||||
getApplicationContext());
|
||||
suspectedGameManager.deleteAll();
|
||||
|
||||
updateConcern(isFirst);
|
||||
}
|
||||
|
||||
private int cCount;
|
||||
|
||||
private void addConcernCount() {
|
||||
synchronized (SplashScreenActivity.class) {
|
||||
cCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConcern(final boolean isFirst) {
|
||||
|
||||
ArrayList<String> concernId = new ArrayList<>();
|
||||
for (ConcernInfo entity : concernManager.getAllConcern()) {
|
||||
concernId.add(entity.getId());
|
||||
}
|
||||
|
||||
if (concernId.size() != 0) {
|
||||
cCount = 0;
|
||||
final int count = concernId.size();
|
||||
for (int i = 0, size = concernId.size(); i < size; i++) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
Config.HOST + "v2d0/game/" + concernId.get(i) + "/digest",
|
||||
new Response.Listener<JSONObject>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
addConcernCount();
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(
|
||||
response.toString(), GameEntity.class);
|
||||
|
||||
ArrayMap<String, ConcernInfo> map = concernManager
|
||||
.getConcernMap();
|
||||
ConcernInfo entity = map.get(gameEntity.getId());
|
||||
if (entity != null) {
|
||||
List<ApkEntity> list = gameEntity.getApk();
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
for (int j = 0, sizej = list.size(); j < sizej; j++) {
|
||||
packageNames.put(list.get(j).getPackageName(), false);
|
||||
}
|
||||
entity.setTime(System.currentTimeMillis());
|
||||
entity.setPackageNames(packageNames);
|
||||
if (isFirst) {
|
||||
//默认安装即为关注
|
||||
if (!concernManager.isConcern(entity.getId())) {
|
||||
concernManager.addByEntity(gameEntity);
|
||||
}
|
||||
}
|
||||
concernManager.updateByConcern(entity);
|
||||
}
|
||||
if (cCount == count) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addConcernCount();
|
||||
if (cCount == count) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, SplashScreenActivity.class);
|
||||
}
|
||||
} else {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
update();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
private void update() {
|
||||
/*
|
||||
* 更新关注列表数据
|
||||
*/
|
||||
TrafficUtils spy = TrafficUtils.getInstance(getApplicationContext(), true);
|
||||
List<ConcernInfo> concernEntities = concernManager.getAllConcern();
|
||||
for (ConcernInfo concernEntity : concernEntities) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
// 不是第一次启动
|
||||
if (!sp.getBoolean("isNewFirstLaunch", true)) {
|
||||
int height = sp.getInt("actionbar_height", 0);
|
||||
if (height == 0) {
|
||||
final ActionBar actionBar = getActionBar();
|
||||
if (actionBar != null) {
|
||||
sp.edit().putInt("actionbar_height", actionBar.getHeight()).apply();
|
||||
}
|
||||
}
|
||||
|
||||
launch();
|
||||
}
|
||||
}
|
||||
|
||||
// 跳转到主界面
|
||||
private void launch() {
|
||||
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
|
||||
|
||||
Reference in New Issue
Block a user