Skip to content

Commit ae715a8

Browse files
committed
Optimize #733
1 parent 46e3027 commit ae715a8

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void run() {
7979
}
8080

8181
void loadRootTransaction(final FragmentManager fm, final int containerId, final ISupportFragment to, final boolean addToBackStack, final boolean allowAnimation) {
82-
enqueue(fm, new Action() {
82+
enqueue(fm, new Action(Action.ACTION_LOAD) {
8383
@Override
8484
public void run() {
8585
bindContainerId(containerId, to);
@@ -98,7 +98,7 @@ public void run() {
9898
}
9999

100100
void loadMultipleRootTransaction(final FragmentManager fm, final int containerId, final int showPosition, final ISupportFragment... tos) {
101-
enqueue(fm, new Action() {
101+
enqueue(fm, new Action(Action.ACTION_LOAD) {
102102
@Override
103103
public void run() {
104104
FragmentTransaction ft = fm.beginTransaction();

fragmentation_core/src/main/java/me/yokeyword/fragmentation/queue/Action.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public abstract class Action {
1313
public static final int ACTION_POP = 1;
1414
public static final int ACTION_POP_MOCK = 2;
1515
public static final int ACTION_BACK = 3;
16+
public static final int ACTION_LOAD = 4;
1617

1718
public FragmentManager fragmentManager;
1819
public int action = ACTION_NORMAL;

fragmentation_core/src/main/java/me/yokeyword/fragmentation/queue/ActionQueue.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.yokeyword.fragmentation.queue;
22

33
import android.os.Handler;
4+
import android.os.Looper;
45

56
import java.util.LinkedList;
67
import java.util.Queue;
@@ -24,6 +25,12 @@ public ActionQueue(Handler mainHandler) {
2425
public void enqueue(final Action action) {
2526
if (isThrottleBACK(action)) return;
2627

28+
if (action.action == Action.ACTION_LOAD && mQueue.isEmpty()
29+
&& Thread.currentThread() == Looper.getMainLooper().getThread()) {
30+
action.run();
31+
return;
32+
}
33+
2734
mMainHandler.post(new Runnable() {
2835
@Override
2936
public void run() {

0 commit comments

Comments
 (0)