Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
MVPArms
提交
31ac578d
M
MVPArms
项目概览
门心叼龙
/
MVPArms
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
MVPArms
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
31ac578d
编写于
2月 07, 2018
作者:
J
jessyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add @Binds on ClientModule
上级
cde48aee
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
27 deletion
+30
-27
arms/src/main/java/com/jess/arms/di/module/ClientModule.java
arms/src/main/java/com/jess/arms/di/module/ClientModule.java
+30
-27
未找到文件。
arms/src/main/java/com/jess/arms/di/module/ClientModule.java
浏览文件 @
31ac578d
...
...
@@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
import
javax.inject.Named
;
import
javax.inject.Singleton
;
import
dagger.Binds
;
import
dagger.Module
;
import
dagger.Provides
;
import
io.rx_cache2.internal.RxCache
;
...
...
@@ -56,23 +57,23 @@ import retrofit2.converter.gson.GsonConverterFactory;
* ================================================
*/
@Module
public
class
ClientModule
{
public
abstract
class
ClientModule
{
private
static
final
int
TIME_OUT
=
10
;
/**
* 提供 {@link Retrofit}
*
* @param application
* @param configuration
* @param builder
* @param client
* @param httpUrl
* @return
* @author: jess
* @date 8/30/16 1:15 PM
* @param gson
* @return {@link Retrofit}
*/
@Singleton
@Provides
Retrofit
provideRetrofit
(
Application
application
,
@Nullable
RetrofitConfiguration
configuration
,
Retrofit
.
Builder
builder
,
OkHttpClient
client
static
Retrofit
provideRetrofit
(
Application
application
,
@Nullable
RetrofitConfiguration
configuration
,
Retrofit
.
Builder
builder
,
OkHttpClient
client
,
HttpUrl
httpUrl
,
Gson
gson
)
{
builder
.
baseUrl
(
httpUrl
)
//域名
...
...
@@ -90,12 +91,17 @@ public class ClientModule {
/**
* 提供 {@link OkHttpClient}
*
* @param application
* @param configuration
* @param builder
* @return
* @param intercept
* @param interceptors
* @param handler
* @return {@link OkHttpClient}
*/
@Singleton
@Provides
OkHttpClient
provideClient
(
Application
application
,
@Nullable
OkhttpConfiguration
configuration
,
OkHttpClient
.
Builder
builder
,
Interceptor
intercept
static
OkHttpClient
provideClient
(
Application
application
,
@Nullable
OkhttpConfiguration
configuration
,
OkHttpClient
.
Builder
builder
,
Interceptor
intercept
,
@Nullable
List
<
Interceptor
>
interceptors
,
@Nullable
GlobalHttpHandler
handler
)
{
builder
.
connectTimeout
(
TIME_OUT
,
TimeUnit
.
SECONDS
)
...
...
@@ -121,37 +127,32 @@ public class ClientModule {
return
builder
.
build
();
}
@Singleton
@Provides
Retrofit
.
Builder
provideRetrofitBuilder
()
{
static
Retrofit
.
Builder
provideRetrofitBuilder
()
{
return
new
Retrofit
.
Builder
();
}
@Singleton
@Provides
OkHttpClient
.
Builder
provideClientBuilder
()
{
static
OkHttpClient
.
Builder
provideClientBuilder
()
{
return
new
OkHttpClient
.
Builder
();
}
@Singleton
@Provides
Interceptor
provideInterceptor
(
RequestInterceptor
intercept
)
{
return
intercept
;
//打印请求信息的拦截器
}
@Binds
abstract
Interceptor
bindInterceptor
(
RequestInterceptor
interceptor
);
/**
* 提供 {@link RxCache}
*
* @param cacheDirectory RxCache缓存路径
* @return
* @param application
* @param configuration
* @param cacheDirectory cacheDirectory RxCache缓存路径
* @return {@link RxCache}
*/
@Singleton
@Provides
RxCache
provideRxCache
(
Application
application
,
@Nullable
RxCacheConfiguration
configuration
,
@Named
(
"RxCacheDirectory"
)
File
cacheDirectory
)
{
static
RxCache
provideRxCache
(
Application
application
,
@Nullable
RxCacheConfiguration
configuration
,
@Named
(
"RxCacheDirectory"
)
File
cacheDirectory
)
{
RxCache
.
Builder
builder
=
new
RxCache
.
Builder
();
RxCache
rxCache
=
null
;
if
(
configuration
!=
null
)
{
...
...
@@ -166,12 +167,12 @@ public class ClientModule {
* 需要单独给 {@link RxCache} 提供缓存路径
*
* @param cacheDir
* @return
* @return
{@link File}
*/
@Singleton
@Provides
@Named
(
"RxCacheDirectory"
)
File
provideRxCacheDirectory
(
File
cacheDir
)
{
static
File
provideRxCacheDirectory
(
File
cacheDir
)
{
File
cacheDirectory
=
new
File
(
cacheDir
,
"RxCache"
);
return
DataHelper
.
makeDirs
(
cacheDirectory
);
}
...
...
@@ -179,11 +180,13 @@ public class ClientModule {
/**
* 提供处理 RxJava 错误的管理器
*
* @return
* @param application
* @param listener
* @return {@link RxErrorHandler}
*/
@Singleton
@Provides
RxErrorHandler
proRxErrorHandler
(
Application
application
,
ResponseErrorListener
listener
)
{
static
RxErrorHandler
proRxErrorHandler
(
Application
application
,
ResponseErrorListener
listener
)
{
return
RxErrorHandler
.
builder
()
.
with
(
application
)
...
...
@@ -206,7 +209,7 @@ public class ClientModule {
*
* @param context
* @param builder
* @return
* @return
{@link RxCache}
*/
RxCache
configRxCache
(
Context
context
,
RxCache
.
Builder
builder
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录