Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
MVPArms
提交
8c88ef50
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,发现更多精彩内容 >>
提交
8c88ef50
编写于
12月 24, 2016
作者:
J
jessyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve appmanager
上级
18d3c24b
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
86 addition
and
101 deletion
+86
-101
MVP_generator_solution
MVP_generator_solution
+4
-3
app/src/main/java/me/jessyan/mvparms/demo/di/module/UserModule.java
...in/java/me/jessyan/mvparms/demo/di/module/UserModule.java
+2
-4
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/UserModel.java
...ain/java/me/jessyan/mvparms/demo/mvp/model/UserModel.java
+5
-0
arms/src/main/java/com/jess/arms/base/AppManager.java
arms/src/main/java/com/jess/arms/base/AppManager.java
+5
-1
arms/src/main/java/com/jess/arms/base/BaseApplication.java
arms/src/main/java/com/jess/arms/base/BaseApplication.java
+4
-4
arms/src/main/java/com/jess/arms/di/component/BaseComponent.java
...c/main/java/com/jess/arms/di/component/BaseComponent.java
+2
-2
arms/src/main/java/com/jess/arms/di/module/AppModule.java
arms/src/main/java/com/jess/arms/di/module/AppModule.java
+1
-7
arms/src/main/java/com/jess/arms/di/module/BaseModule.java
arms/src/main/java/com/jess/arms/di/module/BaseModule.java
+0
-27
arms/src/main/java/com/jess/arms/di/module/ClientModule.java
arms/src/main/java/com/jess/arms/di/module/ClientModule.java
+63
-53
未找到文件。
MVP_generator_solution
浏览文件 @
8c88ef50
...
...
@@ -292,10 +292,12 @@ import static com.jess.arms.utils.Preconditions.checkNotNull;
#parse("File Header.java")
@ActivityScope
public class ${NAME}Model extends BaseModel<ServiceManager,CacheManager> implements ${NAME}Contract.Model{
private Gson mGson;
private Application mApplication;
@Inject
public ${NAME}Model(ServiceManager serviceManager, CacheManager cacheManager, Gson gson, Application application) {
super(serviceManager, cacheManager);
this.mGson = gson;
...
...
@@ -356,9 +358,8 @@ public class ${NAME}Module {
@ActivityScope
@Provides
${NAME}Contract.Model provide${NAME}Model(ServiceManager serviceManager, CacheManager cacheManager
,Gson gson,Application application){
return new ${NAME}Model(serviceManager,cacheManager,gson,application);
${NAME}Contract.Model provide${NAME}Model(${NAME}Model model){
return model;
}
}
--------------------------------------------------------------------------------------
...
...
app/src/main/java/me/jessyan/mvparms/demo/di/module/UserModule.java
浏览文件 @
8c88ef50
...
...
@@ -6,8 +6,6 @@ import dagger.Module;
import
dagger.Provides
;
import
me.jessyan.mvparms.demo.mvp.contract.UserContract
;
import
me.jessyan.mvparms.demo.mvp.model.UserModel
;
import
me.jessyan.mvparms.demo.mvp.model.api.cache.CacheManager
;
import
me.jessyan.mvparms.demo.mvp.model.api.service.ServiceManager
;
/**
* Created by jess on 9/4/16 11:10
...
...
@@ -33,7 +31,7 @@ public class UserModule {
@ActivityScope
@Provides
UserContract
.
Model
provideUserModel
(
ServiceManager
serviceManager
,
CacheManager
cacheManager
){
return
new
UserModel
(
serviceManager
,
cacheManager
)
;
UserContract
.
Model
provideUserModel
(
UserModel
model
){
return
model
;
}
}
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/UserModel.java
浏览文件 @
8c88ef50
package
me.jessyan.mvparms.demo.mvp.model
;
import
com.jess.arms.di.scope.ActivityScope
;
import
com.jess.arms.mvp.BaseModel
;
import
java.util.List
;
import
javax.inject.Inject
;
import
io.rx_cache.DynamicKey
;
import
io.rx_cache.EvictDynamicKey
;
import
io.rx_cache.Reply
;
...
...
@@ -18,9 +21,11 @@ import rx.functions.Func1;
* Created by jess on 9/4/16 10:56
* Contact with jess.yan.effort@gmail.com
*/
@ActivityScope
public
class
UserModel
extends
BaseModel
<
ServiceManager
,
CacheManager
>
implements
UserContract
.
Model
{
public
static
final
int
USERS_PER_PAGE
=
10
;
@Inject
public
UserModel
(
ServiceManager
serviceManager
,
CacheManager
cacheManager
)
{
super
(
serviceManager
,
cacheManager
);
}
...
...
arms/src/main/java/com/jess/arms/base/AppManager.java
浏览文件 @
8c88ef50
...
...
@@ -16,6 +16,9 @@ import java.util.Iterator;
import
java.util.LinkedList
;
import
java.util.List
;
import
javax.inject.Inject
;
import
javax.inject.Singleton
;
import
timber.log.Timber
;
/**
...
...
@@ -25,7 +28,7 @@ import timber.log.Timber;
* Created by jess on 14/12/2016 13:50
* Contact with jess.yan.effort@gmail.com
*/
@Singleton
public
class
AppManager
{
protected
final
String
TAG
=
this
.
getClass
().
getSimpleName
();
public
static
final
String
APPMANAGER_MESSAGE
=
"appmanager_message"
;
...
...
@@ -40,6 +43,7 @@ public class AppManager {
//当前在前台的activity
private
BaseActivity
mCurrentActivity
;
@Inject
public
AppManager
(
Application
application
)
{
this
.
mApplication
=
application
;
EventBus
.
getDefault
().
register
(
this
);
...
...
arms/src/main/java/com/jess/arms/base/BaseApplication.java
浏览文件 @
8c88ef50
...
...
@@ -5,7 +5,6 @@ import android.content.Context;
import
com.jess.arms.di.component.DaggerBaseComponent
;
import
com.jess.arms.di.module.AppModule
;
import
com.jess.arms.di.module.BaseModule
;
import
com.jess.arms.di.module.ClientModule
;
import
com.jess.arms.di.module.ImageModule
;
import
com.jess.arms.http.GlobeHttpHandler
;
...
...
@@ -38,20 +37,21 @@ public abstract class BaseApplication extends Application {
public
void
onCreate
()
{
super
.
onCreate
();
mApplication
=
this
;
this
.
mAppModule
=
new
AppModule
(
this
);
//提供application
DaggerBaseComponent
.
builder
()
.
baseModule
(
new
BaseModule
(
this
)
)
.
appModule
(
mAppModule
)
.
build
()
.
inject
(
this
);
this
.
mImagerModule
=
new
ImageModule
();
//图片加载框架默认使用glide
this
.
mClientModule
=
ClientModule
//用于提供okhttp和retrofit的单列
.
buidler
()
.
baseurl
(
getBaseUrl
())
.
globeHttpHandler
(
getHttpHandler
())
.
interceptors
(
getInterceptors
())
.
appManager
(
mAppManager
)
//DaggerBaseComponent.inject()后,mAppManager才有值
.
responseErroListener
(
getResponseErroListener
())
.
build
();
this
.
mAppModule
=
new
AppModule
(
this
,
mAppManager
);
//提供application
this
.
mImagerModule
=
new
ImageModule
();
//图片加载框架默认使用glide
}
/**
...
...
arms/src/main/java/com/jess/arms/di/component/BaseComponent.java
浏览文件 @
8c88ef50
package
com.jess.arms.di.component
;
import
com.jess.arms.base.BaseApplication
;
import
com.jess.arms.di.module.
Base
Module
;
import
com.jess.arms.di.module.
App
Module
;
import
javax.inject.Singleton
;
...
...
@@ -12,7 +12,7 @@ import dagger.Component;
* Contact with jess.yan.effort@gmail.com
*/
@Singleton
@Component
(
modules
={
Base
Module
.
class
})
@Component
(
modules
={
App
Module
.
class
})
public
interface
BaseComponent
{
void
inject
(
BaseApplication
application
);
}
arms/src/main/java/com/jess/arms/di/module/AppModule.java
浏览文件 @
8c88ef50
...
...
@@ -3,7 +3,6 @@ package com.jess.arms.di.module;
import
android.app.Application
;
import
com.google.gson.Gson
;
import
com.jess.arms.base.AppManager
;
import
javax.inject.Singleton
;
...
...
@@ -16,11 +15,9 @@ import dagger.Provides;
@Module
public
class
AppModule
{
private
Application
mApplication
;
private
AppManager
mAppManager
;
public
AppModule
(
Application
application
,
AppManager
appManager
)
{
public
AppModule
(
Application
application
)
{
this
.
mApplication
=
application
;
this
.
mAppManager
=
appManager
;
}
@Singleton
...
...
@@ -33,7 +30,4 @@ public class AppModule {
@Provides
public
Gson
provideGson
(){
return
new
Gson
();}
@Singleton
@Provides
public
AppManager
provideAppManager
(){
return
mAppManager
;}
}
arms/src/main/java/com/jess/arms/di/module/BaseModule.java
已删除
100644 → 0
浏览文件 @
18d3c24b
package
com.jess.arms.di.module
;
import
android.app.Application
;
import
com.jess.arms.base.AppManager
;
import
javax.inject.Singleton
;
import
dagger.Module
;
import
dagger.Provides
;
/**
* Created by jess on 14/12/2016 13:54
* Contact with jess.yan.effort@gmail.com
*/
@Module
public
class
BaseModule
{
private
Application
mApplication
;
public
BaseModule
(
Application
application
)
{
this
.
mApplication
=
application
;
}
@Singleton
@Provides
public
AppManager
provideAppManager
(){
return
new
AppManager
(
mApplication
);}
}
arms/src/main/java/com/jess/arms/di/module/ClientModule.java
浏览文件 @
8c88ef50
...
...
@@ -3,6 +3,7 @@ package com.jess.arms.di.module;
import
android.app.Application
;
import
android.text.TextUtils
;
import
com.jess.arms.base.AppManager
;
import
com.jess.arms.http.GlobeHttpHandler
;
import
com.jess.arms.http.RequestIntercept
;
import
com.jess.arms.utils.DataHelper
;
...
...
@@ -38,6 +39,7 @@ public class ClientModule {
private
GlobeHttpHandler
mHandler
;
private
Interceptor
[]
mInterceptors
;
private
ResponseErroListener
mErroListener
;
private
AppManager
mAppManager
;
/**
* @author: jess
...
...
@@ -49,42 +51,72 @@ public class ClientModule {
this
.
mHandler
=
buidler
.
handler
;
this
.
mInterceptors
=
buidler
.
interceptors
;
this
.
mErroListener
=
buidler
.
responseErroListener
;
this
.
mAppManager
=
buidler
.
appManager
;
}
public
static
Buidler
buidler
()
{
return
new
Buidler
();
}
/**
* @param cache 缓存
* @param intercept 拦截器
* @param builder
* @param client
* @param httpUrl
* @return
* @author: jess
* @date 8/30/16 1:1
2
PM
* @description:提供
OkhttpClien
t
* @date 8/30/16 1:1
5
PM
* @description:提供
retrofi
t
*/
@Singleton
@Provides
OkHttpClient
provideClient
(
Cache
cache
,
Interceptor
intercept
)
{
final
OkHttpClient
.
Builder
okHttpClient
=
new
OkHttpClient
.
Builder
();
return
configureClient
(
okHttpClient
,
cache
,
intercept
);
Retrofit
provideRetrofit
(
Retrofit
.
Builder
builder
,
OkHttpClient
client
,
HttpUrl
httpUrl
)
{
return
builder
.
baseUrl
(
httpUrl
)
//域名
.
client
(
client
)
//设置okhttp
.
addCallAdapterFactory
(
RxJavaCallAdapterFactory
.
create
())
//使用rxjava
.
addConverterFactory
(
GsonConverterFactory
.
create
())
//使用Gson
.
build
();
}
/**
* @param client
* @param httpUrl
* 提供OkhttpClient
*
* @param okHttpClient
* @return
* @author: jess
* @date 8/30/16 1:13 PM
* @description: 提供retrofit
*/
@Singleton
@Provides
Retrofit
provideRetrofit
(
OkHttpClient
client
,
HttpUrl
httpUrl
)
{
final
Retrofit
.
Builder
builder
=
new
Retrofit
.
Builder
();
return
configureRetrofit
(
builder
,
client
,
httpUrl
);
OkHttpClient
provideClient
(
OkHttpClient
.
Builder
okHttpClient
,
Cache
cache
,
Interceptor
intercept
)
{
OkHttpClient
.
Builder
builder
=
okHttpClient
.
connectTimeout
(
TIME_OUT
,
TimeUnit
.
SECONDS
)
.
readTimeout
(
TIME_OUT
,
TimeUnit
.
SECONDS
)
.
cache
(
cache
)
//设置缓存
.
addNetworkInterceptor
(
intercept
);
if
(
mInterceptors
!=
null
&&
mInterceptors
.
length
>
0
)
{
//如果外部提供了interceptor的数组则遍历添加
for
(
Interceptor
interceptor
:
mInterceptors
)
{
builder
.
addInterceptor
(
interceptor
);
}
}
return
builder
.
build
();
}
@Singleton
@Provides
Retrofit
.
Builder
provideRetrofitBuilder
()
{
return
new
Retrofit
.
Builder
();
}
@Singleton
@Provides
OkHttpClient
.
Builder
provideClientBuilder
()
{
return
new
OkHttpClient
.
Builder
();
}
@Singleton
@Provides
HttpUrl
provideBaseUrl
()
{
...
...
@@ -147,6 +179,7 @@ public class ClientModule {
/**
* 提供权限管理类,用于请求权限,适配6.0的权限管理
*
* @param application
* @return
*/
...
...
@@ -158,44 +191,13 @@ public class ClientModule {
/**
* @param builder
* @param client
* @param httpUrl
* @return
* @author: jess
* @date 8/30/16 1:15 PM
* @description:配置retrofit
*/
private
Retrofit
configureRetrofit
(
Retrofit
.
Builder
builder
,
OkHttpClient
client
,
HttpUrl
httpUrl
)
{
return
builder
.
baseUrl
(
httpUrl
)
//域名
.
client
(
client
)
//设置okhttp
.
addCallAdapterFactory
(
RxJavaCallAdapterFactory
.
create
())
//使用rxjava
.
addConverterFactory
(
GsonConverterFactory
.
create
())
//使用Gson
.
build
();
}
/**
* 配置okhttpclient
*
* @param okHttpClient
* 提供管理所有activity的管理类
* @return
*/
private
OkHttpClient
configureClient
(
OkHttpClient
.
Builder
okHttpClient
,
Cache
cache
,
Interceptor
intercept
)
{
OkHttpClient
.
Builder
builder
=
okHttpClient
.
connectTimeout
(
TIME_OUT
,
TimeUnit
.
SECONDS
)
.
readTimeout
(
TIME_OUT
,
TimeUnit
.
SECONDS
)
.
cache
(
cache
)
//设置缓存
.
addNetworkInterceptor
(
intercept
);
if
(
mInterceptors
!=
null
&&
mInterceptors
.
length
>
0
)
{
//如果外部提供了interceptor的数组则遍历添加
for
(
Interceptor
interceptor
:
mInterceptors
)
{
builder
.
addInterceptor
(
interceptor
);
}
}
return
builder
.
build
();
@Singleton
@Provides
AppManager
provideAppManager
()
{
return
mAppManager
;
}
...
...
@@ -204,6 +206,7 @@ public class ClientModule {
private
GlobeHttpHandler
handler
;
private
Interceptor
[]
interceptors
;
private
ResponseErroListener
responseErroListener
;
private
AppManager
appManager
;
private
Buidler
()
{
}
...
...
@@ -231,11 +234,18 @@ public class ClientModule {
return
this
;
}
public
Buidler
appManager
(
AppManager
appManager
)
{
//管理所有activity的管理类
this
.
appManager
=
appManager
;
return
this
;
}
public
ClientModule
build
()
{
if
(
apiUrl
==
null
)
{
if
(
apiUrl
==
null
)
throw
new
IllegalStateException
(
"baseurl is required"
);
}
if
(
appManager
==
null
)
throw
new
IllegalStateException
(
"appManager is required"
);
return
new
ClientModule
(
this
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录