drake пре 4 година
родитељ
комит
c6cf7a0a64

+ 52 - 52
net/src/main/java/com/drake/net/Net.kt

@@ -57,10 +57,10 @@ inline fun <reified M> CoroutineScope.Get(
     val realPath = if (absolutePath) path else (NetConfig.host + path)
 
     val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.GET)
-            .tag(tag)
-            .uid(uid)
-            .cacheKey(path)
-            .cacheMode(cache)
+        .tag(tag)
+        .uid(uid)
+        .cacheKey(path)
+        .cacheMode(cache)
 
     try {
         request.apply(block).perform<M>(M::class.java)
@@ -92,10 +92,10 @@ inline fun <reified M> CoroutineScope.Post(
     val realPath = if (absolutePath) path else (NetConfig.host + path)
 
     val request = SimpleBodyRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.POST)
-            .tag(tag)
-            .uid(uid)
-            .cacheKey(path)
-            .cacheMode(cache)
+        .tag(tag)
+        .uid(uid)
+        .cacheKey(path)
+        .cacheMode(cache)
 
     try {
         request.apply(block).perform<M>(M::class.java)
@@ -126,10 +126,10 @@ inline fun <reified M> CoroutineScope.Head(
     val realPath = if (absolutePath) path else (NetConfig.host + path)
 
     val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.HEAD)
-            .tag(tag)
-            .uid(uid)
-            .cacheKey(path)
-            .cacheMode(cache)
+        .tag(tag)
+        .uid(uid)
+        .cacheKey(path)
+        .cacheMode(cache)
 
     try {
         request.apply(block).perform<M>(M::class.java)
@@ -159,10 +159,10 @@ inline fun <reified M> CoroutineScope.Options(
     val realPath = if (absolutePath) path else (NetConfig.host + path)
 
     val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.OPTIONS)
-            .tag(tag)
-            .uid(uid)
-            .cacheKey(path)
-            .cacheMode(cache)
+        .tag(tag)
+        .uid(uid)
+        .cacheKey(path)
+        .cacheMode(cache)
 
     try {
         request.apply(block).perform<M>(M::class.java)
@@ -192,10 +192,10 @@ inline fun <reified M> CoroutineScope.Trace(
     val realPath = if (absolutePath) path else (NetConfig.host + path)
 
     val request = SimpleUrlRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.TRACE)
-            .tag(tag)
-            .uid(uid)
-            .cacheKey(path)
-            .cacheMode(cache)
+        .tag(tag)
+        .uid(uid)
+        .cacheKey(path)
+        .cacheMode(cache)
 
     try {
         request.apply(block).perform<M>(M::class.java)
@@ -225,10 +225,10 @@ inline fun <reified M> CoroutineScope.Delete(
     val realPath = if (absolutePath) path else (NetConfig.host + path)
 
     val request = SimpleBodyRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.DELETE)
-            .tag(tag)
-            .uid(uid)
-            .cacheKey(path)
-            .cacheMode(cache)
+        .tag(tag)
+        .uid(uid)
+        .cacheKey(path)
+        .cacheMode(cache)
 
     try {
         request.apply(block).perform<M>(M::class.java)
@@ -258,13 +258,13 @@ inline fun <reified M> CoroutineScope.Put(
     val realPath = if (absolutePath) path else (NetConfig.host + path)
 
     val request = SimpleBodyRequest.newApi(
-            Url.newBuilder(realPath).build(),
-            RequestMethod.PUT
-                                          )
-            .tag(tag)
-            .uid(uid)
-            .cacheKey(path)
-            .cacheMode(cache)
+        Url.newBuilder(realPath).build(),
+        RequestMethod.PUT
+    )
+        .tag(tag)
+        .uid(uid)
+        .cacheKey(path)
+        .cacheMode(cache)
 
     try {
         request.apply(block).perform<M>(M::class.java)
@@ -294,10 +294,10 @@ inline fun <reified M> CoroutineScope.Patch(
     val realPath = if (absolutePath) path else (NetConfig.host + path)
 
     val request = SimpleBodyRequest.newApi(Url.newBuilder(realPath).build(), RequestMethod.PATCH)
-            .tag(tag)
-            .uid(uid)
-            .cacheKey(path)
-            .cacheMode(cache)
+        .tag(tag)
+        .uid(uid)
+        .cacheKey(path)
+        .cacheMode(cache)
 
     try {
         request.apply(block).perform<M>(M::class.java)
@@ -335,8 +335,8 @@ fun CoroutineScope.Download(
     val realPath = if (absolutePath) path else (NetConfig.host + path)
 
     val download =
-        UrlDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag)
-            .uid(uid)
+            UrlDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag)
+                .uid(uid)
 
     try {
         download.apply(block).perform()
@@ -374,8 +374,8 @@ fun CoroutineScope.DownloadBody(
     val realPath = if (absolutePath) path else (NetConfig.host + path)
 
     val download =
-        BodyDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag)
-            .uid(uid)
+            BodyDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag)
+                .uid(uid)
 
     try {
         download.apply(block).perform()
@@ -393,18 +393,18 @@ fun CoroutineScope.DownloadBody(
  * @param height 图片高度
  */
 fun CoroutineScope.DownloadImage(url: String, with: Int = -1, height: Int = -1): Deferred<File> =
-    async(Dispatchers.IO + SupervisorJob()) {
+        async(Dispatchers.IO + SupervisorJob()) {
 
-        val download = Glide.with(NetConfig.app).download(url)
+            val download = Glide.with(NetConfig.app).download(url)
 
-        val futureTarget = if (with == -1 && height == -1) {
-            download.submit()
-        } else {
-            download.submit(with, height)
-        }
+            val futureTarget = if (with == -1 && height == -1) {
+                download.submit()
+            } else {
+                download.submit(with, height)
+            }
 
-        futureTarget.get()
-    }
+            futureTarget.get()
+        }
 
 // </editor-fold>
 
@@ -658,8 +658,8 @@ fun syncDownload(
     }
     val realPath = if (absolutePath) path else (NetConfig.host + path)
     val download =
-        UrlDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag)
-            .uid(uid)
+            UrlDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag)
+                .uid(uid)
     return download.apply(block).perform()
 }
 
@@ -686,8 +686,8 @@ fun syncDownloadBody(
     }
     val realPath = if (absolutePath) path else (NetConfig.host + path)
     val download =
-        BodyDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag)
-            .uid(uid)
+            BodyDownload.newApi(Url.newBuilder(realPath).build(), method).directory(dir).tag(tag)
+                .uid(uid)
     return download.apply(block).perform()
 }
 

+ 11 - 7
net/src/main/java/com/drake/net/convert/DefaultConvert.kt

@@ -37,14 +37,18 @@ import java.lang.reflect.Type
  * @param message  错误信息在JSON中的字段名
  */
 @Suppress("UNCHECKED_CAST")
-abstract class DefaultConvert(val success: String = "0",
-                              val code: String = "code",
-                              val message: String = "msg") : Converter {
+abstract class DefaultConvert(
+    val success: String = "0",
+    val code: String = "code",
+    val message: String = "msg"
+) : Converter {
 
-    override fun <S> convert(succeed: Type,
-                             request: Request,
-                             response: Response,
-                             cache: Boolean): S? {
+    override fun <S> convert(
+        succeed: Type,
+        request: Request,
+        response: Response,
+        cache: Boolean
+    ): S? {
         val body = response.body().string()
         response.logBody = body  // 日志记录响应信息
         val code = response.code()

+ 4 - 2
net/src/main/java/com/drake/net/error/RequestParamsException.kt

@@ -22,5 +22,7 @@ import com.yanzhenjie.kalle.exception.NetException
 /**
  * 404
  */
-class RequestParamsException(val code: Int,
-                             request: Request) : NetException(request, code.toString())
+class RequestParamsException(
+    val code: Int,
+    request: Request
+) : NetException(request, code.toString())

+ 5 - 3
net/src/main/java/com/drake/net/error/ResponseException.kt

@@ -25,6 +25,8 @@ import com.yanzhenjie.kalle.exception.NetException
  * @param code 网络请求错误码
  * @param tag 应对错误码判断为错时但是后端又返回了需要使用的数据(建议后端修改). 一般在Convert中设置数据
  */
-class ResponseException(val code: Int,
-                        val msg: String,
-                        request: Request) : NetException(request, "$code $msg")
+class ResponseException(
+    val code: Int,
+    val msg: String,
+    request: Request
+) : NetException(request, "$code $msg")

+ 4 - 2
net/src/main/java/com/drake/net/error/ServerResponseException.kt

@@ -22,5 +22,7 @@ import com.yanzhenjie.kalle.exception.NetException
 /**
  * 500
  */
-class ServerResponseException(val code: Int,
-                              request: Request) : NetException(request, code.toString())
+class ServerResponseException(
+    val code: Int,
+    request: Request
+) : NetException(request, code.toString())

+ 4 - 4
net/src/main/java/com/drake/net/scope/AndroidScope.kt

@@ -31,7 +31,7 @@ open class AndroidScope(
     lifecycleOwner: LifecycleOwner? = null,
     lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
     val dispatcher: CoroutineDispatcher = Dispatchers.Main
-                       ) : CoroutineScope {
+) : CoroutineScope {
 
     init {
         lifecycleOwner?.lifecycle?.addObserver(object : LifecycleEventObserver {
@@ -50,7 +50,7 @@ open class AndroidScope(
     val uid = exceptionHandler
 
     override val coroutineContext: CoroutineContext =
-        dispatcher + exceptionHandler + SupervisorJob()
+            dispatcher + exceptionHandler + SupervisorJob()
 
 
     open fun launch(block: suspend CoroutineScope.() -> Unit): AndroidScope {
@@ -99,14 +99,14 @@ open class AndroidScope(
 
     open fun cancel(cause: CancellationException? = null) {
         val job = coroutineContext[Job]
-            ?: error("Scope cannot be cancelled because it does not have a job: $this")
+                  ?: error("Scope cannot be cancelled because it does not have a job: $this")
         job.cancel(cause)
     }
 
     open fun cancel(
         message: String,
         cause: Throwable? = null
-                   ) = cancel(CancellationException(message, cause))
+    ) = cancel(CancellationException(message, cause))
 
 }
 

+ 1 - 1
net/src/main/java/com/drake/net/scope/DialogCoroutineScope.kt

@@ -44,7 +44,7 @@ class DialogCoroutineScope(
     var dialog: Dialog? = null,
     val cancelable: Boolean = true,
     dispatcher: CoroutineDispatcher = Dispatchers.Main
-                          ) : NetCoroutineScope(dispatcher = dispatcher), LifecycleObserver {
+) : NetCoroutineScope(dispatcher = dispatcher), LifecycleObserver {
 
     init {
         activity.lifecycle.addObserver(this)

+ 10 - 6
net/src/main/java/com/drake/net/scope/NetCoroutineScope.kt

@@ -28,9 +28,11 @@ import kotlin.coroutines.EmptyCoroutineContext
  * 自动显示网络错误信息协程作用域
  */
 @Suppress("unused", "MemberVisibilityCanBePrivate", "NAME_SHADOWING")
-open class NetCoroutineScope(lifecycleOwner: LifecycleOwner? = null,
-                             lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
-                             dispatcher: CoroutineDispatcher = Dispatchers.Main) : AndroidScope(lifecycleOwner, lifeEvent, dispatcher) {
+open class NetCoroutineScope(
+    lifecycleOwner: LifecycleOwner? = null,
+    lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
+    dispatcher: CoroutineDispatcher = Dispatchers.Main
+) : AndroidScope(lifecycleOwner, lifeEvent, dispatcher) {
 
     protected var isReadCache = true
     protected var preview: (suspend CoroutineScope.() -> Unit)? = null
@@ -99,9 +101,11 @@ open class NetCoroutineScope(lifecycleOwner: LifecycleOwner? = null,
      * @param animate 是否在缓存成功后依然显示加载动画
      * @param block 该作用域内的所有异常都算缓存读取失败, 不会吐司和打印任何错误
      */
-    fun preview(ignore: Boolean = false,
-                animate: Boolean = false,
-                block: suspend CoroutineScope.() -> Unit): AndroidScope {
+    fun preview(
+        ignore: Boolean = false,
+        animate: Boolean = false,
+        block: suspend CoroutineScope.() -> Unit
+    ): AndroidScope {
         this.animate = animate
         this.error = ignore
         this.preview = block

+ 1 - 1
net/src/main/java/com/drake/net/scope/PageCoroutineScope.kt

@@ -27,7 +27,7 @@ import kotlinx.coroutines.Dispatchers
 class PageCoroutineScope(
     val page: PageRefreshLayout,
     dispatcher: CoroutineDispatcher = Dispatchers.Main
-                        ) : NetCoroutineScope(dispatcher = dispatcher) {
+) : NetCoroutineScope(dispatcher = dispatcher) {
 
     val index get() = page.index
 

+ 1 - 1
net/src/main/java/com/drake/net/scope/StateCoroutineScope.kt

@@ -29,7 +29,7 @@ import kotlinx.coroutines.Dispatchers
 class StateCoroutineScope(
     val state: StateLayout,
     dispatcher: CoroutineDispatcher = Dispatchers.Main
-                         ) : NetCoroutineScope(dispatcher = dispatcher) {
+) : NetCoroutineScope(dispatcher = dispatcher) {
 
     init {
         state.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {

+ 3 - 3
net/src/main/java/com/drake/net/time/Interval.kt

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-@file:UseExperimental(ObsoleteCoroutinesApi::class)
+@file:OptIn(ObsoleteCoroutinesApi::class)
 
 package com.drake.net.time
 
@@ -61,13 +61,13 @@ class Interval(
     private val unit: TimeUnit,
     private val start: Long = 0,
     private val initialDelay: Long = 0
-              ) : Serializable {
+) : Serializable {
 
     constructor(
         period: Long,
         unit: TimeUnit,
         initialDelay: Long = 0
-               ) : this(-1, period, unit, 0, initialDelay)
+    ) : this(-1, period, unit, 0, initialDelay)
 
     private val listReceive: MutableList<(Long) -> Unit> = mutableListOf()
     private val listFinish: MutableList<(Long) -> Unit> = mutableListOf()

+ 6 - 4
net/src/main/java/com/drake/net/utils/JetPack.kt

@@ -52,10 +52,12 @@ fun <M> LifecycleOwner.observe(liveData: LiveData<M>?, block: M?.() -> Unit) {
 /**
  * 收集Flow结果并过滤重复结果
  */
-fun <T> Flow<List<T>>.listen(lifecycleOwner: LifecycleOwner? = null,
-                             lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
-                             dispatcher: CoroutineDispatcher = Dispatchers.Main,
-                             block: (List<T>) -> Unit): AndroidScope {
+fun <T> Flow<List<T>>.listen(
+    lifecycleOwner: LifecycleOwner? = null,
+    lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: (List<T>) -> Unit
+): AndroidScope {
     return AndroidScope(lifecycleOwner, lifeEvent, dispatcher).launch {
         distinctUntilChanged().collect { data ->
             block(data)

+ 51 - 35
net/src/main/java/com/drake/net/utils/Scope.kt

@@ -47,18 +47,18 @@ import kotlinx.coroutines.flow.FlowCollector
  * 对话框被取消或者界面关闭作用域被取消
  */
 fun FragmentActivity.scopeDialog(
-        dialog: Dialog? = null,
-        cancelable: Boolean = true,
-        dispatcher: CoroutineDispatcher = Dispatchers.Main,
-        block: suspend CoroutineScope.() -> Unit) =
-        DialogCoroutineScope(this, dialog, cancelable, dispatcher).launch(block)
+    dialog: Dialog? = null,
+    cancelable: Boolean = true,
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: suspend CoroutineScope.() -> Unit
+) = DialogCoroutineScope(this, dialog, cancelable, dispatcher).launch(block)
 
 fun Fragment.scopeDialog(
-        dialog: Dialog? = null,
-        cancelable: Boolean = true,
-        dispatcher: CoroutineDispatcher = Dispatchers.Main,
-        block: suspend CoroutineScope.() -> Unit) =
-        DialogCoroutineScope(requireActivity(), dialog, cancelable, dispatcher).launch(block)
+    dialog: Dialog? = null,
+    cancelable: Boolean = true,
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: suspend CoroutineScope.() -> Unit
+) = DialogCoroutineScope(requireActivity(), dialog, cancelable, dispatcher).launch(block)
 
 // </editor-fold>
 
@@ -76,8 +76,9 @@ fun Fragment.scopeDialog(
  * 布局被销毁或者界面关闭作用域被取消
  */
 fun StateLayout.scope(
-        dispatcher: CoroutineDispatcher = Dispatchers.Main,
-        block: suspend CoroutineScope.() -> Unit): NetCoroutineScope {
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: suspend CoroutineScope.() -> Unit
+): NetCoroutineScope {
     val scope = StateCoroutineScope(this, dispatcher)
     scope.launch(block)
     return scope
@@ -97,8 +98,9 @@ fun StateLayout.scope(
  * 布局被销毁或者界面关闭作用域被取消
  */
 fun PageRefreshLayout.scope(
-        dispatcher: CoroutineDispatcher = Dispatchers.Main,
-        block: suspend CoroutineScope.() -> Unit): PageCoroutineScope {
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: suspend CoroutineScope.() -> Unit
+): PageCoroutineScope {
     val scope = PageCoroutineScope(this, dispatcher)
     scope.launch(block)
     return scope
@@ -111,18 +113,24 @@ fun PageRefreshLayout.scope(
  *
  * 该作用域生命周期跟随整个应用, 注意内存泄漏
  */
-fun scope(dispatcher: CoroutineDispatcher = Dispatchers.Main,
-          block: suspend CoroutineScope.() -> Unit): AndroidScope {
+fun scope(
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: suspend CoroutineScope.() -> Unit
+): AndroidScope {
     return AndroidScope(dispatcher = dispatcher).launch(block)
 }
 
-fun LifecycleOwner.scopeLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
-                             dispatcher: CoroutineDispatcher = Dispatchers.Main,
-                             block: suspend CoroutineScope.() -> Unit) = AndroidScope(this, lifeEvent, dispatcher).launch(block)
-
-fun Fragment.scopeLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_STOP,
-                       dispatcher: CoroutineDispatcher = Dispatchers.Main,
-                       block: suspend CoroutineScope.() -> Unit) = AndroidScope(this, lifeEvent, dispatcher).launch(block)
+fun LifecycleOwner.scopeLife(
+    lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: suspend CoroutineScope.() -> Unit
+) = AndroidScope(this, lifeEvent, dispatcher).launch(block)
+
+fun Fragment.scopeLife(
+    lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_STOP,
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: suspend CoroutineScope.() -> Unit
+) = AndroidScope(this, lifeEvent, dispatcher).launch(block)
 //</editor-fold>
 
 //<editor-fold desc="网络">
@@ -132,20 +140,26 @@ fun Fragment.scopeLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_STOP,
  *
  * 该作用域生命周期跟随整个应用, 注意内存泄漏
  */
-fun scopeNet(dispatcher: CoroutineDispatcher = Dispatchers.Main,
-             block: suspend CoroutineScope.() -> Unit) = NetCoroutineScope(dispatcher = dispatcher).launch(block)
+fun scopeNet(
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: suspend CoroutineScope.() -> Unit
+) = NetCoroutineScope(dispatcher = dispatcher).launch(block)
 
 
-fun LifecycleOwner.scopeNetLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
-                                dispatcher: CoroutineDispatcher = Dispatchers.Main,
-                                block: suspend CoroutineScope.() -> Unit) = NetCoroutineScope(this, lifeEvent, dispatcher).launch(block)
+fun LifecycleOwner.scopeNetLife(
+    lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: suspend CoroutineScope.() -> Unit
+) = NetCoroutineScope(this, lifeEvent, dispatcher).launch(block)
 
 /**
  * Fragment应当在[Lifecycle.Event.ON_STOP]时就取消作用域, 避免[Fragment.onDestroyView]导致引用空视图
  */
-fun Fragment.scopeNetLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_STOP,
-                          dispatcher: CoroutineDispatcher = Dispatchers.Main,
-                          block: suspend CoroutineScope.() -> Unit) = NetCoroutineScope(this, lifeEvent, dispatcher).launch(block)
+fun Fragment.scopeNetLife(
+    lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_STOP,
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    block: suspend CoroutineScope.() -> Unit
+) = NetCoroutineScope(this, lifeEvent, dispatcher).launch(block)
 //</editor-fold>
 
 
@@ -156,10 +170,12 @@ fun Fragment.scopeNetLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_STOP,
  * @param dispatcher 指定调度器
  */
 @OptIn(InternalCoroutinesApi::class)
-inline fun <T> Flow<T>.scope(owner: LifecycleOwner? = null,
-                             event: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
-                             dispatcher: CoroutineDispatcher = Dispatchers.Main,
-                             crossinline action: suspend (value: T) -> Unit): AndroidScope = AndroidScope(owner, event, dispatcher).launch {
+inline fun <T> Flow<T>.scope(
+    owner: LifecycleOwner? = null,
+    event: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
+    dispatcher: CoroutineDispatcher = Dispatchers.Main,
+    crossinline action: suspend (value: T) -> Unit
+): AndroidScope = AndroidScope(owner, event, dispatcher).launch {
     this@scope.collect(object : FlowCollector<T> {
         override suspend fun emit(value: T) = action(value)
     })

+ 10 - 6
net/src/main/java/com/drake/net/utils/ThrottleClickListener.kt

@@ -19,15 +19,19 @@ package com.drake.net.utils
 import android.view.View
 import java.util.concurrent.TimeUnit
 
-internal fun View.throttleClick(interval: Long = 500,
-                                unit: TimeUnit = TimeUnit.MILLISECONDS,
-                                block: View.() -> Unit) {
+internal fun View.throttleClick(
+    interval: Long = 500,
+    unit: TimeUnit = TimeUnit.MILLISECONDS,
+    block: View.() -> Unit
+) {
     setOnClickListener(ThrottleClickListener(interval, unit, block))
 }
 
-internal class ThrottleClickListener(private val interval: Long = 500,
-                                     private val unit: TimeUnit = TimeUnit.MILLISECONDS,
-                                     private var block: View.() -> Unit) : View.OnClickListener {
+internal class ThrottleClickListener(
+    private val interval: Long = 500,
+    private val unit: TimeUnit = TimeUnit.MILLISECONDS,
+    private var block: View.() -> Unit
+) : View.OnClickListener {
 
     private var lastTime: Long = 0