Skip to content

Commit

Permalink
包整理
Browse files Browse the repository at this point in the history
  • Loading branch information
weikaiyun committed Oct 26, 2020
1 parent 8140d06 commit 6ae9a59
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 45 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentationMagician;

import com.weikaiyun.fragmentation.debug.DebugStackDelegate;
import com.weikaiyun.fragmentation.queue.Action;
Expand Down Expand Up @@ -97,7 +96,7 @@ public void run() {
* 请尽量复写该方法,避免复写onBackPress(),以保证SupportFragment内的onBackPressedSupport()回退事件正常执行
*/
public void onBackPressedSupport() {
List<Fragment> list = FragmentationMagician.getActiveFragments(getSupportFragmentManager());
List<Fragment> list = SupportHelper.getActiveFragments(getSupportFragmentManager());
int fragmentNum = 0;
for (Fragment f : list) {
if (f instanceof ISupportFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentationMagician;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -49,7 +48,7 @@ public static ISupportFragment getTopFragment(FragmentManager fragmentManager) {
}

public static ISupportFragment getTopFragment(FragmentManager fragmentManager, int containerId) {
List<Fragment> fragmentList = FragmentationMagician.getActiveFragments(fragmentManager);
List<Fragment> fragmentList = getActiveFragments(fragmentManager);
for (int i = fragmentList.size() - 1; i >= 0; i--) {
Fragment fragment = fragmentList.get(i);
if (fragment instanceof ISupportFragment) {
Expand All @@ -72,7 +71,7 @@ public static ISupportFragment getTopFragment(FragmentManager fragmentManager, i
public static ISupportFragment getPreFragment(Fragment fragment) {
FragmentManager fragmentManager = fragment.getParentFragmentManager();

List<Fragment> fragmentList = FragmentationMagician.getActiveFragments(fragmentManager);
List<Fragment> fragmentList = getActiveFragments(fragmentManager);
int index = fragmentList.indexOf(fragment);
for (int i = index - 1; i >= 0; i--) {
Fragment preFragment = fragmentList.get(i);
Expand Down Expand Up @@ -114,7 +113,7 @@ static <T extends ISupportFragment> T findStackFragment(Class<T> fragmentClass,
Fragment fragment = null;

if (toFragmentTag == null) {
List<Fragment> fragmentList = FragmentationMagician.getActiveFragments(fragmentManager);
List<Fragment> fragmentList = getActiveFragments(fragmentManager);

int sizeChildFrgList = fragmentList.size();

Expand All @@ -133,7 +132,7 @@ static <T extends ISupportFragment> T findStackFragment(Class<T> fragmentClass,
}

private static ISupportFragment getActiveFragment(FragmentManager fragmentManager, ISupportFragment parentFragment) {
List<Fragment> fragmentList = FragmentationMagician.getActiveFragments(fragmentManager);
List<Fragment> fragmentList = getActiveFragments(fragmentManager);
for (int i = fragmentList.size() - 1; i >= 0; i--) {
Fragment fragment = fragmentList.get(i);
if (fragment instanceof ISupportFragment) {
Expand All @@ -149,7 +148,7 @@ static List<Fragment> getWillPopFragments(FragmentManager fm, String targetTag,
Fragment target = fm.findFragmentByTag(targetTag);
List<Fragment> willPopFragments = new ArrayList<>();

List<Fragment> fragmentList = FragmentationMagician.getActiveFragments(fm);
List<Fragment> fragmentList = getActiveFragments(fm);

int size = fragmentList.size();

Expand All @@ -175,4 +174,8 @@ static List<Fragment> getWillPopFragments(FragmentManager fm, String targetTag,
}
return willPopFragments;
}

public static List<Fragment> getActiveFragments(FragmentManager fragmentManager) {
return fragmentManager.getFragments();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.FragmentationMagician;
import androidx.lifecycle.Lifecycle;

import com.weikaiyun.fragmentation.queue.Action;
Expand Down Expand Up @@ -153,7 +152,7 @@ void dispatchStartWithPopTransaction(final FragmentManager fm, final ISupportFra
enqueue(fm, new Action(Action.ACTION_POP) {
@Override
public void run() {
if (FragmentationMagician.isStateSaved(fm)) return;
if (fm.isStateSaved()) return;
ISupportFragment top = getTopFragmentForStart(from, fm);
if (top == null)
throw new NullPointerException("There is no Fragment in the FragmentManager, " +
Expand Down Expand Up @@ -185,7 +184,7 @@ void dispatchStartWithPopToTransaction(final FragmentManager fm, final ISupportF
enqueue(fm, new Action(Action.ACTION_POP) {
@Override
public void run() {
if (FragmentationMagician.isStateSaved(fm)) return;
if (fm.isStateSaved()) return;

final ISupportFragment top = getTopFragmentForStart(from, fm);
if (top == null)
Expand Down Expand Up @@ -215,7 +214,7 @@ public void run() {
* Pop
*/
void pop(final FragmentManager fm) {
if (FragmentationMagician.isStateSaved(fm)) return;
if (fm.isStateSaved()) return;
final ISupportFragment top = SupportHelper.getTopFragment(fm);
enqueue(fm, new Action(Action.ACTION_POP) {
@Override
Expand Down Expand Up @@ -253,7 +252,7 @@ void popTo(final String targetFragmentTag, final boolean includeTargetFragment,
enqueue(fm, new Action(Action.ACTION_POP) {
@Override
public void run() {
if (FragmentationMagician.isStateSaved(fm)) return;
if (fm.isStateSaved()) return;

doPopTo(targetFragmentTag, includeTargetFragment, fm);

Expand Down Expand Up @@ -412,7 +411,7 @@ private void doShowHideFragment(FragmentManager fm, ISupportFragment showFragmen
ft.setMaxLifecycle((Fragment) showFragment, Lifecycle.State.RESUMED);

if (hideFragment == null) {
List<Fragment> fragmentList = FragmentationMagician.getActiveFragments(fm);
List<Fragment> fragmentList = SupportHelper.getActiveFragments(fm);
for (Fragment fragment : fragmentList) {
if (fragment != null && fragment != showFragment) {
ft.hide(fragment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentationMagician;

import com.weikaiyun.fragmentation.Fragmentation;
import com.weikaiyun.fragmentation.ISupportFragment;
import com.weikaiyun.fragmentation.R;
import com.weikaiyun.fragmentation.SupportHelper;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -116,9 +116,9 @@ public void showFragmentStackHierarchyView() {
private List<DebugFragmentRecord> getFragmentRecords() {
List<DebugFragmentRecord> fragmentRecordList = new ArrayList<>();

List<Fragment> fragmentList = FragmentationMagician.getActiveFragments(mActivity.getSupportFragmentManager());
List<Fragment> fragmentList = SupportHelper.getActiveFragments(mActivity.getSupportFragmentManager());

if (fragmentList == null || fragmentList.size() < 1) return null;
if (fragmentList.size() < 1) return null;

for (Fragment fragment : fragmentList) {
addDebugFragmentRecord(fragmentRecordList, fragment);
Expand All @@ -129,8 +129,8 @@ private List<DebugFragmentRecord> getFragmentRecords() {
private List<DebugFragmentRecord> getChildFragmentRecords(Fragment parentFragment) {
List<DebugFragmentRecord> fragmentRecords = new ArrayList<>();

List<Fragment> fragmentList = FragmentationMagician.getActiveFragments(parentFragment.getChildFragmentManager());
if (fragmentList == null || fragmentList.size() < 1) return null;
List<Fragment> fragmentList = SupportHelper.getActiveFragments(parentFragment.getChildFragmentManager());
if (fragmentList.size() < 1) return null;

for (int i = fragmentList.size() - 1; i >= 0; i--) {
Fragment fragment = fragmentList.get(i);
Expand Down

0 comments on commit 6ae9a59

Please sign in to comment.