Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
MVPArms
提交
31ad69ba
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,发现更多精彩内容 >>
提交
31ad69ba
编写于
12月 16, 2016
作者:
J
jessyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize demo
上级
bb0c9c5d
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
433 addition
and
32 deletion
+433
-32
app/src/main/java/me/jessyan/mvparms/demo/app/utils/FastBlur.java
...main/java/me/jessyan/mvparms/demo/app/utils/FastBlur.java
+291
-0
app/src/main/java/me/jessyan/mvparms/demo/di/module/ServiceModule.java
...java/me/jessyan/mvparms/demo/di/module/ServiceModule.java
+7
-0
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/UserModel.java
...ain/java/me/jessyan/mvparms/demo/mvp/model/UserModel.java
+1
-1
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/api/Api.java
.../main/java/me/jessyan/mvparms/demo/mvp/model/api/Api.java
+2
-1
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/api/service/CommonService.java
...yan/mvparms/demo/mvp/model/api/service/CommonService.java
+1
-26
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/api/service/ServiceManager.java
...an/mvparms/demo/mvp/model/api/service/ServiceManager.java
+7
-1
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/api/service/UserService.java
...ssyan/mvparms/demo/mvp/model/api/service/UserService.java
+25
-0
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/entity/BaseJson.java
...va/me/jessyan/mvparms/demo/mvp/model/entity/BaseJson.java
+42
-0
app/src/main/java/me/jessyan/mvparms/demo/mvp/presenter/UserPresenter.java
.../me/jessyan/mvparms/demo/mvp/presenter/UserPresenter.java
+2
-2
arms/src/main/java/com/jess/arms/base/BaseApplication.java
arms/src/main/java/com/jess/arms/base/BaseApplication.java
+0
-1
arms/src/main/java/com/jess/arms/utils/RxUtils.java
arms/src/main/java/com/jess/arms/utils/RxUtils.java
+55
-0
未找到文件。
app/src/main/java/me/jessyan/mvparms/demo/app/utils/FastBlur.java
0 → 100644
浏览文件 @
31ad69ba
package
me.jessyan.mvparms.demo.app.utils
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.Paint
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.util.Log
;
import
android.view.View
;
import
com.jess.arms.utils.DrawableProvider
;
import
com.jess.arms.utils.UiUtils
;
/**
* 使图片高斯模糊
* Created by paveld on 3/6/14.
*/
public
class
FastBlur
{
public
static
Bitmap
doBlur
(
Bitmap
sentBitmap
,
int
radius
,
boolean
canReuseInBitmap
)
{
// Stack Blur v1.0 from
// http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
//
// Java Author: Mario Klingemann <mario at quasimondo.com>
// http://incubator.quasimondo.com
// created Feburary 29, 2004
// Android port : Yahel Bouaziz <yahel at kayenko.com>
// http://www.kayenko.com
// ported april 5th, 2012
// This is a compromise between Gaussian Blur and Box blur
// It creates much better looking blurs than Box Blur, but is
// 7x faster than my Gaussian Blur implementation.
//
// I called it Stack Blur because this describes best how this
// filter works internally: it creates a kind of moving stack
// of colors whilst scanning through the image. Thereby it
// just has to add one new block of color to the right side
// of the stack and remove the leftmost color. The remaining
// colors on the topmost layer of the stack are either added on
// or reduced by one, depending on if they are on the right or
// on the left side of the stack.
//
// If you are using this algorithm in your code please add
// the following line:
//
// Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>
Bitmap
bitmap
;
if
(
canReuseInBitmap
)
{
bitmap
=
sentBitmap
;
}
else
{
bitmap
=
sentBitmap
.
copy
(
sentBitmap
.
getConfig
(),
true
);
}
if
(
radius
<
1
)
{
return
(
null
);
}
int
w
=
bitmap
.
getWidth
();
int
h
=
bitmap
.
getHeight
();
int
[]
pix
=
new
int
[
w
*
h
];
bitmap
.
getPixels
(
pix
,
0
,
w
,
0
,
0
,
w
,
h
);
int
wm
=
w
-
1
;
int
hm
=
h
-
1
;
int
wh
=
w
*
h
;
int
div
=
radius
+
radius
+
1
;
int
r
[]
=
new
int
[
wh
];
int
g
[]
=
new
int
[
wh
];
int
b
[]
=
new
int
[
wh
];
int
rsum
,
gsum
,
bsum
,
x
,
y
,
i
,
p
,
yp
,
yi
,
yw
;
int
vmin
[]
=
new
int
[
Math
.
max
(
w
,
h
)];
int
divsum
=
(
div
+
1
)
>>
1
;
divsum
*=
divsum
;
int
dv
[]
=
new
int
[
256
*
divsum
];
for
(
i
=
0
;
i
<
256
*
divsum
;
i
++)
{
dv
[
i
]
=
(
i
/
divsum
);
}
yw
=
yi
=
0
;
int
[][]
stack
=
new
int
[
div
][
3
];
int
stackpointer
;
int
stackstart
;
int
[]
sir
;
int
rbs
;
int
r1
=
radius
+
1
;
int
routsum
,
goutsum
,
boutsum
;
int
rinsum
,
ginsum
,
binsum
;
for
(
y
=
0
;
y
<
h
;
y
++)
{
rinsum
=
ginsum
=
binsum
=
routsum
=
goutsum
=
boutsum
=
rsum
=
gsum
=
bsum
=
0
;
for
(
i
=
-
radius
;
i
<=
radius
;
i
++)
{
p
=
pix
[
yi
+
Math
.
min
(
wm
,
Math
.
max
(
i
,
0
))];
sir
=
stack
[
i
+
radius
];
sir
[
0
]
=
(
p
&
0xff0000
)
>>
16
;
sir
[
1
]
=
(
p
&
0x00ff00
)
>>
8
;
sir
[
2
]
=
(
p
&
0x0000ff
);
rbs
=
r1
-
Math
.
abs
(
i
);
rsum
+=
sir
[
0
]
*
rbs
;
gsum
+=
sir
[
1
]
*
rbs
;
bsum
+=
sir
[
2
]
*
rbs
;
if
(
i
>
0
)
{
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
}
else
{
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
}
}
stackpointer
=
radius
;
for
(
x
=
0
;
x
<
w
;
x
++)
{
r
[
yi
]
=
dv
[
rsum
];
g
[
yi
]
=
dv
[
gsum
];
b
[
yi
]
=
dv
[
bsum
];
rsum
-=
routsum
;
gsum
-=
goutsum
;
bsum
-=
boutsum
;
stackstart
=
stackpointer
-
radius
+
div
;
sir
=
stack
[
stackstart
%
div
];
routsum
-=
sir
[
0
];
goutsum
-=
sir
[
1
];
boutsum
-=
sir
[
2
];
if
(
y
==
0
)
{
vmin
[
x
]
=
Math
.
min
(
x
+
radius
+
1
,
wm
);
}
p
=
pix
[
yw
+
vmin
[
x
]];
sir
[
0
]
=
(
p
&
0xff0000
)
>>
16
;
sir
[
1
]
=
(
p
&
0x00ff00
)
>>
8
;
sir
[
2
]
=
(
p
&
0x0000ff
);
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
rsum
+=
rinsum
;
gsum
+=
ginsum
;
bsum
+=
binsum
;
stackpointer
=
(
stackpointer
+
1
)
%
div
;
sir
=
stack
[(
stackpointer
)
%
div
];
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
rinsum
-=
sir
[
0
];
ginsum
-=
sir
[
1
];
binsum
-=
sir
[
2
];
yi
++;
}
yw
+=
w
;
}
for
(
x
=
0
;
x
<
w
;
x
++)
{
rinsum
=
ginsum
=
binsum
=
routsum
=
goutsum
=
boutsum
=
rsum
=
gsum
=
bsum
=
0
;
yp
=
-
radius
*
w
;
for
(
i
=
-
radius
;
i
<=
radius
;
i
++)
{
yi
=
Math
.
max
(
0
,
yp
)
+
x
;
sir
=
stack
[
i
+
radius
];
sir
[
0
]
=
r
[
yi
];
sir
[
1
]
=
g
[
yi
];
sir
[
2
]
=
b
[
yi
];
rbs
=
r1
-
Math
.
abs
(
i
);
rsum
+=
r
[
yi
]
*
rbs
;
gsum
+=
g
[
yi
]
*
rbs
;
bsum
+=
b
[
yi
]
*
rbs
;
if
(
i
>
0
)
{
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
}
else
{
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
}
if
(
i
<
hm
)
{
yp
+=
w
;
}
}
yi
=
x
;
stackpointer
=
radius
;
for
(
y
=
0
;
y
<
h
;
y
++)
{
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
pix
[
yi
]
=
(
0xff000000
&
pix
[
yi
])
|
(
dv
[
rsum
]
<<
16
)
|
(
dv
[
gsum
]
<<
8
)
|
dv
[
bsum
];
rsum
-=
routsum
;
gsum
-=
goutsum
;
bsum
-=
boutsum
;
stackstart
=
stackpointer
-
radius
+
div
;
sir
=
stack
[
stackstart
%
div
];
routsum
-=
sir
[
0
];
goutsum
-=
sir
[
1
];
boutsum
-=
sir
[
2
];
if
(
x
==
0
)
{
vmin
[
y
]
=
Math
.
min
(
y
+
r1
,
hm
)
*
w
;
}
p
=
x
+
vmin
[
y
];
sir
[
0
]
=
r
[
p
];
sir
[
1
]
=
g
[
p
];
sir
[
2
]
=
b
[
p
];
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
rsum
+=
rinsum
;
gsum
+=
ginsum
;
bsum
+=
binsum
;
stackpointer
=
(
stackpointer
+
1
)
%
div
;
sir
=
stack
[
stackpointer
];
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
rinsum
-=
sir
[
0
];
ginsum
-=
sir
[
1
];
binsum
-=
sir
[
2
];
yi
+=
w
;
}
}
bitmap
.
setPixels
(
pix
,
0
,
w
,
0
,
0
,
w
,
h
);
return
(
bitmap
);
}
public
static
void
blur
(
Bitmap
bkg
,
View
view
)
{
long
startMs
=
System
.
currentTimeMillis
();
float
radius
=
15
;
float
scaleFactor
=
8
;
//放大到整个view的大小
bkg
=
DrawableProvider
.
getReSizeBitmap
(
bkg
,
view
.
getMeasuredWidth
(),
view
.
getMeasuredHeight
());
Bitmap
overlay
=
Bitmap
.
createBitmap
((
int
)
(
view
.
getMeasuredWidth
()
/
scaleFactor
)
,
(
int
)
(
view
.
getMeasuredHeight
()
/
scaleFactor
),
Bitmap
.
Config
.
ARGB_8888
);
Canvas
canvas
=
new
Canvas
(
overlay
);
canvas
.
translate
(-
view
.
getLeft
()
/
scaleFactor
,
-
view
.
getTop
()
/
scaleFactor
);
canvas
.
scale
(
1
/
scaleFactor
,
1
/
scaleFactor
);
Paint
paint
=
new
Paint
();
paint
.
setFlags
(
Paint
.
FILTER_BITMAP_FLAG
);
canvas
.
drawBitmap
(
bkg
,
0
,
0
,
paint
);
overlay
=
FastBlur
.
doBlur
(
overlay
,
(
int
)
radius
,
true
);
view
.
setBackgroundDrawable
(
new
BitmapDrawable
(
UiUtils
.
getResources
(),
overlay
));
Log
.
w
(
"test"
,
"cost "
+
(
System
.
currentTimeMillis
()
-
startMs
)
+
"ms"
);
}
public
static
Bitmap
blurBitmap
(
Bitmap
bkg
,
int
width
,
int
height
)
{
long
startMs
=
System
.
currentTimeMillis
();
float
radius
=
15
;
//越大模糊效果越大
float
scaleFactor
=
8
;
//放大到整个view的大小
bkg
=
DrawableProvider
.
getReSizeBitmap
(
bkg
,
width
,
height
);
Bitmap
overlay
=
Bitmap
.
createBitmap
((
int
)
(
width
/
scaleFactor
)
,
(
int
)
(
height
/
scaleFactor
),
Bitmap
.
Config
.
ARGB_8888
);
Canvas
canvas
=
new
Canvas
(
overlay
);
canvas
.
scale
(
1
/
scaleFactor
,
1
/
scaleFactor
);
Paint
paint
=
new
Paint
();
paint
.
setFlags
(
Paint
.
FILTER_BITMAP_FLAG
);
canvas
.
drawBitmap
(
bkg
,
0
,
0
,
paint
);
overlay
=
FastBlur
.
doBlur
(
overlay
,
(
int
)
radius
,
true
);
Log
.
w
(
"test"
,
"cost "
+
(
System
.
currentTimeMillis
()
-
startMs
)
+
"ms"
);
return
overlay
;
}
}
app/src/main/java/me/jessyan/mvparms/demo/di/module/ServiceModule.java
浏览文件 @
31ad69ba
...
...
@@ -6,6 +6,7 @@ import javax.inject.Singleton;
import
dagger.Module
;
import
dagger.Provides
;
import
me.jessyan.mvparms.demo.mvp.model.api.service.CommonService
;
import
me.jessyan.mvparms.demo.mvp.model.api.service.UserService
;
import
retrofit2.Retrofit
;
/**
...
...
@@ -20,4 +21,10 @@ public class ServiceModule {
return
retrofit
.
create
(
CommonService
.
class
);
}
@Singleton
@Provides
UserService
provideUserService
(
Retrofit
retrofit
)
{
return
retrofit
.
create
(
UserService
.
class
);
}
}
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/UserModel.java
浏览文件 @
31ad69ba
...
...
@@ -28,7 +28,7 @@ public class UserModel extends BaseModel<ServiceManager, CacheManager> implement
@Override
public
Observable
<
List
<
User
>>
getUsers
(
int
lastIdQueried
,
boolean
update
)
{
Observable
<
List
<
User
>>
users
=
mServiceManager
.
get
Common
Service
()
Observable
<
List
<
User
>>
users
=
mServiceManager
.
get
User
Service
()
.
getUsers
(
lastIdQueried
,
USERS_PER_PAGE
);
//使用rxcache缓存,上拉刷新则不读取缓存,加载更多读取缓存
return
mCacheManager
.
getCommonCache
()
...
...
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/api/Api.java
浏览文件 @
31ad69ba
...
...
@@ -5,5 +5,6 @@ package me.jessyan.mvparms.demo.mvp.model.api;
* contact with jess.yan.effort@gmail.com
*/
public
interface
Api
{
public
static
final
String
APP_DOMAIN
=
"https://api.github.com"
;
String
APP_DOMAIN
=
"https://api.github.com"
;
String
RequestSuccess
=
"0"
;
}
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/api/service/CommonService.java
浏览文件 @
31ad69ba
package
me.jessyan.mvparms.demo.mvp.model.api.service
;
import
java.util.List
;
import
me.jessyan.mvparms.demo.mvp.model.entity.User
;
import
retrofit2.http.GET
;
import
retrofit2.http.Headers
;
import
retrofit2.http.Query
;
import
rx.Observable
;
/**
* 存放通用的一些API
* Created by jess on 8/5/16 12:05
* contact with jess.yan.effort@gmail.com
*/
public
interface
CommonService
{
String
HEADER_API_VERSION
=
"Accept: application/vnd.github.v3+json"
;
@Headers
({
HEADER_API_VERSION
})
@GET
(
"/users"
)
Observable
<
List
<
User
>>
getUsers
(
@Query
(
"since"
)
int
lastIdQueried
,
@Query
(
"per_page"
)
int
perPage
);
// @GET("/api/v2/feed?num=2&udid=26868b32e808498db32fd51fb422d00175e179df&vc=83")
// Observable<HomePicEntity> getDailyList();
//
// @GET("/api/v2/categories?udid=26868b32e808498db32fd51fb422d00175e179df&vc=83")
// Observable<FindMoreEntity> getFindMore();
//
// @GET("/api/v3/ranklist?num=10&strategy=%s&udid=26868b32e808498db32fd51fb422d00175e179df&vc=83")
// Observable<HotStrategyEntity> getHotStrategy();
//
// @GET("/api/v3/videos?categoryName=%s&strategy=%s&udid=26868b32e808498db32fd51fb422d00175e179df&vc=83")
// Observable<FindDetailEntity> getFindDetail();
}
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/api/service/ServiceManager.java
浏览文件 @
31ad69ba
...
...
@@ -12,20 +12,26 @@ import javax.inject.Singleton;
@Singleton
public
class
ServiceManager
implements
BaseServiceManager
{
private
CommonService
mCommonService
;
private
UserService
mUserService
;
/**
* 如果需要添加service只需在构造方法中添加对应的service,在提供get方法返回出去,只要在ServiceModule提供了该service
* Dagger2会自行注入
* @param commonService
*/
@Inject
public
ServiceManager
(
CommonService
commonService
){
@Inject
public
ServiceManager
(
CommonService
commonService
,
UserService
userService
){
this
.
mCommonService
=
commonService
;
this
.
mUserService
=
userService
;
}
public
CommonService
getCommonService
()
{
return
mCommonService
;
}
public
UserService
getUserService
()
{
return
mUserService
;
}
/**
* 这里可以释放一些资源(注意这里是单例,即不需要在activity的生命周期调用)
*/
...
...
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/api/service/UserService.java
0 → 100644
浏览文件 @
31ad69ba
package
me.jessyan.mvparms.demo.mvp.model.api.service
;
import
java.util.List
;
import
me.jessyan.mvparms.demo.mvp.model.entity.User
;
import
retrofit2.http.GET
;
import
retrofit2.http.Headers
;
import
retrofit2.http.Query
;
import
rx.Observable
;
/**
* 存放关于用户的一些api
* Created by jess on 8/5/16 12:05
* contact with jess.yan.effort@gmail.com
*/
public
interface
UserService
{
String
HEADER_API_VERSION
=
"Accept: application/vnd.github.v3+json"
;
@Headers
({
HEADER_API_VERSION
})
@GET
(
"/users"
)
Observable
<
List
<
User
>>
getUsers
(
@Query
(
"since"
)
int
lastIdQueried
,
@Query
(
"per_page"
)
int
perPage
);
}
app/src/main/java/me/jessyan/mvparms/demo/mvp/model/entity/BaseJson.java
0 → 100644
浏览文件 @
31ad69ba
package
me.jessyan.mvparms.demo.mvp.model.entity
;
import
java.io.Serializable
;
import
me.jessyan.mvparms.demo.mvp.model.api.Api
;
/**
* 如果你服务器返回的数据固定为这种方式(字段名可根据服务器更改)
* 替换范型即可重用BaseJson
* Created by jess on 26/09/2016 15:19
* Contact with jess.yan.effort@gmail.com
*/
public
class
BaseJson
<
T
>
implements
Serializable
{
private
T
data
;
private
String
code
;
private
String
msg
;
public
T
getData
()
{
return
data
;
}
public
String
getCode
()
{
return
code
;
}
public
String
getMsg
()
{
return
msg
;
}
/**
* 请求是否成功
* @return
*/
public
boolean
isSuccess
()
{
if
(
code
.
equals
(
Api
.
RequestSuccess
))
{
return
true
;
}
else
{
return
false
;
}
}
}
app/src/main/java/me/jessyan/mvparms/demo/mvp/presenter/UserPresenter.java
浏览文件 @
31ad69ba
...
...
@@ -3,11 +3,11 @@ package me.jessyan.mvparms.demo.mvp.presenter;
import
android.app.Application
;
import
com.jess.arms.base.AppManager
;
import
com.jess.arms.base.BaseActivity
;
import
com.jess.arms.base.DefaultAdapter
;
import
com.jess.arms.di.scope.ActivityScope
;
import
com.jess.arms.mvp.BasePresenter
;
import
com.jess.arms.utils.PermissionUtil
;
import
com.jess.arms.utils.RxUtils
;
import
com.tbruyelle.rxpermissions.RxPermissions
;
import
java.util.ArrayList
;
...
...
@@ -86,7 +86,7 @@ public class UserPresenter extends BasePresenter<UserContract.Model, UserContrac
mRootView
.
endLoadMore
();
}
})
.
compose
(
((
BaseActivity
)
mRootView
).<
List
<
User
>>
bindToLifecycle
(
))
//使用RXlifecycle,使subscription和activity一起销毁
.
compose
(
RxUtils
.<
List
<
User
>>
bindToLifecycle
(
mRootView
))
//使用RXlifecycle,使subscription和activity一起销毁
.
subscribe
(
new
ErrorHandleSubscriber
<
List
<
User
>>(
mErrorHandler
)
{
@Override
public
void
onNext
(
List
<
User
>
users
)
{
...
...
arms/src/main/java/com/jess/arms/base/BaseApplication.java
浏览文件 @
31ad69ba
...
...
@@ -52,7 +52,6 @@ public abstract class BaseApplication extends Application {
.
build
();
this
.
mAppModule
=
new
AppModule
(
this
,
mAppManager
);
//提供application
this
.
mImagerModule
=
new
ImageModule
();
//图片加载框架默认使用glide
}
/**
...
...
arms/src/main/java/com/jess/arms/utils/RxUtils.java
0 → 100644
浏览文件 @
31ad69ba
package
com.jess.arms.utils
;
import
com.jess.arms.base.BaseActivity
;
import
com.jess.arms.base.BaseFragment
;
import
com.jess.arms.mvp.BaseView
;
import
com.trello.rxlifecycle.LifecycleTransformer
;
import
rx.Observable
;
import
rx.android.schedulers.AndroidSchedulers
;
import
rx.functions.Action0
;
import
rx.schedulers.Schedulers
;
/**
* Created by jess on 11/10/2016 16:39
* Contact with jess.yan.effort@gmail.com
*/
public
class
RxUtils
{
public
static
<
T
>
Observable
.
Transformer
<
T
,
T
>
applySchedulers
(
final
BaseView
view
)
{
return
new
Observable
.
Transformer
<
T
,
T
>()
{
@Override
public
Observable
<
T
>
call
(
Observable
<
T
>
observable
)
{
return
observable
.
subscribeOn
(
Schedulers
.
io
())
.
doOnSubscribe
(
new
Action0
()
{
@Override
public
void
call
()
{
//显示进度条
view
.
showLoading
();
}
})
.
subscribeOn
(
AndroidSchedulers
.
mainThread
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
doAfterTerminate
(
new
Action0
()
{
@Override
public
void
call
()
{
view
.
hideLoading
();
//隐藏进度条
}
}).
compose
(
RxUtils
.<
T
>
bindToLifecycle
(
view
));
}
};
}
public
static
<
T
>
LifecycleTransformer
<
T
>
bindToLifecycle
(
BaseView
view
)
{
if
(
view
instanceof
BaseActivity
)
{
return
((
BaseActivity
)
view
).<
T
>
bindToLifecycle
();
}
else
if
(
view
instanceof
BaseFragment
)
{
return
((
BaseFragment
)
view
).<
T
>
bindToLifecycle
();
}
else
{
throw
new
IllegalArgumentException
(
"view isn't activity or fragment"
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录