[Chat]车聊聊架构升级

This commit is contained in:
renwj
2022-03-09 11:18:30 +08:00
committed by zhongchao
parent b16e7edbd3
commit 9275ed5ff2
178 changed files with 8116 additions and 301 deletions

View File

@@ -4,18 +4,19 @@ import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.text.TextUtils
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 androidx.lifecycle.*
import androidx.lifecycle.Lifecycle.Event
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 kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import java.util.*
val <T: View> T.lifecycleOwner: LifecycleOwner
@@ -72,6 +73,37 @@ fun View.onClick(block: (View) -> Unit) {
}
}
val <T: Context> T.lifeCycleScope: LifecycleCoroutineScope
get() = (this as? LifecycleOwner)?.lifecycleScope ?: ProcessLifecycleOwner.get().lifecycleScope
fun <T: View> T.observe(target: Array<Event>, block: ((event: Event) -> Unit) ?= null) {
block?.let {
this.lifecycleOwner.lifecycle.addObserver(object : LifecycleEventObserver {
override fun onStateChanged(source: LifecycleOwner, event: Event) {
if (target.contains(event)) {
it.invoke(event)
}
}
})
}
}
fun Job.safeCancel(cause: String? = null) = try {
this.cancel(if (TextUtils.isEmpty(cause)) null else CancellationException(cause))
} catch (t: Throwable) { t.printStackTrace() }
fun CoroutineScope.safeCancel(cause: String? = null) = try {
this.cancel(if (TextUtils.isEmpty(cause)) null else CancellationException(cause))
} catch (t: Throwable) { t.printStackTrace() }
fun <T: Any> Channel<T>.safeCancel(cause: String? = null) = try {
this.cancel(if (TextUtils.isEmpty(cause)) null else CancellationException(cause))
} catch (t: Throwable) { t.printStackTrace() }
fun <T: Any> Deferred<T>.safeCancel(cause: String? = null) = try {
this.cancel(if (TextUtils.isEmpty(cause)) null else CancellationException(cause))
} catch (t: Throwable) { t.printStackTrace() }
fun shape(@ColorInt solid: Int = Color.TRANSPARENT, @ColorInt stroke: Int = Color.TRANSPARENT, @IntRange(from = 0) strokeWidth: Int = 0, @IntRange(from = 0) radius: Int = 0, radii: FloatArray = FloatArray(8).apply { Arrays.fill(this, radius.toFloat()) }, shape: Int = GradientDrawable.RECTANGLE): Drawable {
val drawable = GradientDrawable()
drawable.shape = shape

View File

@@ -632,11 +632,10 @@ public class ClickUtils {
if (Math.abs(now - past) < (long)duration) {
return true;
}
view.setTag(R.id.tag_click_time, now);
} catch (Exception var7) {
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
}