[BadCase]解决BadCase入口与OCH模块之间的显示问题
[BadCase]解决BadCase入口与OCH模块之间的显示问题 [BadCase]解决BadCase入口与OCH模块之间的显示问题 [BadCase]解决BadCase入口与OCH模块之间的显示问题
This commit is contained in:
@@ -84,6 +84,7 @@ public class MogoApplication extends MainMoGoApplication {
|
||||
HmiBuildConfig.isShowAutopilotStatusView = false;
|
||||
HmiBuildConfig.isShowPerspectiveSwitchView = false;
|
||||
HmiBuildConfig.isShowToolsView = false;
|
||||
HmiBuildConfig.isShowBadCaseView = false;
|
||||
}
|
||||
|
||||
if (DebugConfig.getProductFlavor().equals("fPadLenovoOchTaxi")
|
||||
|
||||
@@ -53,7 +53,6 @@ dependencies {
|
||||
implementation rootProject.ext.dependencies.mogoaicloudtrafficlive
|
||||
|
||||
kapt rootProject.ext.dependencies.aroutercompiler
|
||||
|
||||
kapt rootProject.ext.dependencies.androidxroomcompiler
|
||||
implementation rootProject.ext.dependencies.androidxroomruntime
|
||||
implementation rootProject.ext.dependencies.androidxroomktx
|
||||
|
||||
@@ -7,6 +7,8 @@ import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.view.animation.OvershootInterpolator
|
||||
import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
|
||||
@@ -41,6 +43,7 @@ import com.mogo.eagle.core.function.hmi.ui.tools.AutoPilotBadCaseView
|
||||
import com.mogo.eagle.core.function.hmi.ui.tools.Repository
|
||||
import com.mogo.eagle.core.function.hmi.ui.tools.post
|
||||
import com.mogo.eagle.core.function.hmi.ui.widget.V2XNotificationView
|
||||
import com.mogo.eagle.core.utilcode.kotlin.lifecycleOwner
|
||||
import com.mogo.eagle.core.utilcode.kotlin.onClick
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
@@ -90,6 +93,9 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
|
||||
|
||||
private var autoPilotBadCaseView: AutoPilotBadCaseView? = null
|
||||
|
||||
private var onBadCaseShow: (() -> Unit)? = null
|
||||
private var onBadCaseHide: (() -> Unit)? = null
|
||||
|
||||
companion object {
|
||||
private const val MSG_WHAT_DISMISS_BAD_CASE_ENTRY = 0x1010
|
||||
private val CASE_EXPIRE_DURATION = TimeUnit.HOURS.toMillis(4)
|
||||
@@ -186,6 +192,7 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
|
||||
}
|
||||
dismissBadCaseFloatView()
|
||||
entrance.visibility = View.GONE
|
||||
onBadCaseHide?.invoke()
|
||||
}
|
||||
return@Callback true
|
||||
}
|
||||
@@ -224,7 +231,7 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
CallerAutopilotIdentifyListenerManager.addListener(TAG, this)
|
||||
@@ -242,7 +249,7 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
override fun onAutopilotRecordResult(record: AutoPilotRecordResult?) {
|
||||
record ?: return
|
||||
Log.d("QQQ", "onAutopilotRecordResult:$record")
|
||||
@@ -271,9 +278,11 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
|
||||
private fun showBadCaseEntrance(record: AutoPilotRecordResult) {
|
||||
Log.d("QQQ", "showBadCaseEntrance:$record")
|
||||
lifecycleScope.launch {
|
||||
if (vs_bad_case_entrance?.parent != null) {
|
||||
val inflateView = vs_bad_case_entrance.inflate()
|
||||
autoPilotBadCaseEntrance = inflateView
|
||||
if (HmiBuildConfig.isShowBadCaseView) {
|
||||
if (vs_bad_case_entrance?.parent != null) {
|
||||
val inflateView = vs_bad_case_entrance.inflate()
|
||||
autoPilotBadCaseEntrance = inflateView
|
||||
}
|
||||
}
|
||||
val entrance = autoPilotBadCaseEntrance
|
||||
Log.d("QQQ", "show --- 1 ----")
|
||||
@@ -285,13 +294,42 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
|
||||
entrance.onClick {
|
||||
showBadCasesFloat {
|
||||
it.visibility = View.GONE
|
||||
onBadCaseHide?.invoke()
|
||||
}
|
||||
}
|
||||
dismissBadCaseEntryAfterSomeTime()
|
||||
} else {
|
||||
onBadCaseShow?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun showBadCaseEntrance(entrance: View) {
|
||||
entrance.lifecycleOwner.lifecycle.addObserver(badCaseEntranceObserver)
|
||||
autoPilotBadCaseEntrance = entrance
|
||||
lifecycleScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
val dao = Repository.dao()
|
||||
dao.getAllUnConsumedRecords()?.first()?.let {
|
||||
showBadCaseEntrance(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val badCaseEntranceObserver = LifecycleEventObserver { _, event ->
|
||||
if (event == ON_DESTROY) {
|
||||
onBadCaseShow = null
|
||||
onBadCaseHide = null
|
||||
autoPilotBadCaseEntrance = null
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerBadCaseCallback(onShow: () -> Unit, onHide: (() -> Unit)?) {
|
||||
onBadCaseShow = onShow
|
||||
onBadCaseHide = onHide
|
||||
}
|
||||
|
||||
private fun showBadCasesFloat(dismiss: (() -> Unit)?) {
|
||||
Log.d("QQQ", "showBadCaseToolsFloat")
|
||||
context?.let { it ->
|
||||
@@ -496,7 +534,6 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
|
||||
} else {
|
||||
setToolsViewVisibility(View.GONE)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
|
||||
@@ -29,4 +29,10 @@ object HmiBuildConfig {
|
||||
*/
|
||||
@JvmField
|
||||
var isShowToolsView = true
|
||||
|
||||
/**
|
||||
* 是否展示BadCase按钮
|
||||
*/
|
||||
@JvmField
|
||||
var isShowBadCaseView = true
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mogo.eagle.core.function.api.hmi.warning
|
||||
|
||||
import android.view.View
|
||||
import com.mogo.eagle.core.data.enums.WarningDirectionEnum
|
||||
import com.mogo.eagle.core.data.notice.NoticeNormalData
|
||||
import com.mogo.eagle.core.data.notice.NoticeTrafficStylePushData
|
||||
@@ -179,4 +180,17 @@ interface IMoGoWaringProvider {
|
||||
*/
|
||||
fun showAdUpgradeStatus(upgradeMode : Int,downloadStatus : Int,currentProgress : Int,totalProgress : Int
|
||||
,downloadVersion : String,upgradeStatus : Int)
|
||||
|
||||
|
||||
/**
|
||||
* 显示BadCase入口
|
||||
*/
|
||||
fun showBadCaseEntrance(entrance: View)
|
||||
|
||||
/**
|
||||
* 注册badcase入口展示和隐藏的回调
|
||||
* 当[onShow]被调用时,调用[showBadCaseEntrance]
|
||||
* [onHide]回调不用关心,可以不注册
|
||||
*/
|
||||
fun registerBadCaseCallback(onShow:() -> Unit, onHide: (() -> Unit)?)
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mogo.eagle.core.function.call.hmi
|
||||
|
||||
import android.view.View
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.eagle.core.data.constants.MoGoFragmentPaths
|
||||
import com.mogo.eagle.core.data.enums.WarningDirectionEnum
|
||||
@@ -16,16 +17,16 @@ import com.mogo.eagle.core.function.call.base.CallerBase
|
||||
* HMI 调用者管理,这里对外及其他模块提供功能的调用,用啥写啥,不要过度设计,不允许直接将Provider暴露出去
|
||||
*/
|
||||
object CallerHmiManager : CallerBase() {
|
||||
private val waringProviderApi: IMoGoWaringProvider
|
||||
private val waringProviderApi
|
||||
get() = ARouter.getInstance().build(MoGoFragmentPaths.PATH_FRAGMENT_HMI)
|
||||
.navigation() as IMoGoWaringProvider;
|
||||
.navigation() as? IMoGoWaringProvider;
|
||||
|
||||
/**
|
||||
* 隐藏 脉速表
|
||||
* @param visibility View.VISIBLE, View.INVISIBLE,View.GONE
|
||||
*/
|
||||
fun setSpeedChartViewVisibility(visibility: Int) {
|
||||
waringProviderApi.setSpeedChartViewVisibility(visibility)
|
||||
waringProviderApi?.setSpeedChartViewVisibility(visibility)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param visibility View.VISIBLE, View.INVISIBLE,View.GONE
|
||||
*/
|
||||
fun setAutopilotStatusViewVisibility(visibility: Int) {
|
||||
waringProviderApi.setAutopilotStatusViewVisibility(visibility)
|
||||
waringProviderApi?.setAutopilotStatusViewVisibility(visibility)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +42,7 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param visibility View.VISIBLE, View.INVISIBLE,View.GONE
|
||||
*/
|
||||
fun setPerspectiveSwitchViewVisibility(visibility: Int) {
|
||||
waringProviderApi.setPerspectiveSwitchViewVisibility(visibility)
|
||||
waringProviderApi?.setPerspectiveSwitchViewVisibility(visibility)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,21 +50,21 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param visibility View.VISIBLE, View.INVISIBLE,View.GONE
|
||||
*/
|
||||
fun setToolsViewVisibility(visibility: Int) {
|
||||
waringProviderApi.setToolsViewVisibility(visibility)
|
||||
waringProviderApi?.setToolsViewVisibility(visibility)
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制转向灯和刹车功能
|
||||
*/
|
||||
fun setTurnLightFunction(isOpen: Boolean) {
|
||||
waringProviderApi.setTurnLightFunction(isOpen)
|
||||
waringProviderApi?.setTurnLightFunction(isOpen)
|
||||
}
|
||||
|
||||
/**
|
||||
* 开关DebugView
|
||||
*/
|
||||
fun toggleDebugView(){
|
||||
waringProviderApi.toggleDebugView()
|
||||
waringProviderApi?.toggleDebugView()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +76,7 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param tag tag绑定弹窗的标志
|
||||
*/
|
||||
fun showWarningV2X(v2xType: Int, alertContent: CharSequence?, ttsContent: String?, tag: String?, listenerIMoGo: IMoGoWarningStatusListener?, playTts: Boolean, expireTime: Long = 5000L) {
|
||||
waringProviderApi.showWarningV2X(v2xType, alertContent, ttsContent, tag, listenerIMoGo, playTts, expireTime)
|
||||
waringProviderApi?.showWarningV2X(v2xType, alertContent, ttsContent, tag, listenerIMoGo, playTts, expireTime)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +84,7 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param tag 弹窗标识
|
||||
*/
|
||||
fun disableWarningV2X(tag: String?) {
|
||||
waringProviderApi.disableWarningV2X(tag)
|
||||
waringProviderApi?.disableWarningV2X(tag)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,42 +93,42 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param checkLightId 0-都是默认,1-红,2-黄,3-绿
|
||||
*/
|
||||
fun showWarningTrafficLight(checkLightId: Int) {
|
||||
waringProviderApi.showWarningTrafficLight(checkLightId)
|
||||
waringProviderApi?.showWarningTrafficLight(checkLightId)
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭红绿灯预警
|
||||
*/
|
||||
fun disableWarningTrafficLight() {
|
||||
waringProviderApi.disableWarningTrafficLight()
|
||||
waringProviderApi?.disableWarningTrafficLight()
|
||||
}
|
||||
|
||||
/**
|
||||
* 红绿灯是否展示
|
||||
*/
|
||||
fun isWarningTrafficLightShow(): Boolean {
|
||||
return waringProviderApi.isWarningTrafficLightShow()
|
||||
return waringProviderApi?.isWarningTrafficLightShow() ?: false
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改红灯倒计时
|
||||
*/
|
||||
fun changeCountdownRed(redNum: Int) {
|
||||
waringProviderApi.changeCountdownRed(redNum)
|
||||
waringProviderApi?.changeCountdownRed(redNum)
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改黄灯倒计时
|
||||
*/
|
||||
fun changeCountdownYellow(yellowNum: Int) {
|
||||
waringProviderApi.changeCountdownYellow(yellowNum)
|
||||
waringProviderApi?.changeCountdownYellow(yellowNum)
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改绿灯倒计时
|
||||
*/
|
||||
fun changeCountdownGreen(greenNum: Int) {
|
||||
waringProviderApi.changeCountdownGreen(greenNum)
|
||||
waringProviderApi?.changeCountdownGreen(greenNum)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,7 +137,7 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param greenNum 绿灯倒计时
|
||||
*/
|
||||
fun changeCountdownTrafficLightNum(readNum: Int, yellowNum: Int, greenNum: Int) {
|
||||
waringProviderApi.changeCountdownTrafficLightNum(readNum, yellowNum, greenNum)
|
||||
waringProviderApi?.changeCountdownTrafficLightNum(readNum, yellowNum, greenNum)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,14 +146,14 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param limitingSpeed 限速速度
|
||||
*/
|
||||
fun showLimitingVelocity(limitingSpeed: Int) {
|
||||
waringProviderApi.showLimitingVelocity(limitingSpeed)
|
||||
waringProviderApi?.showLimitingVelocity(limitingSpeed)
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭限速预警
|
||||
*/
|
||||
fun disableLimitingVelocity() {
|
||||
waringProviderApi.disableLimitingVelocity()
|
||||
waringProviderApi?.disableLimitingVelocity()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +162,7 @@ object CallerHmiManager : CallerBase() {
|
||||
* @see WarningDirectionEnum
|
||||
*/
|
||||
fun showWarning(direction: WarningDirectionEnum) {
|
||||
waringProviderApi.showWarning(direction)
|
||||
waringProviderApi?.showWarning(direction)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,14 +172,14 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param closeTime 倒计时
|
||||
*/
|
||||
fun showWarning(direction: WarningDirectionEnum, closeTime: Long) {
|
||||
waringProviderApi.showWarning(direction, closeTime)
|
||||
waringProviderApi?.showWarning(direction, closeTime)
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动消失边框预警
|
||||
*/
|
||||
fun dismissWarning(direction: WarningDirectionEnum) {
|
||||
waringProviderApi.dismissWarning(direction)
|
||||
waringProviderApi?.dismissWarning(direction)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +188,7 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param trafficStylePushData
|
||||
*/
|
||||
fun showTrafficBanner(trafficStylePushData: NoticeTrafficStylePushData?) {
|
||||
waringProviderApi.showNoticeForTrafficWithData(trafficStylePushData)
|
||||
waringProviderApi?.showNoticeForTrafficWithData(trafficStylePushData)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,21 +196,21 @@ object CallerHmiManager : CallerBase() {
|
||||
*
|
||||
*/
|
||||
fun showNoticeNormalData(noticeNormal: NoticeNormalData) {
|
||||
waringProviderApi.showNoticeNormalData(noticeNormal)
|
||||
waringProviderApi?.showNoticeNormalData(noticeNormal)
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示VIP标识
|
||||
*/
|
||||
fun vipIdentification(visible: Boolean) {
|
||||
waringProviderApi.vipIdentification(visible)
|
||||
waringProviderApi?.vipIdentification(visible)
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启道路视频直播
|
||||
*/
|
||||
fun startRoadCameraLive(flvUrl: String) {
|
||||
waringProviderApi.startRoadCameraLive(flvUrl)
|
||||
waringProviderApi?.startRoadCameraLive(flvUrl)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +219,7 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param light
|
||||
*/
|
||||
fun showTurnLight(light: Int) {
|
||||
waringProviderApi.showTurnLight(light)
|
||||
waringProviderApi?.showTurnLight(light)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,19 +228,19 @@ object CallerHmiManager : CallerBase() {
|
||||
* @param brakeLight
|
||||
*/
|
||||
fun showBrakeLight(brakeLight: Int) {
|
||||
waringProviderApi.showBrakeLight(brakeLight)
|
||||
waringProviderApi?.showBrakeLight(brakeLight)
|
||||
}
|
||||
|
||||
fun showNoSignalView() {
|
||||
waringProviderApi.showNoSignView()
|
||||
waringProviderApi?.showNoSignView()
|
||||
}
|
||||
|
||||
fun showToolsView() {
|
||||
waringProviderApi.showToolsView()
|
||||
waringProviderApi?.showToolsView()
|
||||
}
|
||||
|
||||
fun hideToolsView() {
|
||||
waringProviderApi.hideToolsView()
|
||||
waringProviderApi?.hideToolsView()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,8 +254,23 @@ object CallerHmiManager : CallerBase() {
|
||||
*/
|
||||
fun showAdUpgradeStatus(upgradeMode : Int, downloadStatus : Int,currentProgress : Int,totalProgress : Int
|
||||
,downloadVersion : String,upgradeStatus : Int){
|
||||
waringProviderApi.showAdUpgradeStatus(upgradeMode,downloadStatus, currentProgress, totalProgress, downloadVersion, upgradeStatus)
|
||||
waringProviderApi?.showAdUpgradeStatus(upgradeMode,downloadStatus, currentProgress, totalProgress, downloadVersion, upgradeStatus)
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示BadCase入口
|
||||
*/
|
||||
fun showBadCaseEntrance(entrance: View) {
|
||||
waringProviderApi?.showBadCaseEntrance(entrance)
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册badcase入口展示和隐藏的回调
|
||||
* 当[onShow]被调用时,调用[showBadCaseEntrance]
|
||||
* [onHide]回调不用关心,可以不注册
|
||||
*/
|
||||
fun registerBadCaseCallback(onShow:() -> Unit, onHide: (() -> Unit)?) {
|
||||
waringProviderApi?.registerBadCaseCallback(onShow, onHide)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,10 +8,60 @@ import android.util.TypedValue
|
||||
import android.view.View
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.IntRange
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.LifecycleRegistry
|
||||
import com.mogo.eagle.core.utilcode.util.ClickUtils
|
||||
import com.mogo.eagle.core.utilcode.util.R
|
||||
import com.mogo.eagle.core.utilcode.util.Utils
|
||||
import java.util.*
|
||||
|
||||
val <T: View> T.lifecycleOwner: LifecycleOwner
|
||||
get() = getTag(R.id.view_lifecycle_owner) as? LifecycleOwner ?: object : LifecycleOwner, LifecycleEventObserver {
|
||||
|
||||
private val lifecycle = LifecycleRegistry(this)
|
||||
|
||||
init {
|
||||
if (ViewCompat.isAttachedToWindow(this@lifecycleOwner)) {
|
||||
lifecycle.let {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
|
||||
it.currentState = Lifecycle.State.CREATED
|
||||
}
|
||||
}
|
||||
}
|
||||
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
||||
override fun onViewAttachedToWindow(v: View?) {
|
||||
lifecycle.let {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
|
||||
it.currentState = Lifecycle.State.CREATED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewDetachedFromWindow(v: View?) {
|
||||
lifecycle.let {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
||||
this@lifecycleOwner.removeOnAttachStateChangeListener(this)
|
||||
it.currentState = Lifecycle.State.DESTROYED
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
|
||||
lifecycle.currentState = event.targetState
|
||||
}
|
||||
|
||||
override fun getLifecycle(): Lifecycle {
|
||||
return lifecycle
|
||||
}
|
||||
|
||||
}.also {
|
||||
setTag(R.id.view_lifecycle_owner, it)
|
||||
}
|
||||
|
||||
fun View.onClick(block: (View) -> Unit) {
|
||||
this.setOnClickListener {
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.doOnAttach
|
||||
import androidx.core.view.doOnDetach
|
||||
import androidx.lifecycle.*
|
||||
import com.mogo.eagle.core.utilcode.kotlin.lifecycleOwner
|
||||
import com.mogo.eagle.core.utilcode.util.R
|
||||
import com.mogo.eagle.core.utilcode.util.Utils
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@@ -106,52 +107,6 @@ interface IReminder : Comparable<IReminder> {
|
||||
}
|
||||
}
|
||||
|
||||
val <T: View> T.lifecycleOwner: LifecycleOwner
|
||||
get() = getTag(R.id.view_lifecycle_owner) as? LifecycleOwner ?: object : LifecycleOwner, LifecycleEventObserver {
|
||||
|
||||
private val lifecycle = LifecycleRegistry(this)
|
||||
|
||||
init {
|
||||
if (ViewCompat.isAttachedToWindow(this@lifecycleOwner)) {
|
||||
lifecycle.let {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
|
||||
it.currentState = Lifecycle.State.CREATED
|
||||
}
|
||||
}
|
||||
}
|
||||
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
||||
override fun onViewAttachedToWindow(v: View?) {
|
||||
lifecycle.let {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
|
||||
it.currentState = Lifecycle.State.CREATED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewDetachedFromWindow(v: View?) {
|
||||
lifecycle.let {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
||||
this@lifecycleOwner.removeOnAttachStateChangeListener(this)
|
||||
it.currentState = Lifecycle.State.DESTROYED
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
|
||||
lifecycle.currentState = event.targetState
|
||||
}
|
||||
|
||||
override fun getLifecycle(): Lifecycle {
|
||||
return lifecycle
|
||||
}
|
||||
|
||||
}.also {
|
||||
setTag(R.id.view_lifecycle_owner, it)
|
||||
}
|
||||
|
||||
|
||||
val <T: PopupWindow> T.lifecycleOwner: LifecycleOwner
|
||||
get() = popupWindowLifecycleMap[this]
|
||||
?: object : LifecycleOwner, LifecycleEventObserver {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.eagle.core.utilcode.reminder.api.impl
|
||||
import android.view.View
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.mogo.eagle.core.utilcode.kotlin.lifecycleOwner
|
||||
import com.mogo.eagle.core.utilcode.reminder.api.IReminder
|
||||
|
||||
abstract class ViewReminder(private val content: View): IReminder {
|
||||
|
||||
Reference in New Issue
Block a user