From 65a4de0e335547bbb4daea1f7e5852d6906ff423 Mon Sep 17 00:00:00 2001 From: kehaoyuan Date: Tue, 9 Oct 2018 17:48:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E6=8F=92=E4=BB=B6=E5=8C=96?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=98=BE=E7=A4=BA=EF=BC=88=E5=AE=8C=E6=88=90?= =?UTF-8?q?=EF=BC=89https://gitlab.ghzhushou.com/pm/halo-app-issues/issues?= =?UTF-8?q?/350#note=5F10980?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gh/common/constant/Config.java | 2 +- .../gh/common/databind/BindingAdapters.java | 7 +- .../gh/common/util/DetailDownloadUtils.java | 7 +- .../com/gh/common/util/DownloadItemUtils.java | 81 ++++--------------- .../java/com/gh/common/util/GameUtils.java | 16 ++-- .../download/GameUpdateFragmentAdapter.java | 11 ++- .../com/gh/gamecenter/entity/ApkEntity.kt | 4 +- .../gh/gamecenter/entity/GameUpdateEntity.kt | 2 +- .../fragment/SearchToolbarFragment.java | 12 ++- .../com/gh/gamecenter/game/GameViewModel.kt | 1 + .../fragment/game/GamePluginAdapter.java | 4 +- 11 files changed, 59 insertions(+), 88 deletions(-) diff --git a/app/src/main/java/com/gh/common/constant/Config.java b/app/src/main/java/com/gh/common/constant/Config.java index b7fcb7c100..a3130c6153 100644 --- a/app/src/main/java/com/gh/common/constant/Config.java +++ b/app/src/main/java/com/gh/common/constant/Config.java @@ -42,7 +42,7 @@ public class Config { public static final String UMENG_APPKEY = BuildConfig.UMENG_APPKEY; public static final String UMENG_MESSAGE_SECRET = BuildConfig.UMENG_MESSAGE_SECRET; public static final String BUGLY_APPID = BuildConfig.BUGLY_APPID; - public static final String PATCH_VERSION_NAME = BuildConfig.PATCH_VERSION_NAME; // 补丁包版本 对应关于->版本号 + public static final String PATCH_VERSION_NAME = BuildConfig.PATCH_VERSION_NAME; // 补丁包版本 对应关于->版本号 使用:PackageUtils.getPatchVersionName() // http://www.ghzs666.com/article/${articleId}.html public static final String URL_ARTICLE = "http://www.ghzs666.com/article/"; // TODO ghzs/ghzs666 统一 public static final String PATCHES = "patches"; diff --git a/app/src/main/java/com/gh/common/databind/BindingAdapters.java b/app/src/main/java/com/gh/common/databind/BindingAdapters.java index 3f12d64fbf..4b66186cdc 100644 --- a/app/src/main/java/com/gh/common/databind/BindingAdapters.java +++ b/app/src/main/java/com/gh/common/databind/BindingAdapters.java @@ -39,6 +39,7 @@ import com.gh.gamecenter.databinding.KaifuDetailItemRowBinding; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.KaiFuCalendarEntity; +import com.gh.gamecenter.entity.PluginLocation; import com.gh.gamecenter.eventbus.EBReuse; import com.gh.gamecenter.manager.PackageManager; import com.lightgame.download.DownloadEntity; @@ -315,15 +316,13 @@ public class BindingAdapters { progressBar.setText("暂无下载"); progressBar.setDownloadType(DownloadProgressBar.DownloadType.NONE); } else { - String status = GameUtils.getDownloadBtnText(progressBar.getContext(), gameEntity); + String status = GameUtils.getDownloadBtnText(progressBar.getContext(), gameEntity, PluginLocation.only_game); switch (status) { case "插件化": progressBar.setDownloadType(DownloadProgressBar.DownloadType.PLUGIN); break; case "打开": - if (gameEntity.getApk().size() == 1) { - status = "启动"; - } + case "启动": progressBar.setDownloadType(DownloadProgressBar.DownloadType.LAUNCH_OR_OPEN); break; default: diff --git a/app/src/main/java/com/gh/common/util/DetailDownloadUtils.java b/app/src/main/java/com/gh/common/util/DetailDownloadUtils.java index 42a1c11a8a..1fb22c6bc8 100644 --- a/app/src/main/java/com/gh/common/util/DetailDownloadUtils.java +++ b/app/src/main/java/com/gh/common/util/DetailDownloadUtils.java @@ -8,6 +8,7 @@ import com.gh.common.view.DownloadProgressBar; import com.gh.download.DownloadManager; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.DetailViewHolder; +import com.gh.gamecenter.entity.PluginLocation; import com.gh.gamecenter.manager.PackageManager; import com.lightgame.download.DownloadEntity; @@ -33,15 +34,13 @@ public class DetailDownloadUtils { viewHolder.mDownloadPb.setText(TextUtils.isEmpty(viewHolder.downloadOffText) ? "暂无下载" : viewHolder.downloadOffText); viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.NONE); } else { - String status = GameUtils.getDownloadBtnText(viewHolder.context, viewHolder.gameEntity); + String status = GameUtils.getDownloadBtnText(viewHolder.context, viewHolder.gameEntity, PluginLocation.only_game); switch (status) { case "插件化": viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.PLUGIN); break; case "打开": - if (viewHolder.gameEntity.getApk().size() == 1) { - status = "启动"; - } + case "启动": viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.LAUNCH_OR_OPEN); break; default: diff --git a/app/src/main/java/com/gh/common/util/DownloadItemUtils.java b/app/src/main/java/com/gh/common/util/DownloadItemUtils.java index d6626e6b3a..c3f68d3658 100644 --- a/app/src/main/java/com/gh/common/util/DownloadItemUtils.java +++ b/app/src/main/java/com/gh/common/util/DownloadItemUtils.java @@ -96,7 +96,13 @@ public class DownloadItemUtils { } } - public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, boolean isShowPlatform) { + public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, + boolean isShowPlatform) { + updateItem(context, gameEntity, holder, isShowPlatform, PluginLocation.only_game); + } + + public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, + boolean isShowPlatform, PluginLocation pluginLocation) { // 控制是否显示下载按钮 if (!Config.isShowDownload(gameEntity.getId()) || context.getString(R.string.app_name).equals(gameEntity.getName())) { @@ -120,17 +126,16 @@ public class DownloadItemUtils { holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(context, R.color.button_gray)); holder.gameDownloadBtn.setClickable(false); } else if (gameEntity.getApk().size() == 1) { - updateNormalItem(context, holder, gameEntity, isShowPlatform); + updateNormalItem(context, holder, gameEntity, isShowPlatform, pluginLocation); } else { -// updateNormalItem(context, holder, gameEntity, isShowPlatform); - updatePluginItem(context, holder, gameEntity, isShowPlatform); + updatePluginItem(context, holder, gameEntity, isShowPlatform, pluginLocation); } } // 更新正常的条目,只有一个apk包 static void updateNormalItem(Context context, GameViewHolder holder, GameEntity gameEntity, - boolean isShowPlatform) { + boolean isShowPlatform, PluginLocation pluginLocation) { final ArrayMap entryMap = gameEntity.getEntryMap(); final ApkEntity apkEntity = gameEntity.getApk().get(0); @@ -144,75 +149,21 @@ public class DownloadItemUtils { } } + GameUtils.setDownloadBtnStatus(context, gameEntity, holder.gameDownloadBtn, pluginLocation); + holder.gameDes.setVisibility(View.VISIBLE); holder.gameProgressbar.setVisibility(View.GONE); holder.gameInfo.setVisibility(View.GONE); - - holder.gameDownloadBtn.setTextColor(Color.WHITE); - - final String packageName = apkEntity.getPackageName(); - - if (gameEntity.isPluggable() && apkEntity.isShowPlugin(PluginLocation.only_game)) { - holder.gameDownloadBtn.setText(R.string.pluggable); - setwhat(context, holder, apkEntity, packageName); - } else if (PackageManager.INSTANCE.isInstalled(packageName)) { - if (PackageManager.INSTANCE.isCanUpdate(gameEntity.getId(), packageName)) { - holder.gameDownloadBtn.setText(R.string.update); - holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style); - } else { - Object gh_id = PackageUtils.getMetaData(context, packageName, "gh_id"); - if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0 - && !TextUtils.isEmpty(apkEntity.getGhVersion()) - && !PackageUtils.isSignature(context, packageName) - && apkEntity.isShowPlugin(PluginLocation.only_game)) { - holder.gameDownloadBtn.setText(R.string.pluggable); - setwhat(context, holder, apkEntity, packageName); - } else if (gh_id == null || gh_id.equals(gameEntity.getId())) { - holder.gameDownloadBtn.setText(R.string.launch); - holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(context, R.color.theme)); - holder.gameDownloadBtn.setBackgroundResource(R.drawable.detail_download_open_style); - } else { - holder.gameDownloadBtn.setText(R.string.download); - holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style); - } - } - } else { - holder.gameDownloadBtn.setText(R.string.download); - holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style); - } - } - - /** - * 这个干什么鬼? - * - * @param context - * @param holder - * @param apkEntity - * @param packageName - */ - public static void setwhat(Context context, GameViewHolder holder, ApkEntity apkEntity, String packageName) { - DownloadEntity downloadEntity = DownloadManager.getInstance(context).getDownloadEntityByPackageName(packageName); - if (downloadEntity == null || downloadEntity.getUrl().equals(apkEntity.getUrl())) { - holder.gameDownloadBtn.setClickable(true); - holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style); - } else { - holder.gameDownloadBtn.setClickable(false); - holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_up); - } } // 更新插件的条目,有多个apk包 - static void updatePluginItem(Context context, GameViewHolder holder, GameEntity gameEntity, - boolean isShowPlatform) { - - GameUtils.setDownloadBtnStatus(context, gameEntity, holder.gameDownloadBtn); + private static void updatePluginItem(Context context, GameViewHolder holder, GameEntity gameEntity, + boolean isShowPlatform, PluginLocation pluginLocation) { ArrayMap entryMap = gameEntity.getEntryMap(); if (entryMap != null && !entryMap.isEmpty()) { - - DownloadEntity downloadEntity; - LinkedBlockingQueue queue = DownloadManager.getInstance(context).getQueue(gameEntity.getName()); + DownloadEntity downloadEntity; if (queue != null && !queue.isEmpty()) { downloadEntity = entryMap.get(queue.peek()); } else { @@ -226,6 +177,8 @@ public class DownloadItemUtils { } } + GameUtils.setDownloadBtnStatus(context, gameEntity, holder.gameDownloadBtn, pluginLocation); + holder.gameDes.setVisibility(View.VISIBLE); holder.gameProgressbar.setVisibility(View.GONE); holder.gameInfo.setVisibility(View.GONE); diff --git a/app/src/main/java/com/gh/common/util/GameUtils.java b/app/src/main/java/com/gh/common/util/GameUtils.java index 628becc537..7534585f4c 100644 --- a/app/src/main/java/com/gh/common/util/GameUtils.java +++ b/app/src/main/java/com/gh/common/util/GameUtils.java @@ -47,13 +47,13 @@ public class GameUtils { /** * 设置下载按钮状态 */ - public static void setDownloadBtnStatus(Context context, GameEntity gameEntity, TextView downloadBtn) { - String status = getDownloadBtnText(context, gameEntity); + public static void setDownloadBtnStatus(Context context, GameEntity gameEntity, TextView downloadBtn, PluginLocation pluginLocation) { + String status = getDownloadBtnText(context, gameEntity, pluginLocation); downloadBtn.setTextColor(Color.WHITE); downloadBtn.setText(status); if ("插件化".equals(status)) { downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style); - } else if ("打开".equals(status)) { + } else if ("打开".equals(status) || "启动".equals(status)) { downloadBtn.setBackgroundResource(R.drawable.detail_downloading_normal_style); downloadBtn.setTextColor(ContextCompat.getColor(context, R.color.theme)); } else { @@ -64,7 +64,7 @@ public class GameUtils { /** * 获取下载按钮文案 */ - public static String getDownloadBtnText(Context context, GameEntity gameEntity) { + public static String getDownloadBtnText(Context context, GameEntity gameEntity, PluginLocation pluginLocation) { int doneCount = 0; // 下载完成数量 int pluginCount = 0; // 可插件化数量 int updateCount = 0; // 可更新数量 @@ -99,7 +99,7 @@ public class GameUtils { if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0 && !TextUtils.isEmpty(apkEntity.getGhVersion()) && !PackageUtils.isSignature(context, apkEntity.getPackageName()) - && apkEntity.isShowPlugin(PluginLocation.only_game)) { + && apkEntity.isShowPlugin(pluginLocation)) { pluginCount++; } else if (gh_id == null || gh_id.equals(gameEntity.getId())) { installCount++; @@ -113,7 +113,11 @@ public class GameUtils { } else if (updateCount != 0) { return "更新"; } else if (installCount != 0) { - return "打开"; + if (gameEntity.getApk().size() == 1) { + return "启动"; + } else { + return "打开"; + } } else { return "下载"; } diff --git a/app/src/main/java/com/gh/gamecenter/download/GameUpdateFragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/download/GameUpdateFragmentAdapter.java index 75c64ad04a..77be5c7da5 100644 --- a/app/src/main/java/com/gh/gamecenter/download/GameUpdateFragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/download/GameUpdateFragmentAdapter.java @@ -33,6 +33,7 @@ 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; @@ -188,7 +189,11 @@ class GameUpdateFragmentAdapter extends BaseRecyclerAdapter { public void init() { updateList.clear(); - updateList.addAll(PackageManager.INSTANCE.getUpdateList()); + for (GameUpdateEntity updateEntity : PackageManager.INSTANCE.getUpdateList()) { + if (updateEntity.isShowPlugin(PluginLocation.only_index)) { + updateList.add(updateEntity); + } + } sortUpdateList(updateList); initLocationMap(); @@ -247,7 +252,9 @@ class GameUpdateFragmentAdapter extends BaseRecyclerAdapter { private void processingData() { for (GameUpdateEntity updateEntity : PackageManager.INSTANCE.getUpdateList()) { - updateList.add(updateEntity); + if (updateEntity.isShowPlugin(PluginLocation.only_index)) { + updateList.add(updateEntity); + } } sortUpdateList(updateList); diff --git a/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.kt index 390348f23c..0f49afc2ef 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/ApkEntity.kt @@ -21,7 +21,7 @@ data class ApkEntity(@SerializedName("package") var isActive: Boolean = true, var force: Boolean = false, var apkLink: ApkLink? = null, - val plugin: String? = ""/*控制是否显示插件化 默认:open,取值有:open/only_index/only_game/close*/) : Parcelable { + var plugin: String? = ""/*控制是否显示插件化 默认:open,取值有:open/only_index/only_game/close*/) : Parcelable { fun getPlatform(): String? { if (TextUtils.isEmpty(platform)) { return "官方版" @@ -34,7 +34,7 @@ data class ApkEntity(@SerializedName("package") } fun isShowPlugin(location: PluginLocation): Boolean { - if ("open" == location.name || plugin == location.name) { + if (plugin.isNullOrEmpty() || "open" == location.name || plugin == location.name) { return true } return false diff --git a/app/src/main/java/com/gh/gamecenter/entity/GameUpdateEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/GameUpdateEntity.kt index 8fbc5bc98b..a658f5c62c 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/GameUpdateEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/GameUpdateEntity.kt @@ -24,7 +24,7 @@ data class GameUpdateEntity( var plugin: String? = "") { fun isShowPlugin(location: PluginLocation): Boolean { - if ("open" == location.name || plugin == location.name) { + if (plugin.isNullOrEmpty() || "open" == location.name || plugin == location.name) { return true } return false diff --git a/app/src/main/java/com/gh/gamecenter/fragment/SearchToolbarFragment.java b/app/src/main/java/com/gh/gamecenter/fragment/SearchToolbarFragment.java index 653921e0e7..ad89129e81 100644 --- a/app/src/main/java/com/gh/gamecenter/fragment/SearchToolbarFragment.java +++ b/app/src/main/java/com/gh/gamecenter/fragment/SearchToolbarFragment.java @@ -25,6 +25,8 @@ import com.gh.gamecenter.ConcernActivity; import com.gh.gamecenter.DownloadManagerActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.SearchActivity; +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.manager.PackageManager; @@ -189,7 +191,10 @@ public class SearchToolbarFragment extends BaseFragment implements View.OnClickL layoutParams.width = DisplayUtils.dip2px(getContext(), 20); } - int updateSize = PackageManager.INSTANCE.getUpdateListSize(); + int updateSize = 0; + for (GameUpdateEntity updateEntity : PackageManager.INSTANCE.getUpdateList()) { + if (updateEntity.isShowPlugin(PluginLocation.only_index)) updateSize++; + } int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size(); if (downloadSize != 0) { mDownloadHintTv.setVisibility(View.VISIBLE); @@ -259,7 +264,10 @@ public class SearchToolbarFragment extends BaseFragment implements View.OnClickL @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(EBDownloadStatus status) { - int updateSize = PackageManager.INSTANCE.getUpdateListSize(); + int updateSize = 0; + for (GameUpdateEntity updateEntity : PackageManager.INSTANCE.getUpdateList()) { + if (updateEntity.isShowPlugin(PluginLocation.only_index)) updateSize++; + } int downloadSize = DownloadManager.getInstance(getActivity()).getAll().size(); if (downloadSize != 0) { mDownloadHintTv.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/com/gh/gamecenter/game/GameViewModel.kt b/app/src/main/java/com/gh/gamecenter/game/GameViewModel.kt index d4530faab2..6f426aea09 100644 --- a/app/src/main/java/com/gh/gamecenter/game/GameViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/game/GameViewModel.kt @@ -99,6 +99,7 @@ class GameViewModel(application: Application, blockData: SubjectRecommendEntity? apkEntity.ghVersion = gameUpdateEntity.ghVersion apkEntity.setPlatform(gameUpdateEntity.platform!!) apkEntity.etag = gameUpdateEntity.etag + apkEntity.plugin = gameUpdateEntity.plugin val apk = java.util.ArrayList() apk.add(apkEntity) diff --git a/app/src/main/java/com/halo/assistant/fragment/game/GamePluginAdapter.java b/app/src/main/java/com/halo/assistant/fragment/game/GamePluginAdapter.java index eed4c232e3..c0a8c21242 100644 --- a/app/src/main/java/com/halo/assistant/fragment/game/GamePluginAdapter.java +++ b/app/src/main/java/com/halo/assistant/fragment/game/GamePluginAdapter.java @@ -15,6 +15,7 @@ import com.gh.gamecenter.GameDetailActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.GameNormalViewHolder; import com.gh.gamecenter.entity.GameEntity; +import com.gh.gamecenter.entity.PluginLocation; import com.lightgame.adapter.BaseRecyclerAdapter; import java.util.List; @@ -78,8 +79,7 @@ public class GamePluginAdapter extends BaseRecyclerAdapter { GamePluginAdapter.this, StringUtils.buildString("(游戏-专题:", "插件化", "-列表[", String.valueOf(1), "])"), StringUtils.buildString("游戏-专题-", "插件化", ":", gameEntity.getName())); - - DownloadItemUtils.updateItem(mContext, gameEntity, holder, !gameEntity.isPluggable()); + DownloadItemUtils.updateItem(mContext, gameEntity, holder, !gameEntity.isPluggable(), PluginLocation.only_index); } @Override