Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
MVPArms
提交
e1b9bcc3
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,发现更多精彩内容 >>
提交
e1b9bcc3
编写于
11月 28, 2017
作者:
J
jessyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve ActivityLifecycle and FragmentLifecycle
上级
2ba77591
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
13 deletion
+25
-13
arms/src/main/java/com/jess/arms/integration/ActivityLifecycle.java
...ain/java/com/jess/arms/integration/ActivityLifecycle.java
+13
-7
arms/src/main/java/com/jess/arms/integration/FragmentLifecycle.java
...ain/java/com/jess/arms/integration/FragmentLifecycle.java
+12
-6
未找到文件。
arms/src/main/java/com/jess/arms/integration/ActivityLifecycle.java
浏览文件 @
e1b9bcc3
...
...
@@ -18,6 +18,7 @@ package com.jess.arms.integration;
import
android.app.Activity
;
import
android.app.Application
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.v4.app.FragmentActivity
;
import
android.support.v4.app.FragmentManager
;
...
...
@@ -77,10 +78,9 @@ public class ActivityLifecycle implements Application.ActivityLifecycleCallbacks
if
(
activity
instanceof
IActivity
)
{
ActivityDelegate
activityDelegate
=
fetchActivityDelegate
(
activity
);
if
(
activityDelegate
==
null
)
{
IActivity
iActivity
=
(
IActivity
)
activity
;
Preconditions
.
checkNotNull
(
iActivity
.
provideCache
(),
"%s cannot be null on Activity"
,
Cache
.
class
.
getName
());
Cache
<
String
,
Object
>
cache
=
getCacheFromActivity
((
IActivity
)
activity
);
activityDelegate
=
new
ActivityDelegateImpl
(
activity
);
iActivity
.
provideCache
()
.
put
(
ActivityDelegate
.
ACTIVITY_DELEGATE
,
activityDelegate
);
cache
.
put
(
ActivityDelegate
.
ACTIVITY_DELEGATE
,
activityDelegate
);
}
activityDelegate
.
onCreate
(
savedInstanceState
);
}
...
...
@@ -88,7 +88,6 @@ public class ActivityLifecycle implements Application.ActivityLifecycleCallbacks
registerFragmentCallbacks
(
activity
);
}
@Override
public
void
onActivityStarted
(
Activity
activity
)
{
ActivityDelegate
activityDelegate
=
fetchActivityDelegate
(
activity
);
...
...
@@ -142,6 +141,7 @@ public class ActivityLifecycle implements Application.ActivityLifecycleCallbacks
ActivityDelegate
activityDelegate
=
fetchActivityDelegate
(
activity
);
if
(
activityDelegate
!=
null
)
{
activityDelegate
.
onDestroy
();
getCacheFromActivity
((
IActivity
)
activity
).
clear
();
}
}
...
...
@@ -180,11 +180,17 @@ public class ActivityLifecycle implements Application.ActivityLifecycleCallbacks
private
ActivityDelegate
fetchActivityDelegate
(
Activity
activity
)
{
ActivityDelegate
activityDelegate
=
null
;
if
(
activity
instanceof
IActivity
)
{
IActivity
iActivity
=
(
IActivity
)
activity
;
Preconditions
.
checkNotNull
(
iActivity
.
provideCache
(),
"%s cannot be null on Activity"
,
Cache
.
class
.
getName
());
activityDelegate
=
(
ActivityDelegate
)
iActivity
.
provideCache
().
get
(
ActivityDelegate
.
ACTIVITY_DELEGATE
);
Cache
<
String
,
Object
>
cache
=
getCacheFromActivity
((
IActivity
)
activity
);
activityDelegate
=
(
ActivityDelegate
)
cache
.
get
(
ActivityDelegate
.
ACTIVITY_DELEGATE
);
}
return
activityDelegate
;
}
@NonNull
private
Cache
<
String
,
Object
>
getCacheFromActivity
(
IActivity
activity
)
{
Cache
<
String
,
Object
>
cache
=
activity
.
provideCache
();
Preconditions
.
checkNotNull
(
cache
,
"%s cannot be null on Activity"
,
Cache
.
class
.
getName
());
return
cache
;
}
}
arms/src/main/java/com/jess/arms/integration/FragmentLifecycle.java
浏览文件 @
e1b9bcc3
...
...
@@ -17,6 +17,7 @@ package com.jess.arms.integration;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentManager
;
import
android.view.View
;
...
...
@@ -47,10 +48,9 @@ public class FragmentLifecycle extends FragmentManager.FragmentLifecycleCallback
if
(
f
instanceof
IFragment
)
{
FragmentDelegate
fragmentDelegate
=
fetchFragmentDelegate
(
f
);
if
(
fragmentDelegate
==
null
||
!
fragmentDelegate
.
isAdded
())
{
IFragment
iFragment
=
(
IFragment
)
f
;
Preconditions
.
checkNotNull
(
iFragment
.
provideCache
(),
"%s cannot be null on Fragment"
,
Cache
.
class
.
getName
());
Cache
<
String
,
Object
>
cache
=
getCacheFromFragment
((
IFragment
)
f
);
fragmentDelegate
=
new
FragmentDelegateImpl
(
fm
,
f
);
iFragment
.
provideCache
()
.
put
(
FragmentDelegate
.
FRAGMENT_DELEGATE
,
fragmentDelegate
);
cache
.
put
(
FragmentDelegate
.
FRAGMENT_DELEGATE
,
fragmentDelegate
);
}
fragmentDelegate
.
onAttach
(
context
);
}
...
...
@@ -157,11 +157,17 @@ public class FragmentLifecycle extends FragmentManager.FragmentLifecycleCallback
private
FragmentDelegate
fetchFragmentDelegate
(
Fragment
fragment
)
{
if
(
fragment
instanceof
IFragment
)
{
IFragment
iFragment
=
(
IFragment
)
fragment
;
Preconditions
.
checkNotNull
(
iFragment
.
provideCache
(),
"%s cannot be null on Fragment"
,
Cache
.
class
.
getName
());
return
(
FragmentDelegate
)
iFragment
.
provideCache
().
get
(
FragmentDelegate
.
FRAGMENT_DELEGATE
);
Cache
<
String
,
Object
>
cache
=
getCacheFromFragment
((
IFragment
)
fragment
);
return
(
FragmentDelegate
)
cache
.
get
(
FragmentDelegate
.
FRAGMENT_DELEGATE
);
}
return
null
;
}
@NonNull
private
Cache
<
String
,
Object
>
getCacheFromFragment
(
IFragment
fragment
)
{
Cache
<
String
,
Object
>
cache
=
fragment
.
provideCache
();
Preconditions
.
checkNotNull
(
cache
,
"%s cannot be null on Fragment"
,
Cache
.
class
.
getName
());
return
cache
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录