|
|
|
|
@ -41,6 +41,7 @@ import java.util.*
|
|
|
|
|
object DownloadObserver {
|
|
|
|
|
|
|
|
|
|
private val mApplication = HaloApp.getInstance().application
|
|
|
|
|
|
|
|
|
|
// 简单 debounce 因为内存更新 downloadEntity 对象造成的触发双重下载完成事件
|
|
|
|
|
// TODO 修复因为更改内存对象造成的双重下载完成事件问题,具体触发代码见 DownloadDao.updateSnapshotList
|
|
|
|
|
private var mDoneDebouncePair: Pair<String, Long>? = null
|
|
|
|
|
@ -75,15 +76,18 @@ object DownloadObserver {
|
|
|
|
|
val currentActivity = AppManager.getInstance().currentActivity() ?: return
|
|
|
|
|
|
|
|
|
|
DialogHelper.showDialog(currentActivity, "下载失败", "下载链接已失效,建议提交反馈", "立即反馈", "取消", {
|
|
|
|
|
SuggestionActivity.startSuggestionActivity(currentActivity,
|
|
|
|
|
SuggestType.gameQuestion, "notfound",
|
|
|
|
|
StringUtils.buildString(downloadEntity.name, ",问题反馈:下载链接失效"),
|
|
|
|
|
SimpleGameEntity(gameId, downloadEntity.name, ""))
|
|
|
|
|
SuggestionActivity.startSuggestionActivity(
|
|
|
|
|
currentActivity,
|
|
|
|
|
SuggestType.gameQuestion, "notfound",
|
|
|
|
|
StringUtils.buildString(downloadEntity.name, ",问题反馈:下载链接失效"),
|
|
|
|
|
SimpleGameEntity(gameId, downloadEntity.name, "")
|
|
|
|
|
)
|
|
|
|
|
}, extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true))
|
|
|
|
|
return
|
|
|
|
|
} else if (DownloadStatus.neterror == downloadEntity.status || DownloadStatus.timeout == downloadEntity.status) {
|
|
|
|
|
if (downloadEntity.meta[Constants.MARK_RETRY_DOWNLOAD].isNullOrEmpty()
|
|
|
|
|
&& NetworkUtils.isWifiConnected(HaloApp.getInstance().application)) {
|
|
|
|
|
&& NetworkUtils.isWifiConnected(HaloApp.getInstance().application)
|
|
|
|
|
) {
|
|
|
|
|
downloadEntity.meta[Constants.MARK_RETRY_DOWNLOAD] = downloadEntity.progress.toString()
|
|
|
|
|
downloadManager.updateDownloadEntity(downloadEntity)
|
|
|
|
|
downloadManager.resumeDownload(downloadEntity.url)
|
|
|
|
|
@ -123,7 +127,8 @@ object DownloadObserver {
|
|
|
|
|
performDownloadCompleteAction(downloadEntity, gameId, downloadManager)
|
|
|
|
|
} else {
|
|
|
|
|
if (mDoneDebouncePair?.second == 0L
|
|
|
|
|
|| (mDoneDebouncePair?.second ?: 0) - System.currentTimeMillis() > 500) {
|
|
|
|
|
|| System.currentTimeMillis() - (mDoneDebouncePair?.second ?: 0) > 500
|
|
|
|
|
) {
|
|
|
|
|
performDownloadCompleteAction(downloadEntity, gameId, downloadManager)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -137,7 +142,8 @@ object DownloadObserver {
|
|
|
|
|
|
|
|
|
|
// 如果已下载大小发生变化,表示成功恢复下载,则重置重试标记
|
|
|
|
|
if (downloadEntity.status == DownloadStatus.downloading &&
|
|
|
|
|
downloadEntity.progress.toString() != downloadEntity.meta[Constants.MARK_RETRY_DOWNLOAD]) {
|
|
|
|
|
downloadEntity.progress.toString() != downloadEntity.meta[Constants.MARK_RETRY_DOWNLOAD]
|
|
|
|
|
) {
|
|
|
|
|
downloadEntity.meta[Constants.MARK_RETRY_DOWNLOAD] = ""
|
|
|
|
|
downloadManager.updateDownloadEntity(downloadEntity)
|
|
|
|
|
}
|
|
|
|
|
@ -149,9 +155,11 @@ object DownloadObserver {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun performDownloadCompleteAction(downloadEntity: DownloadEntity,
|
|
|
|
|
gameId: String,
|
|
|
|
|
downloadManager: DownloadManager) {
|
|
|
|
|
private fun performDownloadCompleteAction(
|
|
|
|
|
downloadEntity: DownloadEntity,
|
|
|
|
|
gameId: String,
|
|
|
|
|
downloadManager: DownloadManager
|
|
|
|
|
) {
|
|
|
|
|
if (downloadEntity.name.contains(mApplication.getString(R.string.app_name))) {
|
|
|
|
|
statDoneEvent(downloadEntity)
|
|
|
|
|
MtaHelper.onEvent("软件更新", "下载完成")
|
|
|
|
|
@ -196,8 +204,10 @@ object DownloadObserver {
|
|
|
|
|
val currentActivity = AppManager.getInstance().currentActivity()
|
|
|
|
|
?: return
|
|
|
|
|
|
|
|
|
|
SimulatorDownloadManager.getInstance().showDownloadDialog(currentActivity, simulator,
|
|
|
|
|
SimulatorDownloadManager.SimulatorLocation.LAUNCH, downloadEntity.gameId, gameName, null)
|
|
|
|
|
SimulatorDownloadManager.getInstance().showDownloadDialog(
|
|
|
|
|
currentActivity, simulator,
|
|
|
|
|
SimulatorDownloadManager.SimulatorLocation.LAUNCH, downloadEntity.gameId, gameName, null
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
SimulatorGameManager.recordDownloadSimulatorGame(downloadEntity.gameId, simulator.type)
|
|
|
|
|
SimulatorGameManager.postPlayedGame(downloadEntity.gameId, downloadEntity.packageName)
|
|
|
|
|
@ -205,7 +215,8 @@ object DownloadObserver {
|
|
|
|
|
val downloadType = downloadEntity.getMetaExtra(Constants.EXTRA_DOWNLOAD_TYPE)
|
|
|
|
|
// 是否是自动安装
|
|
|
|
|
val isAutoInstall = PreferenceManager.getDefaultSharedPreferences(mApplication).getBoolean(
|
|
|
|
|
GameDownloadSettingFragment.AUTO_INSTALL_SP_KEY, true)
|
|
|
|
|
GameDownloadSettingFragment.AUTO_INSTALL_SP_KEY, true
|
|
|
|
|
)
|
|
|
|
|
if (downloadType == Constants.SIMULATOR_DOWNLOAD || isAutoInstall) {
|
|
|
|
|
if (FileUtils.isEmptyFile(downloadEntity.path)) {
|
|
|
|
|
Utils.toast(mApplication, R.string.install_failure_hint)
|
|
|
|
|
@ -252,7 +263,8 @@ object DownloadObserver {
|
|
|
|
|
val simulator = HaloApp.get(downloadEntity.name, true) as? SimulatorEntity
|
|
|
|
|
?: return@showSimulatorParseErrorDialog
|
|
|
|
|
DownloadManager.getInstance().cancel(downloadEntity.url, true, true)
|
|
|
|
|
SimulatorDownloadManager.getInstance().showDownloadDialog(currentActivity, simulator, SimulatorDownloadManager.SimulatorLocation.SIMULATOR_GAME)
|
|
|
|
|
SimulatorDownloadManager.getInstance()
|
|
|
|
|
.showDownloadDialog(currentActivity, simulator, SimulatorDownloadManager.SimulatorLocation.SIMULATOR_GAME)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -290,15 +302,18 @@ object DownloadObserver {
|
|
|
|
|
}
|
|
|
|
|
val isPlatformRecommend = java.lang.Boolean.parseBoolean(downloadEntity.getMetaExtra(Constants.IS_PLATFORM_RECOMMEND))
|
|
|
|
|
ExposureUtils.logADownloadCompleteExposureEvent(
|
|
|
|
|
GameEntity(id = downloadEntity.gameId,
|
|
|
|
|
mName = downloadEntity.name.removeSuffix(Constants.GAME_NAME_DECORATOR),
|
|
|
|
|
gameVersion = downloadEntity.versionName ?: "",
|
|
|
|
|
isPlatformRecommend = isPlatformRecommend),
|
|
|
|
|
downloadEntity.platform,
|
|
|
|
|
downloadEntity.exposureTrace,
|
|
|
|
|
downloadEntity.meta[DownloadEntity.DOWNLOAD_HOST_KEY] ?: "unknown",
|
|
|
|
|
downloadEntity.meta[DownloadEntity.DOWNLOAD_PATH_KEY] ?: "unknown",
|
|
|
|
|
type)
|
|
|
|
|
GameEntity(
|
|
|
|
|
id = downloadEntity.gameId,
|
|
|
|
|
mName = downloadEntity.name.removeSuffix(Constants.GAME_NAME_DECORATOR),
|
|
|
|
|
gameVersion = downloadEntity.versionName ?: "",
|
|
|
|
|
isPlatformRecommend = isPlatformRecommend
|
|
|
|
|
),
|
|
|
|
|
downloadEntity.platform,
|
|
|
|
|
downloadEntity.exposureTrace,
|
|
|
|
|
downloadEntity.meta[DownloadEntity.DOWNLOAD_HOST_KEY] ?: "unknown",
|
|
|
|
|
downloadEntity.meta[DownloadEntity.DOWNLOAD_PATH_KEY] ?: "unknown",
|
|
|
|
|
type
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
DataCollectionUtils.uploadDownload(mApplication, downloadEntity, "完成")
|
|
|
|
|
}
|
|
|
|
|
@ -320,12 +335,14 @@ object DownloadObserver {
|
|
|
|
|
val params = HashMap<String, String>()
|
|
|
|
|
params["game"] = id
|
|
|
|
|
params["platform"] = platform ?: ""
|
|
|
|
|
val body = RequestBody.create(MediaType.parse("application/json"),
|
|
|
|
|
JSONObject(params as Map<*, *>).toString())
|
|
|
|
|
val body = RequestBody.create(
|
|
|
|
|
MediaType.parse("application/json"),
|
|
|
|
|
JSONObject(params as Map<*, *>).toString()
|
|
|
|
|
)
|
|
|
|
|
RetrofitManager.getInstance().api.postDownload(body)
|
|
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
.subscribe(Response())
|
|
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
|
.subscribe(Response())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|