From fe1209e5b36c081986d5057a19187e0e16307f36 Mon Sep 17 00:00:00 2001 From: wangmingjun Date: Tue, 14 Mar 2023 14:24:10 +0800 Subject: [PATCH] =?UTF-8?q?[M2]=E5=BD=93=E5=89=8D=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../passenger/ui/PM2DrivingInfoFragment.kt | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/PM2DrivingInfoFragment.kt b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/PM2DrivingInfoFragment.kt index 1ed52135ce..47ca090794 100644 --- a/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/PM2DrivingInfoFragment.kt +++ b/OCH/mogo-och-bus-passenger/src/m2/java/com/mogo/och/bus/passenger/ui/PM2DrivingInfoFragment.kt @@ -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() { - 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 = 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 } } \ No newline at end of file