Jelajahi Sumber

| 修改请求函数的参数tag优先级

drake 5 tahun lalu
induk
melakukan
3b25b7e40f

+ 5 - 5
README.md

@@ -80,7 +80,7 @@ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
 // 支持自动下拉刷新和缺省页的, 可选, 刷新头和上拉加载参考SmartRefreshLayout
 implementation 'com.github.liangjingkanji:BRV:1.2.1'
 
-implementation 'com.github.liangjingkanji:Net:2.0.10'
+implementation 'com.github.liangjingkanji:Net:2.0.11'
 ```
 
 
@@ -615,8 +615,8 @@ scopeNetLife {
 
   val data = get<String>(
     "https://raw.githubusercontent.com/liangjingkanji/BRV/master/README.md",
-    CacheMode.NETWORK_YES_THEN_WRITE_CACHE,
-    true
+    cache = CacheMode.NETWORK_YES_THEN_WRITE_CACHE,
+    absolutePath = true
   )
 
   textView.text = data.await()
@@ -627,8 +627,8 @@ scopeNetLife {
 
   val data = get<String>(
     "https://raw.githubusercontent.com/liangjingkanji/BRV/master/README.md",
-    CacheMode.READ_CACHE,
-    true
+    cache = CacheMode.READ_CACHE,
+    absolutePath = true
   )
 
   textView.text = data.await()

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

@@ -34,9 +34,9 @@ import java.io.File
 
 inline fun <reified M> CoroutineScope.get(
     path: String,
+    tag: Any? = null,
     cache: CacheMode = CacheMode.HTTP,
     absolutePath: Boolean = false,
-    tag: Any? = null,
     noinline block: (SimpleUrlRequest.Api.() -> Unit)? = null
 ): Deferred<M> = async(Dispatchers.IO) {
 
@@ -65,9 +65,9 @@ inline fun <reified M> CoroutineScope.get(
 
 inline fun <reified M> CoroutineScope.post(
     path: String,
+    tag: Any? = null,
     cache: CacheMode = CacheMode.HTTP,
     absolutePath: Boolean = false,
-    tag: Any? = null,
     noinline block: (SimpleBodyRequest.Api.() -> Unit)? = null
 ): Deferred<M> = async(Dispatchers.IO) {
 
@@ -108,8 +108,8 @@ inline fun <reified M> CoroutineScope.post(
 fun CoroutineScope.download(
     path: String,
     directory: String = NetConfig.app.externalCacheDir!!.absolutePath,
-    absolutePath: Boolean = false,
     tag: Any? = null,
+    absolutePath: Boolean = false,
     block: (UrlDownload.Api.() -> Unit)? = null
 ): Deferred<String> = async(Dispatchers.IO) {
     val realPath = if (absolutePath) path else (NetConfig.host + path)
@@ -163,9 +163,9 @@ fun CoroutineScope.downImage(
 
 inline fun <reified M> syncGet(
     path: String,
+    tag: Any? = null,
     cache: CacheMode = CacheMode.HTTP,
     absolutePath: Boolean = false,
-    tag: Any? = null,
     noinline block: (SimpleUrlRequest.Api.() -> Unit)? = null
 ): M {
 
@@ -187,9 +187,9 @@ inline fun <reified M> syncGet(
 
 inline fun <reified M> syncPost(
     path: String,
+    tag: Any? = null,
     cache: CacheMode = CacheMode.HTTP,
     absolutePath: Boolean = false,
-    tag: Any? = null,
     noinline block: (SimpleBodyRequest.Api.() -> Unit)? = null
 ): M {
 
@@ -212,8 +212,8 @@ inline fun <reified M> syncPost(
 fun syncDownload(
     path: String,
     directory: String = NetConfig.app.externalCacheDir!!.absolutePath,
-    absolutePath: Boolean = false,
     tag: Any? = null,
+    absolutePath: Boolean = false,
     block: (UrlDownload.Api.() -> Unit)? = null
 ): String {
 

+ 4 - 4
sample/src/main/java/com/drake/net/sample/MainActivity.kt

@@ -24,8 +24,8 @@ class MainActivity : AppCompatActivity() {
 
                 val data = get<String>(
                     "https://raw.githubusercontent.com/liangjingkanji/BRV/master/README.md",
-                    CacheMode.NETWORK_YES_THEN_WRITE_CACHE,
-                    true
+                    cache = CacheMode.NETWORK_YES_THEN_WRITE_CACHE,
+                    absolutePath = true
                 )
 
                 textView.text = data.await()
@@ -36,8 +36,8 @@ class MainActivity : AppCompatActivity() {
 
                 val data = get<String>(
                     "https://raw.githubusercontent.com/liangjingkanji/BRV/master/README.md",
-                    CacheMode.READ_CACHE,
-                    true
+                    cache = CacheMode.READ_CACHE,
+                    absolutePath = true
                 )
 
                 textView.text = data.await()