Coder Social home page Coder Social logo

net's Introduction

原来你也玩原神啊?    

点击开喷

原神, 启动!


『 全部开源项目 』 『 在线简历 』 『 加入我们 』


一个人的技术是有限的



项目 描述
Net 🍉 Android 最强大的创新式协程并发网络请求 GitHub Repo stars
BRV 🌽 Android 最强大的RecyclerView库, 比BRVAH更优雅和强大 GitHub Repo stars
soft-input-event Android软键盘遮挡/平滑动画最佳解决方案 GitHub Repo stars
DrakeTyporaTheme 最好的Typora主题 GitHub Repo stars
spannable Android最好的Spannable构建工具, 首个支持正则匹配/GIF动画/图文混排 GitHub Repo stars
Interval Android计时器工具, 倒计时/正计时/开始/暂停/继续/结束/取消 GitHub Repo stars
Serialize 应用数据存储的神器, 比SQLite/SP更方便, 可创建自动本地读写/应用销毁恢复的字段, GitHub Repo stars
StateLayout 一行代码构建整个应用的缺省页 GitHub Repo stars
StatusBar 🍥 Android 一行代码配置透明状态栏 GitHub Repo stars
Channel 优雅的事件消息框架 🍯 LiveData / Coroutine / 生命周期 特性 EventBus GitHub Repo stars
Tooltip Toast(吐司)BubbleDialog(菊花加载框) GitHub Repo stars
debugKit 开发调试悬浮窗口工具 GitHub Repo stars
LogCat 日志输出工具 GitHub Repo stars
Engine 快速开发基础库 GitHub Repo stars
SougouSkin 简约的搜狗输入法皮肤
简历模板 快速生成简洁的个人简历(部署在线简历) 在线预览
PTCode 为PT Mono添加连字特性(Ligatures)
PlexMono ibm-plex添加连字特性(Ligatures)
cascadia-code-patch 修改cascadia-code字符
JetBrainsMono-patch 修改JetBrainsMono字符

net's People

Contributors

hubrains avatar liangjingkanji avatar lukelmouse-github avatar ojzen avatar saltedfish-extreme avatar the6nnoo avatar tomatowithegg avatar txca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

net's Issues

生命周期关联失败

binding.tvContent.postDelayed({
    scopeNetLife(Lifecycle.Event.ON_DESTROY) {
        val json = Get<String>("https://www.wanandroid.com/article/list/0/json").await()
        val a12 = Looper.myLooper() == Looper.getMainLooper()
        LoggerUtils.i(" TM.530530530---->$a12---json>$json")
    }.catch { }.finally { }
}, 5000)

请问,这样,activitiy关闭了,为什么5s后,还会执行这个请求

networkSecurityConfig导致无法打包

Attribute application@networkSecurityConfig value=(@xml/network_security_config_release) from AndroidManifest.xml:21:9-21
is also present at [com.github.liangjingkanji:Net:3.1.0] AndroidManifest.xml:18:9-69 value=(@xml/network_security_config).
Suggestion: add 'tools:replace="android:networkSecurityConfig"' to <application> element at AndroidManifest.xml:21:9-21:11 to override.

为了开箱即用Net默认使用了一个网络配置文件保证HTTP请求默认支持. 所以当你使用一个另一个名称(即不是network_security_config)的配置时会出现冲突


错误提示也给出解决方案: 在你项目中的AndroidManifest中添加一行tools:replace="android:networkSecurityConfig"

   <application
      ....
      tools:replace="android:networkSecurityConfig">

只能识别android4.0吗

This version of Android Studio cannot open this project, please retry with Android Studio 4.0 or newer.

关于分层设计

我想把具体请求放在一个或多个Repo里,但是请求方法都是CoroutineScope.xxxx。我现在是重新封装了一下post/get方法:

suspend inline fun <reified M> post(
    path: String,
    tag: Any? = null,
    noinline block: (BodyRequest.() -> Unit)? = null
): Deferred<M> = coroutineScope {
    async(Dispatchers.IO + SupervisorJob()) {
        BodyRequest().apply {
            setPath(path)
            method = Method.POST
            setGroup(coroutineContext[CoroutineExceptionHandler])
            setTag(tag)
            block?.invoke(this)
        }.execute()
    }
}

某Repo:

suspend fun fetchXxxxxx() = post(Api.xxxxx) {
    param("xxx", "xxx")
}

某ViewModel:

fun xxxx() {
    scopeNetLife {
        val result = repo.fetchXxxxxx().await()
    }
}

请问有更好的实现方法吗?而且例如scopeDialog等作用域只能在Activity/Fragment中使用,在分层架构中也无法用到。

图片上传

上传文件,接口日志 Not support this type multipart/form-data; boundary=49e67671-b4fc-461a-9fda-78cac66a95a0,然后就是超市异常。这可能是什么原因导致的呢。

关于发起请求时 返回类型 定义为泛型的问题

Dingtalk_20211120091743
Dingtalk_20211120091802
然后看见了这个错:UnsupportedOperationException: This function has a reified type parameter and thus can only be inlined at compilation time, not called directly.
我对kotlin的理解 还不够深刻 网上找了 也没有找到 解决方案
作者大人有时间的话帮忙解答一下吗 蟹蟹

support Api19

由于OkHttp4仅支持Api21以上, 要使用低版本的OkHttp3创建一个兼容Api19以上的Net3分支

如果存在使用文档无法打开请在此反馈

使用文档部署在GitHub. 理论上能打开GitHub就不存在无法打开使用文档, 需要排查下问题

并且描述以下信息

  1. 地理位置
  2. 打不开的网页截图
  3. 是否开启代理
  4. 是否各个时间段一直无法打开

可以加QQ群发送/在此Issues回复/发我邮件都可以

请教一下

在简析数据时我希望返回数据中的有一个公共的提取出来(如成功失败状态,及失败消息等),然后通过泛行连接下面的data数据,类似于xxx,不需要写在一起,但现在使用这种方法报“解析数据时发生异常”,我该怎么处理,希望能得到您的帮助,QQ:1424599591

老哥,你这网络请求文档我咋看不明白呢😂

我想请求玩安卓的接口,一开始没想到还要配置解析器,发现解析数据异常吐司才回头又看了遍文档,然后配置SerializationConverter解析时候有爆红的,又对比看了看demo才发现还要导入它的依赖
微信图片_20220108151632
配置完了之后看文档可以在全局配置,但是不知道是在application里配置还是在哪,在application里的onCreate里面这样配置了还是解析数据异常

NetConfig.init("https://www.wanandroid.com/") {
            setConverter(SerializationConverter())
        }

image
还有你的demo也出这个问题了😂
微信图片_20220108151627

POST 请求会发生 Caused by: java.lang.IllegalStateException: closed 这样的错误

版本:
api "com.squareup.okhttp3:okhttp:4.9.1"
// Net
api 'com.github.liangjingkanji:Net:3.0.13'

场景:
get请求正常,用post请求时发生错误

错误信息:
com.drake.net.interceptor.NetOkHttpInterceptor.intercept(NetOkHttpInterceptor.kt:43)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
com.drake.net.interceptor.LogRecordInterceptor.intercept(LogRecordInterceptor.kt:53)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
com.component.myapplication.ui.login.LoginActivity$getSmsCode$1$invokeSuspend$$inlined$Post$default$1.invokeSuspend(NetCoroutine.kt:148)
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)

Caused by: java.lang.IllegalStateException: closed

业务代码:
初始化:
NetConfig.init(baseUrl) {
setLog(true) // LogCat异常日志
addInterceptor(LogRecordInterceptor(true)) // 添加日志记录器
this.setConverter(FastJsonConverter())
setRequestInterceptor(object : RequestInterceptor {
override fun interceptor(request: BaseRequest) {
request.addHeader("Authorization", "bearer ${SPUtils.getInstance().getString("token", "")}")
request.addHeader("Accept", "application/json")
request.addHeader("X-Requested-With", "XMLHttpRequest")

请求代码:
Post<WbgResponse>("acquire-sms") {
json(GsonUtils.toJson(map))
this.mediaType = JSON
}.await()

其他:百度说是多次调用 response.body.string() 可是并没有呀0.0

请大佬帮忙分析一下咋回事

关于单个拦截器的加入

如题,项目中刚开始登录的时候,在请求头是不需要带有token的,登录完后拿到token,后面的请求都要在这次请求头上加入这个token,像这种情况有什么比较好的解决方案,因为在sample中看到提示拦截器仅仅支持整个项目,谢谢。

协程库和net的版本对应关系是?

非常好的库 但是我在使用的时候 不想升级android studio 目前是4.0.0 协程是1.3.72,
引入后发现 需要升级到1.5.0,请问这里有个对应版本关系图吗

viewModel中多次请求没返回数据

比如在viewmodel中请求fetchUserInfo1和fetchUserInfo2只能返回fetchUserInfo1的数据第二个请求没请求,使用scope请求却可以返回2次的数据

fun fetchUserInfo1() {
scopeNetLife {
Get(Api.userTokenAUth1).await()
}
}

fun fetchUserInfo2() {
scopeNetLife {
Get(Api.userTokenAUth2).await()
}
}

没有我需要的请求参数类型

默认支持的常见HTTP参数类型. 如果没有你需要的请求参数类型可以继承RequestBody实现

scopeNetLife {
    Post<String>("api"){
        body = MyRequestBody()
    }.await()
}

建议

建议你还是写一个demo出来吧

请教一下

Net如何配合Flow在viewmodel里请求数据个BRV加载一页使用呢?我自己试了试,但是感觉没用对,用起来不得劲

错误提示toast 内存泄漏

====================================
HEAP ANALYSIS RESULT
====================================
1 APPLICATION LEAKS

References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.

58888 bytes retained by leaking objects
Signature: 9f79c7a09d09e0075b068958c1330dabc98644dd
┬───
│ GC Root: Thread object
│
├─ android.os.HandlerThread instance
│    Leaking: NO (PathClassLoader↓ is not leaking)
│    Thread name: 'LeakCanary-Heap-Dump'
│    ↓ Thread.contextClassLoader
├─ dalvik.system.PathClassLoader instance
│    Leaking: NO (TipUtils↓ is not leaking and A ClassLoader is never leaking)
│    ↓ ClassLoader.runtimeInternalObjects
├─ java.lang.Object[] array
│    Leaking: NO (TipUtils↓ is not leaking)
│    ↓ Object[88]
├─ com.drake.net.utils.TipUtils class
│    Leaking: NO (a class is never leaking)
│    ↓ static TipUtils.toast
│                      ~~~~~
├─ android.widget.Toast instance
│    Leaking: YES (This toast is done showing (Toast.mTN.mWM != null && Toast.mTN.mView == null))
│    Retaining 58.9 kB in 59 objects
│    mContext instance of android.app.Application
│    ↓ Toast.mNextView
╰→ android.widget.LinearLayout instance
​     Leaking: YES (ObjectWatcher was watching this because android.widget.LinearLayout received
​     View#onDetachedFromWindow() callback)
​     Retaining 58.9 kB in 58 objects
​     key = 2e8d0274-e65f-4cb4-bb28-a4948228f6b0
​     watchDurationMillis = 11917
​     retainedDurationMillis = 6913
​     View not part of a window view hierarchy
​     View.mAttachInfo is null (view detached)
​     View.mID = R.id.null
​     View.mWindowAttachCount = 1
​     mContext instance of android.app.Application
====================================
0 LIBRARY LEAKS

如果没有我需要的功能

Net最大的特点在于完美支持OkHttp的所有功能组件, 而Android上基本上99%都是基于OkHttp的网络请求解决方案

如果存在Net没有实现的功能可以百度/谷歌搜索OkHttp如何实现**, 然后可以很容易在Net中使用

使用inline reified封装请求函数导致崩溃

如下图
44D70AE9-33A7-48a8-B8B0-AE8EE8E8AB16
我是想要实现一个高服用的列表fragment 返回值类型需要再外部定义 于是使用inline reified的方式 但是会
报错.UnsupportedOperationException: This function has a reified type parameter and thus can only be inlined at compilation time, not called directly.
没有找到解决方案 作者大人可以看下吗

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.