diff --git a/README.md b/README.md index d0c9698a..d92173cc 100755 --- a/README.md +++ b/README.md @@ -46,15 +46,15 @@ The first demo shows the basic usage of the library. The second one shows the wa **1、build.gradle** ````gradle // appcompat-v7 is required -compile 'me.yokeyword:fragmentation:1.3.3' +compile 'me.yokeyword:fragmentation:1.3.4' // If you don't want to extends SupportActivity/Fragment and would like to customize your own support, just rely on fragmentation-core -// compile 'me.yokeyword:fragmentation-core:1.3.3' +// compile 'me.yokeyword:fragmentation-core:1.3.4' // To get SwipeBack feature, rely on both fragmentation & fragmentation-swipeback -compile 'me.yokeyword:fragmentation:1.3.3' +compile 'me.yokeyword:fragmentation:1.3.4' // Swipeback is based on fragmentation. Refer to SwipeBackActivity/Fragment for your Customized SupportActivity/Fragment -compile 'me.yokeyword:fragmentation-swipeback:1.3.3' +compile 'me.yokeyword:fragmentation-swipeback:1.3.4' // To simplify the communication between Fragments. compile 'me.yokeyword:eventbus-activity-scope:1.1.0' diff --git a/README_CN.md b/README_CN.md index e982ee28..deed1d3f 100644 --- a/README_CN.md +++ b/README_CN.md @@ -52,15 +52,15 @@ A powerful library that manage Fragment for Android! **1. 项目下app的build.gradle中依赖:** ````gradle // appcompat-v7包是必须的 -compile 'me.yokeyword:fragmentation:1.3.3' +compile 'me.yokeyword:fragmentation:1.3.4' // 如果不想继承SupportActivity/Fragment,自己定制Support,可仅依赖: -// compile 'me.yokeyword:fragmentation-core:1.3.3' +// compile 'me.yokeyword:fragmentation-core:1.3.4' // 如果想使用SwipeBack 滑动边缘退出Fragment/Activity功能,完整的添加规则如下: -compile 'me.yokeyword:fragmentation:1.3.3' +compile 'me.yokeyword:fragmentation:1.3.4' // swipeback基于fragmentation, 如果是自定制SupportActivity/Fragment,则参照SwipeBackActivity/Fragment实现即可 -compile 'me.yokeyword:fragmentation-swipeback:1.3.3' +compile 'me.yokeyword:fragmentation-swipeback:1.3.4' // Activity作用域的EventBus,更安全,可有效避免after onSavenInstanceState()异常 compile 'me.yokeyword:eventbus-activity-scope:1.1.0' diff --git a/build.gradle b/build.gradle index e790c464..277b7c9f 100644 --- a/build.gradle +++ b/build.gradle @@ -28,5 +28,5 @@ ext { minSdkVersion = 14 targetSdkVersion = compileSdkVersion - v4Version = "27.1.0" + v4Version = "27.1.1" } diff --git a/fragmentation_core/src/main/java/android/support/v4/app/FragmentationMagician.java b/fragmentation_core/src/main/java/android/support/v4/app/FragmentationMagician.java index 9226207c..052c5769 100644 --- a/fragmentation_core/src/main/java/android/support/v4/app/FragmentationMagician.java +++ b/fragmentation_core/src/main/java/android/support/v4/app/FragmentationMagician.java @@ -14,18 +14,26 @@ * Created by YoKey on 16/1/22. */ public class FragmentationMagician { - public static boolean sSupportLessThan25dot4 = false; + private static boolean sSupportLessThan25dot4 = false; + private static boolean sSupportGreaterThan27dot1dot0 = false; static { Field[] fields = FragmentManagerImpl.class.getDeclaredFields(); for (Field field : fields) { - if (field.getName().equals("mAvailIndices")) { + if (field.getName().equals("mStopped")) { // > v27.1.0 + sSupportGreaterThan27dot1dot0 = true; + break; + } else if (field.getName().equals("mAvailIndices")) { // < 25.4.0 sSupportLessThan25dot4 = true; break; } } } + public static boolean isSupportLessThan25dot4() { + return sSupportLessThan25dot4; + } + public static boolean isExecutingActions(FragmentManager fragmentManager) { if (!(fragmentManager instanceof FragmentManagerImpl)) return false; @@ -180,10 +188,28 @@ private static void hookStateSaved(FragmentManager fragmentManager, Runnable run FragmentManagerImpl fragmentManagerImpl = (FragmentManagerImpl) fragmentManager; if (isStateSaved(fragmentManager)) { fragmentManagerImpl.mStateSaved = false; - runnable.run(); + compatRunAction(fragmentManagerImpl, runnable); fragmentManagerImpl.mStateSaved = true; } else { runnable.run(); } } + + /** + * Compat v27.1.0+ + *
+ * So the code to compile Fragmentation needs v27.1.0+ + * + * @see FragmentManager#isStateSaved() + */ + private static void compatRunAction(FragmentManagerImpl fragmentManagerImpl, Runnable runnable) { + if (!sSupportGreaterThan27dot1dot0) { + runnable.run(); + return; + } + + fragmentManagerImpl.mStopped = false; + runnable.run(); + fragmentManagerImpl.mStopped = true; + } } \ No newline at end of file diff --git a/fragmentation_core/src/main/java/me/yokeyword/fragmentation/TransactionDelegate.java b/fragmentation_core/src/main/java/me/yokeyword/fragmentation/TransactionDelegate.java index 843a82e1..049e81d0 100755 --- a/fragmentation_core/src/main/java/me/yokeyword/fragmentation/TransactionDelegate.java +++ b/fragmentation_core/src/main/java/me/yokeyword/fragmentation/TransactionDelegate.java @@ -320,13 +320,8 @@ void handleResultRecord(Fragment from) { final ResultRecord resultRecord = args.getParcelable(FRAGMENTATION_ARG_RESULT_RECORD); if (resultRecord == null) return; - final ISupportFragment targetFragment = (ISupportFragment) from.getFragmentManager().getFragment(from.getArguments(), FRAGMENTATION_STATE_SAVE_RESULT); - mHandler.post(new Runnable() { - @Override - public void run() { - targetFragment.onFragmentResult(resultRecord.requestCode, resultRecord.resultCode, resultRecord.resultBundle); - } - }); + ISupportFragment targetFragment = (ISupportFragment) from.getFragmentManager().getFragment(from.getArguments(), FRAGMENTATION_STATE_SAVE_RESULT); + targetFragment.onFragmentResult(resultRecord.requestCode, resultRecord.resultCode, resultRecord.resultBundle); } catch (IllegalStateException ignored) { // Fragment no longer exists } @@ -580,7 +575,7 @@ private void safePopTo(String fragmentTag, final FragmentManager fm, int flag, L FragmentationMagician.executePendingTransactionsAllowingStateLoss(fm); mSupport.getSupportDelegate().mPopMultipleNoAnim = false; - if (FragmentationMagician.sSupportLessThan25dot4) { + if (FragmentationMagician.isSupportLessThan25dot4()) { mHandler.post(new Runnable() { @Override public void run() { diff --git a/fragmentation_core/src/main/java/me/yokeyword/fragmentation/anim/FragmentAnimator.java b/fragmentation_core/src/main/java/me/yokeyword/fragmentation/anim/FragmentAnimator.java index 7545619c..5644b4f2 100644 --- a/fragmentation_core/src/main/java/me/yokeyword/fragmentation/anim/FragmentAnimator.java +++ b/fragmentation_core/src/main/java/me/yokeyword/fragmentation/anim/FragmentAnimator.java @@ -60,32 +60,39 @@ public int getEnter() { return enter; } - public void setEnter(int enter) { + public FragmentAnimator setEnter(int enter) { this.enter = enter; + return this; } public int getExit() { return exit; } - public void setExit(int exit) { + /** + * enter animation + */ + public FragmentAnimator setExit(int exit) { this.exit = exit; + return this; } public int getPopEnter() { return popEnter; } - public void setPopEnter(int popEnter) { + public FragmentAnimator setPopEnter(int popEnter) { this.popEnter = popEnter; + return this; } public int getPopExit() { return popExit; } - public void setPopExit(int popExit) { + public FragmentAnimator setPopExit(int popExit) { this.popExit = popExit; + return this; } @Override diff --git a/fragmentation_swipeback/README.md b/fragmentation_swipeback/README.md index 3f188a7b..6fb22189 100644 --- a/fragmentation_swipeback/README.md +++ b/fragmentation_swipeback/README.md @@ -10,8 +10,8 @@ Activity内Fragment数大于1时,滑动返回的是Fragment,否则滑动返 1、项目下app的build.gradle中依赖: ````gradle // appcompat v7包是必须的 -compile 'me.yokeyword:fragmentation:1.3.3' -compile 'me.yokeyword:fragmentation-swipeback:1.3.3' +compile 'me.yokeyword:fragmentation:1.3.4' +compile 'me.yokeyword:fragmentation-swipeback:1.3.4' ```` 2、如果Activity也需要支持SwipeBack,则继承SwipeBackActivity: