فهرست منبع

+ TAG: 用于动态配置请求标签, 建议定义单例对象继承该类来扩展网络请求的标签
+ REQUEST: 请求参数
+ RESPONSE: 响应参数

drake 5 سال پیش
والد
کامیت
892afecc33

+ 1 - 1
README.md

@@ -83,7 +83,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.11'
+implementation 'com.github.liangjingkanji:Net:2.1.0'
 ```
 
 

+ 13 - 0
net/src/main/java/com/drake/net/tag/REQUEST.kt

@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2018, Umbrella CompanyLimited All rights reserved.
+ * Project:Net
+ * Author:Drake
+ * Date:1/14/20 1:40 PM
+ */
+
+package com.drake.net.tag
+
+/**
+ * 请求参数打印标签
+ */
+object REQUEST : TAG()

+ 13 - 0
net/src/main/java/com/drake/net/tag/RESPONSE.kt

@@ -0,0 +1,13 @@
+/*
+ * Copyright (C) 2018, Umbrella CompanyLimited All rights reserved.
+ * Project:Net
+ * Author:Drake
+ * Date:1/14/20 1:40 PM
+ */
+
+package com.drake.net.tag
+
+/**
+ * 响应体打印标签
+ */
+object RESPONSE : TAG()

+ 72 - 0
net/src/main/java/com/drake/net/tag/TAG.kt

@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2018, Umbrella CompanyLimited All rights reserved.
+ * Project:Net
+ * Author:Drake
+ * Date:1/14/20 1:38 PM
+ */
+
+package com.drake.net.tag
+
+import kotlin.reflect.KClass
+
+
+abstract class TAG {
+
+    private var list: MutableList<TAG>? = null
+
+    operator fun get(key: KClass<out TAG>): TAG? {
+
+        list?.forEach {
+            if (it::class == key) return it
+        }
+
+        return if (this::class == key) this else null
+    }
+
+    operator fun plus(tag: TAG): TAG {
+
+        if (this == tag) return this
+        if (list == null) list = mutableListOf(this)
+
+        list?.apply {
+            add(this@TAG)
+
+            if (tag.list.isNullOrEmpty()) {
+                if (tag !in this) add(tag)
+            } else {
+                addAll(tag.list!!)
+            }
+        }
+
+        return this
+    }
+
+    operator fun minus(tag: TAG): TAG {
+
+        if (this == tag) return this
+
+        val right = tag.list
+
+        if (right.isNullOrEmpty()) {
+            list?.remove(tag)
+        } else {
+            list?.removeAll(right)
+        }
+
+        return this
+    }
+
+    operator fun contains(tag: @UnsafeVariance TAG): Boolean {
+
+        if (tag == this) return true
+
+        val right = tag.list
+
+        return if (right.isNullOrEmpty()) {
+            list?.contains(tag) ?: false
+        } else {
+            list?.containsAll(right) ?: false
+        }
+    }
+
+}

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

@@ -4,7 +4,6 @@ import android.os.Bundle
 import androidx.appcompat.app.AppCompatActivity
 import com.drake.net.get
 import com.drake.net.utils.scope
-import com.yanzhenjie.kalle.simple.cache.CacheMode
 import kotlinx.android.synthetic.main.activity_main.*
 
 class MainActivity : AppCompatActivity() {
@@ -15,13 +14,13 @@ class MainActivity : AppCompatActivity() {
 
         setContentView(R.layout.activity_main)
 
+
         content.onRefresh {
 
             scope {
 
                 val data = get<String>(
                     "https://raw.githubusercontent.com/liangjingkanji/BRV/master/README.md",
-                    cache = CacheMode.NETWORK_YES_THEN_WRITE_CACHE,
                     absolutePath = true
                 )
 
@@ -29,6 +28,7 @@ class MainActivity : AppCompatActivity() {
             }
 
         }.autoRefresh()
+
     }
 }