提交 9c49544e 编写于 作者: J JessYan

Used IntelligentCache on FragmentLifecycle

上级 eea09c98
......@@ -35,8 +35,7 @@ public interface ActivityDelegate {
String LAYOUT_LINEARLAYOUT = "LinearLayout";
String LAYOUT_FRAMELAYOUT = "FrameLayout";
String LAYOUT_RELATIVELAYOUT = "RelativeLayout";
String ACTIVITY_DELEGATE = "activity_delegate";
String ACTIVITY_DELEGATE = "ACTIVITY_DELEGATE";
void onCreate(@Nullable Bundle savedInstanceState);
......
......@@ -34,7 +34,7 @@ import android.view.View;
* ================================================
*/
public interface FragmentDelegate {
String FRAGMENT_DELEGATE = "fragment_delegate";
String FRAGMENT_DELEGATE = "FRAGMENT_DELEGATE";
void onAttach(@NonNull Context context);
......
......@@ -217,9 +217,9 @@ public class GlobalConfigModule {
@Override
public Cache build(CacheType type) {
//若想自定义 LruCache 的 size, 或者不想使用 LruCache, 想使用自己自定义的策略
//并使用 GlobalConfigModule.Builder#cacheFactory() 扩展
//Activity, Fragment 以及 Extras 使用 IntelligentCache (具有 LruCache 和 可永久存储数据的 Map)
//使用 GlobalConfigModule.Builder#cacheFactory() 即可扩展
switch (type.getCacheTypeId()){
//Activity、Fragment 以及 Extras 使用 IntelligentCache (具有 LruCache 和 可永久存储数据的 Map)
case CacheType.EXTRAS_TYPE_ID:
case CacheType.ACTIVITY_CACHE_TYPE_ID:
case CacheType.FRAGMENT_CACHE_TYPE_ID:
......
......@@ -26,6 +26,7 @@ import com.jess.arms.base.delegate.FragmentDelegate;
import com.jess.arms.base.delegate.FragmentDelegateImpl;
import com.jess.arms.base.delegate.IFragment;
import com.jess.arms.integration.cache.Cache;
import com.jess.arms.integration.cache.IntelligentCache;
import com.jess.arms.utils.Preconditions;
import javax.inject.Inject;
......@@ -58,7 +59,9 @@ public class FragmentLifecycle extends FragmentManager.FragmentLifecycleCallback
if (fragmentDelegate == null || !fragmentDelegate.isAdded()) {
Cache<String, Object> cache = getCacheFromFragment((IFragment) f);
fragmentDelegate = new FragmentDelegateImpl(fm, f);
cache.put(FragmentDelegate.FRAGMENT_DELEGATE, fragmentDelegate);
//使用 IntelligentCache.KEY_KEEP 作为 key 的前缀, 可以使储存的数据永久存储在内存中
//否则存储在 LRU 算法的存储空间中, 前提是 Fragment 使用的是 IntelligentCache (框架默认使用)
cache.put(IntelligentCache.KEY_KEEP + FragmentDelegate.FRAGMENT_DELEGATE, fragmentDelegate);
}
fragmentDelegate.onAttach(context);
}
......@@ -166,7 +169,7 @@ public class FragmentLifecycle extends FragmentManager.FragmentLifecycleCallback
private FragmentDelegate fetchFragmentDelegate(Fragment fragment) {
if (fragment instanceof IFragment) {
Cache<String, Object> cache = getCacheFromFragment((IFragment) fragment);
return (FragmentDelegate) cache.get(FragmentDelegate.FRAGMENT_DELEGATE);
return (FragmentDelegate) cache.get(IntelligentCache.KEY_KEEP + FragmentDelegate.FRAGMENT_DELEGATE);
}
return null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册