Skip to content

Commit 8e70853

Browse files
authored
Merge pull request #792 from YoKeyword/dev
1.3.0
2 parents 54ff12f + 4333709 commit 8e70853

File tree

20 files changed

+410
-1795
lines changed

20 files changed

+410
-1795
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.2.7'
49+
compile 'me.yokeyword:fragmentation:1.3.0'
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.2.7'
52+
// compile 'me.yokeyword:fragmentation-core:1.3.0'
5353
5454
// To get SwipeBack feature, rely on both fragmentation & fragmentation-swipeback
55-
compile 'me.yokeyword:fragmentation:1.2.7'
55+
compile 'me.yokeyword:fragmentation:1.3.0'
5656
// Swipeback is based on fragmentation. Refer to SwipeBackActivity/Fragment for your Customized SupportActivity/Fragment
57-
compile 'me.yokeyword:fragmentation-swipeback:1.2.7'
57+
compile 'me.yokeyword:fragmentation-swipeback:1.3.0'
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.2.7'
55+
compile 'me.yokeyword:fragmentation:1.3.0'
5656
5757
// 如果不想继承SupportActivity/Fragment,自己定制Support,可仅依赖:
58-
// compile 'me.yokeyword:fragmentation-core:1.2.7'
58+
// compile 'me.yokeyword:fragmentation-core:1.3.0'
5959
6060
// 如果想使用SwipeBack 滑动边缘退出Fragment/Activity功能,完整的添加规则如下:
61-
compile 'me.yokeyword:fragmentation:1.2.7'
61+
compile 'me.yokeyword:fragmentation:1.3.0'
6262
// swipeback基于fragmentation, 如果是自定制SupportActivity/Fragment,则参照SwipeBackActivity/Fragment实现即可
63-
compile 'me.yokeyword:fragmentation-swipeback:1.2.7'
63+
compile 'me.yokeyword:fragmentation-swipeback:1.3.0'
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.0.2"
31+
v4Version = "27.1.0"
3232
}

demo/src/main/java/me/yokeyword/sample/demo_flow/MainActivity.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public void run() {
141141
int id = item.getItemId();
142142

143143
final ISupportFragment topFragment = getTopFragment();
144+
MySupportFragment myHome = (MySupportFragment) topFragment;
144145

145146
if (id == R.id.nav_home) {
146147

@@ -149,34 +150,23 @@ public void run() {
149150
newBundle.putString("from", "From:" + topFragment.getClass().getSimpleName());
150151
fragment.putNewBundle(newBundle);
151152

152-
start(fragment, SupportFragment.SINGLETASK);
153+
myHome.start(fragment, SupportFragment.SINGLETASK);
153154
} else if (id == R.id.nav_discover) {
154155
DiscoverFragment fragment = findFragment(DiscoverFragment.class);
155156
if (fragment == null) {
156-
popTo(HomeFragment.class, false, new Runnable() {
157-
@Override
158-
public void run() {
159-
start(DiscoverFragment.newInstance());
160-
}
161-
});
157+
myHome.startWithPopTo(DiscoverFragment.newInstance(), HomeFragment.class, false);
162158
} else {
163159
// 如果已经在栈内,则以SingleTask模式start
164-
start(fragment, SupportFragment.SINGLETASK);
160+
myHome.start(fragment, SupportFragment.SINGLETASK);
165161
}
166-
} else if (id == R.id.nav_msg) {
162+
} else if (id == R.id.nav_shop) {
167163
ShopFragment fragment = findFragment(ShopFragment.class);
168164
if (fragment == null) {
169-
popTo(HomeFragment.class, false, new Runnable() {
170-
@Override
171-
public void run() {
172-
start(ShopFragment.newInstance());
173-
// 设置pop动画为: popExit, 配合start(),视觉上动画会很合理(类似startWithPop()的动画)
174-
}
175-
}, getFragmentAnimator().getPopExit());
165+
myHome.startWithPopTo(ShopFragment.newInstance(), HomeFragment.class, false);
176166
} else {
177167
// 如果已经在栈内,则以SingleTask模式start,也可以用popTo
178168
// start(fragment, SupportFragment.SINGLETASK);
179-
popTo(ShopFragment.class, false);
169+
myHome.popTo(ShopFragment.class, false);
180170
}
181171
} else if (id == R.id.nav_login) {
182172
goLogin();

demo/src/main/java/me/yokeyword/sample/demo_flow/base/MySupportActivity.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import me.yokeyword.fragmentation.ISupportActivity;
1111
import me.yokeyword.fragmentation.ISupportFragment;
1212
import me.yokeyword.fragmentation.SupportActivityDelegate;
13+
import me.yokeyword.fragmentation.SupportFragment;
1314
import me.yokeyword.fragmentation.SupportHelper;
1415
import me.yokeyword.fragmentation.anim.FragmentAnimator;
1516

@@ -141,6 +142,17 @@ public void start(ISupportFragment toFragment, @ISupportFragment.LaunchMode int
141142
mDelegate.start(toFragment, launchMode);
142143
}
143144

145+
/**
146+
* It is recommended to use {@link SupportFragment#startWithPopTo(ISupportFragment, Class, boolean)}.
147+
*
148+
* @see #popTo(Class, boolean)
149+
* +
150+
* @see #start(ISupportFragment)
151+
*/
152+
public void startWithPopTo(ISupportFragment toFragment, Class<?> targetFragmentClass, boolean includeTargetFragment) {
153+
mDelegate.startWithPopTo(toFragment, targetFragmentClass, includeTargetFragment);
154+
}
155+
144156
/**
145157
* Pop the fragment.
146158
*/

demo/src/main/java/me/yokeyword/sample/demo_flow/base/MySupportFragment.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ public void startWithPop(ISupportFragment toFragment) {
321321
mDelegate.startWithPop(toFragment);
322322
}
323323

324+
/**
325+
* @see #popTo(Class, boolean)
326+
* +
327+
* @see #start(ISupportFragment)
328+
*/
329+
public void startWithPopTo(ISupportFragment toFragment, Class<?> targetFragmentClass, boolean includeTargetFragment) {
330+
mDelegate.startWithPopTo(toFragment, targetFragmentClass, includeTargetFragment);
331+
}
332+
324333
public void replaceFragment(ISupportFragment toFragment, boolean addToBackStack) {
325334
mDelegate.replaceFragment(toFragment, addToBackStack);
326335
}

demo/src/main/res/menu/activity_main_drawer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
android:icon="@drawable/ic_discover_white_24dp"
1212
android:title="@string/discover"/>
1313
<item
14-
android:id="@+id/nav_msg"
14+
android:id="@+id/nav_shop"
1515
android:icon="@drawable/ic_message_white_24dp"
1616
android:title="@string/shop"/>
1717
</group>

fragmentation/src/main/java/me/yokeyword/fragmentation/SupportActivity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ public void startWithPop(ISupportFragment toFragment) {
188188
mDelegate.startWithPop(toFragment);
189189
}
190190

191+
/**
192+
* It is recommended to use {@link SupportFragment#startWithPopTo(ISupportFragment, Class, boolean)}.
193+
*
194+
* @see #popTo(Class, boolean)
195+
* +
196+
* @see #start(ISupportFragment)
197+
*/
198+
public void startWithPopTo(ISupportFragment toFragment, Class<?> targetFragmentClass, boolean includeTargetFragment) {
199+
mDelegate.startWithPopTo(toFragment, targetFragmentClass, includeTargetFragment);
200+
}
201+
191202
/**
192203
* It is recommended to use {@link SupportFragment#replaceFragment(ISupportFragment, boolean)}.
193204
*/

fragmentation/src/main/java/me/yokeyword/fragmentation/SupportFragment.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ public void setUserVisibleHint(boolean isVisibleToUser) {
103103

104104
/**
105105
* Causes the Runnable r to be added to the action queue.
106-
*
106+
* <p>
107107
* The runnable will be run after all the previous action has been run.
108-
*
108+
* <p>
109109
* 前面的事务全部执行后 执行该Action
110110
*
111111
* @deprecated Use {@link #post(Runnable)} instead.
@@ -118,9 +118,9 @@ public void enqueueAction(Runnable runnable) {
118118

119119
/**
120120
* Causes the Runnable r to be added to the action queue.
121-
*
121+
* <p>
122122
* The runnable will be run after all the previous action has been run.
123-
*
123+
* <p>
124124
* 前面的事务全部执行后 执行该Action
125125
*/
126126
@Override
@@ -216,7 +216,7 @@ public boolean onBackPressedSupport() {
216216

217217
/**
218218
* 类似 {@link Activity#setResult(int, Intent)}
219-
*
219+
* <p>
220220
* Similar to {@link Activity#setResult(int, Intent)}
221221
*
222222
* @see #startForResult(ISupportFragment, int)
@@ -228,7 +228,7 @@ public void setFragmentResult(int resultCode, Bundle bundle) {
228228

229229
/**
230230
* 类似 {@link Activity#onActivityResult(int, int, Intent)}
231-
*
231+
* <p>
232232
* Similar to {@link Activity#onActivityResult(int, int, Intent)}
233233
*
234234
* @see #startForResult(ISupportFragment, int)
@@ -241,12 +241,11 @@ public void onFragmentResult(int requestCode, int resultCode, Bundle data) {
241241
/**
242242
* 在start(TargetFragment,LaunchMode)时,启动模式为SingleTask/SingleTop, 回调TargetFragment的该方法
243243
* 类似 {@link Activity#onNewIntent(Intent)}
244-
*
244+
* <p>
245245
* Similar to {@link Activity#onNewIntent(Intent)}
246246
*
247-
* @see #start(ISupportFragment, int)
248-
*
249247
* @param args putNewBundle(Bundle newBundle)
248+
* @see #start(ISupportFragment, int)
250249
*/
251250
@Override
252251
public void onNewBundle(Bundle args) {
@@ -345,6 +344,16 @@ public void startWithPop(ISupportFragment toFragment) {
345344
mDelegate.startWithPop(toFragment);
346345
}
347346

347+
/**
348+
* @see #popTo(Class, boolean)
349+
* +
350+
* @see #start(ISupportFragment)
351+
*/
352+
public void startWithPopTo(ISupportFragment toFragment, Class<?> targetFragmentClass, boolean includeTargetFragment) {
353+
mDelegate.startWithPopTo(toFragment, targetFragmentClass, includeTargetFragment);
354+
}
355+
356+
348357
public void replaceFragment(ISupportFragment toFragment, boolean addToBackStack) {
349358
mDelegate.replaceFragment(toFragment, addToBackStack);
350359
}
@@ -363,7 +372,7 @@ public void popChild() {
363372
/**
364373
* Pop the last fragment transition from the manager's fragment
365374
* back stack.
366-
*
375+
* <p>
367376
* 出栈到目标fragment
368377
*
369378
* @param targetFragmentClass 目标fragment

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Created by YoKey on 16/1/22.
1515
*/
1616
public class FragmentationMagician {
17-
private static boolean sSupportLessThan25dot4 = false;
17+
public static boolean sSupportLessThan25dot4 = false;
1818

1919
static {
2020
Field[] fields = FragmentManagerImpl.class.getDeclaredFields();

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public abstract ExtraTransaction setCustomAnimations(@AnimatorRes @AnimRes int t
7676

7777
public abstract void startWithPop(ISupportFragment toFragment);
7878

79+
public abstract void startWithPopTo(ISupportFragment toFragment, String targetFragmentTag, boolean includeTargetFragment);
80+
7981
public abstract void replace(ISupportFragment toFragment);
8082

8183
/**
@@ -263,6 +265,12 @@ public void startWithPop(ISupportFragment toFragment) {
263265
mTransactionDelegate.startWithPop(getFragmentManager(), mSupportF, toFragment);
264266
}
265267

268+
@Override
269+
public void startWithPopTo(ISupportFragment toFragment, String targetFragmentTag, boolean includeTargetFragment) {
270+
toFragment.getSupportDelegate().mTransactionRecord = mRecord;
271+
mTransactionDelegate.startWithPopTo(getFragmentManager(), mSupportF, toFragment, targetFragmentTag, includeTargetFragment);
272+
}
273+
266274
@Override
267275
public void replace(ISupportFragment toFragment) {
268276
toFragment.getSupportDelegate().mTransactionRecord = mRecord;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ public void logFragmentStackHierarchy(String TAG) {
133133

134134
/**
135135
* Causes the Runnable r to be added to the action queue.
136-
*
136+
* <p>
137137
* The runnable will be run after all the previous action has been run.
138-
*
138+
* <p>
139139
* 前面的事务全部执行后 执行该Action
140140
*/
141141
public void post(final Runnable runnable) {
@@ -250,6 +250,10 @@ public void startWithPop(ISupportFragment toFragment) {
250250
mTransactionDelegate.startWithPop(getSupportFragmentManager(), getTopFragment(), toFragment);
251251
}
252252

253+
public void startWithPopTo(ISupportFragment toFragment, Class<?> targetFragmentClass, boolean includeTargetFragment) {
254+
mTransactionDelegate.startWithPopTo(getSupportFragmentManager(), getTopFragment(), toFragment, targetFragmentClass.getName(), includeTargetFragment);
255+
}
256+
253257
public void replaceFragment(ISupportFragment toFragment, boolean addToBackStack) {
254258
mTransactionDelegate.dispatchStartTransaction(getSupportFragmentManager(), getTopFragment(), toFragment, 0, ISupportFragment.STANDARD, addToBackStack ? TransactionDelegate.TYPE_REPLACE : TransactionDelegate.TYPE_REPLACE_DONT_BACK);
255259
}

0 commit comments

Comments
 (0)