下载管理-游戏更新接入PackageViewModel
重构PackageManager相关
This commit is contained in:
@ -175,7 +175,6 @@ object DirectUtils {
|
||||
bundle.putString(KEY_GAMEID, gameId)
|
||||
bundle.putString(KEY_PACKAGENAME, packageName)
|
||||
bundle.putInt(BaseFragment_TabLayout.PAGE_INDEX, INDEX_UPDATE)
|
||||
bundle.putBoolean(KEY_AUTO_UPDATE, true)
|
||||
EntranceUtils.jumpActivity(context, bundle)
|
||||
}
|
||||
|
||||
|
||||
@ -103,7 +103,6 @@ public class EntranceUtils {
|
||||
public static final String KEY_QUESTION_TAG = "question_tag";
|
||||
public static final String KEY_COLUMN_ID = "column_id";
|
||||
public static final String KEY_AUTO_DOWNLOAD = "auto_download";
|
||||
public static final String KEY_AUTO_UPDATE = "auto_update";
|
||||
public static final String KEY_HIDE_SUGGEST_HINT = "hide_suggest_hint";
|
||||
public static final String KEY_COMMUNITY_ARTICLE_ID = "communityArticleId";
|
||||
public static final String KEY_ARTICLE_COMMENT_ID = "articleCommentId";
|
||||
|
||||
@ -27,9 +27,6 @@ public class DownloadManagerActivity extends NormalActivity {
|
||||
}
|
||||
|
||||
public static Intent getDownloadMangerIntent(Context context, String url, String entrance) {
|
||||
// Intent intent = new Intent(context, DownloadManagerActivity.class);
|
||||
// intent.putExtra(EntranceUtils.KEY_URL, url);
|
||||
// intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_URL, url);
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
@ -37,53 +34,9 @@ public class DownloadManagerActivity extends NormalActivity {
|
||||
}
|
||||
|
||||
public static Intent getDownloadMangerIntent(Context context, int position, String entrance) {
|
||||
// Intent intent = new Intent(context, DownloadManagerActivity.class);
|
||||
// intent.putExtra(EntranceUtils.KEY_URL, url);
|
||||
// intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
bundle.putInt(BaseFragment_TabLayout.PAGE_INDEX, position);
|
||||
return getTargetIntent(context, DownloadManagerActivity.class, DownloadFragment.class, bundle);
|
||||
}
|
||||
|
||||
|
||||
// public static void startDownloadManagerActivity(Context context, String url, String entrance) {
|
||||
// Intent intent = new Intent(context, DownloadManagerActivity.class);
|
||||
// intent.putExtra(EntranceUtils.KEY_URL, url);
|
||||
// intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// context.startActivity(intent);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected int getLayoutId() {
|
||||
// return R.layout.activity_downloadmanager;
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// protected void onCreate(Bundle savedInstanceState) {
|
||||
// super.onCreate(savedInstanceState);
|
||||
//
|
||||
// setNavigationTitle(getString(R.string.title_downloadmanager));
|
||||
//
|
||||
// startDownloadFragment();
|
||||
// }
|
||||
//
|
||||
// private void startDownloadFragment() {
|
||||
// int currentItem = getIntent().getIntExtra(EntranceUtils.KEY_CURRENTITEM, 0);
|
||||
// Bundle data = getIntent().getBundleExtra(EntranceUtils.KEY_DATA);
|
||||
// if (data != null) {
|
||||
// currentItem = data.getInt(EntranceUtils.KEY_CURRENTITEM, 0);
|
||||
// }
|
||||
//
|
||||
// getSupportFragmentManager().beginTransaction().replace(
|
||||
// R.id.layout_fragment_content, DownloadFragment.newInstance(currentItem)).commitAllowingStateLoss();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onNewIntent(Intent intent) {
|
||||
// super.onNewIntent(intent);
|
||||
// startDownloadFragment();
|
||||
// setIntent(intent);
|
||||
// }
|
||||
}
|
||||
@ -17,7 +17,6 @@ import android.os.SystemClock;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
@ -32,7 +31,6 @@ import com.gh.base.AppUncaughtHandler;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.base.fragment.BaseFragment_ViewPager;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.exposure.ExposureUtils;
|
||||
import com.gh.common.exposure.meta.MetaUtil;
|
||||
import com.gh.common.im.ImManager;
|
||||
@ -47,24 +45,18 @@ import com.gh.common.util.DeviceUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.DirectUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.GsonUtils;
|
||||
import com.gh.common.util.LogUtils;
|
||||
import com.gh.common.util.MtaHelper;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.TrafficUtils;
|
||||
import com.gh.common.util.UrlFilterUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadNotification;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.db.info.InstallInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.CommunityEntity;
|
||||
import com.gh.gamecenter.entity.GameDigestEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.entity.InnerMetaInfoEntity;
|
||||
import com.gh.gamecenter.entity.SettingsEntity;
|
||||
import com.gh.gamecenter.eventbus.EBNetworkState;
|
||||
@ -75,15 +67,10 @@ import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.fragment.MainWrapperFragment;
|
||||
import com.gh.gamecenter.install.PackageViewModel;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.manager.InstallManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.manager.UpdateManager;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
import com.gh.gamecenter.normal.NormalFragment;
|
||||
import com.gh.gamecenter.qa.AskFragment;
|
||||
import com.gh.gamecenter.retrofit.ObservableUtil;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.gh.gamecenter.suggest.SuggestType;
|
||||
@ -104,7 +91,6 @@ import com.tencent.bugly.crashreport.CrashReport;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -112,24 +98,20 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.HttpException;
|
||||
|
||||
import static com.gh.common.util.EntranceUtils.KEY_TO;
|
||||
import static com.gh.gamecenter.fragment.MainWrapperFragment.INDEX_PERSONAL;
|
||||
@ -152,7 +134,6 @@ public class MainActivity extends BaseActivity {
|
||||
private MainWrapperFragment mMainWrapperFragment;
|
||||
|
||||
private SharedPreferences sp;
|
||||
private InstallManager mInstallManager;
|
||||
|
||||
private static final int SKIP_SETTING_REQUEST = 14;
|
||||
private boolean isSkipped;
|
||||
@ -449,260 +430,7 @@ public class MainActivity extends BaseActivity {
|
||||
if (installedList.isEmpty()) {
|
||||
toast("读取应用列表失败");
|
||||
} else {
|
||||
getInstalledListFromServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取已安装游戏
|
||||
private void getInstalledListFromServer() {
|
||||
ArrayList<String> list = PackageUtils.getAllPackageName(getApplicationContext());
|
||||
|
||||
PackageManager.INSTANCE.initData(list);
|
||||
|
||||
// 忽略 xposed 安装器
|
||||
list.remove(Constants.XPOSED_INSTALLER_PACKAGE_NAME);
|
||||
|
||||
//应用上报
|
||||
uploadAppList();
|
||||
|
||||
// 过滤助手收录的包
|
||||
ArrayList<String> localList = new ArrayList<>();
|
||||
FilterManager filterManager = new FilterManager(this);
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
if (filterManager.isFilter(list.get(i))) {
|
||||
localList.add(list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
final CountDownLatch latch = ObservableUtil.latch(localList.size(), o -> updateInstall(), new Object());
|
||||
|
||||
for (int i = 0, size = localList.size(); i < size; i++) {
|
||||
final String packageName = localList.get(i);
|
||||
RetrofitManager.getInstance(this).getApi().getGameDigestByPackageName(UrlFilterUtils.getFilterQuery("package", packageName))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<GameDigestEntity>>() {
|
||||
@Override
|
||||
public void onResponse(List<GameDigestEntity> response) {
|
||||
for (GameDigestEntity gameDigestEntity : response) {
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setGameIcon(gameDigestEntity.getIcon());
|
||||
gameInfo.setPackageName(packageName);
|
||||
gameInfo.setGameName(gameDigestEntity.getName());
|
||||
mInstallManager.updateByEntity(gameInfo);
|
||||
}
|
||||
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void uploadAppList() {
|
||||
//检查是否符合应用上报周期
|
||||
long time = sp.getLong("last_upload_applist_time", 0);
|
||||
if (Utils.getTime(this) - time >= 604800L) {//一周为一个周期
|
||||
DataCollectionUtils.uploadAppList(this, PackageUtils.getAppList(this));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 为已安装的游戏添加助手后台存在的包
|
||||
*/
|
||||
private void updateInstall() {
|
||||
ArrayList<String> concernIdList = new ArrayList<>();
|
||||
for (InstallInfo entity : mInstallManager.getAllInstall()) {
|
||||
concernIdList.add(entity.getId());
|
||||
}
|
||||
if (concernIdList.isEmpty()) {
|
||||
update();
|
||||
} else {
|
||||
List<Observable<GameEntity>> sequences = new ArrayList<>();
|
||||
for (String id : concernIdList) {
|
||||
sequences.add(RetrofitManager.getInstance(this).getApi().getGameDigest(id));
|
||||
}
|
||||
Observable.mergeDelayError(sequences)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onNext(GameEntity response) {
|
||||
InstallInfo installInfo = mInstallManager.findInstallById(response.getId());
|
||||
if (installInfo != null && response.getApk().size() != 0) {
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
for (ApkEntity apkEntity : response.getApk()) {
|
||||
if (PackageManager.INSTANCE.isInstalled(apkEntity.getPackageName())) {
|
||||
packageNames.put(apkEntity.getPackageName(), true);
|
||||
} else {
|
||||
packageNames.put(apkEntity.getPackageName(), false);
|
||||
}
|
||||
}
|
||||
installInfo.setTime(System.currentTimeMillis());
|
||||
installInfo.setPackageNames(packageNames);
|
||||
mInstallManager.updateInstall(installInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@Nullable HttpException e) {
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
update();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新安装列表数据
|
||||
*/
|
||||
private void update() {
|
||||
HaloApp.getInstance().getMainExecutor().execute(() -> {
|
||||
final List<String> installed = new ArrayList<>();
|
||||
TrafficUtils spy = TrafficUtils.getInstance(getApplicationContext(), true);
|
||||
List<InstallInfo> concernList = mInstallManager.getAllInstall();
|
||||
for (InstallInfo concernEntity : concernList) {
|
||||
concernEntity.setTime(System.currentTimeMillis());
|
||||
int quantity = 0;
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
for (String packageName : concernEntity.getPackageNames().keySet()) {
|
||||
if (PackageManager.INSTANCE.isInstalled(packageName)) {
|
||||
quantity++;
|
||||
packageNames.put(packageName, true);
|
||||
installed.add(packageName);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
}
|
||||
concernEntity.setPackageNames(packageNames);
|
||||
concernEntity.setInstalledQuantity(quantity);
|
||||
int weight = 0;
|
||||
long traffic = spy.getTraffic(new ArrayList<>(concernEntity.getPackageNames().keySet()));
|
||||
concernEntity.setTraffic(traffic);
|
||||
if (traffic > 0) {
|
||||
weight++;
|
||||
}
|
||||
concernEntity.setWeight(weight);
|
||||
mInstallManager.updateInstall(concernEntity);
|
||||
}
|
||||
|
||||
// 更新用户已安装游戏
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONArray(installed).toString());
|
||||
RetrofitManager.getInstance(MainActivity.this).getApi().putPackage(UserManager.getInstance().getUserId(), body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
|
||||
handler.postDelayed(() -> DataCollectionUtils.uploadUser(MainActivity.this), 1000);
|
||||
|
||||
// 检查游戏更新
|
||||
checkGameUpdate();
|
||||
|
||||
// 检查可插件化游戏
|
||||
checkGamePlugin();
|
||||
});
|
||||
}
|
||||
|
||||
private void checkGameUpdate() {
|
||||
List<InstallInfo> infos = mInstallManager.getAllInstall();
|
||||
ArrayList<String> packageList = PackageUtils.getAllPackageName(this);
|
||||
for (InstallInfo info : infos) {
|
||||
for (String packageName : info.getPackageNames().keySet()) {
|
||||
if (info.getPackageNames().get(packageName)
|
||||
&& packageList.contains(packageName)) {
|
||||
checkGameUpdate(packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkGamePlugin() {
|
||||
final List<GameEntity> list = new ArrayList<>();
|
||||
List<Observable<GameEntity>> sequences = new ArrayList<>();
|
||||
for (InstallInfo info : mInstallManager.getAllInstall()) {
|
||||
sequences.add(RetrofitManager.getInstance(this).getApi().getGameDigest(info.getId()));
|
||||
}
|
||||
Observable.mergeDelayError(sequences)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onNext(GameEntity response) {
|
||||
list.add(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@Nullable HttpException e) {
|
||||
processPluginData(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
processPluginData(list);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkGameUpdate(String packageName) {
|
||||
Object gh_id = PackageUtils.getMetaData(this, packageName, "gh_id");
|
||||
Observable<GameEntity> observable;
|
||||
if (gh_id == null) {
|
||||
observable = RetrofitManager.getInstance(this).getApi().getGameUpdate(UrlFilterUtils.getFilterQuery("packages", packageName));
|
||||
} else {
|
||||
observable = RetrofitManager.getInstance(this).getApi().getGameUpdateById((String) gh_id);
|
||||
}
|
||||
observable.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onResponse(GameEntity response) {
|
||||
List<GameUpdateEntity> updateList = PackageUtils.isCanUpdate(getApplication(), response);
|
||||
if (updateList.size() > 0) {
|
||||
PackageManager.INSTANCE.addUpdateList(updateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void processPluginData(List<GameEntity> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<InstallInfo> infos = mInstallManager.getAllInstall();
|
||||
HashMap<String, Boolean> map;
|
||||
for (InstallInfo info : infos) {
|
||||
for (GameEntity gameEntity : list) {
|
||||
if (gameEntity.getId().equals(info.getId())
|
||||
&& gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& gameEntity.getApk() != null) {
|
||||
map = info.getPackageNames();
|
||||
for (String key : map.keySet()) {
|
||||
if (map.get(key)) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(key)
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(this, apkEntity.getPackageName())) {
|
||||
PackageManager.INSTANCE.addUpdate(GameUtils.getGameUpdateEntity(gameEntity, apkEntity));
|
||||
break;
|
||||
}
|
||||
}
|
||||
GameManager manager = new GameManager(this);
|
||||
manager.addOrUpdate(gameEntity);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// getInstalledListFromServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -732,8 +460,6 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
replaceFragment(mMainWrapperFragment);
|
||||
|
||||
mInstallManager = new InstallManager(getApplicationContext());
|
||||
|
||||
// 检查助手更新
|
||||
UpdateManager.getInstance(this).checkUpdate(true, null);
|
||||
|
||||
@ -978,7 +704,7 @@ public class MainActivity extends BaseActivity {
|
||||
startActivityForResult(intent, SKIP_SETTING_REQUEST);
|
||||
}, null);
|
||||
} else {
|
||||
getInstalledListFromServer();
|
||||
// getInstalledListFromServer();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1059,6 +785,7 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
DownloadEntity mDownloadEntity = null;
|
||||
for (DownloadEntity downloadEntity : DownloadManager.getInstance(getApplicationContext()).getAll()) {
|
||||
//todo 根据包名获取DownloadEntity? 假如存在相同包名的下载任务,有可能会删除错误
|
||||
if (packageName.equals(downloadEntity.getPackageName())) {
|
||||
mDownloadEntity = downloadEntity;
|
||||
break;
|
||||
@ -1072,9 +799,6 @@ public class MainActivity extends BaseActivity {
|
||||
NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nManager.cancel(packageName.hashCode());
|
||||
|
||||
// 添加进已安装map中
|
||||
PackageManager.INSTANCE.addInstalled(packageName);
|
||||
|
||||
if (mDownloadEntity != null) {
|
||||
if (mDownloadEntity.isPluggable()) {
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
@ -1092,11 +816,6 @@ public class MainActivity extends BaseActivity {
|
||||
mDownloadEntity.getUrl(), false); // 默认不删除安装包 sp.getBoolean("autodelete", true)
|
||||
}
|
||||
|
||||
GameManager gameManager = new GameManager(getApplicationContext());
|
||||
GameInfo gameInfo = gameManager.findGame(packageName);
|
||||
if (gameInfo != null) {
|
||||
mInstallManager.updateByEntity(gameInfo);
|
||||
}
|
||||
|
||||
if (sp.getBoolean("concerngame", true)) { //设置页面控制是否安装后自动关注
|
||||
// 安装后关注游戏
|
||||
@ -1108,8 +827,6 @@ public class MainActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onResponse(List<GameDigestEntity> response) {
|
||||
for (GameDigestEntity gameDigestEntity : response) {
|
||||
concernGame(gameDigestEntity.getId(), packageName);
|
||||
|
||||
if (!TextUtils.isEmpty(gameDigestEntity.getId())) { // 关注游戏
|
||||
if (finalDownloadEntity != null && gameDigestEntity.getId().equals(finalDownloadEntity.getGameId())) {
|
||||
ConcernUtils.INSTANCE.postConcernGameId(MainActivity.this, gameDigestEntity.getId(), null);
|
||||
@ -1117,11 +834,6 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
if (PackageUtils.getMetaData(getApplicationContext(),
|
||||
packageName, "gh_version") != null) {
|
||||
checkGameUpdate(packageName);
|
||||
}
|
||||
|
||||
// 更新已安装游戏
|
||||
RetrofitManager.getInstance(MainActivity.this).getApi()
|
||||
.postPackage(UserManager.getInstance().getUserId(), packageName)
|
||||
@ -1135,8 +847,6 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
if ("卸载".equals(busFour.getType())) {
|
||||
mPackageViewModel.addUninstalledGame(packageName);
|
||||
// 删除map中数据
|
||||
PackageManager.INSTANCE.removeInstalled(packageName);
|
||||
|
||||
if (mDownloadEntity != null && mDownloadEntity.isPluggable()) {
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
@ -1153,11 +863,6 @@ public class MainActivity extends BaseActivity {
|
||||
startActivity(PackageUtils.getInstallIntent(this, mDownloadEntity.getPath()));
|
||||
}
|
||||
|
||||
FilterManager filterManager = new FilterManager(getApplicationContext());
|
||||
if (filterManager.isFilter(packageName)) {
|
||||
mInstallManager.updateByPackageName(packageName);
|
||||
}
|
||||
|
||||
// 更新已安装游戏
|
||||
RetrofitManager.getInstance(this).getApi()
|
||||
.deletePackage(UserManager.getInstance().getUserId(), packageName)
|
||||
@ -1167,36 +872,9 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
if ("卸载".equals(busFour.getType()) || "安装".equals(busFour.getType())) {
|
||||
PackageManager.INSTANCE.removeUpdate(packageName);
|
||||
}
|
||||
DataCollectionUtils.uploadInorunstall(this, busFour.getType(), busFour.getPackageName());
|
||||
}
|
||||
|
||||
private void concernGame(final String id, final String packageName) {
|
||||
RetrofitManager.getInstance(this).getApi().getGameDigest(id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onResponse(GameEntity response) {
|
||||
GameManager manager = new GameManager(getApplicationContext());
|
||||
manager.addOrUpdate(response);
|
||||
// 检查是否能插件化
|
||||
if (response.getTag() != null && response.getTag().size() != 0) {
|
||||
for (ApkEntity apkEntity : response.getApk()) {
|
||||
if (packageName.equals(apkEntity.getPackageName())
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(getApplicationContext(), apkEntity.getPackageName())) {
|
||||
PackageManager.INSTANCE.addUpdate(GameUtils.getGameUpdateEntity(response, apkEntity));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 接收登录和登出更新事件统计的 Meta
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBReuse reuse) {
|
||||
|
||||
@ -33,7 +33,7 @@ import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameNormalSwipeViewHolder;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameInfoEntity;
|
||||
import com.gh.gamecenter.entity.GameInstall;
|
||||
import com.gh.gamecenter.kuaichuan.FileInfo;
|
||||
import com.gh.gamecenter.manager.GameManager;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
@ -44,7 +44,6 @@ import com.lightgame.adapter.BaseRecyclerAdapter;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
@ -65,8 +64,7 @@ public class InstallFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
private SharedPreferences sp;
|
||||
|
||||
private ArrayList<GameEntity> gameList;
|
||||
private ArrayList<GameInfoEntity> sortedList;
|
||||
private ArrayList<GameInfoEntity> installedList;
|
||||
private ArrayList<GameInstall> sortedList;
|
||||
|
||||
//下载用到的map
|
||||
private ArrayMap<String, ArrayList<Integer>> locationMap;
|
||||
@ -99,121 +97,35 @@ public class InstallFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
maxWidth = mContext.getResources().getDisplayMetrics().widthPixels;
|
||||
}
|
||||
|
||||
public void initData(ArrayList<GameInfoEntity> list) {
|
||||
public void initData(ArrayList<GameInstall> list) {
|
||||
sortedList.clear();
|
||||
gameList.clear();
|
||||
this.installedList = list;
|
||||
sortedList.addAll(list);
|
||||
|
||||
if (installedList.isEmpty()) {
|
||||
if (sortedList.isEmpty()) {
|
||||
mActivity.loadEmpty();
|
||||
} else {
|
||||
HaloApp.getInstance().getMainExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
List<String> ids = new ArrayList<>();
|
||||
Collections.sort(sortedList, new Comparator<GameInfoEntity>() { // 按安装时间排序
|
||||
@Override
|
||||
public int compare(GameInfoEntity lhs, GameInfoEntity rhs) {
|
||||
return lhs.getInstallTime() > rhs.getInstallTime() ? -1 : 1;
|
||||
}
|
||||
});
|
||||
for (GameInfoEntity info : sortedList) {
|
||||
if (!ids.contains(info.getId())) {
|
||||
ids.add(info.getId());
|
||||
}
|
||||
HaloApp.getInstance().getMainExecutor().execute(() -> {
|
||||
List<String> ids = new ArrayList<>();
|
||||
Collections.sort(sortedList, (lhs, rhs) -> { // 按安装时间排序
|
||||
if (rhs.getInstallTime() > lhs.getInstallTime()) {
|
||||
return 1;
|
||||
} else if (rhs.getInstallTime() < lhs.getInstallTime()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
for (GameInstall info : sortedList) {
|
||||
if (!ids.contains(info.getId())) {
|
||||
ids.add(info.getId());
|
||||
}
|
||||
initGameList(ids);
|
||||
}
|
||||
initGameList(ids);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//初始化
|
||||
private void init() {
|
||||
ArrayList<GameInfoEntity> signatureList = new ArrayList<>(); // 是我们签名的游戏
|
||||
ArrayList<GameInfoEntity> unsignatureList = new ArrayList<>(); // 不是我们签名的游戏
|
||||
ArrayList<GameInfoEntity> noopenList = new ArrayList<>(); // 未打开过的游戏
|
||||
ArrayList<GameInfoEntity> oftenuseList = new ArrayList<>(); // 已经打开过的游戏
|
||||
|
||||
ArrayMap<String, ArrayList<GameInfoEntity>> map = new ArrayMap<>();
|
||||
ArrayList<GameInfoEntity> mList;
|
||||
for (int i = 0, size = installedList.size(); i < size; i++) {
|
||||
mList = map.get(installedList.get(i).getPackageName());
|
||||
if (mList == null) {
|
||||
mList = new ArrayList<>();
|
||||
map.put(installedList.get(i).getPackageName(), mList);
|
||||
}
|
||||
mList.add(installedList.get(i));
|
||||
}
|
||||
Comparator<GameInfoEntity> comparator = new Comparator<GameInfoEntity>() {
|
||||
@Override
|
||||
public int compare(GameInfoEntity lhs, GameInfoEntity rhs) {
|
||||
return rhs.getId().compareTo(lhs.getId());
|
||||
}
|
||||
};
|
||||
Object gh_id;
|
||||
for (String key : map.keySet()) {
|
||||
mList = map.get(key);
|
||||
if (mList.size() > 1) {
|
||||
Collections.sort(mList, comparator);
|
||||
}
|
||||
if (mList.get(0).isSignature()) {
|
||||
gh_id = PackageUtils.getMetaData(mContext, key, "gh_id");
|
||||
for (GameInfoEntity info : mList) {
|
||||
if (gh_id == null || info.getId().equals(gh_id)) {
|
||||
signatureList.add(info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unsignatureList.add(mList.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
for (GameInfoEntity info : signatureList) {
|
||||
if (info.getTraffic() == 0) {
|
||||
noopenList.add(info);
|
||||
} else {
|
||||
oftenuseList.add(info);
|
||||
}
|
||||
}
|
||||
|
||||
comparator = new Comparator<GameInfoEntity>() {
|
||||
@Override
|
||||
public int compare(GameInfoEntity lhs, GameInfoEntity rhs) {
|
||||
if (rhs.getInstallTime() > lhs.getInstallTime()) {
|
||||
return 1;
|
||||
} else if (rhs.getInstallTime() < lhs.getInstallTime()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
Collections.sort(noopenList, comparator);
|
||||
|
||||
comparator = new Comparator<GameInfoEntity>() {
|
||||
@Override
|
||||
public int compare(GameInfoEntity lhs, GameInfoEntity rhs) {
|
||||
if (rhs.getTraffic() > lhs.getTraffic()) {
|
||||
return 1;
|
||||
} else if (rhs.getTraffic() < lhs.getTraffic()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
Collections.sort(oftenuseList, comparator);
|
||||
|
||||
Collections.sort(unsignatureList, comparator);
|
||||
|
||||
sortedList.addAll(noopenList);
|
||||
sortedList.addAll(oftenuseList);
|
||||
sortedList.addAll(unsignatureList);
|
||||
}
|
||||
|
||||
//获取游戏简介
|
||||
private void initGameList(List<String> ids) {
|
||||
final List<GameEntity> result = new ArrayList<>();
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package com.gh.gamecenter.download;
|
||||
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
@ -11,12 +14,10 @@ import com.gh.base.fragment.BaseFragment;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBMiPush;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.install.PackageViewModel;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
@ -44,6 +45,8 @@ public class GameUpdateFragment extends BaseFragment {
|
||||
@BindView(R.id.reuse_nodata_skip_tv_btn)
|
||||
TextView mNoDataHintBtn;
|
||||
|
||||
private PackageViewModel mPackageViewModel;
|
||||
|
||||
private GameUpdateFragmentAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
@ -51,12 +54,19 @@ public class GameUpdateFragment extends BaseFragment {
|
||||
return R.layout.gameupdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mPackageViewModel = ViewModelProviders.of(this, new PackageViewModel.Factory()).get(PackageViewModel.class);
|
||||
mPackageViewModel.getGameUpdateLiveData().observe(this,
|
||||
updateList -> mAdapter.initData(updateList == null ? new ArrayList<>() : updateList));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView(View view) {
|
||||
super.initView(view);
|
||||
Intent intent = getActivity().getIntent();
|
||||
String packageName = intent.getStringExtra("packageName");
|
||||
boolean isUpdate = intent.getBooleanExtra(EntranceUtils.KEY_AUTO_UPDATE, false);
|
||||
String entrance = intent.getStringExtra(EntranceUtils.KEY_ENTRANCE);
|
||||
|
||||
mGameUpdateNoDataSkip.setVisibility(View.GONE);
|
||||
@ -74,7 +84,7 @@ public class GameUpdateFragment extends BaseFragment {
|
||||
mGameUpdateRv.setHasFixedSize(true);
|
||||
mGameUpdateRv.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
mAdapter = new GameUpdateFragmentAdapter(getActivity(), mGameUpdateLoading,
|
||||
mGameUpdateNoDataSkip, packageName, isUpdate, entrance);
|
||||
mGameUpdateNoDataSkip, packageName, entrance);
|
||||
mGameUpdateRv.setAdapter(mAdapter);
|
||||
|
||||
}
|
||||
@ -89,37 +99,9 @@ public class GameUpdateFragment extends BaseFragment {
|
||||
}
|
||||
mGameUpdateRv.getAdapter().notifyItemChanged(0);
|
||||
}
|
||||
} else if ("update".equals(status.getStatus()) || "plugin".equals(status.getStatus())) {
|
||||
mAdapter.init();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBPackage busFour) {
|
||||
ArrayList<Integer> locationList = mAdapter.getLocationMap().get(busFour.getPackageName());
|
||||
if (locationList != null) {
|
||||
for (int location : locationList) {
|
||||
if ("安装".equals(busFour.getType())) {
|
||||
mGameUpdateRv.getAdapter().notifyItemChanged(location + 1);
|
||||
mGameUpdateRv.getAdapter().notifyItemChanged(0);
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
mAdapter.removeUpdate(busFour.getPackageName());
|
||||
if (mAdapter.getUpdateList().isEmpty()) {
|
||||
mGameUpdateNoDataSkip.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
EventBus.getDefault().post(new EBDownloadChanged("update", View.VISIBLE, -1));
|
||||
}
|
||||
mAdapter.initLocationMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBMiPush miPush) {
|
||||
if ("mipush_plugin".equals(miPush.getFrom())) {
|
||||
mAdapter.getUpdateListFromServer();
|
||||
}
|
||||
}
|
||||
|
||||
//更新平台信息
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
|
||||
@ -2,7 +2,6 @@ package com.gh.gamecenter.download;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@ -32,13 +31,11 @@ import com.gh.gamecenter.DownloadManagerActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.DownloadHeadViewHolder;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameUpdateViewHolder;
|
||||
import com.gh.gamecenter.db.info.InstallInfo;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.entity.PluginLocation;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadChanged;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.manager.InstallManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
@ -78,7 +75,7 @@ class GameUpdateFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
private String entrance;
|
||||
|
||||
GameUpdateFragmentAdapter(Activity activity, LinearLayout loading, LinearLayout none, String packageName,
|
||||
boolean isUpdate, String entrance) {
|
||||
String entrance) {
|
||||
super(activity);
|
||||
|
||||
mGameUpdateLoading = loading;
|
||||
@ -90,11 +87,6 @@ class GameUpdateFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
locationMap = new ArrayMap<>();
|
||||
|
||||
updateList = new ArrayList<>();
|
||||
if (isUpdate) {
|
||||
getUpdateListFromServer();
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
// 根据包名获取更新(单个)
|
||||
@ -122,7 +114,7 @@ class GameUpdateFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
List<GameUpdateEntity> update = PackageUtils.isCanUpdate(mContext, response);
|
||||
if (update.size() > 0) {
|
||||
updateList.addAll(update);
|
||||
PackageManager.INSTANCE.addUpdateList(update);
|
||||
// PackageManager.INSTANCE.addUpdateList(update);
|
||||
EventBus.getDefault().post(new EBDownloadChanged("update",
|
||||
View.VISIBLE, updateList.size()));
|
||||
initLocationMap();
|
||||
@ -146,52 +138,9 @@ class GameUpdateFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
});
|
||||
}
|
||||
|
||||
// 从服务器中获取更新(多个)
|
||||
public void getUpdateListFromServer() {
|
||||
mGameUpdateLoading.setVisibility(View.VISIBLE);
|
||||
|
||||
List<String> packages = getInstalledList();
|
||||
if (packages.size() != 0) {
|
||||
List<Observable<GameEntity>> sequences = new ArrayList<>();
|
||||
Object gh_id;
|
||||
for (String packageName : packages) {
|
||||
gh_id = PackageUtils.getMetaData(mContext, packageName, "gh_id");
|
||||
if (gh_id == null) {
|
||||
sequences.add(RetrofitManager.getInstance(mContext).getApi().getGameUpdate(UrlFilterUtils.getFilterQuery("packages", packageName)));
|
||||
} else {
|
||||
sequences.add(RetrofitManager.getInstance(mContext).getApi().getGameUpdateById((String) gh_id));
|
||||
}
|
||||
}
|
||||
Observable.mergeDelayError(sequences)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<GameEntity>() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
processingData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@Nullable HttpException e) {
|
||||
processingData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(GameEntity response) {
|
||||
List<GameUpdateEntity> update = PackageUtils.isCanUpdate(mContext, response);
|
||||
if (update.size() > 0) {
|
||||
PackageManager.INSTANCE.addUpdateList(update);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGameUpdateLoading.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
void initData(List<GameUpdateEntity> updateData) {
|
||||
updateList.clear();
|
||||
for (GameUpdateEntity updateEntity : PackageManager.INSTANCE.getUpdateList()) {
|
||||
for (GameUpdateEntity updateEntity : updateData) {
|
||||
if (updateEntity.isShowPlugin(PluginLocation.only_index)) {
|
||||
updateList.add(updateEntity);
|
||||
}
|
||||
@ -237,42 +186,6 @@ class GameUpdateFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取已安装游戏包名列表
|
||||
private List<String> getInstalledList() {
|
||||
List<String> packages = new ArrayList<>();
|
||||
InstallManager installManager = new InstallManager(mContext);
|
||||
for (InstallInfo info : installManager.getAllInstall()) {
|
||||
for (String key : info.getPackageNames().keySet()) {
|
||||
if (info.getPackageNames().get(key)
|
||||
&& PackageUtils.getMetaData(mContext, key, "gh_version") != null) {
|
||||
packages.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return packages;
|
||||
}
|
||||
|
||||
private void processingData() {
|
||||
for (GameUpdateEntity updateEntity : PackageManager.INSTANCE.getUpdateList()) {
|
||||
if (updateEntity.isShowPlugin(PluginLocation.only_index)) {
|
||||
updateList.add(updateEntity);
|
||||
}
|
||||
}
|
||||
sortUpdateList(updateList);
|
||||
|
||||
notifyDataSetChanged();
|
||||
|
||||
EventBus.getDefault().post(new EBDownloadChanged("update", View.VISIBLE, updateList.size()));
|
||||
initLocationMap();
|
||||
|
||||
if (updateList.isEmpty()) {
|
||||
mGameUpdateNodataSkip.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mGameUpdateNodataSkip.setVisibility(View.GONE);
|
||||
}
|
||||
mGameUpdateLoading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// 对更新列表进行排序
|
||||
private void sortUpdateList(List<GameUpdateEntity> list) {
|
||||
Comparator<GameUpdateEntity> comparator = (lhs, rhs) -> {
|
||||
@ -578,27 +491,8 @@ class GameUpdateFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
EventBus.getDefault().post(new EBSkip(DownloadManagerActivity.TAG, DownloadManagerActivity.INDEX_UPDATE));
|
||||
}
|
||||
|
||||
public List<GameUpdateEntity> getUpdateList() {
|
||||
return updateList;
|
||||
}
|
||||
|
||||
public ArrayMap<String, ArrayList<Integer>> getLocationMap() {
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
public void removeUpdate(String packageName) {
|
||||
for (int i = 0; i < updateList.size(); i++) {
|
||||
if (updateList.get(i).getPackageName().equals(packageName)) {
|
||||
updateList.remove(i);
|
||||
if (updateList.isEmpty()) {
|
||||
notifyItemRangeRemoved(0, 2);
|
||||
break;
|
||||
}
|
||||
notifyItemRemoved(i + 1);
|
||||
notifyItemChanged(0);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,25 +1,28 @@
|
||||
package com.gh.gamecenter.entity
|
||||
|
||||
import com.gh.common.util.PackageUtils
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.halo.assistant.HaloApp
|
||||
|
||||
data class GameInstall(
|
||||
@SerializedName("_id")
|
||||
var id: String? = "",
|
||||
var packageMap: MutableMap<String, Boolean> = HashMap(), // key: pkgName value: isInstall
|
||||
var packageName: String = "",
|
||||
var name: String? = "",
|
||||
var icon: String? = "") {
|
||||
var icon: String? = "",
|
||||
var isSignature: Boolean = false,
|
||||
var installTime: Long = 0) {
|
||||
|
||||
companion object {
|
||||
fun transformGameInstall(game: GameEntity, installedPkgName: String): GameInstall {
|
||||
val packageMap = HashMap<String, Boolean>()
|
||||
for (apkEntity in game.getApk()) {
|
||||
packageMap[apkEntity.packageName!!] = apkEntity.packageName == installedPkgName
|
||||
}
|
||||
val gameInstall = GameInstall()
|
||||
val application = HaloApp.getInstance().application
|
||||
gameInstall.isSignature = PackageUtils.isSignature(application, installedPkgName)
|
||||
gameInstall.installTime = PackageUtils.getInstalledTime(application, installedPkgName)
|
||||
gameInstall.id = game.id
|
||||
gameInstall.name = game.name
|
||||
gameInstall.icon = game.icon
|
||||
gameInstall.packageMap = packageMap
|
||||
gameInstall.packageName = installedPkgName
|
||||
return gameInstall
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gh.gamecenter.fragment;
|
||||
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -29,12 +30,14 @@ import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.entity.PluginLocation;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.install.PackageViewModel;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
@ -54,6 +57,8 @@ public class SearchToolbarFragment extends BaseFragment implements View.OnClickL
|
||||
@BindView(R.id.actionbar_rl_download)
|
||||
View mDownloadView;
|
||||
|
||||
private PackageViewModel mPackageViewModel;
|
||||
|
||||
private AlphaAnimation mAlphaAnimation;
|
||||
|
||||
private ArrayList<String> mHintList;
|
||||
@ -153,13 +158,12 @@ public class SearchToolbarFragment extends BaseFragment implements View.OnClickL
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mHintIndex = 0;
|
||||
if (savedInstanceState != null) {
|
||||
mHintList = savedInstanceState.getStringArrayList(EntranceUtils.KEY_HINT);
|
||||
}
|
||||
|
||||
mHintIndex = 0;
|
||||
|
||||
mPackageViewModel = ViewModelProviders.of(this, new PackageViewModel.Factory()).get(PackageViewModel.class);
|
||||
mPackageViewModel.getGameUpdateLiveData().observe(this, this::setDownloadHint);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -264,9 +268,15 @@ public class SearchToolbarFragment extends BaseFragment implements View.OnClickL
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBDownloadStatus status) {
|
||||
setDownloadHint(mPackageViewModel.getGameUpdateLiveData().getValue());
|
||||
}
|
||||
|
||||
private void setDownloadHint(List<GameUpdateEntity> updateList) {
|
||||
int updateSize = 0;
|
||||
for (GameUpdateEntity updateEntity : PackageManager.INSTANCE.getUpdateList()) {
|
||||
if (updateEntity.isShowPlugin(PluginLocation.only_index)) updateSize++;
|
||||
if (updateList != null) {
|
||||
for (GameUpdateEntity updateEntity : updateList) {
|
||||
if (updateEntity.isShowPlugin(PluginLocation.only_index)) updateSize++;
|
||||
}
|
||||
}
|
||||
int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size();
|
||||
if (downloadSize != 0) {
|
||||
|
||||
@ -15,7 +15,6 @@ import com.gh.gamecenter.entity.GameUpdateEntity
|
||||
import com.gh.gamecenter.install.PackageRepository.gameInstalled
|
||||
import com.gh.gamecenter.install.PackageRepository.gameUpdate
|
||||
import com.gh.gamecenter.manager.FilterManager
|
||||
import com.gh.gamecenter.manager.InstallManager
|
||||
import com.gh.gamecenter.manager.PackageManager
|
||||
import com.gh.gamecenter.retrofit.ObservableUtil
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
@ -30,6 +29,11 @@ import retrofit2.HttpException
|
||||
/**
|
||||
* 游戏更新以及可插件化的数据统一放在 [gameUpdate] 由 [GameUpdateEntity.isPluggable] 字段区分
|
||||
* 已安装的应用列表[gameInstalled] 存在一个包对应多个游戏问题,如果需要一对一过滤可参考[PackageViewModel.filterSameApk]
|
||||
*
|
||||
* 注意:View不能直接在该类对数据进行 新增/删除/修改/查询 操作
|
||||
* 新增/删除/修改 可以委托 [PackageViewModel] 进行
|
||||
* 查询操作统一由 [PackageManager] 处理
|
||||
*
|
||||
*/
|
||||
object PackageRepository {
|
||||
|
||||
@ -57,8 +61,6 @@ object PackageRepository {
|
||||
|
||||
val list = PackageUtils.getAllPackageName(mApplication)
|
||||
|
||||
PackageManager.initData(list)
|
||||
|
||||
filterPackers(list)
|
||||
|
||||
uploadAppList()
|
||||
@ -82,7 +84,7 @@ object PackageRepository {
|
||||
* 忽略非合法数据
|
||||
*/
|
||||
private fun filterPackers(list: MutableList<String>) {
|
||||
// 忽略特定的包 todo 去除这个包的目的?
|
||||
// 忽略特定的包
|
||||
list.remove(Constants.XPOSED_INSTALLER_PACKAGE_NAME)
|
||||
|
||||
// 忽略非助手收录的包 todo 必须先获取接口数据 否则无法此次操作失败(bug)
|
||||
@ -104,8 +106,8 @@ object PackageRepository {
|
||||
private fun loadInstalledGameDigestAndNotifyData(list: ArrayList<String>) {
|
||||
var isNotifyUpdate = false
|
||||
val latch = ObservableUtil.latch(list.size, {
|
||||
if (isNotifyUpdate) gameUpdateLiveData.postValue(gameUpdate)
|
||||
gameInstalledLiveData.postValue(gameInstalled)
|
||||
if (isNotifyUpdate) notifyGameUpdateData()
|
||||
notifyGameInstallData()
|
||||
}, Any())
|
||||
|
||||
for (pkgName in list) {
|
||||
@ -128,7 +130,6 @@ object PackageRepository {
|
||||
gameInfo.gameIcon = game.icon
|
||||
gameInfo.packageName = pkgName
|
||||
gameInfo.gameName = game.name
|
||||
InstallManager.getInstance().updateByEntity(gameInfo)
|
||||
}
|
||||
}
|
||||
latch.countDown()
|
||||
@ -149,7 +150,6 @@ object PackageRepository {
|
||||
private fun checkGameUpdate(game: GameEntity): Boolean {
|
||||
val updateList = PackageUtils.isCanUpdate(getApplication(), game)
|
||||
if (updateList.size > 0) {
|
||||
PackageManager.addUpdateList(updateList)
|
||||
for (updateEntity in updateList) {
|
||||
addUpdateOrPluggable(updateEntity)
|
||||
}
|
||||
@ -172,7 +172,6 @@ object PackageRepository {
|
||||
&& !PackageUtils.isSignature(getApplication(), apk.packageName)) {
|
||||
val updateEntity = GameUtils.getGameUpdateEntity(game, apk)
|
||||
addUpdateOrPluggable(updateEntity)
|
||||
PackageManager.addUpdate(updateEntity)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -214,7 +213,7 @@ object PackageRepository {
|
||||
for (game in gameUpdate) {
|
||||
if (game.packageName == pkgName) {
|
||||
gameUpdate.remove(game)
|
||||
gameUpdateLiveData.postValue(gameUpdate)
|
||||
notifyGameUpdateData()
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -223,20 +222,22 @@ object PackageRepository {
|
||||
var i = 0
|
||||
while (i < gameInstalled.size) {
|
||||
val game = gameInstalled[i]
|
||||
var isExistInstall = false
|
||||
val packageMap = game.packageMap
|
||||
for (key in packageMap.keys) {
|
||||
if (key == pkgName) {
|
||||
packageMap[pkgName] = false
|
||||
}
|
||||
if (packageMap[key]!!) isExistInstall = true
|
||||
}
|
||||
if (!isExistInstall) {
|
||||
if (game.packageName == pkgName) {
|
||||
gameInstalled.remove(game)
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
notifyGameInstallData()
|
||||
}
|
||||
|
||||
private fun notifyGameInstallData() {
|
||||
PackageManager.initGameInstall(gameInstalled)
|
||||
gameInstalledLiveData.postValue(gameInstalled)
|
||||
}
|
||||
|
||||
private fun notifyGameUpdateData() {
|
||||
PackageManager.initGameUpdate(gameUpdate)
|
||||
gameUpdateLiveData.postValue(gameUpdate)
|
||||
}
|
||||
}
|
||||
@ -6,8 +6,6 @@ import android.arch.lifecycle.MutableLiveData
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import android.text.TextUtils
|
||||
import com.gh.common.util.PackageUtils
|
||||
import com.gh.gamecenter.entity.GameInfoEntity
|
||||
import com.gh.gamecenter.entity.GameInstall
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity
|
||||
import com.halo.assistant.HaloApp
|
||||
@ -36,27 +34,17 @@ class PackageViewModel(application: Application,
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤同包名游戏,按原顺序排序
|
||||
* 过滤同包名游戏,取最后一个
|
||||
* @return
|
||||
*/
|
||||
fun filterSameApk(installedList: List<GameInstall>?): ArrayList<GameInfoEntity> {
|
||||
val list = ArrayList<GameInfoEntity>()
|
||||
fun filterSameApk(installedList: List<GameInstall>?): ArrayList<GameInstall> {
|
||||
val map = HashMap<String, GameInstall>()
|
||||
if (installedList != null) {
|
||||
for (gameInstall in installedList) {
|
||||
for ((key, value) in gameInstall.packageMap) {
|
||||
if (value) {
|
||||
val info = GameInfoEntity()
|
||||
info.id = gameInstall.id
|
||||
info.packageName = key
|
||||
info.isSignature = PackageUtils.isSignature(getApplication(), key)
|
||||
info.installTime = PackageUtils.getInstalledTime(getApplication(), key)
|
||||
list.add(info)
|
||||
}
|
||||
|
||||
}
|
||||
map[gameInstall.packageName] = gameInstall
|
||||
}
|
||||
}
|
||||
return list
|
||||
return ArrayList(map.values)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,6 +52,7 @@ class PackageViewModel(application: Application,
|
||||
* 网络状态变更时调用
|
||||
*/
|
||||
fun checkInstallData() {
|
||||
|
||||
}
|
||||
|
||||
class Factory : ViewModelProvider.NewInstanceFactory() {
|
||||
|
||||
@ -1,78 +1,40 @@
|
||||
package com.gh.gamecenter.manager
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.support.v4.util.ArrayMap
|
||||
import android.text.TextUtils
|
||||
import com.gh.gamecenter.entity.GameInstall
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.util.*
|
||||
|
||||
object PackageManager {
|
||||
|
||||
private const val UPDATE_WHAT = 0
|
||||
private const val PLUGIN_WHAT = 1
|
||||
|
||||
private val mHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
private var updateAndPluginList = ArrayList<GameUpdateEntity>()
|
||||
private var installedMap = ArrayMap<String, Boolean>()
|
||||
private var installedList = ArrayList<String>()
|
||||
private val updateAndPluginList = ArrayList<GameUpdateEntity>()
|
||||
private val installedList = ArrayList<GameInstall>()
|
||||
|
||||
/**
|
||||
* 获取更新列表数量
|
||||
*
|
||||
* @return 更新列表数量
|
||||
*/
|
||||
val updateListSize: Int
|
||||
get() = getUpdateList().size
|
||||
val updateListSize: Int get() = updateAndPluginList.size
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* 初始化更新列表
|
||||
*
|
||||
* @param list 已安装包名list
|
||||
* @param list 更新列表
|
||||
*/
|
||||
fun initData(list: ArrayList<String>) {
|
||||
installedMap = ArrayMap()
|
||||
installedList = ArrayList()
|
||||
for (packageName in list) {
|
||||
installedMap[packageName] = true
|
||||
installedList.add(packageName)
|
||||
}
|
||||
fun initGameUpdate(list: ArrayList<GameUpdateEntity>) {
|
||||
updateAndPluginList.clear()
|
||||
updateAndPluginList.addAll(list)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据包名 判断是否安装该游戏
|
||||
*
|
||||
* @param packageName 包名
|
||||
* @return true 已安装 false 未安装
|
||||
*/
|
||||
fun isInstalled(packageName: String): Boolean {
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return false
|
||||
}
|
||||
val b = getInstalledMap()[packageName]
|
||||
return b != null
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已安装游戏map
|
||||
* 初始化已安装列表
|
||||
*
|
||||
* @return 已安装游戏map
|
||||
* @param list 已安装列表数据
|
||||
*/
|
||||
fun getInstalledMap(): ArrayMap<String, Boolean> {
|
||||
return installedMap
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除一个已安装的游戏
|
||||
*
|
||||
* @param packageName 包名
|
||||
*/
|
||||
fun removeInstalled(packageName: String) {
|
||||
getInstalledMap().remove(packageName)
|
||||
getInstalledList().remove(packageName)
|
||||
fun initGameInstall(list: ArrayList<GameInstall>) {
|
||||
installedList.clear()
|
||||
installedList.addAll(list)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,20 +42,11 @@ object PackageManager {
|
||||
*
|
||||
* @return 包名list
|
||||
*/
|
||||
fun getInstalledList(): ArrayList<String> {
|
||||
@JvmStatic
|
||||
fun getInstalledList(): ArrayList<GameInstall> {
|
||||
return installedList
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个已安装的游戏
|
||||
*
|
||||
* @param packageName 包名
|
||||
*/
|
||||
fun addInstalled(packageName: String) {
|
||||
getInstalledMap()[packageName] = true
|
||||
getInstalledList().add(packageName)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可更新游戏列表
|
||||
*
|
||||
@ -103,6 +56,24 @@ object PackageManager {
|
||||
return updateAndPluginList
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据包名 判断是否安装该游戏
|
||||
*
|
||||
* @param packageName 包名
|
||||
* @return true 已安装 false 未安装
|
||||
*/
|
||||
fun isInstalled(packageName: String): Boolean {
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return false
|
||||
}
|
||||
for (gameInstall in installedList) {
|
||||
if (gameInstall.packageName == packageName) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断包名是否可以更新
|
||||
*
|
||||
@ -110,7 +81,7 @@ object PackageManager {
|
||||
* @return true 可以更新 false 不可以更新
|
||||
*/
|
||||
fun isCanUpdate(gameId: String?, packageName: String?): Boolean {
|
||||
for (entity in getUpdateList()) {
|
||||
for (entity in updateAndPluginList) {
|
||||
if (!entity.isPluggable && entity.packageName == packageName && entity.id == gameId) {
|
||||
return true
|
||||
}
|
||||
@ -118,78 +89,6 @@ object PackageManager {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个更新
|
||||
*
|
||||
* @param game 游戏
|
||||
*/
|
||||
fun addUpdate(game: GameUpdateEntity) {
|
||||
if (!isContain(game.id, game.packageName)) {
|
||||
getUpdateList().add(game)
|
||||
postEventBusMessage(game.isPluggable)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加多个更新
|
||||
*
|
||||
* @param game 游戏
|
||||
*/
|
||||
fun addUpdateList(game: List<GameUpdateEntity>) {
|
||||
for (updateEntity in game) {
|
||||
if (!isContain(updateEntity.id, updateEntity.packageName)) {
|
||||
getUpdateList().add(updateEntity)
|
||||
postEventBusMessage(updateEntity.isPluggable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看更新列表中是否包含该游戏对应的包名
|
||||
*
|
||||
* @param gameId 游戏id
|
||||
* @param packageName 包名
|
||||
* @return true 包含 false 不包含
|
||||
*/
|
||||
fun isContain(gameId: String?, packageName: String?): Boolean {
|
||||
for (entity in updateAndPluginList) {
|
||||
if (entity.packageName == packageName && entity.id == gameId) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 在特定位置添加一个更新
|
||||
*
|
||||
* @param index 位置
|
||||
* @param game 游戏
|
||||
*/
|
||||
fun addUpdate(index: Int, game: GameUpdateEntity) {
|
||||
if (!isContain(game.id, game.packageName)) {
|
||||
getUpdateList().add(index, game)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据包名删除一个更新
|
||||
*
|
||||
* @param packageName 包名
|
||||
*/
|
||||
fun removeUpdate(packageName: String) {
|
||||
var i = 0
|
||||
while (i < updateAndPluginList.size) {
|
||||
val entity = updateAndPluginList[i]
|
||||
if (packageName == entity.packageName) {
|
||||
updateAndPluginList.removeAt(i)
|
||||
postEventBusMessage(entity.isPluggable)
|
||||
i--
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断包名是否可以插件化
|
||||
*/
|
||||
@ -201,21 +100,4 @@ object PackageManager {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 对数据(更新/插件化)增删需要发送消息
|
||||
private fun postEventBusMessage(isPluggable: Boolean) {
|
||||
// 防止短时间内重复发送
|
||||
if (isPluggable) {
|
||||
mHandler.removeMessages(PLUGIN_WHAT)
|
||||
} else {
|
||||
mHandler.removeMessages(UPDATE_WHAT)
|
||||
}
|
||||
mHandler.postDelayed({
|
||||
if (isPluggable) {
|
||||
EventBus.getDefault().post(EBDownloadStatus("plugin"))
|
||||
} else {
|
||||
EventBus.getDefault().post(EBDownloadStatus("update"))
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ public class UpdateManager {
|
||||
gameUpdateEntity.setUrl(appEntity.getUrl());
|
||||
gameUpdateEntity.setPlatform("官方版");
|
||||
gameUpdateEntity.setId(mContext.getString(R.string.ghzs_id));
|
||||
PackageManager.INSTANCE.addUpdate(0, gameUpdateEntity);
|
||||
// PackageManager.INSTANCE.addUpdate(0, gameUpdateEntity); // todo 直接添加?
|
||||
|
||||
if (isCheck) {
|
||||
if (appEntity.isForce()) {
|
||||
|
||||
@ -12,7 +12,6 @@ import com.gh.gamecenter.entity.ApkEntity
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.GameInfoEntity
|
||||
import com.gh.gamecenter.manager.GameManager
|
||||
import com.gh.gamecenter.manager.InstallManager
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.halo.assistant.HaloApp
|
||||
@ -39,8 +38,7 @@ class InstallGameViewModel(application: Application) : AndroidViewModel(applicat
|
||||
|
||||
fun initInstalledData() {
|
||||
val sortList = ArrayList<GameInfoEntity>()
|
||||
val cManager = InstallManager(getApplication())
|
||||
val installedGame = cManager.allInstall
|
||||
val installedGame = ArrayList<InstallInfo>()
|
||||
if (installedGame.isEmpty()) {
|
||||
gameEntity.postValue(null)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user