From 312ce56e0cb6d4733c8a78b8ecefc858091dfb50 Mon Sep 17 00:00:00 2001 From: mingjue Date: Tue, 2 Nov 2021 14:33:54 +0800 Subject: [PATCH] update --- .../foundation/{LifecycleHandler.kt => LiveHandler.kt} | 2 +- .../me/yifeiyuan/onepiece/foundation/data/ICallback.kt | 2 +- .../java/me/yifeiyuan/onepiece/pandora/ktx/Handlerx.kt | 2 +- .../java/me/yifeiyuan/onepiece/pandora/ktx/Pandora.kt | 10 ++++++++++ 4 files changed, 13 insertions(+), 3 deletions(-) rename foundation/src/main/java/me/yifeiyuan/onepiece/foundation/{LifecycleHandler.kt => LiveHandler.kt} (93%) diff --git a/foundation/src/main/java/me/yifeiyuan/onepiece/foundation/LifecycleHandler.kt b/foundation/src/main/java/me/yifeiyuan/onepiece/foundation/LiveHandler.kt similarity index 93% rename from foundation/src/main/java/me/yifeiyuan/onepiece/foundation/LifecycleHandler.kt rename to foundation/src/main/java/me/yifeiyuan/onepiece/foundation/LiveHandler.kt index df41e0a..3dfcaf8 100644 --- a/foundation/src/main/java/me/yifeiyuan/onepiece/foundation/LifecycleHandler.kt +++ b/foundation/src/main/java/me/yifeiyuan/onepiece/foundation/LiveHandler.kt @@ -11,7 +11,7 @@ import androidx.lifecycle.OnLifecycleEvent /** * Created by 程序亦非猿 on 2021/3/24. */ -open class LifecycleHandler @JvmOverloads constructor( +open class LiveHandler @JvmOverloads constructor( private var lifecycleOwner: LifecycleOwner, looper: Looper = Looper.getMainLooper(), callback: Callback? = null diff --git a/foundation/src/main/java/me/yifeiyuan/onepiece/foundation/data/ICallback.kt b/foundation/src/main/java/me/yifeiyuan/onepiece/foundation/data/ICallback.kt index 409e714..e5a3cf7 100644 --- a/foundation/src/main/java/me/yifeiyuan/onepiece/foundation/data/ICallback.kt +++ b/foundation/src/main/java/me/yifeiyuan/onepiece/foundation/data/ICallback.kt @@ -11,6 +11,6 @@ interface ICallback { fun onError(error: E) - fun onComplete() {} +// fun onComplete() {} } \ No newline at end of file diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Handlerx.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Handlerx.kt index 7273fa5..35b1995 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Handlerx.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Handlerx.kt @@ -19,4 +19,4 @@ fun runOnMainThreadDelayed(delay: Long, runnable: Runnable) { fun removeMainThreadRunnable(runnable: Runnable) { mainThreadHandler.removeCallbacks(runnable) -} \ No newline at end of file +} diff --git a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Pandora.kt b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Pandora.kt index a0bd9fb..749459b 100644 --- a/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Pandora.kt +++ b/pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Pandora.kt @@ -1,5 +1,7 @@ package me.yifeiyuan.onepiece.pandora.ktx +import android.os.Looper + /** * Created by 程序亦非猿 on 2021/9/13. */ @@ -8,4 +10,12 @@ fun Any.runIfIs(clazz: Class, block: T.() -> Unit) { if (clazz.isAssignableFrom(this::class.java)) { block(this as T) } +} + +/** + * + * 为什么不用 Looper.myLooper() == Looper.getMainLooper()? 因为 myLooper() 可能会创建 ThreadLocalMap 导致浪费 + */ +fun isOnMainThread() :Boolean{ + return Looper.getMainLooper().thread == Thread.currentThread() } \ No newline at end of file