Browse Source

为NetCallback添加Request对象

drake 3 years ago
parent
commit
e48f283485

+ 3 - 0
net/src/main/java/com/drake/net/interfaces/NetCallback.kt

@@ -25,6 +25,9 @@ abstract class NetCallback<T> constructor(
     val lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY
 ) : Callback {
 
+    lateinit var request: Request
+        internal set
+
     override fun onResponse(call: Call, response: Response) {
         val succeed = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0]
         val data = try {

+ 4 - 1
net/src/main/java/com/drake/net/request/BaseRequest.kt

@@ -384,7 +384,10 @@ abstract class BaseRequest {
         NetConfig.requestInterceptor?.interceptor(this)
         val request = buildRequest()
         val newCall = okHttpClient.newCall(request)
-        if (block is NetCallback<*>) block.onStart(request)
+        if (block is NetCallback<*>) {
+            block.request = request
+            block.onStart(request)
+        }
         newCall.enqueue(block)
         return newCall
     }