Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
AlanCheen committed Nov 2, 2021
1 parent 2d980df commit 312ce56
Showing 4 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@ interface ICallback<R, E> {

fun onError(error: E)

fun onComplete() {}
// fun onComplete() {}

}
Original file line number Diff line number Diff line change
@@ -19,4 +19,4 @@ fun runOnMainThreadDelayed(delay: Long, runnable: Runnable) {

fun removeMainThreadRunnable(runnable: Runnable) {
mainThreadHandler.removeCallbacks(runnable)
}
}
10 changes: 10 additions & 0 deletions pandora/src/main/java/me/yifeiyuan/onepiece/pandora/ktx/Pandora.kt
Original file line number Diff line number Diff line change
@@ -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 <T> Any.runIfIs(clazz: Class<T>, 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()
}

0 comments on commit 312ce56

Please sign in to comment.