Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20190425 update upStream #1

Merged
merged 14 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.6'

// 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.6'

// To get SwipeBack feature, rely on both fragmentation & fragmentation-swipeback
compile 'me.yokeyword:fragmentation:1.3.3'
compile 'me.yokeyword:fragmentation:1.3.6'
// 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.6'

// 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.6'

// 如果不想继承SupportActivity/Fragment,自己定制Support,可仅依赖:
// compile 'me.yokeyword:fragmentation-core:1.3.3'
// compile 'me.yokeyword:fragmentation-core:1.3.6'

// 如果想使用SwipeBack 滑动边缘退出Fragment/Activity功能,完整的添加规则如下:
compile 'me.yokeyword:fragmentation:1.3.3'
compile 'me.yokeyword:fragmentation:1.3.6'
// swipeback基于fragmentation, 如果是自定制SupportActivity/Fragment,则参照SwipeBackActivity/Fragment实现即可
compile 'me.yokeyword:fragmentation-swipeback:1.3.3'
compile 'me.yokeyword:fragmentation-swipeback:1.3.6'

// 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 @@ -68,6 +68,8 @@ public abstract ExtraTransaction setCustomAnimations(@AnimatorRes @AnimRes int t

public abstract void startDontHideSelf(ISupportFragment toFragment);

public abstract void startDontHideSelf(ISupportFragment toFragment, @ISupportFragment.LaunchMode int launchMode);

public abstract void start(ISupportFragment toFragment, @ISupportFragment.LaunchMode int launchMode);

public abstract void startForResult(ISupportFragment toFragment, int requestCode);
Expand Down Expand Up @@ -241,6 +243,12 @@ public void startDontHideSelf(ISupportFragment toFragment) {
mTransactionDelegate.dispatchStartTransaction(getFragmentManager(), mSupportF, toFragment, 0, ISupportFragment.STANDARD, TransactionDelegate.TYPE_ADD_WITHOUT_HIDE);
}

@Override
public void startDontHideSelf(ISupportFragment toFragment, @ISupportFragment.LaunchMode int launchMode) {
toFragment.getSupportDelegate().mTransactionRecord = mRecord;
mTransactionDelegate.dispatchStartTransaction(getFragmentManager(), mSupportF, toFragment, 0, launchMode, TransactionDelegate.TYPE_ADD_WITHOUT_HIDE);
}

@Override
public void start(ISupportFragment toFragment, @ISupportFragment.LaunchMode int launchMode) {
toFragment.getSupportDelegate().mTransactionRecord = mRecord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|| (mFragment.getTag() != null && mFragment.getTag().startsWith("android:switcher:"))
|| (mReplaceMode && !mFirstCreateView)) {
notifyEnterAnimEnd();
} else if (mCustomEnterAnim != Integer.MIN_VALUE) {
fixAnimationListener(mCustomEnterAnim == 0 ?
mAnimHelper.getNoneAnim() : AnimationUtils.loadAnimation(_mActivity, mCustomEnterAnim));
}

if (mFirstCreateView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,23 @@ void pop(final FragmentManager fm) {
@Override
public void run() {
handleAfterSaveInStateTransactionException(fm, "pop()");
removeTopFragment(fm);
FragmentationMagician.popBackStackAllowingStateLoss(fm);
removeTopFragment(fm);
}
});
}

private void removeTopFragment(FragmentManager fm) {
ISupportFragment top = SupportHelper.getBackStackTopFragment(fm);
if (top != null) {
fm.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
.remove((Fragment) top)
.commitAllowingStateLoss();
try { // Safe popBackStack()
ISupportFragment top = SupportHelper.getBackStackTopFragment(fm);
if (top != null) {
fm.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
.remove((Fragment) top)
.commitAllowingStateLoss();
}
} catch (Exception ignored) {

}
}

Expand Down Expand Up @@ -320,13 +324,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 +579,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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

public abstract class Action {
public static final int BUFFER_TIME = 60;
public static final long DEFAULT_POP_TIME = 300L;

public static final int ACTION_NORMAL = 0;
public static final int ACTION_POP = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ private void handleAction() {
private void executeNextAction(Action action) {
if (action.action == Action.ACTION_POP) {
ISupportFragment top = SupportHelper.getBackStackTopFragment(action.fragmentManager);
if (top == null) return;
action.duration = top.getSupportDelegate().getExitAnimDuration();
action.duration = top == null ? Action.DEFAULT_POP_TIME : top.getSupportDelegate().getExitAnimDuration();
}

mMainHandler.postDelayed(new Runnable() {
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.6'
compile 'me.yokeyword:fragmentation-swipeback:1.3.6'
````

2、如果Activity也需要支持SwipeBack,则继承SwipeBackActivity:
Expand Down