From a6f9e120823655dfa89c9c7464100f2f46d40090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=8E=89=E4=B9=85?= <1484288157@qq.com> Date: Wed, 21 Oct 2020 17:16:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=89=E7=8E=AF=E5=8A=A9=E6=89=8BV4.4.0-?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1=E9=9C=80=E6=B1=82=EF=BC=88?= =?UTF-8?q?=E5=8D=95=E6=9C=BA=E6=A8=A1=E6=8B=9F=E5=99=A8=EF=BC=89(?= =?UTF-8?q?=E4=B8=80=E3=80=811=EF=BC=8C=E4=BA=8C)=20https://gitlab.ghzs.co?= =?UTF-8?q?m/pm/halo-app-issues/-/issues/1033?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gh/common/databind/BindingAdapters.java | 3 +- .../simulator/SimulatorDownloadManager.kt | 39 +++++++++++++++---- .../com/gh/common/util/DownloadItemUtils.java | 3 +- .../com/gh/common/util/DownloadObserver.kt | 4 +- .../java/com/gh/common/util/LogUtils.java | 7 ++-- .../adapter/viewholder/DetailViewHolder.java | 3 +- .../gh/gamecenter/entity/SimulatorEntity.kt | 2 + .../simulatorgame/SimulatorGameFragment.kt | 11 ++++-- .../simulatorgame/SimulatorGameListAdapter.kt | 18 ++++++--- .../SimulatorManagementAdapter.kt | 2 +- 10 files changed, 67 insertions(+), 25 deletions(-) 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 7971549aac..b35bdcc393 100644 --- a/app/src/main/java/com/gh/common/databind/BindingAdapters.java +++ b/app/src/main/java/com/gh/common/databind/BindingAdapters.java @@ -443,7 +443,8 @@ public class BindingAdapters { if (gameEntity.getSimulator() != null) { boolean isInstalled = PackageUtils.isInstalled(v.getContext(), gameEntity.getSimulator().getApk().getPackageName()); if (downloadEntity != null && SimulatorGameManager.isSimulatorGame(gameEntity) && !isInstalled) { - SimulatorDownloadManager.getInstance().showDownloadDialog(v.getContext(), gameEntity.getSimulator()); + SimulatorDownloadManager.getInstance().showDownloadDialog(v.getContext(), gameEntity.getSimulator(), + SimulatorDownloadManager.SimulatorLocation.LAUNCH, gameEntity.getId(), gameEntity.getName()); return; } } diff --git a/app/src/main/java/com/gh/common/simulator/SimulatorDownloadManager.kt b/app/src/main/java/com/gh/common/simulator/SimulatorDownloadManager.kt index 33ad04f69d..4d4b70d380 100644 --- a/app/src/main/java/com/gh/common/simulator/SimulatorDownloadManager.kt +++ b/app/src/main/java/com/gh/common/simulator/SimulatorDownloadManager.kt @@ -35,9 +35,14 @@ class SimulatorDownloadManager private constructor() { private var appProgressPercent: TextView? = null private var appProgressFilling: View? = null private var appProgressAnchor: View? = null - private var downloadDialog: Dialog? = null + private var simulatorLocation: SimulatorLocation? = null + private var simulator: SimulatorEntity? = null + private var gameId: String = "" + private var gameName: String = "" + private var downloadType: String = "" + private val dataWatcher = object : DataWatcher() { override fun onDataChanged(downloadEntity: DownloadEntity?) { if (downloadEntity?.isSimulatorDownload() == true) { @@ -63,9 +68,10 @@ class SimulatorDownloadManager private constructor() { appProgressPercent?.text = if (downloadEntity.percent != 100.0) "${downloadEntity.percent}%" else "100%" when { DownloadStatus.done == downloadEntity.status -> { + val locationStr = if (simulatorLocation == SimulatorLocation.LAUNCH) "${simulatorLocation?.value}《${gameName}》" else simulatorLocation?.value + LogUtils.uploadSimulatorDownload("simulator_download_complete", simulator?.id, downloadEntity.name, gameId, locationStr, downloadType) DownloadManager.getInstance(HaloApp.getInstance().application).cancel(downloadEntity.url, false, true) downloadDialog?.dismiss() - } DownloadStatus.neterror == downloadEntity.status -> { ToastUtils.showToast("网络不稳定,下载任务已暂停") @@ -84,7 +90,15 @@ class SimulatorDownloadManager private constructor() { } } - fun showDownloadDialog(context: Context, simulator: SimulatorEntity?) { + fun showDownloadDialog(context: Context, simulator: SimulatorEntity?, location: SimulatorLocation) { + showDownloadDialog(context, simulator, location, "", "") + } + + fun showDownloadDialog(context: Context, simulator: SimulatorEntity?, location: SimulatorLocation, gameId: String = "", gameName: String = "") { + this.simulatorLocation = location + this.simulator = simulator + this.gameId = gameId + this.gameName = gameName //判断是否隐藏 if (simulator?.active == false) { showNoneEmulatorDialog(context) @@ -107,6 +121,9 @@ class SimulatorDownloadManager private constructor() { }, { showDownloadingDialog(context, simulator) MtaHelper.onEvent(trackableEntity.event, trackableEntity.key, if (shouldShowUpdate && isInstalled) "点击更新" else "点击下载") + val locationStr = if (location == SimulatorLocation.LAUNCH) "${location.value}《${gameName}》" else location.value + downloadType = if (shouldShowUpdate && isInstalled) "update" else "download" + LogUtils.uploadSimulatorDownload("simulator_download", simulator?.id, simulator?.name, gameId, locationStr, downloadType) }) } @@ -134,16 +151,16 @@ class SimulatorDownloadManager private constructor() { view.findViewById(R.id.app_tv_cancel).setOnClickListener { DownloadManager.getInstance(context).cancel(simulator?.apk?.url) - MtaHelper.onEvent("模拟器下载”", "下载中弹窗", "点击关闭") + MtaHelper.onEvent("模拟器下载", "下载中弹窗", "点击关闭") downloadDialog?.dismiss() } downloadDialog?.setOnCancelListener { - MtaHelper.onEvent("模拟器下载”", "下载中弹窗", "点击空白") + MtaHelper.onEvent("模拟器下载", "下载中弹窗", "点击空白") } downloadDialog?.setOnKeyListener { _, keyCode, event -> if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) { - MtaHelper.onEvent("模拟器下载”", "下载中弹窗", "点击返回") + MtaHelper.onEvent("模拟器下载", "下载中弹窗", "点击返回") } false } @@ -162,7 +179,7 @@ class SimulatorDownloadManager private constructor() { createDownload(context, simulator) downloadDialog?.show() - MtaHelper.onEvent("模拟器下载”", "下载中弹窗", "出现弹窗") + MtaHelper.onEvent("模拟器下载", "下载中弹窗", "出现弹窗") } private fun showNoneEmulatorDialog(context: Context) { @@ -181,7 +198,6 @@ class SimulatorDownloadManager private constructor() { downloadEntity.path = getDownloadPath(simulator.name, apkEntity.format) downloadEntity.platform = apkEntity.getPlatform() downloadEntity.packageName = apkEntity.packageName - downloadEntity.gameId = simulator.id downloadEntity.versionName = apkEntity.version downloadEntity.addMetaExtra(Constants.EXTRA_DOWNLOAD_TYPE, Constants.SIMULATOR_DOWNLOAD) @@ -203,5 +219,12 @@ class SimulatorDownloadManager private constructor() { instance ?: SimulatorDownloadManager().also { instance = it } } } + + } + + enum class SimulatorLocation(val value: String) { + LAUNCH("启动"), + SIMULATOR_GAME("模拟器游戏"), + SIMULATOR_MANAGE("模拟器游戏-模拟器管理") } } \ No newline at end of file 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 ff3946dedd..376d6197c8 100644 --- a/app/src/main/java/com/gh/common/util/DownloadItemUtils.java +++ b/app/src/main/java/com/gh/common/util/DownloadItemUtils.java @@ -588,7 +588,8 @@ public class DownloadItemUtils { if (gameEntity.getSimulator() != null) { boolean isInstalled = PackageUtils.isInstalled(context, gameEntity.getSimulator().getApk().getPackageName()); if (downloadEntity != null && SimulatorGameManager.isSimulatorGame(gameEntity) && !isInstalled) { - SimulatorDownloadManager.getInstance().showDownloadDialog(context, gameEntity.getSimulator()); + SimulatorDownloadManager.getInstance().showDownloadDialog(context, gameEntity.getSimulator(), + SimulatorDownloadManager.SimulatorLocation.LAUNCH, gameEntity.getId(), gameEntity.getName()); return; } } diff --git a/app/src/main/java/com/gh/common/util/DownloadObserver.kt b/app/src/main/java/com/gh/common/util/DownloadObserver.kt index f757d78362..cc89ca1d6f 100644 --- a/app/src/main/java/com/gh/common/util/DownloadObserver.kt +++ b/app/src/main/java/com/gh/common/util/DownloadObserver.kt @@ -137,7 +137,9 @@ object DownloadObserver { if (gameEntity?.simulator != null) { val isInstalled = PackageUtils.isInstalled(HaloApp.getInstance().application, gameEntity.simulator!!.apk!!.packageName) if (!isInstalled) { - SimulatorDownloadManager.getInstance().showDownloadDialog(AppManager.getInstance().currentActivity(), gameEntity.simulator) + SimulatorDownloadManager.getInstance().showDownloadDialog(AppManager.getInstance().currentActivity(), gameEntity.simulator, + SimulatorDownloadManager.SimulatorLocation.LAUNCH, gameEntity.id, gameEntity.name + ?: "") } SimulatorGameManager.recordDownloadSimulatorGames(gameEntity.id) } diff --git a/app/src/main/java/com/gh/common/util/LogUtils.java b/app/src/main/java/com/gh/common/util/LogUtils.java index 897c2e73e6..ebb932c7a3 100644 --- a/app/src/main/java/com/gh/common/util/LogUtils.java +++ b/app/src/main/java/com/gh/common/util/LogUtils.java @@ -545,13 +545,12 @@ public class LogUtils { return metaObject; } - public static void uploadSimulatorDownload(String status, String id, String simulatorId, String simulatorName, String gameId, String location, String downloadType) { + public static void uploadSimulatorDownload(String event, String simulatorId, String simulatorName, String gameId, String location, String downloadType) { JSONObject object = new JSONObject(); JSONObject payload = new JSONObject(); try { - object.put("event", "simulator_download"); - object.put("status", status);// 取值有开始/完成 start/complete - object.put("id", id);//事件标识,同一次下载开始和完成取同一个值,可以通过这个id来查找同一次的下载任务 + object.put("event", event);// 取值有[开始, 完成] [simulator_download, simulator_download_complete] + object.put("id", simulatorId);//事件标识,同一次下载开始和完成取同一个值,可以通过这个id来查找同一次的下载任务 object.put("meta", getMetaObject()); object.put("timestamp", System.currentTimeMillis() / 1000); diff --git a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/DetailViewHolder.java b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/DetailViewHolder.java index b479d99a27..e577d504ec 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/viewholder/DetailViewHolder.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/viewholder/DetailViewHolder.java @@ -228,7 +228,8 @@ public class DetailViewHolder { if (mGameEntity.getSimulator() != null) { boolean isInstalled = PackageUtils.isInstalled(mViewHolder.context, mGameEntity.getSimulator().getApk().getPackageName()); if (downloadEntity != null && SimulatorGameManager.isSimulatorGame(mGameEntity) && !isInstalled) { - SimulatorDownloadManager.getInstance().showDownloadDialog(mViewHolder.context, mGameEntity.getSimulator()); + SimulatorDownloadManager.getInstance().showDownloadDialog(mViewHolder.context, mGameEntity.getSimulator(), + SimulatorDownloadManager.SimulatorLocation.LAUNCH, mGameEntity.getId(), mGameEntity.getName()); return; } } diff --git a/app/src/main/java/com/gh/gamecenter/entity/SimulatorEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/SimulatorEntity.kt index c18a0a0899..c1f894a51e 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/SimulatorEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/SimulatorEntity.kt @@ -11,6 +11,8 @@ data class SimulatorEntity( var active: Boolean = false, var name: String = "", var type: String = "", + @SerializedName("type_alias") + var typeAlias: String = "", @SerializedName("file_type") var fileType: List = listOf(), var apk: ApkEntity? = null diff --git a/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorGameFragment.kt b/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorGameFragment.kt index ff28236a06..17d5001d9c 100644 --- a/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorGameFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorGameFragment.kt @@ -10,9 +10,7 @@ import androidx.lifecycle.Observer import androidx.viewpager.widget.ViewPager import com.gh.base.adapter.FragmentAdapter import com.gh.base.fragment.BaseFragment_TabLayout -import com.gh.common.util.EntranceUtils -import com.gh.common.util.toColor -import com.gh.common.util.viewModelProvider +import com.gh.common.util.* import com.gh.common.view.TabIndicatorView import com.gh.gamecenter.R import com.gh.gamecenter.normal.NormalFragment @@ -31,6 +29,7 @@ class SimulatorGameFragment : NormalFragment() { private lateinit var mViewModel: SimulatorGameViewModel private var mFragmentsList = ArrayList() private var mTabTitleList = ArrayList() + private var mTypeAliasList = ArrayList() override fun getLayoutId() = R.layout.fragment_simulator_game @@ -50,6 +49,7 @@ class SimulatorGameFragment : NormalFragment() { super.onMenuItemClick(menuItem) if (menuItem.itemId == R.id.menu_simulator_manager) { startActivity(SimulatorManagementActivity.getIntent(requireContext())) + MtaHelper.onEvent("我的光环_新", "模拟器游戏", "点击模拟器管理") } } @@ -66,6 +66,7 @@ class SimulatorGameFragment : NormalFragment() { list.forEach { // mTabContainer.goneIf(list.size == 1) mTabTitleList.add(it.name) + mTypeAliasList.add(it.typeAlias) mFragmentsList.add(SimulatorGameListFragment().apply { with(bundleOf(EntranceUtils.KEY_SIMULATOR to it)) }) @@ -73,6 +74,10 @@ class SimulatorGameFragment : NormalFragment() { initViewPager() } }) + mViewPager.doOnPageSelected { + val typeAlias = mTypeAliasList[it] + MtaHelper.onEvent("我的光环_新", "模拟器游戏", "点击${typeAlias}") + } } private fun initViewPager() { diff --git a/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorGameListAdapter.kt b/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorGameListAdapter.kt index 4552290d82..bfc6b07c52 100644 --- a/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorGameListAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorGameListAdapter.kt @@ -84,6 +84,7 @@ class SimulatorGameListAdapter(context: Context, var simulator: SimulatorEntity, showOptionWindow() notifyDataSetChanged() mCurrentOption = OPTION_ALL_SELECT + MtaHelper.onEvent("我的光环_新", "模拟器游戏", "点击${simulator.typeAlias}+管理") } OPTION_ALL_SELECT -> { @@ -109,14 +110,16 @@ class SimulatorGameListAdapter(context: Context, var simulator: SimulatorEntity, setTextColor(if (shouldShowUpdate) R.color.theme.toColor() else R.color.text_999999.toColor()) if (shouldShowUpdate) { setOnClickListener { - SimulatorDownloadManager.getInstance().showDownloadDialog(context, simulator) + SimulatorDownloadManager.getInstance().showDownloadDialog(context, simulator, SimulatorDownloadManager.SimulatorLocation.SIMULATOR_GAME) + MtaHelper.onEvent("我的光环_新", "模拟器游戏", "点击${simulator.typeAlias}+更新模拟器") } } } else { text = "安装模拟器" setTextColor(R.color.theme.toColor()) setOnClickListener { - SimulatorDownloadManager.getInstance().showDownloadDialog(context, simulator) + SimulatorDownloadManager.getInstance().showDownloadDialog(context, simulator, SimulatorDownloadManager.SimulatorLocation.SIMULATOR_GAME) + MtaHelper.onEvent("我的光环_新", "模拟器游戏", "点击${simulator.typeAlias}+下载模拟器") } } } @@ -144,7 +147,8 @@ class SimulatorGameListAdapter(context: Context, var simulator: SimulatorEntity, DownloadItemUtils.updateItem(mContext, gameEntity, GameViewHolder(holder.binding.gameItemIncluded), true) optionsIv.setOnClickListener { - showSingleOptionWindow(optionsIv, gameEntity?.name ?: "", gameEntity?.icon ?: "") + showSingleOptionWindow(optionsIv, gameEntity?.name ?: "", gameEntity?.icon + ?: "") } root.setOnClickListener { @@ -180,6 +184,7 @@ class SimulatorGameListAdapter(context: Context, var simulator: SimulatorEntity, popWindow.dismiss() resetStatus() notifyDataSetChanged() + MtaHelper.onEvent("我的光环_新", "模拟器游戏", "点击${simulator.typeAlias}+管理+完成") } deleteItem.setOnClickListener { @@ -197,6 +202,7 @@ class SimulatorGameListAdapter(context: Context, var simulator: SimulatorEntity, SimulatorGameManager.deleteLocalGames(list) fragment.onLoadRefresh() } + MtaHelper.onEvent("我的光环_新", "模拟器游戏", "点击${simulator.typeAlias}+管理+删除游戏") } } } @@ -224,10 +230,12 @@ class SimulatorGameListAdapter(context: Context, var simulator: SimulatorEntity, popupWindow.dismiss() DialogUtils.showShortCutPermissionDialog(mContext) createShortcut(gameName, gameIcon) + MtaHelper.onEvent("我的光环_新", "模拟器游戏", "点击${gameName}+添加到桌面") } deleteGameItem.setOnClickListener { popupWindow.dismiss() + MtaHelper.onEvent("我的光环_新", "模拟器游戏", "点击${gameName}+删除游戏") DialogUtils.showNewAlertDialog(mContext, "删除游戏", "即将删除游戏记录和本地文件,是否确定删除", "取消", "确定", null) { SimulatorGameManager.deleteLocalGame(gameName) fragment.onLoadRefresh() @@ -256,13 +264,13 @@ class SimulatorGameListAdapter(context: Context, var simulator: SimulatorEntity, val shortcutManager = mContext.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager if (shortcutManager.isRequestPinShortcutSupported) { - var shortcutInfoIntent = Intent(mContext, MainActivity::class.java) + var shortcutInfoIntent = Intent(mContext, MainActivity::class.java) shortcutInfoIntent.run { action = Intent.ACTION_VIEW // putExtra(INTENT_TYPE, INTENT_H5_SHORTCUT) // putExtra(KEY_DATA, gameUrl) // putExtra(KEY_LANDSCAPE, mContext.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) - var info = ShortcutInfo.Builder(mContext, gameName) + var info = ShortcutInfo.Builder(mContext, gameName) .setIcon(Icon.createWithBitmap(first)) .setShortLabel(gameName).setIntent(this).build() // var shortcutCallbackIntent = PendingIntent.getBroadcast(linearLayout.context, 0, diff --git a/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorManagementAdapter.kt b/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorManagementAdapter.kt index 506c06d44c..5aa9476dd3 100644 --- a/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorManagementAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/simulatorgame/SimulatorManagementAdapter.kt @@ -31,7 +31,7 @@ class SimulatorManagementAdapter(context: Context) : ListAdapter