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.ReserveDialogFragment; import com.gh.common.exposure.ExposureEvent; import com.gh.common.exposure.ExposureUtils; import com.gh.common.repository.ReservationRepository; import com.gh.download.DownloadManager; import com.gh.download.dialog.DownloadDialog; 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.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.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)); } else if ("appointment".equals(gameEntity.getReserveStatus())) { // 已预约 holder.gameDownloadBtn.setVisibility(View.VISIBLE); holder.gameDownloadBtn.setText("已预约"); holder.gameDownloadBtn.setTextColor(Color.WHITE); holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_dn); } } public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, boolean isShowPlatform) { updateItem(context, gameEntity, holder, isShowPlatform, PluginLocation.only_game, false); } public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, boolean isShowPlatform, boolean hideDownloadBtnIfNoAvailableContent) { updateItem(context, gameEntity, holder, isShowPlatform, PluginLocation.only_game, hideDownloadBtnIfNoAvailableContent); } public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, boolean isShowPlatform, PluginLocation pluginLocation, boolean hideDownloadBtnIfNoAvailableContent) { // 控制是否显示下载按钮 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()) { holder.gameDes.setVisibility(View.VISIBLE); holder.gameProgressbar.setVisibility(View.GONE); holder.gameInfo.setVisibility(View.GONE); 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(); holder.gameDes.setVisibility(View.VISIBLE); holder.gameProgressbar.setVisibility(View.GONE); holder.gameInfo.setVisibility(View.GONE); 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 { 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); } else { updatePluginItem(context, holder, gameEntity, isShowPlatform, pluginLocation); } } // 更新正常的条目,只有一个apk包 static void updateNormalItem(Context context, GameViewHolder holder, GameEntity gameEntity, boolean isShowPlatform, PluginLocation pluginLocation) { 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) { // 更改进度条和提示文本的状态 changeStatus(context, holder, downloadEntity, isShowPlatform, true); return; } } GameUtils.setDownloadBtnStatus(context, gameEntity, holder.gameDownloadBtn, pluginLocation); holder.gameDes.setVisibility(View.VISIBLE); holder.gameProgressbar.setVisibility(View.GONE); holder.gameInfo.setVisibility(View.GONE); } // 更新插件的条目,有多个apk包 private static void updatePluginItem(Context context, GameViewHolder holder, GameEntity gameEntity, boolean isShowPlatform, PluginLocation pluginLocation) { 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; } } holder.gameDes.setVisibility(View.VISIBLE); holder.gameProgressbar.setVisibility(View.GONE); holder.gameInfo.setVisibility(View.GONE); } // 更改进度条和提示文本的状态 public static void changeStatus(Context context, GameViewHolder holder, DownloadEntity downloadEntity, boolean isShowPlatform, boolean isNormal) { holder.gameDes.setVisibility(View.GONE); holder.gameProgressbar.setVisibility(View.VISIBLE); holder.gameInfo.setVisibility(View.VISIBLE); 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)) { 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); } } } } 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) { if (gameEntity.isReservable()) { if (!ReservationRepository.thisGameHasBeenReserved(gameEntity.getId())) { downloadBtn.setOnClickListener(v -> { CheckLoginUtils.checkLogin(context, entrance, () -> { if (clickCallback != null) { clickCallback.onCallback(); } PermissionHelper.checkReadPhoneStatePermissionBeforeAction(context, () -> { ReserveDialogFragment dialogFragment = ReserveDialogFragment.getInstance( gameEntity, () -> { LogUtils.logReservation(gameEntity, traceEvent); adapter.notifyItemChanged(position); } ); dialogFragment.show(((AppCompatActivity) context).getSupportFragmentManager(), "reserve"); }); }); }); } else { downloadBtn.setOnClickListener(v -> { if (clickCallback != null) { clickCallback.onCallback(); } if ("download".equals(gameEntity.getReserveStatus())) { ReservationHelper.showDeleteReservationDialog(context, () -> { ReservationHelper.deleteReservation(gameEntity, () -> { adapter.notifyItemChanged(position); }); }); } else { ReservationHelper.showCancelReservationDialog(context, () -> { ReservationHelper.cancelReservation(gameEntity, () -> { adapter.notifyItemChanged(position); }); }); } }); } return; } if (gameEntity.getApk().size() == 0 && gameEntity.getH5Link() != null) { downloadBtn.setOnClickListener(v -> { MtaHelper.onEvent("H5页面", "入口", "列表页_" + gameEntity.getName()); Intent i = WebActivity.getIntentForWebGame(context, gameEntity.getH5Link().getLink(), gameEntity.getName(), "play".equals(gameEntity.getH5Link().getType())); context.startActivity(i); }); } else if (gameEntity.getApk().size() == 1) { downloadBtn.setOnClickListener(v -> { EmptyCallback clickRunnable = () -> { if (clickCallback != null) { clickCallback.onCallback(); } onNormalClick(context, downloadBtn, gameEntity, position, adapter, entrance, location, traceEvent); }; // 启动不需要请求存储权限 if (downloadBtn.getText().toString().equals(context.getString(R.string.launch))) { clickRunnable.onCallback(); } else { PermissionHelper.checkStoragePermissionBeforeAction(context, clickRunnable); } }); } else { downloadBtn.setOnClickListener(v -> { if (clickCallback != null) { clickCallback.onCallback(); } PermissionHelper.checkStoragePermissionBeforeAction(context, () -> { CertificationDialog.showCertificationDialog(context, gameEntity, () -> { DialogUtils.showVersionNumberDialog(context, gameEntity, () -> { DownloadDialog.showDownloadDialog( v.getContext(), gameEntity, 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); } 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) { String str = downloadBtn.getText().toString(); ApkEntity apk = gameEntity.getApk().get(0); if (str.equals(context.getString(R.string.download))) { // 先弹下载弹窗(如果需要的话) DownloadDialogHelper.findAvailableDialogAndShow(context, gameEntity, apk, () -> { CertificationDialog.showCertificationDialog(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))) { DownloadDialogHelper.findAvailableDialogAndShow(context, gameEntity, apk, () -> { CertificationDialog.showCertificationDialog(context, gameEntity, () -> { DialogUtils.showVersionNumberDialog(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, 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))) { install(context, gameEntity, position, adapter); } else if (str.equals(context.getString(R.string.launch))) { 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()); } else if (str.equals(context.getString(R.string.waiting)) || str.equals(context.getString(R.string.downloading))) { context.startActivity(DownloadManagerActivity.getDownloadMangerIntent(context, apk.getUrl(), entrance + "+(" + location.split(":")[0] + ")")); } 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)); }); } } //下载 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, "下载开始", "下载"); ExposureEvent downloadExposureEvent = ExposureUtils.logADownloadExposureEvent(gameEntity, gameEntity.getApk().get(0).getPlatform(), traceEvent, ExposureUtils.DownloadType.DOWNLOAD); DownloadManager.createDownload(context, gameEntity, context.getString(R.string.download), entrance, location, isSubscribe, downloadExposureEvent); 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, "下载开始", "插件化"); ExposureEvent downloadExposureEvent = ExposureUtils.logADownloadExposureEvent(gameEntity, gameEntity.getApk().get(0).getPlatform(), traceEvent, ExposureUtils.DownloadType.PLUGIN_DOWNLOAD); DownloadManager.createDownload(context, gameEntity, "插件化", entrance, location, isSubscribe, downloadExposureEvent); 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) { 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()); } adapter.notifyItemChanged(position); } else if (PackageUtils.isCanPluggable(apkEntity)) { DialogUtils.showPluginDialog(context, () -> context.startActivity(PackageUtils.getUninstallIntent(context, path))); } else { PackageUtils.launchSetup(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); ExposureUtils.DownloadType downloadType = ExposureUtils.getUpdateType(apkEntity); DataUtils.onGameUpdateEvent(context, gameEntity.getName(), apkEntity.getPlatform(), "下载开始"); ExposureEvent downloadExposureEvent = ExposureUtils.logADownloadExposureEvent(gameEntity, apkEntity .getPlatform(), traceEvent, downloadType); DownloadManager.createDownload(context, gameEntity, "更新", entrance, location, isSubscribe, downloadExposureEvent); } }