Skip to content

Commit

Permalink
Extract 'forward' to reuse in replace when localStackCopy.size > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
adolgiy committed Feb 20, 2020
1 parent d08e6b1 commit 05a8ec8
Showing 1 changed file with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,7 @@ protected void fragmentForward(@NotNull Forward command) {
FragmentParams fragmentParams = screen.getFragmentParams();
Fragment fragment = fragmentParams == null ? createFragment(screen) : null;

FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

setupFragmentTransaction(
command,
fragmentManager.findFragmentById(containerId),
fragment,
fragmentTransaction);

fragmentReplaceInternal(fragmentTransaction, screen, fragmentParams, fragment);

fragmentTransaction
.addToBackStack(screen.getScreenKey())
.commit();

localStackCopy.add(screen.getScreenKey());
forwardFragmentInternal(command, screen, fragmentParams, fragment);
}

protected void fragmentBack() {
Expand Down Expand Up @@ -159,6 +145,9 @@ protected void fragmentReplace(@NotNull Replace command) {
fragmentManager.popBackStack();
localStackCopy.removeLast();

forwardFragmentInternal(command, screen, fragmentParams, fragment);

} else {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

setupFragmentTransaction(
Expand All @@ -168,31 +157,37 @@ protected void fragmentReplace(@NotNull Replace command) {
fragmentTransaction
);

fragmentReplaceInternal(fragmentTransaction, screen, fragmentParams, fragment);
replaceFragmentInternal(fragmentTransaction, screen, fragmentParams, fragment);

fragmentTransaction
.addToBackStack(screen.getScreenKey())
.commit();
fragmentTransaction.commit();
}
}

localStackCopy.add(screen.getScreenKey());
private void forwardFragmentInternal(
@NotNull Command command,
@NotNull SupportAppScreen screen,
@Nullable FragmentParams fragmentParams,
@Nullable Fragment fragment
) {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

} else {
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
setupFragmentTransaction(
command,
fragmentManager.findFragmentById(containerId),
fragment,
fragmentTransaction
);

setupFragmentTransaction(
command,
fragmentManager.findFragmentById(containerId),
fragment,
fragmentTransaction
);
replaceFragmentInternal(fragmentTransaction, screen, fragmentParams, fragment);

fragmentReplaceInternal(fragmentTransaction, screen, fragmentParams, fragment);
fragmentTransaction
.addToBackStack(screen.getScreenKey())
.commit();

fragmentTransaction.commit();
}
localStackCopy.add(screen.getScreenKey());
}

private void fragmentReplaceInternal(
private void replaceFragmentInternal(
@NotNull FragmentTransaction transaction,
@NotNull SupportAppScreen screen,
@Nullable FragmentParams params,
Expand Down

0 comments on commit 05a8ec8

Please sign in to comment.