# Package com.drake.net.utils

## Types

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

## Functions

debounce
Link copied to clipboard
fun EditText.debounce(timeoutMillis: Long = 800): <ERROR CLASS>
Content copied to clipboard
为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
Content copied to clipboard
该函数将选择listDeferred中的Deferred执行Deferred.await, 然后将返回最快的结果 执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常
suspend fun <T> fastest(listDeferred: List<Deferred<T>>, group: Any? = null): T
Content copied to clipboard
该函数将选择listDeferred中的Deferred执行Deferred.await, 然后将返回最快的结果 执行过程中的异常将被忽略, 如果全部抛出异常则将抛出最后一个Deferred的异常
fileName
Link copied to clipboard
fun Uri.fileName(): String?
Content copied to clipboard
isNetworking
Link copied to clipboard
fun Context.isNetworking(): Boolean
Content copied to clipboard
是否处于联网中
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
Content copied to clipboard
Flow直接创建作用域
md5
Link copied to clipboard
fun File.md5(base64: Boolean = false): String?
Content copied to clipboard
返回文件的MD5值
mediaType
Link copied to clipboard
fun Uri.mediaType(): MediaType?
Content copied to clipboard
fun File.mediaType(): MediaType?
Content copied to clipboard
返回文件的MediaType值, 如果不存在返回null
runMain
Link copied to clipboard
fun runMain(block: () -> Unit)
Content copied to clipboard
在主线程运行
scope
Link copied to clipboard
fun scope(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): AndroidScope
Content copied to clipboard
异步作用域该作用域生命周期跟随整个应用, 注意内存泄漏
fun PageRefreshLayout.scope(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): PageCoroutineScope
Content copied to clipboard
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
Content copied to clipboard
自动处理缺省页的异步作用域 作用域开始执行时显示加载中缺省页 作用域正常结束时显示成功缺省页 作用域抛出异常时显示错误缺省页 并且自动吐司错误信息, 可配置 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
Content copied to clipboard
作用域开始时自动显示加载对话框, 结束时自动关闭加载对话框 可以设置全局对话框 com.drake.net.NetConfig.dialogFactory 对话框被取消或者界面关闭作用域被取消
fun FragmentActivity.scopeDialog(dialog: Dialog? = null, cancelable: Boolean = true, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope
Content copied to clipboard
作用域开始时自动显示加载对话框, 结束时自动关闭加载对话框 可以设置全局对话框 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
Content copied to clipboard
异步作用域该作用域生命周期跟随Fragment
fun LifecycleOwner.scopeLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): AndroidScope
Content copied to clipboard
异步作用域该作用域生命周期跟随LifecycleOwner
scopeNet
Link copied to clipboard
fun scopeNet(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope
Content copied to clipboard
该函数比scope多了以下功能

- 在作用域内抛出异常时会被回调的com.drake.net.interfaces.NetErrorHandler.onError函数中

- 自动显示错误信息吐司, 可以通过指定com.drake.net.interfaces.NetErrorHandler.onError来取消或者增加自己的处理

该作用域生命周期跟随整个应用, 注意内存泄漏
scopeNetLife
Link copied to clipboard
fun View.scopeNetLife(dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): ViewCoroutineScope
Content copied to clipboard
视图作用域 会在视图销毁时自动取消作用域
fun Fragment.scopeNetLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope
Content copied to clipboard
和scopeNetLife功能相同, 只是接受者为Fragment
fun LifecycleOwner.scopeNetLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope
Content copied to clipboard
该函数比scopeNet多了自动取消作用域功能该作用域生命周期跟随LifecycleOwner.
toRequestBody
Link copied to clipboard
fun Uri.toRequestBody(): RequestBody
Content copied to clipboard
当Uri指向的文件不存在时将抛出异常FileNotFoundException
fun File.toRequestBody(contentType: MediaType? = null): RequestBody
Content copied to clipboard
创建File的RequestBody
withDefault
Link copied to clipboard
suspend fun <T> withDefault(block: suspend CoroutineScope.() -> T): <ERROR CLASS>
Content copied to clipboard
切换到默认调度器
withIO
Link copied to clipboard
suspend fun <T> withIO(block: suspend CoroutineScope.() -> T): <ERROR CLASS>
Content copied to clipboard
切换到IO程调度器
withMain
Link copied to clipboard
suspend fun <T> withMain(block: suspend CoroutineScope.() -> T): <ERROR CLASS>
Content copied to clipboard
切换到主线程调度器
withUnconfined
Link copied to clipboard
suspend fun <T> withUnconfined(block: suspend CoroutineScope.() -> T): <ERROR CLASS>
Content copied to clipboard
切换到没有限制的调度器