Browse Source

| README.md

drake 4 years ago
parent
commit
744aa8347b

+ 1 - 1
README.md

@@ -89,7 +89,7 @@ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
 // 支持自动下拉刷新和缺省页的, 可选, 刷新头和上拉加载参考SmartRefreshLayout (可选)
 implementation 'com.github.liangjingkanji:BRV:1.3.6'
 
-implementation 'com.github.liangjingkanji:Net:2.2.5'
+implementation 'com.github.liangjingkanji:Net:2.2.6'
 ```
 
 

+ 2 - 2
kalle/src/main/java/com/yanzhenjie/kalle/NetDispose.kt → kalle/src/main/java/com/yanzhenjie/kalle/NetCancel.kt

@@ -16,7 +16,7 @@
 package com.yanzhenjie.kalle
 
 
-object NetDispose {
+object NetCancel {
 
     private val map = mutableMapOf<Canceller, Any>()
 
@@ -48,7 +48,7 @@ object NetDispose {
      * According to the tag to cancel a task.
      *
      */
-    fun dispose(uid: Any?) {
+    fun cancel(uid: Any?) {
         uid ?: return
         val iterator = map.iterator()
         while (iterator.hasNext()) {

+ 7 - 7
kalle/src/main/java/com/yanzhenjie/kalle/download/DownloadManager.java

@@ -17,7 +17,7 @@ package com.yanzhenjie.kalle.download;
 
 import com.yanzhenjie.kalle.Canceller;
 import com.yanzhenjie.kalle.Kalle;
-import com.yanzhenjie.kalle.NetDispose;
+import com.yanzhenjie.kalle.NetCancel;
 
 import java.util.concurrent.Executor;
 
@@ -56,10 +56,10 @@ public class DownloadManager {
             @Override
             public void onEnd() {
                 super.onEnd();
-                NetDispose.INSTANCE.remove(download.uid());
+                NetCancel.INSTANCE.remove(download.uid());
             }
         });
-        NetDispose.INSTANCE.add(download.uid(), work);
+        NetCancel.INSTANCE.add(download.uid(), work);
         mExecutor.execute(work);
         return work;
     }
@@ -72,7 +72,7 @@ public class DownloadManager {
      */
     public String perform(UrlDownload download) throws Exception {
         UrlWorker worker = new UrlWorker(download);
-        NetDispose.INSTANCE.add(download.uid(), worker);
+        NetCancel.INSTANCE.add(download.uid(), worker);
         return worker.call();
     }
 
@@ -88,10 +88,10 @@ public class DownloadManager {
             @Override
             public void onEnd() {
                 super.onEnd();
-                NetDispose.INSTANCE.remove(download.uid());
+                NetCancel.INSTANCE.remove(download.uid());
             }
         });
-        NetDispose.INSTANCE.add(download.uid(), work);
+        NetCancel.INSTANCE.add(download.uid(), work);
         mExecutor.execute(work);
         return work;
     }
@@ -104,7 +104,7 @@ public class DownloadManager {
      */
     public String perform(BodyDownload download) throws Exception {
         BodyWorker worker = new BodyWorker(download);
-        NetDispose.INSTANCE.add(download.uid(), worker);
+        NetCancel.INSTANCE.add(download.uid(), worker);
         return worker.call();
     }
 

+ 7 - 7
kalle/src/main/java/com/yanzhenjie/kalle/simple/RequestManager.java

@@ -17,7 +17,7 @@ package com.yanzhenjie.kalle.simple;
 
 import com.yanzhenjie.kalle.Canceller;
 import com.yanzhenjie.kalle.Kalle;
-import com.yanzhenjie.kalle.NetDispose;
+import com.yanzhenjie.kalle.NetCancel;
 
 import java.lang.reflect.Type;
 import java.util.concurrent.Executor;
@@ -59,10 +59,10 @@ public class RequestManager {
             @Override
             public void onEnd() {
                 super.onEnd();
-                NetDispose.INSTANCE.remove(request.uid());
+                NetCancel.INSTANCE.remove(request.uid());
             }
         });
-        NetDispose.INSTANCE.add(request.uid(), work);
+        NetCancel.INSTANCE.add(request.uid(), work);
         mExecutor.execute(work);
         return work;
     }
@@ -79,7 +79,7 @@ public class RequestManager {
      */
     public <S, F> Result<S, F> perform(SimpleUrlRequest request, Type succeed, Type failed) throws Exception {
         UrlWorker<S, F> worker = new UrlWorker<>(request, succeed, failed);
-        NetDispose.INSTANCE.add(request.uid(), worker);
+        NetCancel.INSTANCE.add(request.uid(), worker);
         return worker.call();
     }
 
@@ -97,10 +97,10 @@ public class RequestManager {
             @Override
             public void onEnd() {
                 super.onEnd();
-                NetDispose.INSTANCE.remove(request.uid());
+                NetCancel.INSTANCE.remove(request.uid());
             }
         });
-        NetDispose.INSTANCE.add(request.uid(), work);
+        NetCancel.INSTANCE.add(request.uid(), work);
         mExecutor.execute(work);
         return work;
     }
@@ -117,7 +117,7 @@ public class RequestManager {
      */
     public <S, F> Result<S, F> perform(SimpleBodyRequest request, Type succeed, Type failed) throws Exception {
         BodyWorker<S, F> worker = new BodyWorker<>(request, succeed, failed);
-        NetDispose.INSTANCE.add(request.uid(), worker);
+        NetCancel.INSTANCE.add(request.uid(), worker);
         return worker.call();
     }
 

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

@@ -12,7 +12,7 @@ package com.drake.net
 import android.content.Context
 import com.bumptech.glide.Glide
 import com.drake.net.error.ResponseException
-import com.yanzhenjie.kalle.NetDispose
+import com.yanzhenjie.kalle.NetCancel
 import com.yanzhenjie.kalle.RequestMethod
 import com.yanzhenjie.kalle.Url
 import com.yanzhenjie.kalle.download.BodyDownload
@@ -45,7 +45,7 @@ inline fun <reified M> CoroutineScope.Get(path: String,
     if (!isActive) throw CancellationException()
 
     coroutineContext[Job]?.invokeOnCompletion {
-        if (it != null) NetDispose.dispose(uid) else NetDispose.remove(uid)
+        if (it != null) NetCancel.cancel(uid) else NetCancel.remove(uid)
     }
 
     val realPath = if (absolutePath) path else (NetConfig.host + path)
@@ -76,7 +76,7 @@ inline fun <reified M> CoroutineScope.Post(path: String,
             if (!isActive) throw CancellationException()
 
             coroutineContext[Job]?.invokeOnCompletion {
-                if (it != null) NetDispose.dispose(uid) else NetDispose.remove(uid)
+                if (it != null) NetCancel.cancel(uid) else NetCancel.remove(uid)
             }
 
             val realPath = if (absolutePath) path else (NetConfig.host + path)
@@ -106,7 +106,7 @@ inline fun <reified M> CoroutineScope.Head(path: String,
     if (!isActive) throw CancellationException()
 
     coroutineContext[Job]?.invokeOnCompletion {
-        if (it != null) NetDispose.dispose(uid) else NetDispose.remove(uid)
+        if (it != null) NetCancel.cancel(uid) else NetCancel.remove(uid)
     }
 
     val realPath = if (absolutePath) path else (NetConfig.host + path)
@@ -136,7 +136,7 @@ inline fun <reified M> CoroutineScope.Options(path: String,
     if (!isActive) throw CancellationException()
 
     coroutineContext[Job]?.invokeOnCompletion {
-        if (it != null) NetDispose.dispose(uid) else NetDispose.remove(uid)
+        if (it != null) NetCancel.cancel(uid) else NetCancel.remove(uid)
     }
 
     val realPath = if (absolutePath) path else (NetConfig.host + path)
@@ -167,7 +167,7 @@ inline fun <reified M> CoroutineScope.Trace(path: String,
     if (!isActive) throw CancellationException()
 
     coroutineContext[Job]?.invokeOnCompletion {
-        if (it != null) NetDispose.dispose(uid) else NetDispose.remove(uid)
+        if (it != null) NetCancel.cancel(uid) else NetCancel.remove(uid)
     }
 
     val realPath = if (absolutePath) path else (NetConfig.host + path)
@@ -197,7 +197,7 @@ inline fun <reified M> CoroutineScope.Delete(path: String,
     if (!isActive) throw CancellationException()
 
     coroutineContext[Job]?.invokeOnCompletion {
-        if (it != null) NetDispose.dispose(uid) else NetDispose.remove(uid)
+        if (it != null) NetCancel.cancel(uid) else NetCancel.remove(uid)
     }
 
     val realPath = if (absolutePath) path else (NetConfig.host + path)
@@ -227,7 +227,7 @@ inline fun <reified M> CoroutineScope.Put(path: String,
     if (!isActive) throw CancellationException()
 
     coroutineContext[Job]?.invokeOnCompletion {
-        if (it != null) NetDispose.dispose(uid) else NetDispose.remove(uid)
+        if (it != null) NetCancel.cancel(uid) else NetCancel.remove(uid)
     }
 
     val realPath = if (absolutePath) path else (NetConfig.host + path)
@@ -258,7 +258,7 @@ inline fun <reified M> CoroutineScope.Patch(path: String,
     if (!isActive) throw CancellationException()
 
     coroutineContext[Job]?.invokeOnCompletion {
-        if (it != null) NetDispose.dispose(uid) else NetDispose.remove(uid)
+        if (it != null) NetCancel.cancel(uid) else NetCancel.remove(uid)
     }
 
     val realPath = if (absolutePath) path else (NetConfig.host + path)
@@ -303,7 +303,7 @@ fun CoroutineScope.Download(path: String,
     }
 
     coroutineContext[Job]?.invokeOnCompletion {
-        if (it != null && it !is CancellationException) NetDispose.dispose(uid) else NetDispose.remove(uid)
+        if (it != null && it !is CancellationException) NetCancel.cancel(uid) else NetCancel.remove(uid)
     }
 
     val realPath = if (absolutePath) path else (NetConfig.host + path)
@@ -335,7 +335,7 @@ fun CoroutineScope.DownloadBody(path: String,
     }
 
     coroutineContext[Job]?.invokeOnCompletion {
-        if (it != null && it !is CancellationException) NetDispose.dispose(uid) else NetDispose.remove(uid)
+        if (it != null && it !is CancellationException) NetCancel.cancel(uid) else NetCancel.remove(uid)
     }
 
     val realPath = if (absolutePath) path else (NetConfig.host + path)

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

@@ -7,7 +7,7 @@
 
 package com.drake.net.error
 
-import com.yanzhenjie.kalle.NetDispose
+import com.yanzhenjie.kalle.NetCancel
 import kotlinx.coroutines.CoroutineExceptionHandler
 import kotlinx.coroutines.CoroutineScope
 import java.util.concurrent.CancellationException
@@ -15,7 +15,7 @@ import java.util.concurrent.CancellationException
 class NetCancellationException(coroutineScope: CoroutineScope,
                                message: String? = null) : CancellationException(message) {
     init {
-        NetDispose.dispose(coroutineScope.coroutineContext[CoroutineExceptionHandler])
+        NetCancel.cancel(coroutineScope.coroutineContext[CoroutineExceptionHandler])
     }
 }
 

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

@@ -11,7 +11,7 @@ import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.LifecycleEventObserver
 import androidx.lifecycle.LifecycleOwner
 import com.drake.net.NetConfig
-import com.yanzhenjie.kalle.NetDispose
+import com.yanzhenjie.kalle.NetCancel
 import kotlinx.coroutines.CancellationException
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.launch
@@ -100,7 +100,7 @@ open class NetCoroutineScope() : AndroidScope() {
     }
 
     override fun cancel(cause: CancellationException?) {
-        NetDispose.dispose(uid)
+        NetCancel.cancel(uid)
         super.cancel(cause)
     }
 }