diff --git a/app/src/main/java/com/gh/common/provider/AppProviderImpl.kt b/app/src/main/java/com/gh/common/provider/AppProviderImpl.kt index c6b3069776..74f8c677c0 100644 --- a/app/src/main/java/com/gh/common/provider/AppProviderImpl.kt +++ b/app/src/main/java/com/gh/common/provider/AppProviderImpl.kt @@ -21,6 +21,10 @@ class AppProviderImpl : IAppProvider { return HaloApp.getInstance().gid ?: "" } + override fun refreshGid() { + HaloApp.getInstance().refreshGid() + } + override fun getOaid(): String { return HaloApp.getInstance().oaid ?: "" } 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 4ac8603d0e..f2738b1f95 100644 --- a/app/src/main/java/com/gh/common/simulator/SimulatorDownloadManager.kt +++ b/app/src/main/java/com/gh/common/simulator/SimulatorDownloadManager.kt @@ -18,10 +18,7 @@ import com.gh.gamecenter.common.base.TrackableDialog import com.gh.gamecenter.common.constant.Constants import com.gh.gamecenter.common.utils.* import com.gh.gamecenter.core.AppExecutor.uiExecutor -import com.gh.gamecenter.core.utils.DisplayUtils -import com.gh.gamecenter.core.utils.MtaHelper -import com.gh.gamecenter.core.utils.SpeedUtils -import com.gh.gamecenter.core.utils.ToastUtils +import com.gh.gamecenter.core.utils.* import com.gh.gamecenter.entity.ApkEntity import com.gh.gamecenter.entity.SimulatorEntity import com.gh.gamecenter.entity.TrackableEntity @@ -118,53 +115,59 @@ class SimulatorDownloadManager private constructor() { fun showDownloadDialog(context: Context?, simulator: SimulatorEntity?, location: SimulatorLocation, gameId: String = "", gameName: String = "", cancelCallback: (() -> Unit)? = null) { if (context == null) return + mContextRef = WeakReference(context) this.simulatorLocation = location this.simulator = simulator this.gameId = gameId this.gameName = gameName - //判断是否隐藏 - if (simulator?.active == false) { - showNoneEmulatorDialog(context) - return - } - val isInstalled = PackageUtils.isInstalledFromAllPackage(context, simulator?.apk?.packageName) - val versionFromInstalledApp = PackageUtils.getVersionNameByPackageName(simulator?.apk?.packageName) - val shouldShowUpdate = Version(simulator?.apk?.version).isHigherThan(versionFromInstalledApp) - val title = if (shouldShowUpdate && isInstalled) "更新模拟器" else "安装模拟器" - val message = if (shouldShowUpdate && isInstalled) "检测到模拟器存在更高版本,是否前往更新" else "模拟器游戏需要先下载安装对应的模拟器,才可以运行" - val positiveText = if (shouldShowUpdate && isInstalled) "更新(${simulator?.apk?.size})" else "下载(${simulator?.apk?.size})" - val negativeText = if (shouldShowUpdate && isInstalled) "下次再说" else "取消" - downloadType = if (shouldShowUpdate && isInstalled) "update" else "download" - val trackableEntity = TrackableEntity("模拟器下载", - key = if (shouldShowUpdate && isInstalled) "更新弹窗" else "下载弹窗", - logShowEvent = true - ) - DialogHelper.showDialog( - context, - title, - message, - positiveText, - negativeText, - trackMtaEvent = true, - cancelClickCallback = { - if (shouldShowUpdate && isInstalled) { - cancelCallback?.invoke() - MtaHelper.onEvent(trackableEntity.event, trackableEntity.key, "点击下次再说") + PermissionHelper.checkGetInstalledAppsListBeforeAction(context, object : EmptyCallback { + override fun onCallback() { + //判断是否隐藏 + if (simulator?.active == false) { + showNoneEmulatorDialog(context) + return } - }, - confirmClickCallback = { - showDownloadingDialog(context, simulator) - MtaHelper.onEvent( - trackableEntity.event, - trackableEntity.key, - if (shouldShowUpdate && isInstalled) "点击更新" else "点击下载" + val isInstalled = PackageUtils.isInstalledFromAllPackage(context, simulator?.apk?.packageName) + val versionFromInstalledApp = PackageUtils.getVersionNameByPackageName(simulator?.apk?.packageName) + val shouldShowUpdate = Version(simulator?.apk?.version).isHigherThan(versionFromInstalledApp) + val title = if (shouldShowUpdate && isInstalled) "更新模拟器" else "安装模拟器" + val message = if (shouldShowUpdate && isInstalled) "检测到模拟器存在更高版本,是否前往更新" else "模拟器游戏需要先下载安装对应的模拟器,才可以运行" + val positiveText = if (shouldShowUpdate && isInstalled) "更新(${simulator?.apk?.size})" else "下载(${simulator?.apk?.size})" + val negativeText = if (shouldShowUpdate && isInstalled) "下次再说" else "取消" + downloadType = if (shouldShowUpdate && isInstalled) "update" else "download" + + val trackableEntity = TrackableEntity("模拟器下载", + key = if (shouldShowUpdate && isInstalled) "更新弹窗" else "下载弹窗", + logShowEvent = true ) - }, - mtaEvent = trackableEntity.event, mtaKey = trackableEntity.key, - extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true) - ) + DialogHelper.showDialog( + context, + title, + message, + positiveText, + negativeText, + trackMtaEvent = true, + cancelClickCallback = { + if (shouldShowUpdate && isInstalled) { + cancelCallback?.invoke() + MtaHelper.onEvent(trackableEntity.event, trackableEntity.key, "点击下次再说") + } + }, + confirmClickCallback = { + showDownloadingDialog(context, simulator) + MtaHelper.onEvent( + trackableEntity.event, + trackableEntity.key, + if (shouldShowUpdate && isInstalled) "点击更新" else "点击下载" + ) + }, + mtaEvent = trackableEntity.event, mtaKey = trackableEntity.key, + extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true) + ) + } + }) } private fun showDownloadingDialog(context: Context, simulator: SimulatorEntity?) { diff --git a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.kt b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.kt index 28da3fb1f8..3fd1bcfb62 100644 --- a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.kt +++ b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.kt @@ -1,6 +1,5 @@ package com.gh.gamecenter -import android.Manifest import android.content.Context import android.content.Intent import android.content.SharedPreferences @@ -63,8 +62,6 @@ class SplashScreenActivity : BaseActivity() { private var mViewModel: SplashScreenViewModel? = null private val mPermissions = arrayOf( - Manifest.permission.WRITE_EXTERNAL_STORAGE, - Manifest.permission.READ_EXTERNAL_STORAGE, PermissionHelper.PERMISSION_GET_INSTALLED_LIST ) @@ -160,6 +157,8 @@ class SplashScreenActivity : BaseActivity() { // 恢复畅玩数据 VHelper.recoverVDataIfPossible() + requestPermission() + // 检查是否有旧版本光环,有就删掉 AppExecutor.ioExecutor.execute { deleteOutdatedUpdatePackage() } if (mStartMainActivityDirectly) { @@ -379,10 +378,10 @@ class SplashScreenActivity : BaseActivity() { private fun checkAndRequestPermission() { if (EasyPermissions.hasPermissions(this, *mPermissions)) { // 恢复畅玩数据 - VHelper.recoverVDataIfPossible() +// VHelper.recoverVDataIfPossible() // 检查是否有旧版本光环,有就删掉 - AppExecutor.ioExecutor.execute { deleteOutdatedUpdatePackage() } +// AppExecutor.ioExecutor.execute { deleteOutdatedUpdatePackage() } if (mStartMainActivityDirectly) { if (com.gh.gamecenter.common.BuildConfig.BUILD_TIME != 0L) { showGitLogDialogIfNeeded() diff --git a/app/src/main/java/com/gh/gamecenter/game/doublecard/DoubleCardListAdapter.kt b/app/src/main/java/com/gh/gamecenter/game/doublecard/DoubleCardListAdapter.kt index a71b3b0fb8..9ae6d78a40 100644 --- a/app/src/main/java/com/gh/gamecenter/game/doublecard/DoubleCardListAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/game/doublecard/DoubleCardListAdapter.kt @@ -5,10 +5,13 @@ import android.graphics.Color import android.graphics.drawable.GradientDrawable import android.view.ViewGroup import com.gh.common.exposure.ExposureEvent -import com.gh.gamecenter.core.utils.StringUtils import com.gh.gamecenter.GameDetailActivity import com.gh.gamecenter.common.base.BaseRecyclerViewHolder -import com.gh.gamecenter.common.utils.* +import com.gh.gamecenter.common.utils.dip2px +import com.gh.gamecenter.common.utils.display +import com.gh.gamecenter.common.utils.goneIf +import com.gh.gamecenter.common.utils.toBinding +import com.gh.gamecenter.core.utils.StringUtils import com.gh.gamecenter.databinding.GameDoubleCardItemBinding import com.gh.gamecenter.entity.GameEntity import com.gh.gamecenter.entity.SubjectEntity @@ -64,7 +67,7 @@ class DoubleCardListAdapter( root.setOnClickListener { GameDetailActivity.startGameDetailActivity( mContext, - gameEntity, + gameEntity.id, StringUtils.buildString("(游戏-专题:", mSubjectEntity.name, "-列表[", (position + 1).toString(), "])"), traceEvent = exposureEventList?.get(position) ) diff --git a/app/src/main/java/com/halo/assistant/HaloApp.java b/app/src/main/java/com/halo/assistant/HaloApp.java index a14163b5b9..94efa6e4c5 100644 --- a/app/src/main/java/com/halo/assistant/HaloApp.java +++ b/app/src/main/java/com/halo/assistant/HaloApp.java @@ -125,6 +125,10 @@ public class HaloApp extends MultiDexApplication { return mGid; } + public void refreshGid() { + DataUtils.getGid(); + } + public void setLocalTemporaryDeviceId(String key) { mTemporaryLocalDeviceId = key; } diff --git a/module_common/src/main/java/com/gh/gamecenter/common/utils/PermissionHelper.kt b/module_common/src/main/java/com/gh/gamecenter/common/utils/PermissionHelper.kt index 695cd6f2b3..6cbe6c7f85 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/utils/PermissionHelper.kt +++ b/module_common/src/main/java/com/gh/gamecenter/common/utils/PermissionHelper.kt @@ -10,6 +10,7 @@ import android.content.pm.PermissionInfo import android.net.Uri import android.os.Build import android.provider.Settings +import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.fragment.app.FragmentActivity import com.alibaba.android.arouter.launcher.ARouter @@ -17,6 +18,7 @@ import com.gh.gamecenter.common.R import com.gh.gamecenter.common.constant.Constants import com.gh.gamecenter.common.constant.RouteConsts import com.gh.gamecenter.core.provider.IActivationProvider +import com.gh.gamecenter.core.provider.IAppProvider import com.gh.gamecenter.core.provider.IDirectProvider import com.gh.gamecenter.core.utils.EmptyCallback import com.gh.gamecenter.core.utils.SPUtils @@ -34,10 +36,10 @@ object PermissionHelper { @SuppressLint("CheckResult") @JvmStatic fun checkGetInstalledAppsListBeforeAction( - context: FragmentActivity, + context: Context, emptyCallback: EmptyCallback ) { - if (isGetInstalledListPermissionDisabled(context)) { + if (context is AppCompatActivity && isGetInstalledListPermissionDisabled(context)) { showDialogBeforeRequestingGetInstalledListDialog(context, emptyCallback) } else { emptyCallback.onCallback() @@ -97,6 +99,9 @@ object PermissionHelper { permission.granted -> { emptyCallback.onCallback() SPUtils.setBoolean(Constants.SP_USER_HAS_PERMANENTLY_DENIED_STORAGE_PERMISSION, false) + + // 获得存储权限后刷新 gid 避免下载仍需实名 + (ARouter.getInstance().build(RouteConsts.provider.app).navigation() as? IAppProvider)?.refreshGid() } permission.shouldShowRequestPermissionRationale -> { // do nothing diff --git a/module_core/src/main/java/com/gh/gamecenter/core/provider/IAppProvider.kt b/module_core/src/main/java/com/gh/gamecenter/core/provider/IAppProvider.kt index ff25eb4c4d..1b66c4272c 100644 --- a/module_core/src/main/java/com/gh/gamecenter/core/provider/IAppProvider.kt +++ b/module_core/src/main/java/com/gh/gamecenter/core/provider/IAppProvider.kt @@ -8,6 +8,8 @@ interface IAppProvider : IProvider { fun getGid():String + fun refreshGid() + fun getOaid():String fun getChannel():String