Skip to content

Commit a214ab3

Browse files
author
chetan-fueled
committed
refactor(*): backStackIdentifier and targetFragmentId
1 parent 5c5e2c2 commit a214ab3

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

flowr/src/main/java/com/fueled/flowr/Flowr.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public class Flowr implements FragmentManager.OnBackStackChangedListener,
5656

5757
private List<FlowrDeepLinkHandler> deepLinkHandlers;
5858

59-
6059
/**
6160
* Constructor to use when creating a new router for an activity
6261
* that has no toolbar.
@@ -250,6 +249,12 @@ protected final String getTagPrefix() {
250249
return tagPrefix;
251250
}
252251

252+
/**
253+
*
254+
* @param data TransactionData used to configure fragment transaction
255+
* @param <T> type Fragment & FlowrFragment
256+
* @return id Identifier of the committed transaction.
257+
*/
253258
protected <T extends Fragment & FlowrFragment> int displayFragment(TransactionData<T> data) {
254259
int identifier = -1;
255260
try {
@@ -288,7 +293,6 @@ protected <T extends Fragment & FlowrFragment> int displayFragment(TransactionDa
288293
if (data.isSkipBackStack()) {
289294
setCurrentFragment(fragment);
290295
}
291-
292296
} catch (Exception e) {
293297
Log.e(TAG, "Error while displaying fragment.", e);
294298
}
@@ -406,9 +410,9 @@ public void close(int n) {
406410

407411
/**
408412
* Closes the current activity if the fragments back stack is empty,
409-
* otherwise pop the top n fragments from the stack.
413+
* otherwise pop upto fragments with id Identifier from the stack.
410414
*
411-
* @param id Identifier of the stated to be popped.
415+
* @param id Identifier of the committed transaction.
412416
*/
413417
public void closeUpto(int id) {
414418
if (screen == null) {
@@ -451,10 +455,10 @@ public void closeWithResults(ResultResponse resultResponse, int n) {
451455

452456
/**
453457
* Closes the current activity if the fragments back stack is empty,
454-
* otherwise pop the top n fragments from the stack and publish the results response.
458+
* otherwise pop upto fragments with id Identifier from the stack and publish the results response.
455459
*
456-
* @param resultResponse the results response to be published
457-
* @param id Identifier of the stated to be popped.
460+
* @param resultResponse the results response to be published
461+
* @param id Identifier of the committed transaction.
458462
*/
459463
public void closeUptoWithResults(ResultResponse resultResponse, int id) {
460464
closeUpto(id);
@@ -778,7 +782,7 @@ public Builder noTransactionAnimation() {
778782
/**
779783
* Displays the fragment using this builder configurations.
780784
*
781-
* @return id Identifier of the stated to be popped.
785+
* @return id Identifier of the committed transaction.
782786
*/
783787
public int displayFragment() {
784788
return Flowr.this.displayFragment(data);
@@ -792,7 +796,7 @@ public int displayFragment() {
792796
* @param requestCode this code will be returned in {@link ResultResponse} when the fragment is closed,
793797
* and it can be used to identify the request from which the results were returned.
794798
*
795-
* @return id Identifier of the stated to be popped.
799+
* @return id Identifier of the committed transaction.
796800
*/
797801
public int displayFragmentForResults(String fragmentId, int requestCode) {
798802
if (!TextUtils.isEmpty(fragmentId)) {

sample/src/main/java/com/fueled/flowr/sample/FirstFragment.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import com.fueled.flowr.annotations.DeepLink;
77
import com.fueled.flowr.sample.core.AbstractFragment;
88

9-
import static com.fueled.flowr.sample.core.FragmentResultPublisherImpl.sourceFragmentId;
10-
119
/**
1210
* Created by [email protected] on 18/05/2017.
1311
* Copyright (c) 2017 Fueled. All rights reserved.
@@ -39,6 +37,6 @@ public NavigationIconType getNavigationIconType() {
3937
@Override
4038
public void onClick(View view) {
4139
getFlowr().open("/second")
42-
.displayFragmentForResults(sourceFragmentId, HomeFragment.RC_STACK);
40+
.displayFragmentForResults(HomeFragment.targetFragmentId, HomeFragment.RC_STACK);
4341
}
4442
}

sample/src/main/java/com/fueled/flowr/sample/HomeFragment.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
import com.fueled.flowr.sample.core.AbstractFragment;
1010
import com.fueled.flowr.sample.databinding.FragmentHomeBinding;
1111

12-
import static com.fueled.flowr.sample.core.FragmentResultPublisherImpl.backStackIdentifier;
13-
import static com.fueled.flowr.sample.core.FragmentResultPublisherImpl.sourceFragmentId;
14-
1512
/**
1613
* Created by [email protected] on 13/02/2017.
1714
* Copyright (c) 2017 Fueled. All rights reserved.
1815
*/
1916
public class HomeFragment extends AbstractFragment implements View.OnClickListener {
2017

2118
public static final int RC_STACK = 101;
19+
public static int backStackIdentifier;
20+
public static String targetFragmentId;
2221

2322
private FragmentHomeBinding binding;
2423

@@ -71,9 +70,9 @@ private void displayLinkFragment() {
7170
}
7271

7372
private void displayFirstFragment() {
74-
sourceFragmentId = getFragmentId();
73+
targetFragmentId = getFragmentId();
7574
backStackIdentifier = getFlowr().open("/first")
76-
.displayFragmentForResults(sourceFragmentId, RC_STACK);
75+
.displayFragmentForResults(targetFragmentId, RC_STACK);
7776
}
7877

7978
@Override

sample/src/main/java/com/fueled/flowr/sample/SecondFragment.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import com.fueled.flowr.annotations.DeepLink;
1111
import com.fueled.flowr.sample.core.AbstractFragment;
1212

13-
import static com.fueled.flowr.sample.core.FragmentResultPublisherImpl.backStackIdentifier;
14-
1513
/**
1614
* Created by [email protected] on 18/05/2017.
1715
* Copyright (c) 2017 Fueled. All rights reserved.
@@ -46,7 +44,7 @@ public NavigationIconType getNavigationIconType() {
4644
public void onClick(View view) {
4745
getFlowr().closeUptoWithResults(
4846
Flowr.getResultsResponse(getArguments(), Activity.RESULT_OK, getBundle()),
49-
backStackIdentifier);
47+
HomeFragment.backStackIdentifier);
5048
}
5149

5250
@NonNull

sample/src/main/java/com/fueled/flowr/sample/core/FragmentResultPublisherImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,4 @@ public static FragmentResultPublisherImpl getInstance() {
5252

5353
return instance;
5454
}
55-
56-
public static int backStackIdentifier;
57-
public static String sourceFragmentId;
5855
}

0 commit comments

Comments
 (0)