Skip to content

Commit

Permalink
接口优化
Browse files Browse the repository at this point in the history
  • Loading branch information
weikaiyun committed Oct 22, 2020
1 parent cdb2a6a commit 3f59d77
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
15 changes: 3 additions & 12 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public abstract ExtraTransaction setCustomAnimations(@AnimatorRes @AnimRes int t

public abstract void replace(ISupportFragment toFragment);

public abstract void removeChild(ISupportFragment toFragment);

/**
* 使用setTag()自定义Tag时,使用下面popTo()/popToChild()出栈
*
Expand All @@ -59,6 +61,8 @@ public abstract ExtraTransaction setCustomAnimations(@AnimatorRes @AnimRes int t

public abstract void popTo(String targetFragmentTag, boolean includeTargetFragment, Runnable afterPopTransactionRunnable);

public abstract void loadChildRootFragment(int containerId, ISupportFragment toFragment);

public abstract void remove(ISupportFragment toFragment);

public abstract void popToChild(String targetFragmentTag, boolean includeTargetFragment);
Expand All @@ -72,12 +76,12 @@ public abstract ExtraTransaction setCustomAnimations(@AnimatorRes @AnimRes int t
final static class ExtraTransactionImpl<T extends ISupportFragment>
extends ExtraTransaction {

private FragmentActivity mActivity;
private T mSupportF;
private Fragment mFragment;
private TransactionDelegate mTransactionDelegate;
private boolean mFromActivity;
private TransactionRecord mRecord;
private final FragmentActivity mActivity;
private final T mSupportF;
private final Fragment mFragment;
private final TransactionDelegate mTransactionDelegate;
private final boolean mFromActivity;
private final TransactionRecord mRecord;

ExtraTransactionImpl(FragmentActivity activity, T supportF,
TransactionDelegate transactionDelegate, boolean fromActivity) {
Expand Down Expand Up @@ -123,11 +127,22 @@ public void loadRootFragment(int containerId, ISupportFragment toFragment) {
mTransactionDelegate.loadRootTransaction(getFragmentManager(), containerId, toFragment);
}

@Override
public void loadChildRootFragment(int containerId, ISupportFragment toFragment) {
toFragment.getSupportDelegate().mTransactionRecord = mRecord;
mTransactionDelegate.loadRootTransaction(getChildFragmentManager(), containerId, toFragment);
}

@Override
public void remove(ISupportFragment toFragment) {
mTransactionDelegate.remove(getFragmentManager(), toFragment);
}

@Override
public void removeChild(ISupportFragment toFragment) {
mTransactionDelegate.remove(getChildFragmentManager(), toFragment);
}

@Override
public void popTo(String targetFragmentTag, boolean includeTargetFragment) {
popTo(targetFragmentTag, includeTargetFragment, null);
Expand All @@ -136,7 +151,6 @@ public void popTo(String targetFragmentTag, boolean includeTargetFragment) {
@Override
public void popTo(String targetFragmentTag, boolean includeTargetFragment,
Runnable afterPopTransactionRunnable) {

mTransactionDelegate.popTo(targetFragmentTag, includeTargetFragment,
afterPopTransactionRunnable, getFragmentManager());
}
Expand All @@ -149,13 +163,8 @@ public void popToChild(String targetFragmentTag, boolean includeTargetFragment)
@Override
public void popToChild(String targetFragmentTag, boolean includeTargetFragment,
Runnable afterPopTransactionRunnable) {

if (mFromActivity) {
popTo(targetFragmentTag, includeTargetFragment, afterPopTransactionRunnable);
} else {
mTransactionDelegate.popTo(targetFragmentTag, includeTargetFragment,
afterPopTransactionRunnable, mFragment.getChildFragmentManager());
}
mTransactionDelegate.popTo(targetFragmentTag, includeTargetFragment,
afterPopTransactionRunnable, getChildFragmentManager());
}

@Override
Expand Down Expand Up @@ -210,6 +219,10 @@ private FragmentManager getFragmentManager() {
if (mFragment == null) {
return mActivity.getSupportFragmentManager();
}
return mFragment.getParentFragmentManager();
}

private FragmentManager getChildFragmentManager() {
return mFragment.getChildFragmentManager();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TransactionDelegate {
static final int TYPE_ADD_RESULT_WITHOUT_HIDE = 3;
static final int TYPE_REPLACE = 4;

private Handler mHandler;
private final Handler mHandler;

ActionQueue mActionQueue;

Expand Down

0 comments on commit 3f59d77

Please sign in to comment.