Ver Fonte

feat: Net.kt支持Java静态调用

drake há 2 anos atrás
pai
commit
f38e252144
1 ficheiros alterados com 24 adições e 0 exclusões
  1. 24 0
      net/src/main/java/com/drake/net/Net.kt

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

@@ -33,6 +33,8 @@ object Net {
      * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断
      * @param block 函数中可以配置请求参数
      */
+    @JvmOverloads
+    @JvmStatic
     fun get(
         path: String,
         tag: Any? = null,
@@ -51,6 +53,8 @@ object Net {
      * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断
      * @param block 函数中可以配置请求参数
      */
+    @JvmOverloads
+    @JvmStatic
     fun post(
         path: String,
         tag: Any? = null,
@@ -69,6 +73,8 @@ object Net {
      * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断
      * @param block 函数中可以配置请求参数
      */
+    @JvmOverloads
+    @JvmStatic
     fun head(
         path: String,
         tag: Any? = null,
@@ -87,6 +93,8 @@ object Net {
      * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断
      * @param block 函数中可以配置请求参数
      */
+    @JvmOverloads
+    @JvmStatic
     fun options(
         path: String,
         tag: Any? = null,
@@ -105,6 +113,8 @@ object Net {
      * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断
      * @param block 函数中可以配置请求参数
      */
+    @JvmOverloads
+    @JvmStatic
     fun trace(
         path: String,
         tag: Any? = null,
@@ -123,6 +133,8 @@ object Net {
      * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断
      * @param block 函数中可以配置请求参数
      */
+    @JvmOverloads
+    @JvmStatic
     fun delete(
         path: String,
         tag: Any? = null,
@@ -141,6 +153,8 @@ object Net {
      * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断
      * @param block 函数中可以配置请求参数
      */
+    @JvmOverloads
+    @JvmStatic
     fun put(
         path: String,
         tag: Any? = null,
@@ -159,6 +173,8 @@ object Net {
      * @param tag 可以传递对象给Request请求, 一般用于在拦截器/转换器中进行针对某个接口行为判断
      * @param block 函数中可以配置请求参数
      */
+    @JvmOverloads
+    @JvmStatic
     fun patch(
         path: String,
         tag: Any? = null,
@@ -175,6 +191,7 @@ object Net {
     /**
      * 取消全部网络请求
      */
+    @JvmStatic
     fun cancelAll() {
         NetConfig.runningCalls.forEach { it.get()?.cancel() }
         NetConfig.runningCalls.clear()
@@ -185,6 +202,7 @@ object Net {
      * 取消指定的网络请求, Id理论上是唯一的, 所以该函数一次只能取消一个请求
      * @return 如果成功取消返回true
      */
+    @JvmStatic
     fun cancelId(id: Any?): Boolean {
         if (id == null) return false
         val iterator = NetConfig.runningCalls.iterator()
@@ -203,6 +221,7 @@ object Net {
      * 根据分组取消网络请求
      * @return 如果成功取消返回true, 无论取消个数
      */
+    @JvmStatic
     fun cancelGroup(group: Any?): Boolean {
         if (group == null) return false
         val iterator = NetConfig.runningCalls.iterator()
@@ -226,6 +245,7 @@ object Net {
      * @param id 请求的Id
      * @see com.drake.net.request.BaseRequest.setId
      */
+    @JvmStatic
     fun addUploadListener(id: Any, progressListener: ProgressListener) {
         NetConfig.runningCalls.forEach {
             val request = it.get()?.request() ?: return@forEach
@@ -240,6 +260,7 @@ object Net {
      * @param id 请求的Id
      * @see com.drake.net.request.BaseRequest.setId
      */
+    @JvmStatic
     fun removeUploadListener(id: Any, progressListener: ProgressListener) {
         NetConfig.runningCalls.forEach {
             val request = it.get()?.request() ?: return@forEach
@@ -254,6 +275,7 @@ object Net {
      * @param id 请求的Id
      * @see com.drake.net.request.BaseRequest.setId
      */
+    @JvmStatic
     fun addDownloadListener(id: Any, progressListener: ProgressListener) {
         NetConfig.runningCalls.forEach {
             val request = it.get()?.request() ?: return@forEach
@@ -269,6 +291,7 @@ object Net {
      * @param id 请求的Id
      * @see com.drake.net.request.BaseRequest.setId
      */
+    @JvmStatic
     fun removeDownloadListener(id: Any, progressListener: ProgressListener) {
         NetConfig.runningCalls.forEach {
             val request = it.get()?.request() ?: return@forEach
@@ -295,6 +318,7 @@ object Net {
      * @param message 如果非[Throwable]则会自动追加代码位置(文件:行号)
      * @see NetConfig.debug
      */
+    @JvmStatic
     fun debug(message: Any) {
         if (NetConfig.debug) {
             val adjustMessage = if (message is Throwable) {