From bfcc3fff30487b44eae6dae9e1671b5592f29c59 Mon Sep 17 00:00:00 2001 From: wangmingjun Date: Mon, 27 Feb 2023 15:11:02 +0800 Subject: [PATCH] =?UTF-8?q?[M2]=20m2=20EB5=E6=97=B6=E9=97=B4=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../passenger/ui/PM2DrivingInfoFragment.kt | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 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 1182752a5a..85b1cdd90f 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 @@ -2,16 +2,13 @@ package com.mogo.och.bus.passenger.ui import android.graphics.BitmapFactory import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.os.Message import android.view.View import androidx.core.content.ContextCompat import com.amap.api.maps.model.LatLng import com.mogo.commons.mvp.MvpFragment -import com.mogo.eagle.core.data.msgbox.MsgBoxBean -import com.mogo.eagle.core.data.msgbox.MsgBoxType -import com.mogo.eagle.core.data.msgbox.NoticeFrCloudMsg -import com.mogo.eagle.core.data.msgbox.V2XMsg -import com.mogo.eagle.core.data.notice.NoticeTrafficStylePushData -import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager 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 @@ -21,6 +18,7 @@ import com.mogo.och.bus.passenger.presenter.PM2DrivingPresenter import com.mogo.och.common.module.utils.DateTimeUtil.* import com.mogo.och.common.module.utils.NumberFormatUtil import kotlinx.android.synthetic.m2.p_m2_driving_info_fragment.* +import java.lang.ref.WeakReference import kotlin.math.ceil import kotlin.math.roundToInt @@ -30,6 +28,9 @@ import kotlin.math.roundToInt */ class PM2DrivingInfoFragment : MvpFragment() { + + private var timeHandler: TimeHandler? = null + /** * 改变自动驾驶状态 * @@ -71,6 +72,8 @@ class PM2DrivingInfoFragment : // BPRouteDataTestUtils.converToRouteData() } updateCurrentTime() + timeHandler = TimeHandler(this) + timeHandler?.sendEmptyMessageDelayed(WHAT_TIME_CURRENT, LOOP_TIME_TEXT) } override fun initViews(savedInstanceState: Bundle?) { @@ -89,6 +92,7 @@ class PM2DrivingInfoFragment : } override fun onDestroy() { + timeHandler?.removeCallbacksAndMessages(null) super.onDestroy() overMapView.onDestroy() } @@ -216,8 +220,27 @@ class PM2DrivingInfoFragment : "$remainDis$disUnit | $time 分钟".also { remain_mt.text = it } } - companion object { - private val TAG = PM2DrivingInfoFragment::class.java.simpleName + 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 -> {} + } + } + } } + companion object { + private val TAG = PM2DrivingInfoFragment::class.java.simpleName + const val LOOP_TIME_TEXT = 60 * 1000L + const val WHAT_TIME_CURRENT = 10001 //MSG_WHAT + } } \ No newline at end of file