[2.14.0][Fix]解决首次安装App时无法获得高德定位的问题

This commit is contained in:
chenfufeng
2023-02-22 21:30:42 +08:00
parent 662b082e30
commit 7af97da137
8 changed files with 158 additions and 30 deletions

View File

@@ -6,11 +6,9 @@ import android.view.View
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.annotation.MainThread
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.marginTop
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.function.hmi.R
@@ -40,6 +38,8 @@ class OfflineMapDialog(context: Context): BaseFloatDialog(context) {
private var isConfirm = true
private var isRetry = false
var location: MogoLocation? = null
init {
setContentView(R.layout.dialog_offline_map)
setCanceledOnTouchOutside(true)
@@ -92,8 +92,8 @@ class OfflineMapDialog(context: Context): BaseFloatDialog(context) {
}
}
private fun cacheHDOfflineData() {
CallerMapUIServiceManager.cacheHDDataByCity(object : IHdCacheListener {
private fun cacheHDDataByCityByLonLat() {
CallerMapUIServiceManager.cacheHDDataByCityByLonLat(object : IHdCacheListener {
override fun onMapHdCacheProgress(cityId: Int, progress: Double) {
updateProgress(progress.toInt())
}
@@ -103,7 +103,25 @@ class OfflineMapDialog(context: Context): BaseFloatDialog(context) {
showNewContent(isLoading = false, false)
}
}
})
}, location!!)
}
private fun cacheHDOfflineData() {
if (location == null) {// 拿到了高德地图的cityCode
CallerMapUIServiceManager.cacheHDDataByCity(object : IHdCacheListener {
override fun onMapHdCacheProgress(cityId: Int, progress: Double) {
updateProgress(progress.toInt())
}
override fun onMapHdCacheResult(cityId: Int, state: Int) {
if (state == 0) {// 失败
showNewContent(isLoading = false, false)
}
}
})
} else {// 只拿到了高精的经纬度
cacheHDDataByCityByLonLat()
}
}
@SuppressLint("SetTextI18n")

View File

@@ -8,11 +8,14 @@ import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo
import com.mogo.eagle.core.data.bindingcar.AdUpgradeStateHelper
import com.mogo.eagle.core.data.bindingcar.IPCUpgradeStateInfo
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
import com.mogo.eagle.core.function.api.bindingcar.IMoGoBindingCarListener
import com.mogo.eagle.core.function.api.map.listener.IMoGoMapLocationListener
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
import com.mogo.eagle.core.function.call.bindingcar.CallerBindingCarListenerManager
import com.mogo.eagle.core.function.call.bindingcar.CallerBindingcarManager
import com.mogo.eagle.core.function.call.map.CallerMapLocationListenerManager
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.function.hmi.ui.map.OfflineMapDialog
@@ -34,7 +37,8 @@ class SystemVersionView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr), IMoGoAutopilotStatusListener,IMoGoBindingCarListener {
) : ConstraintLayout(context, attrs, defStyleAttr), IMoGoAutopilotStatusListener,
IMoGoBindingCarListener, IMoGoMapLocationListener {
companion object {
const val TAG = "SystemVersionView"
@@ -44,14 +48,15 @@ class SystemVersionView @JvmOverloads constructor(
private var dockerVersion: String? = null //工控机版本
private var autopilotStatus: Int? = null //自动驾驶状态 0代表不可自动驾驶,1代表可自动驾驶,2代表自动驾驶中
private var ipcUpgradeStateInfo: IPCUpgradeStateInfo?=null
private var ipcUpgradeStateInfo: IPCUpgradeStateInfo? = null
private var needQueryContainers: Boolean = false
private var dockerList: List<String>?=null
private var dockerList: List<String>? = null
private var previousProgress: Int = -1 //前一秒的下载进度,用于计算下载剩余时间
private var currentProgress: Int = -1 //当前已下载包体大小
private var isHDCached = false
private var location: MogoLocation? = null
init {
LayoutInflater.from(context).inflate(R.layout.view_system_version, this, true)
@@ -98,15 +103,16 @@ class SystemVersionView @JvmOverloads constructor(
when {
AdUpgradeStateHelper.isDownloading(it.status) -> {
//下载中点击Toast提示下载剩余时间
it.progress?.let { progress->
progress.progressDetail?.let {progressDetail->
if(AdUpgradeStateHelper.getRemainingTime(
it.progress?.let { progress ->
progress.progressDetail?.let { progressDetail ->
if (AdUpgradeStateHelper.getRemainingTime(
progressDetail.total,
previousProgress,
currentProgress
).isEmpty()){
).isEmpty()
) {
ToastUtils.showShort("下载已完成")
}else{
} else {
ToastUtils.showShort(
"预计" + AdUpgradeStateHelper.getRemainingTime(
progressDetail.total,
@@ -143,13 +149,23 @@ class SystemVersionView @JvmOverloads constructor(
if (isHDCached) {// 已缓存
ToastUtils.showShort(resources.getString(R.string.offline_had_downloaded))
} else {// 未缓存
OfflineMapDialog(context).show()
if (CallerMapUIServiceManager.getCityCode().isNullOrEmpty()) {// 未拿到高德的cityCode
if (location == null || (location!!.longitude <= 0.0 && location!!.latitude <= 0.0)) {// 未拿到高精的经纬度
ToastUtils.showShort(resources.getString(R.string.location_try_again))
} else {// 拿到了高精的经纬度
val dialog = OfflineMapDialog(context)
dialog.location = location
dialog.show()
}
} else {// 拿到高德的cityCode
OfflineMapDialog(context).show()
}
}
}
updateHDDataCacheStatus(CallerMapUIServiceManager.isCityDataCached())
if(AdUpgradeStateHelper.isConfirmUpgrade()){
if (AdUpgradeStateHelper.isConfirmUpgrade()) {
//将角标改为“下载中”
ivAdStatus?.setImageResource(R.drawable.icon_downloading)
ivAdVersion?.setBackgroundResource(R.drawable.version_latest_background)
@@ -165,7 +181,7 @@ class SystemVersionView @JvmOverloads constructor(
private fun setAdUpgradeInfo(ipcUpgradeStateInfo: IPCUpgradeStateInfo) {
this.previousProgress = this.currentProgress
ipcUpgradeStateInfo.progress?.let {
it.progressDetail?.let {progressDetail->
it.progressDetail?.let { progressDetail ->
this.currentProgress = progressDetail.current
}
}
@@ -176,22 +192,22 @@ class SystemVersionView @JvmOverloads constructor(
* 展示工控机下载、升级状态信息
*
*/
fun showAdUpgradeStatus(ipcUpgradeStateInfo: IPCUpgradeStateInfo){
ThreadUtils.runOnUiThread{
fun showAdUpgradeStatus(ipcUpgradeStateInfo: IPCUpgradeStateInfo) {
ThreadUtils.runOnUiThread {
setAdUpgradeInfo(ipcUpgradeStateInfo)
AdUpgradeStateHelper.setUpgradeableStatus(false)
ipcUpgradeStateInfo.status.let {status->
ipcUpgradeStateInfo.status.let { status ->
when {
AdUpgradeStateHelper.isDownloading(status) -> {
//正在下载,展示“下载中”角标,展示进度条,并设置当前下载进度
ivAdStatus?.setImageResource(R.drawable.icon_downloading)
adCircularProgressView?.let {adCircularProgressView->
adCircularProgressView?.let { adCircularProgressView ->
adCircularProgressView.visibility = View.VISIBLE
CallerLogger.i(
"$M_HMI$$TAG", "showAdUpgradeStatus status=$status"
)
ipcUpgradeStateInfo.progress?.let { progress->
progress.progressDetail?.let {progressDetail->
ipcUpgradeStateInfo.progress?.let { progress ->
progress.progressDetail?.let { progressDetail ->
adCircularProgressView.setProgress(
AdUpgradeStateHelper.downloadProgress(
progressDetail.current,
@@ -212,14 +228,14 @@ class SystemVersionView @JvmOverloads constructor(
ivAdVersion?.setBackgroundResource(R.drawable.version_latest_background)
AdUpgradeStateHelper.setConfirmUpgrade(false)
}
AdUpgradeStateHelper.isDownloadFinish(status) ->{
AdUpgradeStateHelper.isDownloadFinish(status) -> {
//升级中,将状态设为“升级中”角标,并隐藏进度条
ivAdStatus?.setImageResource(R.drawable.icon_upgrading)
adCircularProgressView?.visibility = View.GONE
ivAdVersion?.setBackgroundResource(R.drawable.version_latest_background)
AdUpgradeStateHelper.setConfirmUpgrade(false)
}
AdUpgradeStateHelper.isUpgrading(status) ->{
AdUpgradeStateHelper.isUpgrading(status) -> {
//升级中,将状态设为“升级中”角标,并隐藏进度条
ivAdStatus?.setImageResource(R.drawable.icon_upgrading)
adCircularProgressView?.visibility = View.GONE
@@ -291,7 +307,8 @@ class SystemVersionView @JvmOverloads constructor(
return
}
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
CallerBindingCarListenerManager.registerDevaToolsLogCatchListener(TAG,this)
CallerBindingCarListenerManager.registerDevaToolsLogCatchListener(TAG, this)
CallerMapLocationListenerManager.addListener(TAG, this, true)
needQueryContainers = true
}
@@ -302,6 +319,7 @@ class SystemVersionView @JvmOverloads constructor(
}
CallerAutoPilotStatusListenerManager.removeListener(TAG)
CallerBindingCarListenerManager.unRegisterDevaToolsLogCatchListener(TAG)
CallerMapLocationListenerManager.removeListener(TAG, true)
needQueryContainers = false
}
@@ -332,13 +350,13 @@ class SystemVersionView @JvmOverloads constructor(
*/
override fun queryContainersResponse(dockerList: List<String>) {
this.dockerList = dockerList
if(dockerList.isNotEmpty()){
if (dockerList.isNotEmpty()) {
//有更新任务,将状态设为“可升级”角标,并隐藏进度条
ivAdStatus?.setImageResource(R.drawable.icon_upgradeable)
adCircularProgressView?.visibility = View.GONE
ivAdVersion?.setBackgroundResource(R.drawable.version_upgradeable_background)
AdUpgradeStateHelper.setUpgradeableStatus(true)
}else{
} else {
ToastUtils.showLong("已是最新版本")
ivAdStatus?.setImageResource(R.drawable.icon_latest_version)
adCircularProgressView?.visibility = View.GONE
@@ -360,4 +378,7 @@ class SystemVersionView @JvmOverloads constructor(
adCircularProgressView?.visibility = View.GONE
}
override fun onLocationChanged(location: MogoLocation?, from: Int, isGps: Boolean) {
this.location = location
}
}

View File

@@ -59,6 +59,7 @@
<string name="offline_download_success">离线地图下载成功</string>
<string name="offline_download_failure">离线地图下载失败</string>
<string name="offline_had_downloaded">当前已为最新版本</string>
<string name="location_try_again">请检查定位是否正常</string>
<string name="ok_tip">确定</string>
<string name="retry">重试</string>
</resources>