Skip to content

Commit 8a82c03

Browse files
committed
Optimize DebugStackBubble
1 parent 80c66cc commit 8a82c03

File tree

9 files changed

+21
-8
lines changed

9 files changed

+21
-8
lines changed

fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportActivityDelegate.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public SupportActivityDelegate(ISupportActivity support) {
3232
throw new RuntimeException("Must extends FragmentActivity/AppCompatActivity");
3333
this.mSupport = support;
3434
this.mActivity = (FragmentActivity) support;
35+
this.mDebugStackDelegate = new DebugStackDelegate(this.mActivity);
3536
}
3637

3738
/**
@@ -44,8 +45,6 @@ public ExtraTransaction extraTransaction() {
4445

4546
public void onCreate(@Nullable Bundle savedInstanceState) {
4647
mTransactionDelegate = getTransactionDelegate();
47-
mDebugStackDelegate = new DebugStackDelegate(mActivity);
48-
4948
mFragmentAnimator = mSupport.onCreateFragmentAnimator();
5049
mDebugStackDelegate.onCreate(Fragmentation.getDefault().getMode());
5150
}

fragmentation_core/src/main/java/me/yokeyword/fragmentation/debug/DebugHierarchyViewContainer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private LinearLayout getTitleLayout() {
8484
mTitleLayout.setLayoutParams(flParams);
8585

8686
TextView title = new TextView(mContext);
87-
title.setText("栈视图(Stack)");
87+
title.setText(R.string.fragmentation_stack_view);
8888
title.setTextSize(20);
8989
title.setTextColor(Color.BLACK);
9090
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
@@ -101,7 +101,7 @@ private LinearLayout getTitleLayout() {
101101
mTitleLayout.setOnClickListener(new OnClickListener() {
102102
@Override
103103
public void onClick(View v) {
104-
Toast.makeText(mContext, "* means not in backBack.", Toast.LENGTH_SHORT).show();
104+
Toast.makeText(mContext, R.string.fragmentation_stack_help, Toast.LENGTH_LONG).show();
105105
}
106106
});
107107
mTitleLayout.addView(img);

fragmentation_core/src/main/java/me/yokeyword/fragmentation/debug/DebugStackDelegate.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525

2626
import me.yokeyword.fragmentation.Fragmentation;
27+
import me.yokeyword.fragmentation.ISupportFragment;
2728
import me.yokeyword.fragmentation.R;
2829

2930
/**
@@ -196,7 +197,7 @@ private void addDebugFragmentRecord(List<DebugFragmentRecord> fragmentRecords, F
196197
int backStackCount = fragment.getFragmentManager().getBackStackEntryCount();
197198
CharSequence name = fragment.getClass().getSimpleName();
198199
if (backStackCount == 0) {
199-
name = span(name);
200+
name = span(name, " *");
200201
} else {
201202
for (int j = 0; j < backStackCount; j++) {
202203
FragmentManager.BackStackEntry entry = fragment.getFragmentManager().getBackStackEntryAt(j);
@@ -205,17 +206,22 @@ private void addDebugFragmentRecord(List<DebugFragmentRecord> fragmentRecords, F
205206
break;
206207
}
207208
if (j == backStackCount - 1) {
208-
name = span(name);
209+
name = span(name, " *");
209210
}
210211
}
211212
}
213+
214+
if (fragment instanceof ISupportFragment && ((ISupportFragment)fragment).isSupportVisible()) {
215+
name = span(name, " ☀");
216+
}
217+
212218
fragmentRecords.add(new DebugFragmentRecord(name, getChildFragmentRecords(fragment)));
213219
}
214220
}
215221

216222
@NonNull
217-
private CharSequence span(CharSequence name) {
218-
name = name + " *";
223+
private CharSequence span(CharSequence name, String str) {
224+
name = name + str;
219225
return name;
220226
}
221227

-343 Bytes
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
<string name="fragmentation_stack_view">栈视图</string>
3+
<string name="fragmentation_stack_help">*: 不在回退栈中\n☀: 可见的Fragment</string>
4+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
<string name="fragmentation_stack_view">Stack</string>
3+
<string name="fragmentation_stack_help">*: Not in backStack\n☀: Visible</string>
4+
</resources>

0 commit comments

Comments
 (0)