Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
MVPArms
提交
02100092
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,发现更多精彩内容 >>
提交
02100092
编写于
11月 10, 2017
作者:
J
jessyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Activity provide Cache
上级
aca83931
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
93 addition
and
20 deletion
+93
-20
arms/src/main/java/com/jess/arms/base/BaseActivity.java
arms/src/main/java/com/jess/arms/base/BaseActivity.java
+8
-0
arms/src/main/java/com/jess/arms/base/delegate/IActivity.java
.../src/main/java/com/jess/arms/base/delegate/IActivity.java
+23
-14
arms/src/main/java/com/jess/arms/di/component/AppComponent.java
...rc/main/java/com/jess/arms/di/component/AppComponent.java
+3
-0
arms/src/main/java/com/jess/arms/integration/cache/CacheType.java
.../main/java/com/jess/arms/integration/cache/CacheType.java
+59
-6
未找到文件。
arms/src/main/java/com/jess/arms/base/BaseActivity.java
浏览文件 @
02100092
...
...
@@ -25,8 +25,11 @@ import android.util.AttributeSet;
import
android.view.View
;
import
com.jess.arms.base.delegate.IActivity
;
import
com.jess.arms.integration.cache.Cache
;
import
com.jess.arms.integration.cache.CacheType
;
import
com.jess.arms.integration.lifecycle.ActivityLifecycleable
;
import
com.jess.arms.mvp.IPresenter
;
import
com.jess.arms.utils.ArmsUtils
;
import
com.trello.rxlifecycle2.android.ActivityEvent
;
import
javax.inject.Inject
;
...
...
@@ -52,9 +55,14 @@ public abstract class BaseActivity<P extends IPresenter> extends AppCompatActivi
protected
final
String
TAG
=
this
.
getClass
().
getSimpleName
();
private
Unbinder
mUnbinder
;
private
final
BehaviorSubject
<
ActivityEvent
>
mLifecycleSubject
=
BehaviorSubject
.
create
();
private
final
Cache
<
String
,
Object
>
mCache
=
ArmsUtils
.
obtainAppComponentFromContext
(
this
).
cacheFactory
().
build
(
CacheType
.
ACTIVITY_CACHE
);
@Inject
protected
P
mPresenter
;
@Override
public
Cache
<
String
,
Object
>
provideCache
()
{
return
mCache
;
}
@NonNull
@Override
...
...
arms/src/main/java/com/jess/arms/base/delegate/IActivity.java
浏览文件 @
02100092
/**
* Copyright 2017 JessYan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2017 JessYan
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
*
http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.jess.arms.base.delegate
;
...
...
@@ -23,6 +23,8 @@ import android.support.v4.app.FragmentManager;
import
com.jess.arms.base.BaseActivity
;
import
com.jess.arms.base.BaseFragment
;
import
com.jess.arms.di.component.AppComponent
;
import
com.jess.arms.integration.cache.Cache
;
import
com.jess.arms.integration.cache.LruCache
;
import
org.simple.eventbus.EventBus
;
...
...
@@ -38,6 +40,13 @@ import org.simple.eventbus.EventBus;
*/
public
interface
IActivity
{
/**
* 提供在 {@link Activity} 生命周期内的缓存容器, 可向此 {@link Activity} 存取一些必要的数据
*
* @return like {@link LruCache}
*/
Cache
<
String
,
Object
>
provideCache
();
/**
* 提供 AppComponent(提供所有的单例对象)给实现类,进行 Component 依赖
*
...
...
arms/src/main/java/com/jess/arms/di/component/AppComponent.java
浏览文件 @
02100092
...
...
@@ -76,5 +76,8 @@ public interface AppComponent {
//用来存取一些整个App公用的数据,切勿大量存放大容量数据
Cache
<
String
,
Object
>
extras
();
//用于创建框架所需缓存对象的工厂
Cache
.
Factory
cacheFactory
();
void
inject
(
AppDelegate
delegate
);
}
arms/src/main/java/com/jess/arms/integration/cache/CacheType.java
浏览文件 @
02100092
...
...
@@ -15,8 +15,13 @@
*/
package
com.jess.arms.integration.cache
;
import
android.app.Activity
;
import
android.app.ActivityManager
;
import
android.content.Context
;
import
android.support.v4.app.Fragment
;
import
com.jess.arms.di.component.AppComponent
;
import
com.jess.arms.integration.RepositoryManager
;
/**
* ================================================
...
...
@@ -33,8 +38,10 @@ public interface CacheType {
int
RETROFIT_SERVICE_CACHE_TYPE_ID
=
0
;
int
CACHE_SERVICE_CACHE_TYPE_ID
=
1
;
int
EXTRAS_TYPE_ID
=
2
;
int
ACTIVITY_CACHE_TYPE_ID
=
3
;
int
FRAGMENT_CACHE_TYPE_ID
=
4
;
/**
*
RepositoryManager
中存储 Retrofit Service 的容器
*
{@link RepositoryManager}
中存储 Retrofit Service 的容器
*/
CacheType
RETROFIT_SERVICE_CACHE
=
new
CacheType
()
{
private
static
final
int
MAX_SIZE
=
150
;
...
...
@@ -49,7 +56,7 @@ public interface CacheType {
public
int
calculateCacheSize
(
Context
context
)
{
ActivityManager
activityManager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
int
targetMemoryCacheSize
=
(
int
)
(
activityManager
.
getMemoryClass
()
*
MAX_SIZE_MULTIPLIER
*
1024
);
if
(
targetMemoryCacheSize
>=
MAX_SIZE
){
if
(
targetMemoryCacheSize
>=
MAX_SIZE
)
{
return
MAX_SIZE
;
}
return
targetMemoryCacheSize
;
...
...
@@ -57,7 +64,7 @@ public interface CacheType {
};
/**
*
RepositoryManager
中储存 Cache Service 的容器
*
{@link RepositoryManager}
中储存 Cache Service 的容器
*/
CacheType
CACHE_SERVICE_CACHE
=
new
CacheType
()
{
private
static
final
int
MAX_SIZE
=
150
;
...
...
@@ -72,7 +79,7 @@ public interface CacheType {
public
int
calculateCacheSize
(
Context
context
)
{
ActivityManager
activityManager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
int
targetMemoryCacheSize
=
(
int
)
(
activityManager
.
getMemoryClass
()
*
MAX_SIZE_MULTIPLIER
*
1024
);
if
(
targetMemoryCacheSize
>=
MAX_SIZE
){
if
(
targetMemoryCacheSize
>=
MAX_SIZE
)
{
return
MAX_SIZE
;
}
return
targetMemoryCacheSize
;
...
...
@@ -80,7 +87,7 @@ public interface CacheType {
};
/**
*
AppComponent
中的 extras
*
{@link AppComponent}
中的 extras
*/
CacheType
EXTRAS
=
new
CacheType
()
{
private
static
final
int
MAX_SIZE
=
500
;
...
...
@@ -95,7 +102,53 @@ public interface CacheType {
public
int
calculateCacheSize
(
Context
context
)
{
ActivityManager
activityManager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
int
targetMemoryCacheSize
=
(
int
)
(
activityManager
.
getMemoryClass
()
*
MAX_SIZE_MULTIPLIER
*
1024
);
if
(
targetMemoryCacheSize
>=
MAX_SIZE
){
if
(
targetMemoryCacheSize
>=
MAX_SIZE
)
{
return
MAX_SIZE
;
}
return
targetMemoryCacheSize
;
}
};
/**
* {@link Activity} 中存储数据的容器
*/
CacheType
ACTIVITY_CACHE
=
new
CacheType
()
{
private
static
final
int
MAX_SIZE
=
80
;
private
static
final
float
MAX_SIZE_MULTIPLIER
=
0.0008f
;
@Override
public
int
getCacheTypeId
()
{
return
ACTIVITY_CACHE_TYPE_ID
;
}
@Override
public
int
calculateCacheSize
(
Context
context
)
{
ActivityManager
activityManager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
int
targetMemoryCacheSize
=
(
int
)
(
activityManager
.
getMemoryClass
()
*
MAX_SIZE_MULTIPLIER
*
1024
);
if
(
targetMemoryCacheSize
>=
MAX_SIZE
)
{
return
MAX_SIZE
;
}
return
targetMemoryCacheSize
;
}
};
/**
* {@link Fragment} 中存储数据的容器
*/
CacheType
FRAGMENT_CACHE
=
new
CacheType
()
{
private
static
final
int
MAX_SIZE
=
80
;
private
static
final
float
MAX_SIZE_MULTIPLIER
=
0.0008f
;
@Override
public
int
getCacheTypeId
()
{
return
FRAGMENT_CACHE_TYPE_ID
;
}
@Override
public
int
calculateCacheSize
(
Context
context
)
{
ActivityManager
activityManager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
int
targetMemoryCacheSize
=
(
int
)
(
activityManager
.
getMemoryClass
()
*
MAX_SIZE_MULTIPLIER
*
1024
);
if
(
targetMemoryCacheSize
>=
MAX_SIZE
)
{
return
MAX_SIZE
;
}
return
targetMemoryCacheSize
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录