package com.gh.common.util; import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.os.Message; import android.text.TextUtils; import android.view.View; import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.collection.ArrayMap; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import com.gh.common.constant.Config; import com.gh.common.dialog.CertificationDialog; import com.gh.common.dialog.DeviceRemindDialog; import com.gh.common.dialog.PackageCheckDialogFragment; import com.gh.common.dialog.ReserveDialogFragment; import com.gh.common.exposure.ExposureEvent; import com.gh.common.history.HistoryHelper; import com.gh.common.repository.ReservationRepository; import com.gh.common.simulator.SimulatorDownloadManager; import com.gh.common.simulator.SimulatorGameManager; import com.gh.common.xapk.XapkInstaller; import com.gh.common.xapk.XapkUnzipStatus; import com.gh.download.DownloadManager; import com.gh.download.dialog.DownloadDialog; import com.gh.download.server.BrowserInstallHelper; import com.gh.gamecenter.DownloadManagerActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.WebActivity; import com.gh.gamecenter.adapter.viewholder.GameViewHolder; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.LinkEntity; import com.gh.gamecenter.entity.PluginLocation; import com.gh.gamecenter.gamedetail.dialog.GamePermissionDialogFragment; import com.gh.gamecenter.manager.PackagesManager; import com.lightgame.download.DownloadConfig; import com.lightgame.download.DownloadEntity; import com.lightgame.download.DownloadStatus; import com.lightgame.download.FileUtils; import com.lightgame.utils.Utils; import java.io.File; import java.util.concurrent.LinkedBlockingQueue; /** * todo 下载判断不能以按钮文案为判断条件,否则按钮文案修改时又要修改判断逻辑 */ public class DownloadItemUtils { // 更新下载进度条 public static void processDate(Context context, GameEntity gameEntity, DownloadEntity downloadEntity, RecyclerView.Adapter adapter, int index) { if (!gameEntity.getId().equals(downloadEntity.getGameId())) { adapter.notifyItemChanged(index); return; } LinkedBlockingQueue queue = DownloadManager.getInstance(context).getQueue(downloadEntity.getName()); if (queue == null) { queue = new LinkedBlockingQueue<>(); DownloadManager.getInstance(context).putQueue(downloadEntity.getName(), queue); } String platform = downloadEntity.getPlatform(); ArrayMap entryMap = gameEntity.getEntryMap(); DownloadStatus status = downloadEntity.getStatus(); if (status.equals(DownloadStatus.pause) || status.equals(DownloadStatus.cancel) || status.equals(DownloadStatus.done)) { queue.remove(platform); if (entryMap == null) { entryMap = new ArrayMap<>(); gameEntity.setEntryMap(entryMap); } entryMap.put(platform, downloadEntity); adapter.notifyItemChanged(index); // if (!DownloadStatus.pause.equals(DownloadManager.getInstance(context).getStatus(downloadEntity.getUrl()))) { // adapter.notifyItemChanged(index); // } } else { if (!queue.contains(platform) && !TextUtils.isEmpty(platform)) { queue.offer(platform); if (AppDebugConfig.IS_DEBUG) { AppDebugConfig.logMethodWithParams(DownloadItemUtils.class, queue.size(), gameEntity.getBrief(), downloadEntity.getPlatform(), index); } // 有两个平台同时下载的时候启用 if (queue.size() == 2) { //TODO fuck this Message msg = Message.obtain(); msg.obj = downloadEntity.getName(); msg.what = DownloadConfig.DOWNLOAD_ROLL; DownloadManager.getInstance(context).sendMessageDelayed(msg, 3000); } } if (platform != null && platform.equals(queue.peek())) { if (entryMap == null) { entryMap = new ArrayMap<>(); gameEntity.setEntryMap(entryMap); } entryMap.put(platform, downloadEntity); if (!DownloadStatus.pause.equals(DownloadManager.getInstance(context).getStatus(downloadEntity.getUrl()))) { adapter.notifyItemChanged(index); } } } } // 下载按钮显示为查看,并且不提供下载功能 public static void updateItemWithViewOnlyStyle(GameViewHolder holder) { holder.gameDownloadBtn.setVisibility(View.VISIBLE); holder.gameDownloadBtn.setText("查看"); holder.gameDownloadBtn.setClickable(false); } // 根据预约状态更新下载按钮 public static void updateItemWithReserveStatus(GameViewHolder holder, GameEntity gameEntity) { if ("download".equals(gameEntity.getReserveStatus())) { // 已上线 // holder.gameDownloadBtn.setVisibility(View.VISIBLE); // holder.gameDownloadBtn.setText("已上线"); // holder.gameDownloadBtn.setTextColor(Color.WHITE); // holder.gameDownloadBtn.setBackground(ContextCompat.getDrawable(holder.gameDes.getContext(), R.drawable.game_item_btn_pause_dn)); updateItem(holder.gameDes.getContext(), gameEntity, holder, false); } else if ("appointment".equals(gameEntity.getReserveStatus())) { // 已预约 holder.gameDownloadBtn.setVisibility(View.VISIBLE); holder.gameDownloadBtn.setText("已预约"); holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(holder.gameDes.getContext(), R.color.aaaaaa)); holder.gameDownloadBtn.setBackgroundResource(R.drawable.button_round_f5f5f5); updateItemViewStatus(holder, false, null, null); } } public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, boolean isShowPlatform) { updateItem(context, gameEntity, holder, isShowPlatform, PluginLocation.only_game, false, null); } public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, boolean isShowPlatform, boolean hideDownloadBtnIfNoAvailableContent) { updateItem(context, gameEntity, holder, isShowPlatform, PluginLocation.only_game, hideDownloadBtnIfNoAvailableContent, null); } public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, boolean isShowPlatform, String briefStyle) { updateItem(context, gameEntity, holder, isShowPlatform, PluginLocation.only_game, false, briefStyle); } public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, boolean isShowPlatform, PluginLocation pluginLocation, boolean hideDownloadBtnIfNoAvailableContent, @Nullable String briefStyle) { // 控制是否显示下载按钮 if (!Config.isShowDownload(gameEntity.getId()) || context.getString(R.string.app_name).equals(gameEntity.getName())) { holder.gameDownloadBtn.setVisibility(View.GONE); } else { holder.gameDownloadBtn.setVisibility(View.VISIBLE); } // 显示预约 if (gameEntity.isReservable()) { updateItemViewStatus(holder, false, briefStyle, gameEntity.getColumnRecommend()); if (!ReservationRepository.thisGameHasBeenReserved(gameEntity.getId())) { holder.gameDownloadBtn.setText("预约"); holder.gameDownloadBtn.setTextColor(Color.WHITE); holder.gameDownloadBtn.setBackgroundResource(R.drawable.button_reserve); } else { holder.gameDownloadBtn.setText("已预约"); holder.gameDownloadBtn.setTextColor(Color.WHITE); holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_dn); } return; } if (gameEntity.getApk().isEmpty() || gameEntity.getDownloadOffStatus() != null) { LinkEntity h5LinkEntity = gameEntity.getH5Link(); String offStatus = gameEntity.getDownloadOffStatus(); updateItemViewStatus(holder, false, briefStyle, gameEntity.getColumnRecommend()); if (h5LinkEntity != null) { if ("play".equals(h5LinkEntity.getType())) { holder.gameDownloadBtn.setText("开始玩"); } else { holder.gameDownloadBtn.setText("查看"); } holder.gameDownloadBtn.setClickable(true); } else { if ("dialog".equals(offStatus)) { holder.gameDownloadBtn.setText("查看"); holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(context, R.color.white)); holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style); } else if ("updating".equals(offStatus)) { holder.gameDownloadBtn.setText("更新中"); holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(context, R.color.white)); holder.gameDownloadBtn.setBackgroundResource(R.drawable.download_button_updating_style); } else { holder.gameDownloadBtn.setText("暂无"); holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(context, R.color.button_gray)); holder.gameDownloadBtn.setBackgroundResource(R.drawable.news_detail_comment); if (hideDownloadBtnIfNoAvailableContent) { holder.gameDownloadBtn.setVisibility(View.GONE); } } holder.gameDownloadBtn.setClickable(false); } } else if (gameEntity.getApk().size() == 1) { updateNormalItem(context, holder, gameEntity, isShowPlatform, pluginLocation, briefStyle); } else { updatePluginItem(context, holder, gameEntity, isShowPlatform, pluginLocation, briefStyle); } } // 更新正常的条目,只有一个apk包 static void updateNormalItem(Context context, GameViewHolder holder, GameEntity gameEntity, boolean isShowPlatform, PluginLocation pluginLocation, String briefStyle) { final ArrayMap entryMap = gameEntity.getEntryMap(); final ApkEntity apkEntity = gameEntity.getApk().get(0); if (entryMap != null && !entryMap.isEmpty()) { DownloadEntity downloadEntity = entryMap.get(apkEntity.getPlatform()); if (downloadEntity != null) { if (ExtensionsKt.isSimulatorGame(downloadEntity)) { if (downloadEntity.getStatus() != DownloadStatus.done) { // 更改进度条和提示文本的状态 changeStatus(context, holder, downloadEntity, isShowPlatform, true); return; } } else { // 更改进度条和提示文本的状态 changeStatus(context, holder, downloadEntity, isShowPlatform, true); return; } } } GameUtils.setDownloadBtnStatus(context, gameEntity, holder.gameDownloadBtn, pluginLocation); updateItemViewStatus(holder, false, briefStyle, gameEntity.getColumnRecommend()); } // 更新插件的条目,有多个apk包 private static void updatePluginItem(Context context, GameViewHolder holder, GameEntity gameEntity, boolean isShowPlatform, PluginLocation pluginLocation, String briefStyle) { GameUtils.setDownloadBtnStatus(context, gameEntity, holder.gameDownloadBtn, pluginLocation); ArrayMap entryMap = gameEntity.getEntryMap(); if (entryMap != null && !entryMap.isEmpty()) { LinkedBlockingQueue queue = DownloadManager.getInstance(context).getQueue(gameEntity.getName()); DownloadEntity downloadEntity; if (queue != null && !queue.isEmpty()) { downloadEntity = entryMap.get(queue.peek()); } else { downloadEntity = entryMap.get(entryMap.keyAt(0)); } if (downloadEntity != null) { // 更改进度条和提示文本的状态 changeStatus(context, holder, downloadEntity, isShowPlatform, false); return; } } updateItemViewStatus(holder, false, briefStyle, gameEntity.getColumnRecommend()); } // 更改进度条和提示文本的状态 public static void changeStatus(Context context, GameViewHolder holder, DownloadEntity downloadEntity, boolean isShowPlatform, boolean isNormal) { updateItemViewStatus(holder, true, null, null); holder.gameProgressbar.setProgressDrawable(context.getResources().getDrawable(R.drawable.progressbar_bg_style)); String platform = PlatformUtils.getInstance(context).getPlatformName(downloadEntity.getPlatform()); DownloadStatus status = downloadEntity.getStatus(); if (status.equals(DownloadStatus.downloading)) { if (!DownloadStatus.pause.equals(DownloadManager.getInstance(context).getStatus(downloadEntity.getUrl()))) { holder.gameProgressbar.setProgress((int) (downloadEntity.getPercent() * 10)); if (isShowPlatform && platform != null) { holder.gameDownloadSpeed.setText(String.format("%s - %s(剩%s)", platform, SpeedUtils.getSpeed(downloadEntity.getSpeed()), SpeedUtils.getRemainTime(downloadEntity.getSize(), downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024))); } else { holder.gameDownloadSpeed.setText(String.format("%s(剩%s)", SpeedUtils.getSpeed(downloadEntity.getSpeed()), SpeedUtils.getRemainTime(downloadEntity.getSize(), downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024))); } holder.gameDownloadPercentage.setText(downloadEntity.getPercent() + "%"); } if (isNormal) { holder.gameDownloadBtn.setText(R.string.downloading); holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style); holder.gameDownloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style)); } } else if (status.equals(DownloadStatus.waiting)) { holder.gameProgressbar.setProgress((int) (downloadEntity.getPercent() * 10)); if (isShowPlatform && platform != null) { holder.gameDownloadSpeed.setText(String.format("%s - 等待", platform)); } else { holder.gameDownloadSpeed.setText("等待"); } holder.gameDownloadPercentage.setText(downloadEntity.getPercent() + "%"); if (isNormal) { holder.gameDownloadBtn.setText(R.string.downloading); holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style); holder.gameDownloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style)); } } else if (status.equals(DownloadStatus.pause) || status.equals(DownloadStatus.timeout) || status.equals(DownloadStatus.neterror) || status.equals(DownloadStatus.subscribe) || status.equals(DownloadStatus.overflow)) { holder.gameProgressbar.setProgress((int) (downloadEntity.getPercent() * 10)); if (isShowPlatform && platform != null) { holder.gameDownloadSpeed.setText(String.format("%s - 暂停", platform)); } else { holder.gameDownloadSpeed.setText("暂停"); } holder.gameDownloadPercentage.setText(downloadEntity.getPercent() + "%"); if (isNormal) { if (status.equals(DownloadStatus.waiting)) { holder.gameDownloadBtn.setText(R.string.waiting); } else { holder.gameDownloadBtn.setText(R.string.downloading); } holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style); holder.gameDownloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style)); } } else if (status.equals(DownloadStatus.done)) { String xapkStatus = downloadEntity.getMeta().get(XapkInstaller.XAPK_UNZIP_STATUS); if (XapkUnzipStatus.UNZIPPING.name().equals(xapkStatus)) { String percent = downloadEntity.getMeta().get(XapkInstaller.XAPK_UNZIP_PERCENT); holder.gameProgressbar.setProgressDrawable(context.getResources().getDrawable(R.drawable.progressbar_xapk_style)); holder.gameDownloadSpeed.setText(R.string.unzipping); holder.gameProgressbar.setProgress((int) (Float.valueOf(percent) * 10)); holder.gameDownloadPercentage.setText(percent + "%"); holder.gameDownloadBtn.setText(R.string.unzipping); return; } holder.gameProgressbar.setProgress(1000); if (isShowPlatform && platform != null) { holder.gameDownloadSpeed.setText(String.format("%s - 下载完成", platform)); } else { holder.gameDownloadSpeed.setText("下载完成"); } holder.gameDownloadPercentage.setText(R.string.hundred_percent); if (isNormal) { holder.gameDownloadBtn.setText(R.string.install); holder.gameDownloadBtn.setTextColor(Color.WHITE); if (downloadEntity.isPluggable() && PackagesManager.isInstalled(downloadEntity.getPackageName())) { holder.gameDownloadBtn.setBackgroundResource(R.drawable.download_button_pluggable_style); } else { holder.gameDownloadBtn.setBackgroundResource(R.drawable.download_button_normal_style); } } } } private static void updateItemViewStatus(GameViewHolder holder, boolean hasDownload, @Nullable String briefStyle, @Nullable LinkEntity recommendStyle) { if (hasDownload) { if (holder.gameRating != null) holder.gameRating.setVisibility(View.GONE); holder.gameDes.setVisibility(View.GONE); holder.gameProgressbar.setVisibility(View.VISIBLE); holder.gameInfo.setVisibility(View.VISIBLE); if (holder.recommendContainer != null) { holder.recommendContainer.setVisibility(View.GONE); } } else { holder.gameProgressbar.setVisibility(View.GONE); holder.gameInfo.setVisibility(View.GONE); // 推荐优先,有推荐内容时不执行下面的 star 和 brief 代码块 if (briefStyle != null && recommendStyle != null && briefStyle.contains("recommend")) { if (holder.recommendContainer != null) { holder.recommendContainer.setVisibility(View.VISIBLE); } if (holder.gameRating != null) holder.gameRating.setVisibility(View.GONE); holder.gameDes.setVisibility(View.GONE); holder.recommendTv.setText(recommendStyle.getText()); if ("none".equals(recommendStyle.getType())) { holder.recommendIv.setVisibility(View.GONE); } else { Context context = holder.recommendContainer.getContext(); int drawableId = context.getResources().getIdentifier( "ic_recommend_" + recommendStyle.getType(), "drawable", context.getPackageName()); holder.recommendIv.setVisibility(View.VISIBLE); holder.recommendIv.setImageResource(drawableId); } return; } else { if (holder.recommendContainer != null) { holder.recommendContainer.setVisibility(View.GONE); } } if (briefStyle != null && briefStyle.contains("star")) { if (holder.gameRating != null) holder.gameRating.setVisibility(View.VISIBLE); } else { if (holder.gameRating != null) holder.gameRating.setVisibility(View.GONE); } // 缺省情况下回落到游戏简介 if (TextUtils.isEmpty(briefStyle) || briefStyle.contains("brief") || briefStyle.contains("recommend")) { holder.gameDes.setVisibility(View.VISIBLE); } else { holder.gameDes.setVisibility(View.GONE); } } } public static void setOnClickListener(final Context context, final TextView downloadBtn, final GameEntity gameEntity, final int position, final RecyclerView.Adapter adapter, final String entrance, final String location) { setOnClickListener(context, downloadBtn, gameEntity, position, adapter, entrance, location, null); } public static void setOnClickListener(final Context context, final TextView downloadBtn, final GameEntity gameEntity, final int position, final RecyclerView.Adapter adapter, final String entrance, final String location, final ExposureEvent traceEvent) { setOnClickListener(context, downloadBtn, gameEntity, position, adapter, entrance, location, traceEvent, null); } /** * @param clickCallback 供那些需要知道点击回调的地方使用,触发具体响应才会回调 */ public static void setOnClickListener(final Context context, final TextView downloadBtn, final GameEntity gameEntity, final int position, final RecyclerView.Adapter adapter, final String entrance, final String location, final ExposureEvent traceEvent, @Nullable final EmptyCallback clickCallback) { setOnClickListener(context, downloadBtn, gameEntity, position, adapter, entrance, location, traceEvent, clickCallback, null, null); } /** * @param allStateClickCallback 供那些需要知道点击回调的地方使用,只要触发点击动作就会回调 */ public static void setOnClickListener(final Context context, final TextView downloadBtn, final GameEntity gameEntity, final int position, final RecyclerView.Adapter adapter, final String entrance, final String location, final ExposureEvent traceEvent, @Nullable final EmptyCallback clickCallback, @Nullable final EmptyCallback refreshCallback, @Nullable final EmptyCallback allStateClickCallback) { if (gameEntity.isReservable()) { if (!ReservationRepository.thisGameHasBeenReserved(gameEntity.getId())) { downloadBtn.setOnClickListener(v -> { if (allStateClickCallback != null) { allStateClickCallback.onCallback(); } CheckLoginUtils.checkLogin(context, entrance, () -> { if (clickCallback != null) { clickCallback.onCallback(); } ReserveDialogFragment dialogFragment = ReserveDialogFragment.getInstance( gameEntity, () -> { LogUtils.logReservation(gameEntity, traceEvent); if (adapter != null) { adapter.notifyItemChanged(position); } if (refreshCallback != null) { refreshCallback.onCallback(); } } ); dialogFragment.show(((AppCompatActivity) context).getSupportFragmentManager(), "reserve"); }); }); } else { downloadBtn.setOnClickListener(v -> { if (allStateClickCallback != null) { allStateClickCallback.onCallback(); } if (clickCallback != null) { clickCallback.onCallback(); } if ("download".equals(gameEntity.getReserveStatus())) { ReservationHelper.showDeleteReservationDialog(context, () -> { ReservationHelper.deleteReservation(gameEntity, () -> { if (adapter != null) { adapter.notifyItemChanged(position); } if (refreshCallback != null) { refreshCallback.onCallback(); } }); }); } else { ReservationHelper.showCancelReservationDialog(context, () -> { ReservationHelper.cancelReservation(gameEntity, () -> { if (adapter != null) { adapter.notifyItemChanged(position); } if (refreshCallback != null) { refreshCallback.onCallback(); } }); }); } }); } return; } if (gameEntity.getApk().size() == 0 && gameEntity.getH5Link() != null) { downloadBtn.setOnClickListener(v -> { if (allStateClickCallback != null) { allStateClickCallback.onCallback(); } MtaHelper.onEvent("H5页面", "入口", "列表页_" + gameEntity.getName()); LinkEntity linkEntity = gameEntity.getH5Link(); boolean isPlay = "play".equals(linkEntity.getType()); // 是否为开始玩 if (isPlay) { HistoryHelper.insertGameEntity(gameEntity); } Intent i = WebActivity.getIntentForWebGame(context, gameEntity.getH5Link().getLink(), gameEntity.getName(), isPlay, linkEntity.getCloseButton()); context.startActivity(i); }); } else if (gameEntity.getApk().size() == 1) { downloadBtn.setOnClickListener(v -> { EmptyCallback clickRunnable = () -> { if (allStateClickCallback != null) { allStateClickCallback.onCallback(); } if (clickCallback != null) { clickCallback.onCallback(); } onNormalClick(context, downloadBtn, gameEntity, position, adapter, entrance, location, traceEvent, refreshCallback); }; // 启动不需要请求存储权限 if (downloadBtn.getText().toString().equals(context.getString(R.string.launch))) { clickRunnable.onCallback(); } else { PermissionHelper.checkStoragePermissionBeforeAction(context, clickRunnable); } }); } else { downloadBtn.setOnClickListener(v -> { if (allStateClickCallback != null) { allStateClickCallback.onCallback(); } if (clickCallback != null) { clickCallback.onCallback(); } RealNameHelper.checkIfAuth(v.getContext(), gameEntity, () -> { GamePermissionDialogFragment.show((AppCompatActivity) context, gameEntity, gameEntity.getInfo(), () -> { PermissionHelper.checkStoragePermissionBeforeAction(context, () -> { CertificationDialog.showCertificationDialog(context, gameEntity, () -> { DialogUtils.showVersionNumberDialog(context, gameEntity, () -> { DownloadDialog.showDownloadDialog( v.getContext(), gameEntity, traceEvent, entrance, location); }); }); }); }); }); }); } } public static void onNormalClick(final Context context, final TextView downloadBtn, final GameEntity gameEntity, final int position, final RecyclerView.Adapter adapter, final String entrance, final String location) { onNormalClick(context, downloadBtn, gameEntity, position, adapter, entrance, location, null, null); } public static void onNormalClick(final Context context, final TextView downloadBtn, final GameEntity gameEntity, final int position, final RecyclerView.Adapter adapter, final String entrance, final String location, @Nullable final ExposureEvent traceEvent, @Nullable final EmptyCallback refreshCallback) { String str = downloadBtn.getText().toString(); if (gameEntity.getApk().isEmpty()) return; ApkEntity apk = ExtensionsKt.safelyGetInRelease(gameEntity.getApk(), 0); if (apk == null) return; if (str.equals(context.getString(R.string.download))) { // 先弹下载弹窗(如果需要的话) RealNameHelper.checkIfAuth(context, gameEntity, () -> { GamePermissionDialogFragment.show((AppCompatActivity) context, gameEntity, gameEntity.getInfo(), () -> { BrowserInstallHelper.showBrowserInstallHintDialog(context, () -> { PackageCheckDialogFragment.show((AppCompatActivity) context, gameEntity, () -> { DownloadDialogHelper.findAvailableDialogAndShow(context, gameEntity, apk, () -> { CertificationDialog.showCertificationDialog(context, gameEntity, () -> { DialogUtils.showOverseaDownloadDialog(context, gameEntity, () -> { DialogUtils.checkDownload(context, apk.getSize(), isSubscribe -> download(context, gameEntity, downloadBtn, entrance, location, isSubscribe, traceEvent)); }); }); }); }); }); }); }); DataLogUtils.uploadGameLog(context, gameEntity.getId(), gameEntity.getName(), entrance); } else if (str.equals(context.getString(R.string.attempt))) { RealNameHelper.checkIfAuth(context, gameEntity, () -> { GamePermissionDialogFragment.show((AppCompatActivity) context, gameEntity, gameEntity.getInfo(), () -> { BrowserInstallHelper.showBrowserInstallHintDialog(context, () -> { PackageCheckDialogFragment.show((AppCompatActivity) context, gameEntity, () -> { DownloadDialogHelper.findAvailableDialogAndShow(context, gameEntity, apk, () -> { CertificationDialog.showCertificationDialog(context, gameEntity, () -> { DialogUtils.showVersionNumberDialog(context, gameEntity, () -> { DialogUtils.showOverseaDownloadDialog(context, gameEntity, () -> { DialogUtils.checkDownload(context, apk.getSize(), isSubscribe -> download(context, gameEntity, downloadBtn, entrance, location, isSubscribe, traceEvent)); }); }); }); }); }); }); }); }); DataLogUtils.uploadGameLog(context, gameEntity.getId(), gameEntity.getName(), entrance); } else if (str.contains("化")) { if (entrance.contains("我的游戏")) { MtaHelper.onEvent("我的游戏_启动", "插件化", gameEntity.getName()); } if (gameEntity.getPluggableCollection() != null) { DownloadDialog.showDownloadDialog(context, gameEntity, traceEvent, entrance, location); } else { DownloadDialogHelper.findAvailableDialogAndShow(context, gameEntity, apk, () -> { CertificationDialog.showCertificationDialog(context, gameEntity, () -> { DialogUtils.checkDownload(context, apk.getSize(), isSubscribe -> plugin(context, gameEntity, downloadBtn, entrance, location, isSubscribe, traceEvent)); }); }); } } else if (str.equals(context.getString(R.string.install))) { DownloadEntity downloadEntity = SimulatorGameManager.findDownloadEntityByUrl(apk.getUrl()); if (gameEntity.getSimulator() != null) { boolean isInstalled = PackageUtils.isInstalledFromAllPackage(context, gameEntity.getSimulator().getApk().getPackageName()); if (downloadEntity != null && SimulatorGameManager.isSimulatorGame(gameEntity) && !isInstalled) { SimulatorDownloadManager.getInstance().showDownloadDialog(context, gameEntity.getSimulator(), SimulatorDownloadManager.SimulatorLocation.LAUNCH, gameEntity.getId(), gameEntity.getName(), null); return; } } install(context, gameEntity, position, adapter, refreshCallback); } else if (str.equals(context.getString(R.string.launch))) { //启动模拟器游戏 if (SimulatorGameManager.isSimulatorGame(gameEntity)) { DownloadEntity downloadEntity = SimulatorGameManager.findDownloadEntityByUrl(gameEntity.getApk().get(0).getUrl()); if (downloadEntity != null) { File file = new File(downloadEntity.getPath()); if (!file.exists()) { download(context, gameEntity, downloadBtn, entrance, location, false, traceEvent); return; } SimulatorGameManager.launchSimulatorGame(downloadEntity, gameEntity); } return; } if (entrance.contains("我的游戏")) { MtaHelper.onEvent("我的游戏_启动", "启动", gameEntity.getName()); } DataUtils.onGameLaunchEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), location); PackageUtils.launchApplicationByPackageName(context, gameEntity.getApk().get(0).getPackageName()); EnergyTaskHelper.postEnergyTask("play_game", gameEntity.getId(), gameEntity.getApk().get(0).getPackageName()); } else if (str.equals(context.getString(R.string.update))) { if (entrance.contains("我的游戏")) { MtaHelper.onEvent("我的游戏_启动", "更新", gameEntity.getName()); } DownloadDialogHelper.findAvailableDialogAndShow(context, gameEntity, apk, () -> { DialogUtils.checkDownload(context, apk.getSize(), isSubscribe -> update(context, gameEntity, entrance, location, isSubscribe, traceEvent)); }); } else { context.startActivity(DownloadManagerActivity.getDownloadMangerIntent(context, apk.getUrl(), entrance + "+(" + location.split(":")[0] + ")")); } } //下载 private static void download(Context context, GameEntity gameEntity, TextView downloadBtn, String entrance, String location, boolean isSubscribe, @Nullable ExposureEvent traceEvent) { String msg = FileUtils.isCanDownload(context, gameEntity.getApk().get(0).getSize()); if (TextUtils.isEmpty(msg)) { DataUtils.onGameDownloadEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), entrance, "下载开始", "下载"); DownloadManager.createDownload(context, gameEntity, context.getString(R.string.download), entrance, location, isSubscribe, traceEvent); Utils.toast(context, gameEntity.getName() + "已加入下载队列"); downloadBtn.setText(R.string.downloading); downloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style); downloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style)); DeviceRemindDialog.Companion.showDeviceRemindDialog(context, gameEntity); } else { Utils.toast(context, msg); } } //插件化 private static void plugin(Context context, GameEntity gameEntity, TextView downloadBtn, String entrance, String location, boolean isSubscribe, @Nullable ExposureEvent traceEvent) { String msg = FileUtils.isCanDownload(context, gameEntity.getApk().get(0).getSize()); if (TextUtils.isEmpty(msg)) { DataUtils.onGameDownloadEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), entrance, "下载开始", "插件化"); DownloadManager.createDownload(context, gameEntity, "插件化", entrance, location, isSubscribe, traceEvent); Utils.toast(context, gameEntity.getName() + "已加入下载队列"); downloadBtn.setText(R.string.downloading); downloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style); downloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style)); } else { Utils.toast(context, msg); } } //安装 private static void install(final Context context, GameEntity gameEntity, int position, RecyclerView.Adapter adapter, @Nullable final EmptyCallback refreshCallback) { ApkEntity apkEntity = gameEntity.getApk().get(0); DownloadEntity downloadEntity = DownloadManager.getInstance(context).getDownloadEntityByUrl(apkEntity.getUrl()); if (downloadEntity != null) { final String path = downloadEntity.getPath(); if (FileUtils.isEmptyFile(path)) { Utils.toast(context, R.string.install_failure_hint); DownloadManager.getInstance(context).cancel(downloadEntity.getUrl()); if (gameEntity.getEntryMap() != null) { gameEntity.getEntryMap().remove(apkEntity.getPlatform()); } if (adapter != null) { adapter.notifyItemChanged(position); } if (refreshCallback != null) { refreshCallback.onCallback(); } } else if (PackageUtils.isCanPluggable(apkEntity)) { DialogHelper.showPluginDialog(context, () -> { PackageInstaller.uninstall(context, path); return null; }); } else { PackageInstaller.install(context, downloadEntity); } } } //更新 private static void update(Context context, GameEntity gameEntity, String entrance, String location, boolean isSubscribe, @Nullable ExposureEvent traceEvent) { ApkEntity apkEntity = gameEntity.getApk().get(0); DataUtils.onGameUpdateEvent(context, gameEntity.getName(), apkEntity.getPlatform(), "下载开始"); DownloadManager.createDownload(context, gameEntity, "更新", entrance, location, isSubscribe, traceEvent); } }