Skip to content

Commit cef5447

Browse files
authored
Merge pull request #872 from YoKeyword/dev
v1.3.4
2 parents c877b11 + 28aff48 commit cef5447

File tree

7 files changed

+54
-26
lines changed

7 files changed

+54
-26
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ The first demo shows the basic usage of the library. The second one shows the wa
4646
**1、build.gradle**
4747
````gradle
4848
// appcompat-v7 is required
49-
compile 'me.yokeyword:fragmentation:1.3.3'
49+
compile 'me.yokeyword:fragmentation:1.3.4'
5050
5151
// If you don't want to extends SupportActivity/Fragment and would like to customize your own support, just rely on fragmentation-core
52-
// compile 'me.yokeyword:fragmentation-core:1.3.3'
52+
// compile 'me.yokeyword:fragmentation-core:1.3.4'
5353
5454
// To get SwipeBack feature, rely on both fragmentation & fragmentation-swipeback
55-
compile 'me.yokeyword:fragmentation:1.3.3'
55+
compile 'me.yokeyword:fragmentation:1.3.4'
5656
// Swipeback is based on fragmentation. Refer to SwipeBackActivity/Fragment for your Customized SupportActivity/Fragment
57-
compile 'me.yokeyword:fragmentation-swipeback:1.3.3'
57+
compile 'me.yokeyword:fragmentation-swipeback:1.3.4'
5858
5959
// To simplify the communication between Fragments.
6060
compile 'me.yokeyword:eventbus-activity-scope:1.1.0'

README_CN.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ A powerful library that manage Fragment for Android!
5252
**1. 项目下app的build.gradle中依赖:**
5353
````gradle
5454
// appcompat-v7包是必须的
55-
compile 'me.yokeyword:fragmentation:1.3.3'
55+
compile 'me.yokeyword:fragmentation:1.3.4'
5656
5757
// 如果不想继承SupportActivity/Fragment,自己定制Support,可仅依赖:
58-
// compile 'me.yokeyword:fragmentation-core:1.3.3'
58+
// compile 'me.yokeyword:fragmentation-core:1.3.4'
5959
6060
// 如果想使用SwipeBack 滑动边缘退出Fragment/Activity功能,完整的添加规则如下:
61-
compile 'me.yokeyword:fragmentation:1.3.3'
61+
compile 'me.yokeyword:fragmentation:1.3.4'
6262
// swipeback基于fragmentation, 如果是自定制SupportActivity/Fragment,则参照SwipeBackActivity/Fragment实现即可
63-
compile 'me.yokeyword:fragmentation-swipeback:1.3.3'
63+
compile 'me.yokeyword:fragmentation-swipeback:1.3.4'
6464
6565
// Activity作用域的EventBus,更安全,可有效避免after onSavenInstanceState()异常
6666
compile 'me.yokeyword:eventbus-activity-scope:1.1.0'

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ ext {
2828
minSdkVersion = 14
2929
targetSdkVersion = compileSdkVersion
3030

31-
v4Version = "27.1.0"
31+
v4Version = "27.1.1"
3232
}

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

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

1920
static {
2021
Field[] fields = FragmentManagerImpl.class.getDeclaredFields();
2122
for (Field field : fields) {
22-
if (field.getName().equals("mAvailIndices")) {
23+
if (field.getName().equals("mStopped")) { // > v27.1.0
24+
sSupportGreaterThan27dot1dot0 = true;
25+
break;
26+
} else if (field.getName().equals("mAvailIndices")) { // < 25.4.0
2327
sSupportLessThan25dot4 = true;
2428
break;
2529
}
2630
}
2731
}
2832

33+
public static boolean isSupportLessThan25dot4() {
34+
return sSupportLessThan25dot4;
35+
}
36+
2937
public static boolean isExecutingActions(FragmentManager fragmentManager) {
3038
if (!(fragmentManager instanceof FragmentManagerImpl))
3139
return false;
@@ -180,10 +188,28 @@ private static void hookStateSaved(FragmentManager fragmentManager, Runnable run
180188
FragmentManagerImpl fragmentManagerImpl = (FragmentManagerImpl) fragmentManager;
181189
if (isStateSaved(fragmentManager)) {
182190
fragmentManagerImpl.mStateSaved = false;
183-
runnable.run();
191+
compatRunAction(fragmentManagerImpl, runnable);
184192
fragmentManagerImpl.mStateSaved = true;
185193
} else {
186194
runnable.run();
187195
}
188196
}
197+
198+
/**
199+
* Compat v27.1.0+
200+
* <p>
201+
* So the code to compile Fragmentation needs v27.1.0+
202+
*
203+
* @see FragmentManager#isStateSaved()
204+
*/
205+
private static void compatRunAction(FragmentManagerImpl fragmentManagerImpl, Runnable runnable) {
206+
if (!sSupportGreaterThan27dot1dot0) {
207+
runnable.run();
208+
return;
209+
}
210+
211+
fragmentManagerImpl.mStopped = false;
212+
runnable.run();
213+
fragmentManagerImpl.mStopped = true;
214+
}
189215
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,8 @@ void handleResultRecord(Fragment from) {
320320
final ResultRecord resultRecord = args.getParcelable(FRAGMENTATION_ARG_RESULT_RECORD);
321321
if (resultRecord == null) return;
322322

323-
final ISupportFragment targetFragment = (ISupportFragment) from.getFragmentManager().getFragment(from.getArguments(), FRAGMENTATION_STATE_SAVE_RESULT);
324-
mHandler.post(new Runnable() {
325-
@Override
326-
public void run() {
327-
targetFragment.onFragmentResult(resultRecord.requestCode, resultRecord.resultCode, resultRecord.resultBundle);
328-
}
329-
});
323+
ISupportFragment targetFragment = (ISupportFragment) from.getFragmentManager().getFragment(from.getArguments(), FRAGMENTATION_STATE_SAVE_RESULT);
324+
targetFragment.onFragmentResult(resultRecord.requestCode, resultRecord.resultCode, resultRecord.resultBundle);
330325
} catch (IllegalStateException ignored) {
331326
// Fragment no longer exists
332327
}
@@ -580,7 +575,7 @@ private void safePopTo(String fragmentTag, final FragmentManager fm, int flag, L
580575
FragmentationMagician.executePendingTransactionsAllowingStateLoss(fm);
581576
mSupport.getSupportDelegate().mPopMultipleNoAnim = false;
582577

583-
if (FragmentationMagician.sSupportLessThan25dot4) {
578+
if (FragmentationMagician.isSupportLessThan25dot4()) {
584579
mHandler.post(new Runnable() {
585580
@Override
586581
public void run() {

fragmentation_core/src/main/java/me/yokeyword/fragmentation/anim/FragmentAnimator.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,39 @@ public int getEnter() {
6060
return enter;
6161
}
6262

63-
public void setEnter(int enter) {
63+
public FragmentAnimator setEnter(int enter) {
6464
this.enter = enter;
65+
return this;
6566
}
6667

6768
public int getExit() {
6869
return exit;
6970
}
7071

71-
public void setExit(int exit) {
72+
/**
73+
* enter animation
74+
*/
75+
public FragmentAnimator setExit(int exit) {
7276
this.exit = exit;
77+
return this;
7378
}
7479

7580
public int getPopEnter() {
7681
return popEnter;
7782
}
7883

79-
public void setPopEnter(int popEnter) {
84+
public FragmentAnimator setPopEnter(int popEnter) {
8085
this.popEnter = popEnter;
86+
return this;
8187
}
8288

8389
public int getPopExit() {
8490
return popExit;
8591
}
8692

87-
public void setPopExit(int popExit) {
93+
public FragmentAnimator setPopExit(int popExit) {
8894
this.popExit = popExit;
95+
return this;
8996
}
9097

9198
@Override

fragmentation_swipeback/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Activity内Fragment数大于1时,滑动返回的是Fragment,否则滑动返
1010
1、项目下app的build.gradle中依赖:
1111
````gradle
1212
// appcompat v7包是必须的
13-
compile 'me.yokeyword:fragmentation:1.3.3'
14-
compile 'me.yokeyword:fragmentation-swipeback:1.3.3'
13+
compile 'me.yokeyword:fragmentation:1.3.4'
14+
compile 'me.yokeyword:fragmentation-swipeback:1.3.4'
1515
````
1616

1717
2、如果Activity也需要支持SwipeBack,则继承SwipeBackActivity:

0 commit comments

Comments
 (0)