Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
MVPArms
提交
741fab02
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,发现更多精彩内容 >>
提交
741fab02
编写于
2月 21, 2017
作者:
J
jessyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve AppManager
上级
97bf1a2f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
22 addition
and
62 deletion
+22
-62
app/src/main/java/me/jessyan/mvparms/demo/mvp/ui/activity/UserActivity.java
...me/jessyan/mvparms/demo/mvp/ui/activity/UserActivity.java
+3
-20
arms/src/main/java/com/jess/arms/base/ActivityLifecycle.java
arms/src/main/java/com/jess/arms/base/ActivityLifecycle.java
+3
-3
arms/src/main/java/com/jess/arms/base/AppManager.java
arms/src/main/java/com/jess/arms/base/AppManager.java
+14
-13
arms/src/main/java/com/jess/arms/base/BaseActivity.java
arms/src/main/java/com/jess/arms/base/BaseActivity.java
+0
-24
config.gradle
config.gradle
+2
-2
未找到文件。
app/src/main/java/me/jessyan/mvparms/demo/mvp/ui/activity/UserActivity.java
浏览文件 @
741fab02
...
...
@@ -3,7 +3,6 @@ package me.jessyan.mvparms.demo.mvp.ui.activity;
import
android.content.Intent
;
import
android.support.annotation.Nullable
;
import
android.support.v4.widget.SwipeRefreshLayout
;
import
android.support.v7.widget.DefaultItemAnimator
;
import
android.support.v7.widget.GridLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.LayoutInflater
;
...
...
@@ -15,13 +14,13 @@ import com.paginate.Paginate;
import
com.tbruyelle.rxpermissions.RxPermissions
;
import
butterknife.BindView
;
import
me.jessyan.mvparms.demo.R
;
import
common.AppComponent
;
import
common.WEActivity
;
import
me.jessyan.mvparms.demo.R
;
import
me.jessyan.mvparms.demo.di.component.DaggerUserComponent
;
import
me.jessyan.mvparms.demo.di.module.UserModule
;
import
me.jessyan.mvparms.demo.mvp.contract.UserContract
;
import
me.jessyan.mvparms.demo.mvp.presenter.UserPresenter
;
import
common.WEActivity
;
import
rx.Observable
;
import
rx.android.schedulers.AndroidSchedulers
;
import
rx.functions.Action1
;
...
...
@@ -74,23 +73,7 @@ public class UserActivity extends WEActivity<UserPresenter> implements UserContr
*/
private
void
initRecycleView
()
{
mSwipeRefreshLayout
.
setOnRefreshListener
(
this
);
configRecycleView
(
mRecyclerView
,
new
GridLayoutManager
(
this
,
2
));
}
/**
* 配置recycleview
*
* @param recyclerView
* @param layoutManager
*/
private
void
configRecycleView
(
RecyclerView
recyclerView
,
RecyclerView
.
LayoutManager
layoutManager
)
{
recyclerView
.
setLayoutManager
(
layoutManager
);
//如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
recyclerView
.
setHasFixedSize
(
true
);
recyclerView
.
setItemAnimator
(
new
DefaultItemAnimator
());
UiUtils
.
configRecycleView
(
mRecyclerView
,
new
GridLayoutManager
(
this
,
2
));
}
...
...
arms/src/main/java/com/jess/arms/base/ActivityLifecycle.java
浏览文件 @
741fab02
...
...
@@ -32,7 +32,7 @@ public class ActivityLifecycle implements Application.ActivityLifecycleCallbacks
isNotAdd
=
activity
.
getIntent
().
getBooleanExtra
(
IS_NOT_ADD_ACTIVITY_LIST
,
false
);
if
(!
isNotAdd
)
mAppManager
.
addActivity
(
(
BaseActivity
)
activity
);
mAppManager
.
addActivity
(
activity
);
}
@Override
...
...
@@ -42,7 +42,7 @@ public class ActivityLifecycle implements Application.ActivityLifecycleCallbacks
@Override
public
void
onActivityResumed
(
Activity
activity
)
{
mAppManager
.
setCurrentActivity
(
(
BaseActivity
)
activity
);
mAppManager
.
setCurrentActivity
(
activity
);
}
@Override
...
...
@@ -64,6 +64,6 @@ public class ActivityLifecycle implements Application.ActivityLifecycleCallbacks
@Override
public
void
onActivityDestroyed
(
Activity
activity
)
{
mAppManager
.
removeActivity
(
(
BaseActivity
)
activity
);
mAppManager
.
removeActivity
(
activity
);
}
}
arms/src/main/java/com/jess/arms/base/AppManager.java
浏览文件 @
741fab02
package
com.jess.arms.base
;
import
android.app.Activity
;
import
android.app.ActivityManager
;
import
android.app.Application
;
import
android.content.Context
;
...
...
@@ -39,9 +40,9 @@ public class AppManager {
private
Application
mApplication
;
//管理所有activity
public
List
<
Base
Activity
>
mActivityList
;
public
List
<
Activity
>
mActivityList
;
//当前在前台的activity
private
Base
Activity
mCurrentActivity
;
private
Activity
mCurrentActivity
;
@Inject
public
AppManager
(
Application
application
)
{
...
...
@@ -141,7 +142,7 @@ public class AppManager {
*
* @param currentActivity
*/
public
void
setCurrentActivity
(
Base
Activity
currentActivity
)
{
public
void
setCurrentActivity
(
Activity
currentActivity
)
{
this
.
mCurrentActivity
=
currentActivity
;
}
...
...
@@ -150,7 +151,7 @@ public class AppManager {
*
* @return
*/
public
Base
Activity
getCurrentActivity
()
{
public
Activity
getCurrentActivity
()
{
return
mCurrentActivity
;
}
...
...
@@ -159,7 +160,7 @@ public class AppManager {
*
* @return
*/
public
List
<
Base
Activity
>
getActivityList
()
{
public
List
<
Activity
>
getActivityList
()
{
if
(
mActivityList
==
null
)
{
mActivityList
=
new
LinkedList
<>();
}
...
...
@@ -170,7 +171,7 @@ public class AppManager {
/**
* 添加Activity到集合
*/
public
void
addActivity
(
Base
Activity
activity
)
{
public
void
addActivity
(
Activity
activity
)
{
if
(
mActivityList
==
null
)
{
mActivityList
=
new
LinkedList
<>();
}
...
...
@@ -186,9 +187,9 @@ public class AppManager {
*
* @param activity
*/
public
void
removeActivity
(
Base
Activity
activity
)
{
public
void
removeActivity
(
Activity
activity
)
{
if
(
mActivityList
==
null
)
{
Timber
.
tag
(
TAG
).
w
(
"mActivityList == null when removeActivity(
Base
Activity)"
);
Timber
.
tag
(
TAG
).
w
(
"mActivityList == null when removeActivity(Activity)"
);
return
;
}
synchronized
(
AppManager
.
class
)
{
...
...
@@ -203,7 +204,7 @@ public class AppManager {
*
* @param location
*/
public
Base
Activity
removeActivity
(
int
location
)
{
public
Activity
removeActivity
(
int
location
)
{
if
(
mActivityList
==
null
)
{
Timber
.
tag
(
TAG
).
w
(
"mActivityList == null when removeActivity(int)"
);
return
null
;
...
...
@@ -226,7 +227,7 @@ public class AppManager {
Timber
.
tag
(
TAG
).
w
(
"mActivityList == null when killActivity"
);
return
;
}
for
(
Base
Activity
activity
:
mActivityList
)
{
for
(
Activity
activity
:
mActivityList
)
{
if
(
activity
.
getClass
().
equals
(
activityClass
))
{
activity
.
finish
();
}
...
...
@@ -240,7 +241,7 @@ public class AppManager {
* @param activity
* @return
*/
public
boolean
activityInstanceIsLive
(
Base
Activity
activity
)
{
public
boolean
activityInstanceIsLive
(
Activity
activity
)
{
if
(
mActivityList
==
null
)
{
Timber
.
tag
(
TAG
).
w
(
"mActivityList == null when activityInstanceIsLive"
);
return
false
;
...
...
@@ -260,7 +261,7 @@ public class AppManager {
Timber
.
tag
(
TAG
).
w
(
"mActivityList == null when activityClassIsLive"
);
return
false
;
}
for
(
Base
Activity
activity
:
mActivityList
)
{
for
(
Activity
activity
:
mActivityList
)
{
if
(
activity
.
getClass
().
equals
(
activityClass
))
{
return
true
;
}
...
...
@@ -278,7 +279,7 @@ public class AppManager {
// getActivityList().remove(0).finish();
// }
Iterator
<
Base
Activity
>
iterator
=
getActivityList
().
iterator
();
Iterator
<
Activity
>
iterator
=
getActivityList
().
iterator
();
while
(
iterator
.
hasNext
())
{
iterator
.
next
().
finish
();
iterator
.
remove
();
...
...
arms/src/main/java/com/jess/arms/base/BaseActivity.java
浏览文件 @
741fab02
...
...
@@ -54,34 +54,11 @@ public abstract class BaseActivity<P extends Presenter> extends RxAppCompatActiv
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
mApplication
.
getAppManager
().
setCurrentActivity
(
this
);
}
@Override
protected
void
onPause
()
{
super
.
onPause
();
if
(
mApplication
.
getAppManager
().
getCurrentActivity
()
==
this
)
{
mApplication
.
getAppManager
().
setCurrentActivity
(
null
);
}
}
@Nullable
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
mApplication
=
(
BaseApplication
)
getApplication
();
//如果intent包含了此字段,并且为true说明不加入到list
// 默认为false,如果不需要管理(比如不需要在退出所有activity(killAll)时,退出此activity就在intent加此字段为true)
boolean
isNotAdd
=
false
;
if
(
getIntent
()
!=
null
)
isNotAdd
=
getIntent
().
getBooleanExtra
(
IS_NOT_ADD_ACTIVITY_LIST
,
false
);
if
(!
isNotAdd
)
mApplication
.
getAppManager
().
addActivity
(
this
);
if
(
useEventBus
())
//如果要使用eventbus请将此方法返回true
EventBus
.
getDefault
().
register
(
this
);
//注册到事件主线
setContentView
(
initView
());
...
...
@@ -113,7 +90,6 @@ public abstract class BaseActivity<P extends Presenter> extends RxAppCompatActiv
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
mApplication
.
getAppManager
().
removeActivity
(
this
);
if
(
mPresenter
!=
null
)
mPresenter
.
onDestroy
();
//释放资源
if
(
mUnbinder
!=
Unbinder
.
EMPTY
)
mUnbinder
.
unbind
();
if
(
useEventBus
())
//如果要使用eventbus请将此方法返回true
...
...
config.gradle
浏览文件 @
741fab02
...
...
@@ -4,8 +4,8 @@ ext {
buildToolsVersion
:
"25.0.2"
,
minSdkVersion
:
15
,
targetSdkVersion
:
25
,
versionCode
:
2
3
,
versionName
:
"1.2.
3
"
,
versionCode
:
2
4
,
versionName
:
"1.2.
4
"
,
androidSupportSdkVersion:
"25.1.1"
,
retrofitSdkVersion
:
"2.1.0"
,
dagger2SdkVersion
:
"2.8"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录