ad upgrade

ad upgrade code update
This commit is contained in:
xuxinchao
2022-01-27 18:55:06 +08:00
parent 81e76f2dd4
commit 183f6f0661
8 changed files with 334 additions and 172 deletions

View File

@@ -0,0 +1,142 @@
package com.mogo.eagle.core.data.autopilot
/**
* @author XuXinChao
* @description 工控机升级状态实体类
* @since: 2022/1/21
*/
class AdUpgradeStateHelper {
companion object{
private const val UPGRADE_QUIET = 0 //静默升级
private const val UPGRADE_HINT = 3 //提示升级
private const val DOWNLOAD_START = 30 //开始下载
private const val DOWNLOAD_FINISH = 31 //下载完成
private const val DOWNLOAD_FAILED = 32 //下载失败
private const val UPGRADE_AFFIRM = 60 //是否升级
private const val UPGRADE_SUCCEED = 61 //升级成功
private const val UPGRADE_FAILED = 62 //升级失败
private const val USER_AFFIRM = 63 //用户确认
private const val USER_CANCEL = 64 //用户取消
private var UPGRADING = false //工控机是否处于“升级中”状态
/**
* 如果工控机处于“下载中”、“可升级(下载完成)”、“升级中”、“升级失败”状态时,工具箱入口显示红色角标
* @param downloadStatus 下载状态
* @param upgradeStatus 升级状态
*/
fun showUpgradeTips(downloadStatus: Int,upgradeStatus: Int) : Boolean{
return isDownloading(downloadStatus) || isDownloadFinish(downloadStatus) || isUpgradeFailed(upgradeStatus)
}
/**
* 工控机是否处于“下载中”状态
* @param downloadStatus 下载状态
*/
fun isDownloading(downloadStatus: Int) : Boolean{
return downloadStatus == DOWNLOAD_START
}
/**
* 工控机是否处于“下载完成”(可升级)状态
* @param downloadStatus 下载状态
*/
fun isDownloadFinish(downloadStatus: Int) : Boolean{
return downloadStatus == DOWNLOAD_FINISH
}
/**
* 工控机是否处于“下载失败”状态
* @param downloadStatus 下载状态
*/
fun isDownloadFailed(downloadStatus: Int) : Boolean{
return downloadStatus == DOWNLOAD_FAILED
}
/**
* 工控机是否处于“升级成功”状态
* @param upgradeStatus 升级状态
*/
fun isUpgradeSuccess(upgradeStatus: Int) : Boolean{
return upgradeStatus == UPGRADE_SUCCEED
}
/**
* 工控机是否处于“升级失败”状态
* @param upgradeStatus 升级状态
*/
fun isUpgradeFailed(upgradeStatus: Int) : Boolean{
return upgradeStatus == UPGRADE_FAILED
}
/**
* 根据已下载包体大小和包体总大小获取当前下载进度 0-100
* @param currentProgress 当前已下载包体大小
* @param totalProgress 包体总大小
*/
fun downloadProgress(currentProgress: Int,totalProgress: Int) : Int{
return currentProgress*100/totalProgress
}
/**
* 工控机升级模式是否是静默升级
* @param upgradeMode 升级模式
*/
fun isQuietUpgradeMode(upgradeMode: Int) : Boolean{
return upgradeMode == UPGRADE_QUIET
}
/**
* 工控机升级模式是否是提示升级
* @param upgradeMode 升级模式
*/
fun isHintUpgradeMode(upgradeMode: Int) : Boolean{
return upgradeMode == UPGRADE_HINT
}
/**
* 获取是否处于“升级中”状态
*/
fun getUpgradeStatus() : Boolean{
return UPGRADING
}
/**
* 设置是否处于“升级中”状态
* @param upgrading 是否是升级中
*/
fun setUpgradeStatus(upgrading: Boolean){
UPGRADING = upgrading
}
/**
* 获取工控机包体下载剩余时间
*/
fun getRemainingTime(totalProgress: Int,previousProgress: Int,currentProgress: Int) : String{
//剩余包体大小
val remainingSize = totalProgress - currentProgress
//目前下载进度回调是1秒回调一次据此计算每秒下载的包大小
val speed = currentProgress - previousProgress
//剩余包体的大小除以每秒下载的大小,获得剩余下载时间
val time = remainingSize/speed
//转换为分秒格式返回
val minute = time/60
val second = time%60
if(minute>0 && second>0){
return minute.toString()+"分钟"+second+""
}else if(minute>0){
return minute.toString()+"分钟"
}else if(second>0){
return second.toString()+""
}else{
return ""
}
}
}
}