Package com.drake.net.utils

Types

Https
Link copied to clipboard
object Https
TipUtils
Link copied to clipboard
object TipUtils

Functions

debounce
Link copied to clipboard
fun EditText.debounce(timeoutMillis: Long = 800): <ERROR CLASS>
为EditText的输入框文本变化启用节流阀, 即超过指定时间后(默认800毫秒)的输入框文本变化事件TextWatcher.onTextChanged会被下游收集到
fastest
Link copied to clipboard
@JvmName(name = fastestTransform)
suspend fun <T, R> fastest(listDeferred: List<DeferredTransform<T, R>>?, group: Any? = null): R
该函数将选择listDeferred中的Deferred执行Deferred.await, 然后将返回最快的结果 执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常
suspend fun <T> fastest(listDeferred: List<Deferred<T>>, group: Any? = null): T
该函数将选择listDeferred中的Deferred执行Deferred.await, 然后将返回最快的结果 执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常
fileName
Link copied to clipboard
fun Uri.fileName(): String?
isNetworking
Link copied to clipboard
fun Context.isNetworking(): Boolean
是否处于联网中
launchIn
Link copied to clipboard
inline fun <T> Flow<T>.launchIn(owner: LifecycleOwner? = null, event: Lifecycle.Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, crossinline action: suspend CoroutineScope.(T) -> Unit): AndroidScope
Flow直接创建作用域
md5
Link copied to clipboard
fun File.md5(base64: Boolean = false): String?
返回文件的MD5值
mediaType
Link copied to clipboard
fun Uri.mediaType(): MediaType?
fun File.mediaType(): MediaType?
返回文件的MediaType值, 如果不存在返回null
runMain
Link copied to clipboard
fun runMain(block: () -> Unit)
在主线程运行
scope
Link copied to clipboard
fun scope(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): AndroidScope
异步作用域该作用域生命周期跟随整个应用, 注意内存泄漏
fun PageRefreshLayout.scope(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): PageCoroutineScope
PageRefreshLayout的异步作用域
  1. 下拉刷新自动结束

  2. 上拉加载自动结束

  3. 捕获异常

  4. 打印异常日志

  5. 吐司部分异常com.drake.net.interfaces.NetErrorHandler.onStateError

  6. 判断添加还是覆盖数据

  7. 自动显示缺省页

布局被销毁或者界面关闭作用域被取消
fun StateLayout.scope(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope
自动处理缺省页的异步作用域 作用域开始执行时显示加载中缺省页 作用域正常结束时显示成功缺省页 作用域抛出异常时显示错误缺省页 并且自动吐司错误信息, 可配置 com.drake.net.interfaces.NetErrorHandler.onStateError 自动打印异常日志 布局被销毁或者界面关闭作用域被取消
scopeDialog
Link copied to clipboard
fun Fragment.scopeDialog(dialog: Dialog? = null, cancelable: Boolean = true, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope
作用域开始时自动显示加载对话框, 结束时自动关闭加载对话框 可以设置全局对话框 com.drake.net.NetConfig.dialogFactory 对话框被取消或者界面关闭作用域被取消
fun FragmentActivity.scopeDialog(dialog: Dialog? = null, cancelable: Boolean = true, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope
作用域开始时自动显示加载对话框, 结束时自动关闭加载对话框 可以设置全局对话框 com.drake.net.NetConfig.dialogFactory 对话框被取消或者界面关闭作用域被取消
scopeLife
Link copied to clipboard
fun Fragment.scopeLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): AndroidScope
异步作用域该作用域生命周期跟随Fragment
fun LifecycleOwner.scopeLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): AndroidScope
异步作用域该作用域生命周期跟随LifecycleOwner
scopeNet
Link copied to clipboard
fun scopeNet(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope
该函数比scope多了以下功能该作用域生命周期跟随整个应用, 注意内存泄漏
scopeNetLife
Link copied to clipboard
fun View.scopeNetLife(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): ViewCoroutineScope
视图作用域 会在视图销毁时自动取消作用域
fun Fragment.scopeNetLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope
scopeNetLife功能相同, 只是接受者为Fragment
fun LifecycleOwner.scopeNetLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope
该函数比scopeNet多了自动取消作用域功能该作用域生命周期跟随LifecycleOwner.
toRequestBody
Link copied to clipboard
fun Uri.toRequestBody(): RequestBody
当Uri指向的文件不存在时将抛出异常FileNotFoundException
fun File.toRequestBody(contentType: MediaType? = null): RequestBody
创建File的RequestBody
withDefault
Link copied to clipboard
suspend fun <T> withDefault(block: suspend CoroutineScope.() -> T): <ERROR CLASS>
切换到默认调度器
withIO
Link copied to clipboard
suspend fun <T> withIO(block: suspend CoroutineScope.() -> T): <ERROR CLASS>
切换到IO程调度器
withMain
Link copied to clipboard
suspend fun <T> withMain(block: suspend CoroutineScope.() -> T): <ERROR CLASS>
切换到主线程调度器
withUnconfined
Link copied to clipboard
suspend fun <T> withUnconfined(block: suspend CoroutineScope.() -> T): <ERROR CLASS>
切换到没有限制的调度器