fix: 修复部分逻辑问题和 UI 问题 https://git.shanqu.cc/pm/halo/halo-app-issues/-/issues/1923#note_155241
This commit is contained in:
@ -382,7 +382,7 @@ public class BindingAdapters {
|
||||
return;
|
||||
}
|
||||
}
|
||||
VHelper.checkVSpaceBeforeAction(v.getContext(), gameEntity, true, () -> {
|
||||
VHelper.validateVSpaceBeforeAction(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, true) {
|
||||
VHelper.validateVSpaceBeforeAction(context, gameEntity, true) {
|
||||
DialogUtils.checkDownload(context, apk.size) { isSubscribe: Boolean ->
|
||||
download(context, gameEntity, downloadBtn, entrance, location, isSubscribe, traceEvent)
|
||||
}
|
||||
@ -776,7 +776,7 @@ object DownloadItemUtils {
|
||||
if (gameEntity.isVGame()) {
|
||||
PackagesManager.getUpdateList().firstOrNull { it.id == gameEntity.id }?.let { updateEntity ->
|
||||
VHelper.getDownloadEntitySnapshotByPackageName(gameEntity.getUniquePackageName() ?: "")?.let { downloadEntity ->
|
||||
VHelper.update(downloadEntity, updateEntity)
|
||||
VHelper.updateOrReDownload(downloadEntity, updateEntity)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
@ -191,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, true) {
|
||||
VHelper.validateVSpaceBeforeAction(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, true, () -> {
|
||||
VHelper.validateVSpaceBeforeAction(mViewHolder.context, mGameEntity, true, () -> {
|
||||
GamePermissionDialogFragment.show((AppCompatActivity) mViewHolder.context, mGameEntity, mGameEntity.getInfo(), () -> {
|
||||
PermissionHelper.checkStoragePermissionBeforeAction(mViewHolder.context, () -> {
|
||||
if (mGameEntity.getApk().size() == 1) {
|
||||
|
||||
@ -193,7 +193,7 @@ class HomeRecentVGameAdapter(context: Context) : DiffUtilAdapter<GameEntity>(con
|
||||
binding.root.setOnClickListener {
|
||||
PackagesManager.getUpdateList().firstOrNull { it.id == downloadEntity.gameId }
|
||||
?.let {
|
||||
VHelper.update(downloadEntity, it)
|
||||
VHelper.updateOrReDownload(downloadEntity, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,6 @@ import com.gh.gamecenter.common.constant.ItemViewType
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.core.AppExecutor
|
||||
import com.gh.gamecenter.core.utils.CurrentActivityHolder
|
||||
import com.gh.gamecenter.core.utils.NumberUtils
|
||||
import com.gh.gamecenter.core.utils.SPUtils
|
||||
import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.databinding.ItemVgameDownloadManagerBinding
|
||||
@ -98,13 +97,12 @@ class VDownloadManagerAdapter(context: Context, private val mViewModel: VDownloa
|
||||
when (holder) {
|
||||
is VGameItemViewHolder -> {
|
||||
val gameEntity = mEntityList[position]
|
||||
val totalPlayedTimeString = NumberUtils.transSimpleUsageTime(gameEntity.playedTime)
|
||||
|
||||
BindingAdapters.setGameName(holder.binding.nameTv, gameEntity, false, true)
|
||||
holder.binding.iconIv.displayGameIcon(gameEntity)
|
||||
|
||||
holder.binding.descTv.goneIf(mViewModel.isTypeDownloaded())
|
||||
holder.binding.descTv.text = "已畅玩$totalPlayedTimeString"
|
||||
holder.binding.descTv.goneIf(!mViewModel.isTypeDownloaded())
|
||||
holder.binding.descTv.text = gameEntity.des
|
||||
|
||||
(holder.binding.selectIv.layoutParams as ConstraintLayout.LayoutParams).apply {
|
||||
width = 20F.dip2px()
|
||||
@ -239,6 +237,8 @@ class VDownloadManagerAdapter(context: Context, private val mViewModel: VDownloa
|
||||
return
|
||||
}
|
||||
|
||||
downloadBtn.goneIf(mCurrentOption != ManageOption.OPTION_MANAGER)
|
||||
|
||||
val downloadEntity = DownloadManager.getInstance().getDownloadEntitySnapshotByUrl(gameEntity.getApk()[0].url)
|
||||
if (downloadEntity != null) {
|
||||
val status = downloadEntity.status
|
||||
@ -276,7 +276,7 @@ class VDownloadManagerAdapter(context: Context, private val mViewModel: VDownloa
|
||||
setOnClickListener {
|
||||
PackagesManager.getUpdateList()
|
||||
.firstOrNull { it.id == downloadEntity.gameId }?.let {
|
||||
VHelper.update(downloadEntity, it)
|
||||
VHelper.updateOrReDownload(downloadEntity, it)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -4,6 +4,8 @@ import android.app.Application
|
||||
import com.gh.download.DownloadManager
|
||||
import com.gh.download.PackageObserver
|
||||
import com.gh.gamecenter.baselist.ListViewModel
|
||||
import com.gh.gamecenter.common.utils.toProperReadableSize
|
||||
import com.gh.gamecenter.core.utils.NumberUtils
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.eventbus.EBPackage
|
||||
import com.lightgame.download.DownloadStatus
|
||||
@ -35,7 +37,15 @@ class VDownloadManagerViewModel(application: Application) :
|
||||
for (downloadEntity in vDownloadList) {
|
||||
if (downloadEntity.status == DownloadStatus.done) {
|
||||
gameIdSet.add(downloadEntity.gameId)
|
||||
vGameList.add(VHelper.toGameEntity(downloadEntity))
|
||||
|
||||
val gameEntity = VHelper.toGameEntity(downloadEntity)
|
||||
if (gameEntity.playedTime != 0L) {
|
||||
gameEntity.des = "已畅玩${NumberUtils.transSimpleUsageTime(gameEntity.playedTime)}"
|
||||
} else {
|
||||
gameEntity.des = VHelper.getAppOccupiedSpace(downloadEntity.packageName).toProperReadableSize()
|
||||
}
|
||||
|
||||
vGameList.add(gameEntity)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -44,6 +44,7 @@ import com.lightgame.utils.AppManager
|
||||
import com.lightgame.utils.Utils
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.io.File
|
||||
|
||||
object VHelper {
|
||||
|
||||
@ -156,13 +157,13 @@ object VHelper {
|
||||
* 在执行 callback 前先检查组件是否已安装,是否可下载
|
||||
*/
|
||||
@JvmStatic
|
||||
fun checkVSpaceBeforeAction(
|
||||
fun validateVSpaceBeforeAction(
|
||||
context: Context,
|
||||
gameEntity: GameEntity?,
|
||||
requireStoragePermission: Boolean,
|
||||
callback: EmptyCallback
|
||||
) {
|
||||
checkVSpaceBeforeAction(context, gameEntity, requireStoragePermission) {
|
||||
validateVSpaceBeforeAction(context, gameEntity, requireStoragePermission) {
|
||||
callback.onCallback()
|
||||
}
|
||||
}
|
||||
@ -188,17 +189,29 @@ object VHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取游戏占用的空间
|
||||
*/
|
||||
fun getAppOccupiedSpace(packageName: String): Long {
|
||||
return try {
|
||||
mDelegateManager.getAppOccupiedSpace(packageName)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在执行 callback 前先检查组件是否已安装,是否可下载
|
||||
*/
|
||||
fun checkVSpaceBeforeAction(
|
||||
fun validateVSpaceBeforeAction(
|
||||
context: Context,
|
||||
gameEntity: GameEntity?,
|
||||
requireStoragePermission: Boolean,
|
||||
callback: () -> Unit
|
||||
) {
|
||||
// 仅下载类型为畅玩的类型才执行判断
|
||||
if (gameEntity?.isVGame() == true) {
|
||||
if (gameEntity == null || gameEntity.isVGame()) {
|
||||
if (showDialogIfVSpaceIsNeeded(context)) {
|
||||
return
|
||||
}
|
||||
@ -219,7 +232,11 @@ object VHelper {
|
||||
cancelText = "立即更新",
|
||||
confirmText = "继续游戏",
|
||||
cancelClickCallback = {
|
||||
VSpaceDialogFragment.showDownloadDialog(context, getVSpaceDownloadEntity(true), true)
|
||||
VSpaceDialogFragment.showDownloadDialog(
|
||||
context,
|
||||
getVSpaceDownloadEntity(true),
|
||||
true
|
||||
)
|
||||
},
|
||||
confirmClickCallback = {
|
||||
callback.invoke()
|
||||
@ -381,14 +398,26 @@ object VHelper {
|
||||
return
|
||||
}
|
||||
|
||||
if (isInstalled(packageName)) {
|
||||
launch(context, packageName)
|
||||
} else {
|
||||
val downloadEntity = getDownloadEntitySnapshotByPackageName(packageName)
|
||||
if (downloadEntity != null) {
|
||||
install(context, downloadEntity, true)
|
||||
checkStoragePermissionBeforeAction(context) {
|
||||
if (isInstalled(packageName)) {
|
||||
launch(context, packageName)
|
||||
} else {
|
||||
ToastUtils.toast("找不到下载文件")
|
||||
val downloadEntity = getDownloadEntitySnapshotByPackageName(packageName)
|
||||
if (downloadEntity != null) {
|
||||
runOnIoThread {
|
||||
if (File(downloadEntity.path).exists()) {
|
||||
install(context, downloadEntity, true)
|
||||
} else {
|
||||
// 重新下载
|
||||
runOnUiThread {
|
||||
ToastUtils.toast("检测到数据异常,将会为你重新下载安装")
|
||||
updateOrReDownload(downloadEntity, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ToastUtils.toast("找不到下载文件")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -403,29 +432,22 @@ object VHelper {
|
||||
return
|
||||
}
|
||||
|
||||
// val launchClosure: () -> Unit = {
|
||||
try {
|
||||
val intent = mDelegateManager.getStartGameIntent(packageName)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
validateVSpaceBeforeAction(context, null, false) {
|
||||
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)
|
||||
DownloadManager.getInstance().getDownloadEntitySnapshotByPackageName(packageName)
|
||||
?.let {
|
||||
mLastSuccessfullyLaunchedGame = Pair(System.currentTimeMillis(), it.gameId)
|
||||
}
|
||||
|
||||
updateLastPlayedTime(packageName)
|
||||
} catch (e: Exception) {
|
||||
ToastUtils.toast(e.localizedMessage ?: "")
|
||||
}
|
||||
|
||||
updateLastPlayedTime(packageName)
|
||||
} catch (e: Exception) {
|
||||
ToastUtils.toast(e.localizedMessage ?: "")
|
||||
}
|
||||
// }
|
||||
|
||||
// if (mDelegateManager.isConnectAidlInterface) {
|
||||
// context, launchClosure)
|
||||
// } else {
|
||||
// checkStoragePermissionBeforeAction(context) {
|
||||
// connectService(launchClosure)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -539,26 +561,32 @@ object VHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行单个更新
|
||||
* 更新或重下载
|
||||
*
|
||||
* @param originDownloadEntity 旧的下载实体
|
||||
* @param update 更新内容
|
||||
* @param updateEntity 更新内容,当 updateEntity 为空时重新下载
|
||||
*/
|
||||
fun update(originDownloadEntity: DownloadEntity, update: GameUpdateEntity) {
|
||||
fun updateOrReDownload(originDownloadEntity: DownloadEntity, updateEntity: GameUpdateEntity? = null) {
|
||||
Utils.log(LOG_TAG, "更新应用${originDownloadEntity.packageName}")
|
||||
|
||||
DownloadManager.getInstance().cancel(originDownloadEntity.url)
|
||||
|
||||
originDownloadEntity.url = update.url
|
||||
originDownloadEntity.name = update.name
|
||||
originDownloadEntity.eTag = update.etag
|
||||
originDownloadEntity.icon = update.icon
|
||||
originDownloadEntity.platform = update.platform
|
||||
originDownloadEntity.packageName = update.packageName
|
||||
originDownloadEntity.versionName = update.version
|
||||
originDownloadEntity.addMetaExtra(Constants.RAW_GAME_ICON, update.rawIcon)
|
||||
originDownloadEntity.addMetaExtra(Constants.GAME_ICON_SUBSCRIPT, update.iconSubscript)
|
||||
originDownloadEntity.addMetaExtra(Constants.APK_MD5, update.md5)
|
||||
if (updateEntity != null) {
|
||||
originDownloadEntity.url = updateEntity.url
|
||||
originDownloadEntity.name = updateEntity.name
|
||||
originDownloadEntity.eTag = updateEntity.etag
|
||||
originDownloadEntity.icon = updateEntity.icon
|
||||
originDownloadEntity.platform = updateEntity.platform
|
||||
originDownloadEntity.packageName = updateEntity.packageName
|
||||
originDownloadEntity.versionName = updateEntity.version
|
||||
originDownloadEntity.addMetaExtra(Constants.RAW_GAME_ICON, updateEntity.rawIcon)
|
||||
originDownloadEntity.addMetaExtra(
|
||||
Constants.GAME_ICON_SUBSCRIPT,
|
||||
updateEntity.iconSubscript
|
||||
)
|
||||
originDownloadEntity.addMetaExtra(Constants.APK_MD5, updateEntity.md5)
|
||||
}
|
||||
|
||||
originDownloadEntity.isUpdate = true
|
||||
originDownloadEntity.progress = 0
|
||||
originDownloadEntity.finalRedirectedUrl = ""
|
||||
@ -566,19 +594,19 @@ object VHelper {
|
||||
|
||||
// 确定下载类型
|
||||
val downloadType = ExposureUtils.DownloadType.UPDATE
|
||||
val gameEntity = GameEntity(update.id, update.name)
|
||||
gameEntity.gameVersion = update.version ?: ""
|
||||
val gameEntity = GameEntity(originDownloadEntity.gameId, originDownloadEntity.name)
|
||||
gameEntity.gameVersion = originDownloadEntity.versionName ?: ""
|
||||
|
||||
val event = ExposureUtils.logADownloadExposureEvent(
|
||||
gameEntity,
|
||||
update.platform,
|
||||
update.exposureEvent,
|
||||
originDownloadEntity.platform,
|
||||
null,
|
||||
downloadType
|
||||
)
|
||||
|
||||
originDownloadEntity.exposureTrace = GsonUtils.toJson(event)
|
||||
|
||||
HistoryHelper.insertGameEntity(update)
|
||||
HistoryHelper.insertGameEntity(gameEntity)
|
||||
DownloadManager.getInstance().add(originDownloadEntity)
|
||||
|
||||
// 收集下载数据
|
||||
|
||||
Reference in New Issue
Block a user