ad upgrade
fix bug
This commit is contained in:
@@ -32,10 +32,12 @@ class AdUpgradeDialog(context: Context) : BaseFloatDialog(context), LifecycleObs
|
||||
upgradeConfirm?.setOnClickListener{
|
||||
Logger.i(TAG,"upgradeConfirm click")
|
||||
clickListener?.confirm()
|
||||
dismiss()
|
||||
}
|
||||
upgradeCancel?.setOnClickListener {
|
||||
Logger.i(TAG,"upgradeCancel click")
|
||||
clickListener?.cancel()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@ import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.mogo.eagle.core.utilcode.util.AppUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import kotlinx.android.synthetic.main.view_system_version.view.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* @author XuXinChao
|
||||
@@ -39,13 +42,12 @@ class SystemVersionView @JvmOverloads constructor(
|
||||
|
||||
private var upgradeMode: Int=-1 //升级模式
|
||||
private var downloadStatus: Int=-1 //下载状态
|
||||
private var currentProgress: Int=0 //当前已下载包体大小
|
||||
private var previousProgress: Int=0 //前一秒的下载进度,用于计算下载剩余时间
|
||||
private var totalProgress: Int=0 //包体总大小
|
||||
private var currentProgress: Int=-1 //当前已下载包体大小
|
||||
private var previousProgress: Int=-1 //前一秒的下载进度,用于计算下载剩余时间
|
||||
private var totalProgress: Int=-1 //包体总大小
|
||||
private var downloadVersion: String?=null //工控机docker版本
|
||||
private var upgradeStatus: Int=-1 //升级状态
|
||||
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.view_system_version, this, true)
|
||||
initView()
|
||||
@@ -55,10 +57,18 @@ class SystemVersionView @JvmOverloads constructor(
|
||||
showCurrentPadVersion()
|
||||
showCurrentAdVersion()
|
||||
|
||||
|
||||
|
||||
//鹰眼版本视图点击事件
|
||||
ivPadVersion.setOnClickListener {
|
||||
Logger.i(TAG,"pad version view clicked")
|
||||
}
|
||||
if(autopilotStatus==2){
|
||||
//当前处于自动驾驶状态,不可进行升级,Toast提示
|
||||
ToastUtils.showShort("升级前请先退出自动驾驶模式,autopilotStatus="+autopilotStatus)
|
||||
}else{
|
||||
ToastUtils.showShort("当前不是自动驾驶模式,autopilotStatus="+autopilotStatus)
|
||||
}
|
||||
}
|
||||
//工控机版本视图点击事件
|
||||
ivAdVersion.setOnClickListener {
|
||||
Logger.i(TAG,"ad version view clicked")
|
||||
@@ -66,7 +76,7 @@ class SystemVersionView @JvmOverloads constructor(
|
||||
if(AdUpgradeStateHelper.isDownloading(downloadStatus)){
|
||||
//点击Toast提示:下载剩余时间
|
||||
ToastUtils.showShort("预计"+AdUpgradeStateHelper.getRemainingTime(totalProgress,previousProgress,currentProgress)+"下载完成")
|
||||
}else if(AdUpgradeStateHelper.isHintUpgradeMode(upgradeMode) && AdUpgradeStateHelper.isDownloadFinish(downloadStatus)){
|
||||
}else if(AdUpgradeStateHelper.isHintUpgradeMode(upgradeMode) && AdUpgradeStateHelper.isDownloadFinish(downloadStatus,upgradeStatus)){
|
||||
//如果升级模式为“提示升级”,并且下载状态为已经下载完成,点击弹出升级确认弹窗
|
||||
if(adUpgradeDialog == null){
|
||||
adUpgradeDialog = AdUpgradeDialog(context)
|
||||
@@ -87,7 +97,8 @@ class SystemVersionView @JvmOverloads constructor(
|
||||
override fun cancel() {
|
||||
//取消升级
|
||||
Logger.i(TAG,"upgrade cancel")
|
||||
CallerAutoPilotManager.setIPCUpgradeCancel()
|
||||
//取消升级命令不下发
|
||||
// CallerAutoPilotManager.setIPCUpgradeCancel()
|
||||
}
|
||||
|
||||
})
|
||||
@@ -136,45 +147,56 @@ class SystemVersionView @JvmOverloads constructor(
|
||||
*/
|
||||
fun showAdUpgradeStatus(upgradeMode: Int,downloadStatus: Int,currentProgress: Int,totalProgress: Int
|
||||
,downloadVersion: String,upgradeStatus: Int){
|
||||
//设置工控机下载、升级状态信息
|
||||
setAdUpgradeInfo(upgradeMode, downloadStatus, currentProgress, totalProgress, downloadVersion, upgradeStatus)
|
||||
|
||||
if(AdUpgradeStateHelper.isDownloading(downloadStatus)){
|
||||
//正在下载,展示“下载中”角标,展示进度条,并设置当前下载进度
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_downloading)
|
||||
adCircularProgressView?.let {
|
||||
it.visibility = View.VISIBLE
|
||||
it.setProgress(AdUpgradeStateHelper.downloadProgress(currentProgress,totalProgress))
|
||||
GlobalScope.launch(Dispatchers.Main){
|
||||
//设置工控机下载、升级状态信息
|
||||
setAdUpgradeInfo(upgradeMode, downloadStatus, currentProgress, totalProgress, downloadVersion, upgradeStatus)
|
||||
|
||||
if(AdUpgradeStateHelper.isDownloading(downloadStatus)){
|
||||
//正在下载,展示“下载中”角标,展示进度条,并设置当前下载进度
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_downloading)
|
||||
adCircularProgressView?.let {
|
||||
it.visibility = View.VISIBLE
|
||||
Logger.i(TAG,"下载中="+"currentProgress="+currentProgress+" totalProgress="+totalProgress+" downloadProgress="+AdUpgradeStateHelper.downloadProgress(currentProgress,totalProgress))
|
||||
|
||||
it.setProgress(AdUpgradeStateHelper.downloadProgress(currentProgress,totalProgress))
|
||||
}
|
||||
}else if(AdUpgradeStateHelper.isDownloadFinish(downloadStatus,upgradeStatus)){
|
||||
//下载完成,处于可升级状态,展示“可升级”角标,将AD背景变为蓝色,并隐藏下载进度条
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_upgradeable)
|
||||
ivAdVersion?.setBackgroundResource(R.drawable.version_upgradeable_background)
|
||||
adCircularProgressView?.visibility = View.GONE
|
||||
if(AdUpgradeStateHelper.isQuietUpgradeMode(upgradeMode)){
|
||||
//如果升级模式为“静默升级”,则下载完成后,调用升级命令进行升级
|
||||
CallerAutoPilotManager.setIPCUpgradeAffirm()
|
||||
AdUpgradeStateHelper.setUpgradeStatus(true)
|
||||
}
|
||||
}else if(AdUpgradeStateHelper.isDownloadFailed(downloadStatus)){
|
||||
//下载失败,将状态设为“最新版”角标,并隐藏进度条
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_latest_version)
|
||||
adCircularProgressView?.visibility = View.GONE
|
||||
ivAdVersion?.setBackgroundResource(R.drawable.version_latest_background)
|
||||
} else if(AdUpgradeStateHelper.isUpgradeSuccess(upgradeStatus)){
|
||||
//升级成功,将状态设为“最新版”角标,并隐藏进度条
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_latest_version)
|
||||
adCircularProgressView?.visibility = View.GONE
|
||||
AdUpgradeStateHelper.setUpgradeStatus(false)
|
||||
ivAdVersion?.setBackgroundResource(R.drawable.version_latest_background)
|
||||
}else if(AdUpgradeStateHelper.isUpgradeFailed(upgradeStatus)){
|
||||
//升级失败,将状态设为“升级失败”角标,并隐藏进度条
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_upgrade_failed)
|
||||
adCircularProgressView?.visibility = View.GONE
|
||||
AdUpgradeStateHelper.setUpgradeStatus(false)
|
||||
ivAdVersion?.setBackgroundResource(R.drawable.version_latest_background)
|
||||
}else{
|
||||
//其他状态,均显示“最新版”,并隐藏进度条
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_latest_version)
|
||||
adCircularProgressView?.visibility = View.GONE
|
||||
ivAdVersion?.setBackgroundResource(R.drawable.version_latest_background)
|
||||
}
|
||||
}else if(AdUpgradeStateHelper.isDownloadFinish(downloadStatus)){
|
||||
//下载完成,处于可升级状态,展示“可升级”角标,将AD背景变为蓝色,并隐藏下载进度条
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_upgradeable)
|
||||
ivAdVersion?.setBackgroundResource(R.drawable.version_upgradeable_background)
|
||||
adCircularProgressView?.visibility = View.GONE
|
||||
if(AdUpgradeStateHelper.isQuietUpgradeMode(upgradeMode)){
|
||||
//如果升级模式为“静默升级”,则下载完成后,调用升级命令进行升级
|
||||
CallerAutoPilotManager.setIPCUpgradeAffirm()
|
||||
AdUpgradeStateHelper.setUpgradeStatus(true)
|
||||
}
|
||||
}else if(AdUpgradeStateHelper.isDownloadFailed(downloadStatus)){
|
||||
//下载失败,将状态设为“最新版”角标,并隐藏进度条
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_latest_version)
|
||||
adCircularProgressView?.visibility = View.GONE
|
||||
} else if(AdUpgradeStateHelper.isUpgradeSuccess(upgradeStatus)){
|
||||
//升级成功,将状态设为“最新版”角标,并隐藏进度条
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_latest_version)
|
||||
adCircularProgressView?.visibility = View.GONE
|
||||
AdUpgradeStateHelper.setUpgradeStatus(false)
|
||||
}else if(AdUpgradeStateHelper.isUpgradeFailed(upgradeStatus)){
|
||||
//升级失败,将状态设为“升级失败”角标,并隐藏进度条
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_upgrade_failed)
|
||||
adCircularProgressView?.visibility = View.GONE
|
||||
AdUpgradeStateHelper.setUpgradeStatus(false)
|
||||
}else{
|
||||
//其他状态,均显示“最新版”,并隐藏进度条
|
||||
ivAdStatus?.setImageResource(R.drawable.icon_latest_version)
|
||||
adCircularProgressView?.visibility = View.GONE
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +239,7 @@ class SystemVersionView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private fun setViewStatus(){
|
||||
|
||||
showCurrentAdVersion()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.mogo.eagle.core.data.autopilot
|
||||
|
||||
import android.util.Log
|
||||
import java.util.logging.Logger
|
||||
|
||||
/**
|
||||
* @author XuXinChao
|
||||
* @description 工控机升级状态实体类
|
||||
@@ -30,7 +33,7 @@ class AdUpgradeStateHelper {
|
||||
* @param upgradeStatus 升级状态
|
||||
*/
|
||||
fun showUpgradeTips(downloadStatus: Int,upgradeStatus: Int) : Boolean{
|
||||
return isDownloading(downloadStatus) || isDownloadFinish(downloadStatus) || isUpgradeFailed(upgradeStatus)
|
||||
return isDownloading(downloadStatus) || isDownloadFinish(downloadStatus,upgradeStatus) || getUpgradeStatus() || isUpgradeFailed(upgradeStatus)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,9 +47,10 @@ class AdUpgradeStateHelper {
|
||||
/**
|
||||
* 工控机是否处于“下载完成”(可升级)状态
|
||||
* @param downloadStatus 下载状态
|
||||
* @param upgradeStatus 升级状态
|
||||
*/
|
||||
fun isDownloadFinish(downloadStatus: Int) : Boolean{
|
||||
return downloadStatus == DOWNLOAD_FINISH
|
||||
fun isDownloadFinish(downloadStatus: Int,upgradeStatus: Int) : Boolean{
|
||||
return downloadStatus == DOWNLOAD_FINISH && upgradeStatus == USER_AFFIRM
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +83,7 @@ class AdUpgradeStateHelper {
|
||||
* @param totalProgress 包体总大小
|
||||
*/
|
||||
fun downloadProgress(currentProgress: Int,totalProgress: Int) : Int{
|
||||
return currentProgress*100/totalProgress
|
||||
return (currentProgress.toDouble()/totalProgress.toDouble()*100).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user