Skip to content

Commit

Permalink
Merge pull request #872 from YoKeyword/dev
Browse files Browse the repository at this point in the history
v1.3.4
  • Loading branch information
YoKeyword authored May 17, 2018
2 parents c877b11 + 28aff48 commit cef5447
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 26 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ ext {
minSdkVersion = 14
targetSdkVersion = compileSdkVersion

v4Version = "27.1.0"
v4Version = "27.1.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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+
* <p>
* 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions fragmentation_swipeback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cef5447

Please sign in to comment.