Skip to content

Commit 28aff48

Browse files
committed
Optimized FragmentationMagician.java
1 parent 45982cf commit 28aff48

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

fragmentation_core/src/main/java/android/support/v4/app/FragmentationMagician.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* Created by YoKey on 16/1/22.
1515
*/
1616
public class FragmentationMagician {
17-
public static boolean sSupportLessThan25dot4 = false;
18-
public static boolean sSupportGreaterThan27dot1dot0 = false;
17+
private static boolean sSupportLessThan25dot4 = false;
18+
private static boolean sSupportGreaterThan27dot1dot0 = false;
1919

2020
static {
2121
Field[] fields = FragmentManagerImpl.class.getDeclaredFields();
@@ -30,6 +30,10 @@ public class FragmentationMagician {
3030
}
3131
}
3232

33+
public static boolean isSupportLessThan25dot4() {
34+
return sSupportLessThan25dot4;
35+
}
36+
3337
public static boolean isExecutingActions(FragmentManager fragmentManager) {
3438
if (!(fragmentManager instanceof FragmentManagerImpl))
3539
return false;
@@ -193,18 +197,19 @@ private static void hookStateSaved(FragmentManager fragmentManager, Runnable run
193197

194198
/**
195199
* Compat v27.1.0+
196-
*
200+
* <p>
197201
* So the code to compile Fragmentation needs v27.1.0+
198202
*
199203
* @see FragmentManager#isStateSaved()
200204
*/
201205
private static void compatRunAction(FragmentManagerImpl fragmentManagerImpl, Runnable runnable) {
202-
if (sSupportGreaterThan27dot1dot0) {
203-
fragmentManagerImpl.mStopped = false;
204-
runnable.run();
205-
fragmentManagerImpl.mStopped = true;
206-
} else {
206+
if (!sSupportGreaterThan27dot1dot0) {
207207
runnable.run();
208+
return;
208209
}
210+
211+
fragmentManagerImpl.mStopped = false;
212+
runnable.run();
213+
fragmentManagerImpl.mStopped = true;
209214
}
210215
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ private void safePopTo(String fragmentTag, final FragmentManager fm, int flag, L
575575
FragmentationMagician.executePendingTransactionsAllowingStateLoss(fm);
576576
mSupport.getSupportDelegate().mPopMultipleNoAnim = false;
577577

578-
if (FragmentationMagician.sSupportLessThan25dot4) {
578+
if (FragmentationMagician.isSupportLessThan25dot4()) {
579579
mHandler.post(new Runnable() {
580580
@Override
581581
public void run() {

0 commit comments

Comments
 (0)