Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
MVPArms
提交
6b48d482
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,发现更多精彩内容 >>
提交
6b48d482
编写于
4月 07, 2017
作者:
J
jessyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
demo use lambda
上级
435cec35
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
35 addition
and
43 deletion
+35
-43
app/build.gradle
app/build.gradle
+6
-0
app/src/main/java/common/WEApplication.java
app/src/main/java/common/WEApplication.java
+3
-9
app/src/main/java/me/jessyan/mvparms/demo/mvp/presenter/UserPresenter.java
.../me/jessyan/mvparms/demo/mvp/presenter/UserPresenter.java
+12
-22
app/src/main/java/me/jessyan/mvparms/demo/mvp/ui/activity/UserActivity.java
...me/jessyan/mvparms/demo/mvp/ui/activity/UserActivity.java
+1
-7
arms/build.gradle
arms/build.gradle
+6
-0
arms/src/main/java/com/jess/arms/base/BaseApplication.java
arms/src/main/java/com/jess/arms/base/BaseApplication.java
+5
-5
build.gradle
build.gradle
+2
-0
未找到文件。
app/build.gradle
浏览文件 @
6b48d482
apply
plugin:
'com.android.application'
apply
plugin:
'me.tatarka.retrolambda'
android
{
compileSdkVersion
rootProject
.
ext
.
android
[
"compileSdkVersion"
]
buildToolsVersion
rootProject
.
ext
.
android
[
"buildToolsVersion"
]
useLibrary
'org.apache.http.legacy'
compileOptions
{
targetCompatibility
JavaVersion
.
VERSION_1_8
sourceCompatibility
JavaVersion
.
VERSION_1_8
}
defaultConfig
{
applicationId
"me.jessyan.mvparms.demo"
minSdkVersion
rootProject
.
ext
.
android
[
"minSdkVersion"
]
...
...
app/src/main/java/common/WEApplication.java
浏览文件 @
6b48d482
...
...
@@ -18,7 +18,6 @@ import me.jessyan.mvparms.demo.BuildConfig;
import
me.jessyan.mvparms.demo.di.module.CacheModule
;
import
me.jessyan.mvparms.demo.di.module.ServiceModule
;
import
me.jessyan.mvparms.demo.mvp.model.api.Api
;
import
me.jessyan.rxerrorhandler.handler.listener.ResponseErroListener
;
import
okhttp3.Interceptor
;
import
okhttp3.Request
;
import
okhttp3.Response
;
...
...
@@ -146,14 +145,9 @@ public class WEApplication extends BaseApplication {
return
request
;
}
})
.
responseErroListener
(
new
ResponseErroListener
()
{
// 用来提供处理所有错误的监听
// rxjava必要要使用ErrorHandleSubscriber(默认实现Subscriber的onError方法),此监听才生效
@Override
public
void
handleResponseError
(
Context
context
,
Exception
e
)
{
.
responseErroListener
((
context
,
e
)
->
{
Timber
.
tag
(
TAG
).
w
(
"------------>"
+
e
.
getMessage
());
UiUtils
.
SnackbarText
(
"net error"
);
}
}).
build
();
}
...
...
app/src/main/java/me/jessyan/mvparms/demo/mvp/presenter/UserPresenter.java
浏览文件 @
6b48d482
...
...
@@ -21,7 +21,6 @@ import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import
me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber
;
import
me.jessyan.rxerrorhandler.handler.RetryWithDelay
;
import
rx.android.schedulers.AndroidSchedulers
;
import
rx.functions.Action0
;
import
rx.schedulers.Schedulers
;
/**
...
...
@@ -52,11 +51,8 @@ public class UserPresenter extends BasePresenter<UserContract.Model, UserContrac
public
void
requestUsers
(
final
boolean
pullToRefresh
)
{
//请求外部存储权限用于适配android6.0的权限管理机制
PermissionUtil
.
externalStorage
(
new
PermissionUtil
.
RequestPermission
()
{
@Override
public
void
onRequestPermissionSuccess
()
{
PermissionUtil
.
externalStorage
(()
->
{
//request permission success, do something.
}
},
mRootView
.
getRxPermissions
(),
mRootView
,
mErrorHandler
);
...
...
@@ -74,24 +70,18 @@ public class UserPresenter extends BasePresenter<UserContract.Model, UserContrac
mModel
.
getUsers
(
lastUserId
,
isEvictCache
)
.
subscribeOn
(
Schedulers
.
io
())
.
retryWhen
(
new
RetryWithDelay
(
3
,
2
))
//遇到错误时重试,第一个参数为重试几次,第二个参数为重试的间隔
.
doOnSubscribe
(
new
Action0
()
{
@Override
public
void
call
()
{
.
doOnSubscribe
(()
->
{
if
(
pullToRefresh
)
mRootView
.
showLoading
();
//显示上拉刷新的进度条
else
mRootView
.
startLoadMore
();
//显示下拉加载更多的进度条
}
}).
subscribeOn
(
AndroidSchedulers
.
mainThread
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
doAfterTerminate
(
new
Action0
()
{
@Override
public
void
call
()
{
.
doAfterTerminate
(()
->
{
if
(
pullToRefresh
)
mRootView
.
hideLoading
();
//隐藏上拉刷新的进度条
else
mRootView
.
endLoadMore
();
//隐藏下拉加载更多的进度条
}
})
.
compose
(
RxUtils
.<
List
<
User
>>
bindToLifecycle
(
mRootView
))
//使用RXlifecycle,使subscription和activity一起销毁
.
subscribe
(
new
ErrorHandleSubscriber
<
List
<
User
>>(
mErrorHandler
)
{
...
...
app/src/main/java/me/jessyan/mvparms/demo/mvp/ui/activity/UserActivity.java
浏览文件 @
6b48d482
...
...
@@ -23,7 +23,6 @@ import me.jessyan.mvparms.demo.mvp.contract.UserContract;
import
me.jessyan.mvparms.demo.mvp.presenter.UserPresenter
;
import
rx.Observable
;
import
rx.android.schedulers.AndroidSchedulers
;
import
rx.functions.Action1
;
import
timber.log.Timber
;
...
...
@@ -80,12 +79,7 @@ public class UserActivity extends WEActivity<UserPresenter> implements UserContr
Timber
.
tag
(
TAG
).
w
(
"showLoading"
);
Observable
.
just
(
1
)
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
new
Action1
<
Integer
>()
{
@Override
public
void
call
(
Integer
integer
)
{
mSwipeRefreshLayout
.
setRefreshing
(
true
);
}
});
.
subscribe
(
integer
->
mSwipeRefreshLayout
.
setRefreshing
(
true
));
}
@Override
...
...
arms/build.gradle
浏览文件 @
6b48d482
apply
plugin:
'com.android.library'
apply
plugin:
'me.tatarka.retrolambda'
android
{
compileSdkVersion
rootProject
.
ext
.
android
[
"compileSdkVersion"
]
buildToolsVersion
rootProject
.
ext
.
android
[
"buildToolsVersion"
]
useLibrary
'org.apache.http.legacy'
compileOptions
{
targetCompatibility
JavaVersion
.
VERSION_1_8
sourceCompatibility
JavaVersion
.
VERSION_1_8
}
defaultConfig
{
minSdkVersion
rootProject
.
ext
.
android
[
"minSdkVersion"
]
targetSdkVersion
rootProject
.
ext
.
android
[
"targetSdkVersion"
]
...
...
arms/src/main/java/com/jess/arms/base/BaseApplication.java
浏览文件 @
6b48d482
...
...
@@ -26,7 +26,7 @@ public abstract class BaseApplication extends Application {
static
private
BaseApplication
mApplication
;
private
ClientModule
mClientModule
;
private
AppModule
mAppModule
;
private
ImageModule
mImage
r
Module
;
private
ImageModule
mImageModule
;
private
GlobeConfigModule
mGlobeConfigModule
;
@Inject
protected
AppManager
mAppManager
;
...
...
@@ -45,7 +45,7 @@ public abstract class BaseApplication extends Application {
.
appModule
(
mAppModule
)
.
build
()
.
inject
(
this
);
this
.
mImage
r
Module
=
new
ImageModule
();
//图片加载框架默认使用glide
this
.
mImageModule
=
new
ImageModule
();
//图片加载框架默认使用glide
this
.
mClientModule
=
new
ClientModule
(
mAppManager
);
//用于提供okhttp和retrofit的单例
this
.
mGlobeConfigModule
=
checkNotNull
(
getGlobeConfigModule
(),
"lobeConfigModule is required"
);
registerActivityLifecycleCallbacks
(
mActivityLifecycle
);
...
...
@@ -61,8 +61,8 @@ public abstract class BaseApplication extends Application {
this
.
mClientModule
=
null
;
if
(
mAppModule
!=
null
)
this
.
mAppModule
=
null
;
if
(
mImage
r
Module
!=
null
)
this
.
mImage
r
Module
=
null
;
if
(
mImageModule
!=
null
)
this
.
mImageModule
=
null
;
if
(
mActivityLifecycle
!=
null
)
{
unregisterActivityLifecycleCallbacks
(
mActivityLifecycle
);
}
...
...
@@ -92,7 +92,7 @@ public abstract class BaseApplication extends Application {
}
public
ImageModule
getImageModule
()
{
return
mImage
r
Module
;
return
mImageModule
;
}
...
...
build.gradle
浏览文件 @
6b48d482
...
...
@@ -10,6 +10,8 @@ buildscript {
classpath
'com.github.dcendents:android-maven-gradle-plugin:1.5'
//Gradle Bintray Plugin
classpath
'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
//lambda
classpath
'me.tatarka:gradle-retrolambda:3.6.0'
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录