This commit is contained in:
@ -25,6 +25,7 @@ import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.common.retrofit.BiResponse;
|
||||
import com.gh.gamecenter.common.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.gh.vspace.VHelper;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
@ -328,7 +329,6 @@ public class Config {
|
||||
RetrofitManager.getInstance()
|
||||
.getVApi().getSettings(BuildConfig.VERSION_NAME)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new BiResponse<VSetting>() {
|
||||
@Override
|
||||
public void onSuccess(VSetting data) {
|
||||
|
||||
@ -382,7 +382,7 @@ public class BindingAdapters {
|
||||
return;
|
||||
}
|
||||
}
|
||||
VHelper.checkVSpaceBeforeAction(v.getContext(), gameEntity, () -> {
|
||||
VHelper.checkVSpaceBeforeAction(v.getContext(), gameEntity, true, () -> {
|
||||
GamePermissionDialogFragment.show((AppCompatActivity) v.getContext(), gameEntity, gameEntity.getInfo(), () -> {
|
||||
BrowserInstallHelper.showBrowserInstallHintDialog(v.getContext(), gameEntity.isVGame(), () -> {
|
||||
PackageCheckDialogFragment.show((AppCompatActivity) v.getContext(), gameEntity, () -> {
|
||||
|
||||
@ -701,7 +701,7 @@ object DownloadItemUtils {
|
||||
CertificationDialog.showCertificationDialog(context, gameEntity) {
|
||||
DialogUtils.showVersionNumberDialog(context, gameEntity) {
|
||||
DialogUtils.showOverseaDownloadDialog(context, gameEntity) {
|
||||
VHelper.checkVSpaceBeforeAction(context, gameEntity) {
|
||||
VHelper.checkVSpaceBeforeAction(context, gameEntity, true) {
|
||||
DialogUtils.checkDownload(context, apk.size) { isSubscribe: Boolean ->
|
||||
download(context, gameEntity, downloadBtn, entrance, location, isSubscribe, traceEvent)
|
||||
}
|
||||
|
||||
@ -16,8 +16,8 @@ import com.gh.gamecenter.common.eventbus.EBShowDialog
|
||||
import com.gh.gamecenter.common.retrofit.Response
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.core.utils.GsonUtils
|
||||
import com.gh.gamecenter.core.utils.StringUtils
|
||||
import com.gh.gamecenter.core.utils.MtaHelper
|
||||
import com.gh.gamecenter.core.utils.StringUtils
|
||||
import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.SimpleGameEntity
|
||||
@ -26,6 +26,7 @@ import com.gh.gamecenter.eventbus.EBDownloadStatus
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.gh.gamecenter.setting.GameDownloadSettingFragment
|
||||
import com.gh.gamecenter.suggest.SuggestType
|
||||
import com.gh.vspace.VHelper
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.lightgame.download.DataWatcher
|
||||
import com.lightgame.download.DownloadEntity
|
||||
@ -216,10 +217,20 @@ object DownloadObserver {
|
||||
)
|
||||
)
|
||||
downloadEntity.isPlugin -> Utils.toast(mApplication, downloadEntity.name + " - " + platform + " - 下载完成")
|
||||
else -> Utils.toast(mApplication, downloadEntity.name + " - 下载完成")
|
||||
else -> {
|
||||
if (downloadEntity.isSmoothGame()) {
|
||||
VHelper.showFloatingWindow(downloadEntity.packageName)
|
||||
} else {
|
||||
Utils.toast(mApplication, downloadEntity.name + " - 下载完成")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Utils.toast(mApplication, downloadEntity.name + " - 下载完成")
|
||||
if (downloadEntity.isSmoothGame()) {
|
||||
VHelper.showFloatingWindow(downloadEntity.packageName)
|
||||
} else {
|
||||
Utils.toast(mApplication, downloadEntity.name + " - 下载完成")
|
||||
}
|
||||
}
|
||||
if (!downloadEntity.isPluggable) {
|
||||
if (downloadEntity.isSimulatorGame()) {
|
||||
|
||||
@ -5,7 +5,6 @@ import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.gh.common.DefaultJsApi
|
||||
import com.gh.gamecenter.common.constant.Constants
|
||||
import com.gh.common.dialog.CertificationDialog
|
||||
import com.gh.common.exposure.ExposureEvent
|
||||
import com.gh.common.exposure.ExposureManager
|
||||
@ -13,29 +12,31 @@ import com.gh.common.exposure.ExposureSource
|
||||
import com.gh.common.exposure.ExposureType
|
||||
import com.gh.common.history.HistoryHelper
|
||||
import com.gh.common.repository.ReservationRepository
|
||||
import com.gh.gamecenter.core.runOnUiThread
|
||||
import com.gh.gamecenter.common.view.dsbridge.CompletionHandler
|
||||
import com.gh.download.DownloadManager
|
||||
import com.gh.download.dialog.DownloadDialog
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.WebActivity
|
||||
import com.gh.gamecenter.common.callback.ConfirmListener
|
||||
import com.gh.gamecenter.common.constant.Constants
|
||||
import com.gh.gamecenter.common.retrofit.ApiResponse
|
||||
import com.gh.gamecenter.common.retrofit.EmptyResponse
|
||||
import com.gh.gamecenter.common.retrofit.Response
|
||||
import com.gh.gamecenter.common.utils.DataLogUtils
|
||||
import com.gh.gamecenter.common.utils.DialogHelper
|
||||
import com.gh.gamecenter.common.utils.observableToMain
|
||||
import com.gh.gamecenter.common.utils.singleToMain
|
||||
import com.gh.gamecenter.common.utils.DialogHelper
|
||||
import com.gh.gamecenter.core.utils.*
|
||||
import com.gh.gamecenter.common.view.dsbridge.CompletionHandler
|
||||
import com.gh.gamecenter.core.runOnUiThread
|
||||
import com.gh.gamecenter.core.utils.EmptyCallback
|
||||
import com.gh.gamecenter.core.utils.SPUtils
|
||||
import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.entity.ApkEntity
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.PluginLocation
|
||||
import com.gh.gamecenter.gamedetail.dialog.GamePermissionDialogFragment
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.common.retrofit.EmptyResponse
|
||||
import com.gh.gamecenter.common.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.gh.gamecenter.teenagermode.TeenagerModeActivity
|
||||
import com.gh.gamecenter.common.retrofit.ApiResponse
|
||||
import com.gh.vspace.VHelper
|
||||
import com.gh.gamecenter.common.utils.DataLogUtils
|
||||
import com.lightgame.download.FileUtils
|
||||
|
||||
/**
|
||||
@ -190,7 +191,7 @@ object GameActivityDownloadHelper {
|
||||
}
|
||||
DataLogUtils.uploadGameLog(context, gameEntity.id, gameEntity.name, entrance)
|
||||
} else if (str == context.getString(R.string.smooth)) {
|
||||
VHelper.checkVSpaceBeforeAction(context, gameEntity) {
|
||||
VHelper.checkVSpaceBeforeAction(context, gameEntity, true) {
|
||||
GamePermissionDialogFragment.show((context as AppCompatActivity), gameEntity, gameEntity.info) {
|
||||
CertificationDialog.showCertificationDialog(context, gameEntity) {
|
||||
DialogUtils.checkDownload(context, apk.size) { isSubscribe: Boolean ->
|
||||
|
||||
@ -191,7 +191,7 @@ public class DetailViewHolder {
|
||||
case NORMAL:
|
||||
DataLogUtils.uploadGameLog(mViewHolder.context, mGameEntity.getId(), mGameEntity.getName(), mEntrance);
|
||||
case PLUGIN:
|
||||
VHelper.checkVSpaceBeforeAction(mViewHolder.context, mGameEntity, () -> {
|
||||
VHelper.checkVSpaceBeforeAction(mViewHolder.context, mGameEntity, true, () -> {
|
||||
GamePermissionDialogFragment.show((AppCompatActivity) mViewHolder.context, mGameEntity, mGameEntity.getInfo(), () -> {
|
||||
PermissionHelper.checkStoragePermissionBeforeAction(mViewHolder.context, () -> {
|
||||
if (mGameEntity.getApk().size() == 1) {
|
||||
|
||||
@ -1,25 +1,27 @@
|
||||
package com.gh.gamecenter.entity
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
class AppEntity {
|
||||
|
||||
var version: String? = null
|
||||
@Parcelize
|
||||
data class AppEntity(
|
||||
var version: String? = null,
|
||||
|
||||
@SerializedName("version_code")
|
||||
var versionCode: Int = 0
|
||||
var versionCode: Int = 0,
|
||||
|
||||
var url: String? = null
|
||||
var url: String? = null,
|
||||
|
||||
var size: String? = null
|
||||
var size: String? = null,
|
||||
|
||||
var content: String? = null
|
||||
var content: String? = null,
|
||||
|
||||
@SerializedName("force")
|
||||
var isForce: Boolean = false
|
||||
var isForce: Boolean = false,
|
||||
|
||||
@SerializedName("spare_link")
|
||||
var spareLink: String? = ""
|
||||
var spareLink: String? = "",
|
||||
|
||||
/**
|
||||
* NEVER(从不)
|
||||
@ -28,5 +30,7 @@ class AppEntity {
|
||||
* ONCE_A_DAY(每天一次)
|
||||
* EVERY_TIME_OPEN(每次打开)
|
||||
*/
|
||||
var alert: String? = null
|
||||
}
|
||||
var alert: String? = null,
|
||||
) : Parcelable
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package com.gh.gamecenter.retrofit.service
|
||||
|
||||
import com.gh.gamecenter.entity.AppEntity
|
||||
import com.gh.gamecenter.entity.VSetting
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Query
|
||||
@ -17,7 +16,7 @@ interface VApiService {
|
||||
@Query("version") version: String?,
|
||||
@Query("version_code") code: Int,
|
||||
@Query("package") packageName: String?
|
||||
): Observable<AppEntity>
|
||||
): Single<AppEntity>
|
||||
|
||||
/**
|
||||
* 获取设置
|
||||
|
||||
@ -5,6 +5,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
@ -18,6 +19,7 @@ import com.gh.download.PackageObserver
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.SplashScreenActivity
|
||||
import com.gh.gamecenter.common.constant.Constants
|
||||
import com.gh.gamecenter.common.retrofit.BiResponse
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.core.AppExecutor
|
||||
import com.gh.gamecenter.core.runOnIoThread
|
||||
@ -26,11 +28,13 @@ import com.gh.gamecenter.core.utils.EmptyCallback
|
||||
import com.gh.gamecenter.core.utils.GsonUtils
|
||||
import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.entity.ApkEntity
|
||||
import com.gh.gamecenter.entity.AppEntity
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity
|
||||
import com.gh.gamecenter.eventbus.EBPackage
|
||||
import com.gh.gamecenter.eventbus.EBReuse
|
||||
import com.gh.gamecenter.packagehelper.PackageRepository
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.lg.vspace.VirtualAppManager
|
||||
import com.lg.vspace.remote.listener.RemoteConnectListener
|
||||
@ -38,6 +42,7 @@ import com.lg.vspace.remote.model.AppInstallerInfo
|
||||
import com.lightgame.download.DownloadEntity
|
||||
import com.lightgame.utils.AppManager
|
||||
import com.lightgame.utils.Utils
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
object VHelper {
|
||||
@ -51,6 +56,8 @@ object VHelper {
|
||||
private val mInstallationLiveData by lazy { MutableLiveData<String>() }
|
||||
private var mLastSuccessfullyLaunchedGame: Pair<Long, String>? = null
|
||||
|
||||
private var mUpdateEntity: AppEntity? = null
|
||||
|
||||
private val mPackageObserver by lazy {
|
||||
PackageObserver.PackageChangeListener {
|
||||
val vaConfig = Config.getVSettingEntity()?.va ?: return@PackageChangeListener
|
||||
@ -77,6 +84,24 @@ object VHelper {
|
||||
&& PackageUtils.isInstalled(context, config.arch64?.packageName)
|
||||
) {
|
||||
connectService()
|
||||
|
||||
val installedVersionName =
|
||||
PackageUtils.getVersionNameByPackageName(config.arch64?.packageName)
|
||||
val installedVersionCode =
|
||||
PackageUtils.getVersionCodeByPackageName(config.arch64?.packageName)
|
||||
RetrofitManager.getInstance()
|
||||
.vApi
|
||||
.getPackageUpdate(
|
||||
installedVersionName,
|
||||
installedVersionCode,
|
||||
config.arch64?.packageName
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(object : BiResponse<AppEntity>() {
|
||||
override fun onSuccess(data: AppEntity) {
|
||||
mUpdateEntity = data
|
||||
}
|
||||
})
|
||||
}
|
||||
PackageObserver.registerPackageChangeChangeListener(mPackageObserver)
|
||||
}
|
||||
@ -85,8 +110,6 @@ object VHelper {
|
||||
* 连接服务
|
||||
*/
|
||||
private fun connectService(callbackClosure: (() -> Unit)? = null) {
|
||||
invokeVSpace()
|
||||
|
||||
mDelegateManager.connectService(object : RemoteConnectListener {
|
||||
override fun onServiceConnectionSuccessed() {
|
||||
Utils.log(LOG_TAG, "V 服务连接成功")
|
||||
@ -126,7 +149,7 @@ object VHelper {
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isInstalled(packageName: String?): Boolean {
|
||||
return mInstalledInfoList.any { it?.packageName == packageName }
|
||||
return mInstalledInfoList.any { it.packageName == packageName }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,9 +159,10 @@ object VHelper {
|
||||
fun checkVSpaceBeforeAction(
|
||||
context: Context,
|
||||
gameEntity: GameEntity?,
|
||||
requireStoragePermission: Boolean,
|
||||
callback: EmptyCallback
|
||||
) {
|
||||
checkVSpaceBeforeAction(context, gameEntity) {
|
||||
checkVSpaceBeforeAction(context, gameEntity, requireStoragePermission) {
|
||||
callback.onCallback()
|
||||
}
|
||||
}
|
||||
@ -155,10 +179,11 @@ object VHelper {
|
||||
&& System.currentTimeMillis() - timeOfLastSuccessfullyLaunchedGame < 5000
|
||||
&& !VFeedbackSuppressedSimpleDao().contains(gameIdOfLastSuccessfullyLaunchedGame)
|
||||
) {
|
||||
DownloadManager.getInstance().getDownloadEntitySnapshotByGameId(gameIdOfLastSuccessfullyLaunchedGame)?.let {
|
||||
VFeedbackDialogFragment.show(activity, toGameEntity(it))
|
||||
mLastSuccessfullyLaunchedGame = null
|
||||
}
|
||||
DownloadManager.getInstance()
|
||||
.getDownloadEntitySnapshotByGameId(gameIdOfLastSuccessfullyLaunchedGame)?.let {
|
||||
VFeedbackDialogFragment.show(activity, toGameEntity(it))
|
||||
mLastSuccessfullyLaunchedGame = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -166,41 +191,59 @@ object VHelper {
|
||||
/**
|
||||
* 在执行 callback 前先检查组件是否已安装,是否可下载
|
||||
*/
|
||||
fun checkVSpaceBeforeAction(context: Context, gameEntity: GameEntity?, callback: () -> Unit) {
|
||||
fun checkVSpaceBeforeAction(
|
||||
context: Context,
|
||||
gameEntity: GameEntity?,
|
||||
requireStoragePermission: Boolean,
|
||||
callback: () -> Unit
|
||||
) {
|
||||
// 仅下载类型为畅玩的类型才执行判断
|
||||
if (gameEntity?.isVGame() == true) {
|
||||
if (showDialogIfVSpaceIsNeeded(context)) {
|
||||
return
|
||||
}
|
||||
|
||||
val vaConfig64 = Config.getVSettingEntity()?.va?.arch64
|
||||
val installedSpaceVersionCode =
|
||||
PackageUtils.getVersionCodeByPackageName(vaConfig64?.packageName)
|
||||
|
||||
// 检查更新
|
||||
val containsUpdate =
|
||||
vaConfig64?.versionCode ?: 0 > PackageUtils.getVersionCodeByPackageName(vaConfig64?.packageName)
|
||||
mUpdateEntity != null && installedSpaceVersionCode < mUpdateEntity!!.versionCode
|
||||
|
||||
if (containsUpdate) {
|
||||
// 触发更新弹窗
|
||||
DialogHelper.showDialog(
|
||||
context = context,
|
||||
title = "服务工具更新提示",
|
||||
content = "单机类游戏被删除将可能导致本地存档、充值数据丢失,请确认后操作(网游类游戏删除不会影响游戏存档和充值数据)",
|
||||
content = mUpdateEntity!!.content.toString(),
|
||||
cancelText = "立即更新",
|
||||
confirmText = "继续游戏",
|
||||
cancelClickCallback = {
|
||||
VSpaceDialogFragment.showDownloadDialog(context)
|
||||
VSpaceDialogFragment.showDownloadDialog(context, getVSpaceDownloadEntity(true), true)
|
||||
},
|
||||
confirmClickCallback = {
|
||||
callback.invoke()
|
||||
},
|
||||
extraConfig = DialogHelper.Config(centerTitle = true),
|
||||
uiModificationCallback = {
|
||||
if (mUpdateEntity!!.isForce) {
|
||||
it.confirmTv.visibility = View.GONE
|
||||
it.cancelTv.setTextColor(R.color.theme_font.toColor(context))
|
||||
}
|
||||
|
||||
it.confirmTv.setTextColor(R.color.text_subtitle.toColor(context))
|
||||
}
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
callback.invoke()
|
||||
if (requireStoragePermission) {
|
||||
checkStoragePermissionBeforeAction(context) {
|
||||
callback.invoke()
|
||||
}
|
||||
} else {
|
||||
callback.invoke()
|
||||
}
|
||||
} else {
|
||||
callback.invoke()
|
||||
}
|
||||
@ -270,7 +313,11 @@ object VHelper {
|
||||
/**
|
||||
* 安装新应用
|
||||
*/
|
||||
fun install(context: Context, downloadEntity: DownloadEntity, isManualInstall: Boolean = false) {
|
||||
fun install(
|
||||
context: Context,
|
||||
downloadEntity: DownloadEntity,
|
||||
isManualInstall: Boolean = false
|
||||
) {
|
||||
Utils.log(LOG_TAG, "尝试安装新应用 ${downloadEntity.path}")
|
||||
|
||||
if (showDialogIfVSpaceIsNeeded(context)) {
|
||||
@ -296,7 +343,6 @@ object VHelper {
|
||||
val result = VirtualAppManager.get().installGame(downloadEntity.path)
|
||||
if (result.status == 0) {
|
||||
updateInstalledList()
|
||||
showFloatingWindow(result.packageName)
|
||||
PackageObserver.onPackageChanged(
|
||||
EBPackage(
|
||||
"安装",
|
||||
@ -357,29 +403,29 @@ object VHelper {
|
||||
return
|
||||
}
|
||||
|
||||
val launchClosure: () -> Unit = {
|
||||
try {
|
||||
val intent = mDelegateManager.getStartGameIntent(packageName)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
// val launchClosure: () -> Unit = {
|
||||
try {
|
||||
val intent = mDelegateManager.getStartGameIntent(packageName)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
|
||||
DownloadManager.getInstance().getDownloadEntitySnapshotByPackageName(packageName)?.let {
|
||||
mLastSuccessfullyLaunchedGame = Pair(System.currentTimeMillis(), it.gameId)
|
||||
}
|
||||
|
||||
updateLastPlayedTime(packageName)
|
||||
} catch (e: Exception) {
|
||||
ToastUtils.toast(e.localizedMessage ?: "")
|
||||
DownloadManager.getInstance().getDownloadEntitySnapshotByPackageName(packageName)?.let {
|
||||
mLastSuccessfullyLaunchedGame = Pair(System.currentTimeMillis(), it.gameId)
|
||||
}
|
||||
}
|
||||
|
||||
if (mDelegateManager.isConnectAidlInterface) {
|
||||
checkStoragePermissionBeforeAction(context, launchClosure)
|
||||
} else {
|
||||
checkStoragePermissionBeforeAction(context) {
|
||||
connectService(launchClosure)
|
||||
}
|
||||
updateLastPlayedTime(packageName)
|
||||
} catch (e: Exception) {
|
||||
ToastUtils.toast(e.localizedMessage ?: "")
|
||||
}
|
||||
// }
|
||||
|
||||
// if (mDelegateManager.isConnectAidlInterface) {
|
||||
// context, launchClosure)
|
||||
// } else {
|
||||
// checkStoragePermissionBeforeAction(context) {
|
||||
// connectService(launchClosure)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -448,12 +494,14 @@ object VHelper {
|
||||
return mInstallationLiveData
|
||||
}
|
||||
|
||||
private fun showFloatingWindow(packageName: String) {
|
||||
fun showFloatingWindow(packageName: String) {
|
||||
val vDownloadList = DownloadManager.getInstance().allVDownloadTaskSnapshots
|
||||
vDownloadList.firstOrNull {
|
||||
it.packageName == packageName
|
||||
}?.let {
|
||||
val topActivity = AppManager.getInstance().currentActivity() ?: return
|
||||
if (topActivity.isFinishing || topActivity is VSpaceLoadingActivity) return
|
||||
|
||||
VLoadCompleteWindowHelper.showFloatingWindow(topActivity, toGameEntity(it))
|
||||
}
|
||||
}
|
||||
@ -462,19 +510,35 @@ object VHelper {
|
||||
* 畅玩空间是否已安装
|
||||
* 如果已安装或配置为空返回 true
|
||||
* 未安装的情况下会弹弹窗
|
||||
*
|
||||
* @param forUpdate 是不是为了更新而来,是更新的时候用更新的数据
|
||||
*/
|
||||
private fun showDialogIfVSpaceIsNeeded(context: Context): Boolean {
|
||||
private fun showDialogIfVSpaceIsNeeded(context: Context, forUpdate: Boolean = false): Boolean {
|
||||
val vaConfig = Config.getVSettingEntity()?.va ?: return true
|
||||
|
||||
// TODO 检测 32 位
|
||||
if (!PackageUtils.isInstalled(context, vaConfig.arch64?.packageName)) {
|
||||
VSpaceDialogFragment.showDownloadDialog(context)
|
||||
VSpaceDialogFragment.showDownloadDialog(context, getVSpaceDownloadEntity(false))
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun getVSpaceDownloadEntity(forUpdate: Boolean): AppEntity {
|
||||
if (!forUpdate) {
|
||||
val appEntity = AppEntity()
|
||||
val vaConfig64 = Config.getVSettingEntity()?.va?.arch64
|
||||
appEntity.versionCode = vaConfig64?.versionCode ?: 0
|
||||
appEntity.version = vaConfig64?.versionName
|
||||
appEntity.url = vaConfig64?.url
|
||||
|
||||
return appEntity
|
||||
} else {
|
||||
return mUpdateEntity!!
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行单个更新
|
||||
*
|
||||
@ -537,7 +601,9 @@ object VHelper {
|
||||
)
|
||||
icon = downloadEntity.icon
|
||||
lastPlayedTime = if (lastPlayedTimeString == "") 0L else lastPlayedTimeString.toLong()
|
||||
playedTime = mInstalledInfoList.firstOrNull { it.packageName == getUniquePackageName() }?.appTotalPlayTime ?: 0
|
||||
playedTime =
|
||||
mInstalledInfoList.firstOrNull { it.packageName == getUniquePackageName() }?.appTotalPlayTime
|
||||
?: 0
|
||||
downloadStatus = "smooth"
|
||||
setEntryMap(DownloadManager.getInstance().getEntryMap(name))
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.gh.common.constant.Config
|
||||
import com.gh.common.util.PackageInstaller
|
||||
import com.gh.common.view.DownloadProgressBar
|
||||
import com.gh.download.DownloadManager
|
||||
@ -24,16 +23,18 @@ import com.gh.gamecenter.common.utils.toColor
|
||||
import com.gh.gamecenter.common.utils.viewModelProvider
|
||||
import com.gh.gamecenter.core.AppExecutor
|
||||
import com.gh.gamecenter.databinding.DialogVspaceBinding
|
||||
import com.gh.gamecenter.entity.AppEntity
|
||||
import com.gh.gamecenter.eventbus.EBPackage
|
||||
import com.lightgame.download.DataWatcher
|
||||
import com.lightgame.download.DownloadEntity
|
||||
import com.lightgame.download.DownloadStatus.*
|
||||
import com.lightgame.download.FileUtils
|
||||
import com.lightgame.utils.AppManager
|
||||
import splitties.bundle.put
|
||||
|
||||
class VSpaceDialogFragment : BaseDraggableDialogFragment() {
|
||||
|
||||
private val mDownloadUrl by lazy { Config.getVSettingEntity()?.va?.arch64?.url } // TODO 支持 32 位地址
|
||||
private var mAppEntity: AppEntity? = null
|
||||
private val mDownloadUrl by lazy { mAppEntity?.url ?: "" }
|
||||
private val mBinding by lazy { DialogVspaceBinding.inflate(layoutInflater) }
|
||||
private val mDataWatcher = object : DataWatcher() {
|
||||
override fun onDataChanged(downloadEntity: DownloadEntity) {
|
||||
@ -46,6 +47,12 @@ class VSpaceDialogFragment : BaseDraggableDialogFragment() {
|
||||
override fun getRootView(): View = mBinding.root
|
||||
override fun getDragCloseView(): View = mBinding.dragClose
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
mAppEntity = arguments?.get(KEY_ENTITY) as AppEntity
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@ -60,9 +67,7 @@ class VSpaceDialogFragment : BaseDraggableDialogFragment() {
|
||||
|
||||
val mViewModel = viewModelProvider<VSpaceDialogViewModel>()
|
||||
mViewModel.packageLiveData.observe(this) {
|
||||
if (it.packageName == Config.getVSettingEntity()?.va?.arch32?.packageName
|
||||
&& it.type == "安装"
|
||||
) {
|
||||
if (it.packageName == "com.lg.vspace") {
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
}
|
||||
@ -77,26 +82,26 @@ class VSpaceDialogFragment : BaseDraggableDialogFragment() {
|
||||
mBinding.downloadBtn.downloadType = DownloadProgressBar.DownloadType.NORMAL
|
||||
mBinding.descTv.text = spanBuilder
|
||||
mBinding.downloadBtn.setOnClickListener {
|
||||
val vSpaceInfo = Config.getVSettingEntity()?.va?.arch32!!
|
||||
val name = "畅玩助手V" + vSpaceInfo.versionName
|
||||
val name = "畅玩助手V" + mAppEntity?.version
|
||||
val downloadId = PackageInstaller.createDownloadId(name)
|
||||
|
||||
val downloadEntity = DownloadEntity()
|
||||
downloadEntity.url = mDownloadUrl
|
||||
downloadEntity.name = "畅玩助手V" + vSpaceInfo.versionName
|
||||
downloadEntity.path = FileUtils.getDownloadPath(
|
||||
requireContext(),
|
||||
"畅玩助手V" + vSpaceInfo.versionName + ".apk"
|
||||
)
|
||||
downloadEntity.name = name
|
||||
downloadEntity.platform = "官方版"
|
||||
downloadEntity.gameId = ""
|
||||
downloadEntity.path = PackageInstaller.getDownloadPathWithId(downloadId, "apk")
|
||||
downloadEntity.packageName = vSpaceInfo.packageName
|
||||
downloadEntity.packageName = "com.lg.vspace"
|
||||
|
||||
AppExecutor.uiExecutor.executeWithDelay({
|
||||
DownloadManager.getInstance().cancel(mDownloadUrl)
|
||||
DownloadManager.getInstance().add(downloadEntity)
|
||||
}, 200)
|
||||
}
|
||||
|
||||
if (arguments?.getBoolean(KEY_AUTO_DOWNLOAD) == true) {
|
||||
mBinding.downloadBtn.performClick()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
@ -166,8 +171,11 @@ class VSpaceDialogFragment : BaseDraggableDialogFragment() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KEY_ENTITY = "entity"
|
||||
const val KEY_AUTO_DOWNLOAD = "auto_download"
|
||||
|
||||
@JvmStatic
|
||||
fun showDownloadDialog(context: Context?) {
|
||||
fun showDownloadDialog(context: Context?, appEntity: AppEntity, autoDownload: Boolean = false) {
|
||||
val fragmentActivity: FragmentActivity = if (context is FragmentActivity) {
|
||||
context
|
||||
} else {
|
||||
@ -182,7 +190,12 @@ class VSpaceDialogFragment : BaseDraggableDialogFragment() {
|
||||
// 防止重复弹出
|
||||
if (hasDialogDisplayedInCurrentActivity(fragmentActivity)) return
|
||||
|
||||
val downloadDialog = VSpaceDialogFragment()
|
||||
val downloadDialog = VSpaceDialogFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
put(KEY_ENTITY, appEntity)
|
||||
put(KEY_AUTO_DOWNLOAD, autoDownload)
|
||||
}
|
||||
}
|
||||
downloadDialog.show(
|
||||
fragmentActivity.supportFragmentManager,
|
||||
VSpaceDialogFragment::class.java.name
|
||||
|
||||
Reference in New Issue
Block a user