[M2]当前时间展示逻辑修改

This commit is contained in:
wangmingjun
2023-03-14 14:24:10 +08:00
parent 153c23a817
commit fe1209e5b3

View File

@@ -12,6 +12,7 @@ import com.mogo.commons.mvp.MvpFragment
import com.mogo.eagle.core.function.hmi.ui.setting.ToggleDebugView
import com.mogo.eagle.core.utilcode.kotlin.onClick
import com.mogo.eagle.core.utilcode.util.DateTimeUtils
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import com.mogo.och.bus.passenger.R
import com.mogo.och.bus.passenger.bean.PM2Station
import com.mogo.och.bus.passenger.presenter.PM2DrivingPresenter
@@ -29,7 +30,7 @@ import kotlin.math.roundToInt
class PM2DrivingInfoFragment :
MvpFragment<PM2DrivingInfoFragment?, PM2DrivingPresenter?>() {
private var timeHandler: TimeHandler? = null
// private var timeHandler: TimeHandler? = null
/**
* 改变自动驾驶状态
@@ -76,8 +77,6 @@ class PM2DrivingInfoFragment :
// BPRouteDataTestUtils.converToRouteData()
// }
updateCurrentTime()
timeHandler = TimeHandler(this)
timeHandler?.sendEmptyMessageDelayed(WHAT_TIME_CURRENT, LOOP_TIME_TEXT)
}
override fun initViews(savedInstanceState: Bundle?) {
@@ -102,7 +101,7 @@ class PM2DrivingInfoFragment :
}
override fun onDestroy() {
timeHandler?.removeCallbacksAndMessages(null)
// timeHandler?.removeCallbacksAndMessages(null)
super.onDestroy()
overMapView?.let{
it.onDestroy()
@@ -133,6 +132,8 @@ class PM2DrivingInfoFragment :
DateTimeUtils.getCurrentDateTime(), yy_MM_dd)
val weekDay = DateTimeUtils.getWeekDayFromCalendar1(DateTimeUtils.getCurrentDateTime())
"$date $weekDay".also { current_weekday_tv.text = it }
sendUpdateTimeTask() // 每10s更新一次
}
fun changeOperationStatus(status:Boolean){
@@ -238,27 +239,14 @@ class PM2DrivingInfoFragment :
"$remainDis$disUnit | $time 分钟".also { remain_mt.text = it }
}
class TimeHandler(obj: PM2DrivingInfoFragment) : Handler(Looper.getMainLooper()) {
private val mRef: WeakReference<PM2DrivingInfoFragment> = WeakReference(obj)
val drivingInfoFragment = mRef.get() as PM2DrivingInfoFragment
override fun handleMessage(msg: Message) {
mRef.get()?.run {
when (msg.what) {
WHAT_TIME_CURRENT -> {
drivingInfoFragment.updateCurrentTime()
sendEmptyMessageDelayed(
WHAT_TIME_CURRENT, LOOP_TIME_TEXT)
} //可以直接访问Activity中的变量
else -> {}
}
}
}
private fun sendUpdateTimeTask() {
UiThreadHandler.postDelayed({
updateCurrentTime()
},LOOP_TIME_TEXT)
}
companion object {
private val TAG = PM2DrivingInfoFragment::class.java.simpleName
const val LOOP_TIME_TEXT = 10 * 1000L
const val WHAT_TIME_CURRENT = 10001 //MSG_WHAT
}
}