TransactionSetup fix

This commit is contained in:
Gavriil Sitnikov 2018-10-01 18:58:43 +03:00
parent ae81477a1d
commit fbc64cfb1f
2 changed files with 36 additions and 34 deletions

View File

@ -30,6 +30,7 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.MenuItem;
import io.reactivex.functions.BiFunction;
import io.reactivex.functions.Function;
import ru.touchin.roboswag.core.log.Lc;
@ -130,7 +131,7 @@ public class FragmentNavigation {
final boolean addToStack,
@Nullable final Bundle args,
@Nullable final String backStackTag,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
if (fragmentManager.isDestroyed()) {
Lc.assertion("FragmentManager is destroyed");
return;
@ -151,7 +152,7 @@ public class FragmentNavigation {
}
if (transactionSetup != null) {
try {
fragmentTransaction = transactionSetup.apply(fragmentTransaction);
fragmentTransaction = transactionSetup.apply(fragmentTransaction, fragment);
} catch (final Exception exception) {
Lc.assertion(exception);
}
@ -255,7 +256,7 @@ public class FragmentNavigation {
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
*/
public void push(@NonNull final Class<? extends Fragment> fragmentClass,
@NonNull final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@NonNull final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(fragmentClass, null, true, null, null, transactionSetup);
}
@ -268,7 +269,7 @@ public class FragmentNavigation {
*/
public void push(@NonNull final Class<? extends Fragment> fragmentClass,
@Nullable final Bundle args,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(fragmentClass, null, true, args, null, transactionSetup);
}
@ -305,7 +306,7 @@ public class FragmentNavigation {
*/
public void pushForResult(@NonNull final Class<? extends Fragment> fragmentClass,
@NonNull final Fragment targetFragment,
@NonNull final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@NonNull final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(fragmentClass, targetFragment, true, null, fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
}
@ -320,7 +321,7 @@ public class FragmentNavigation {
public void pushForResult(@NonNull final Class<? extends Fragment> fragmentClass,
@NonNull final Fragment targetFragment,
@Nullable final Bundle args,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(fragmentClass, targetFragment, true, args, fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
}
@ -352,7 +353,7 @@ public class FragmentNavigation {
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
*/
public void setAsTop(@NonNull final Class<? extends Fragment> fragmentClass,
@NonNull final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@NonNull final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(fragmentClass, null, true, null, fragmentClass.getName() + ';' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
}
@ -366,7 +367,7 @@ public class FragmentNavigation {
*/
public void setAsTop(@NonNull final Class<? extends Fragment> fragmentClass,
@Nullable final Bundle args,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(fragmentClass, null, true, args, fragmentClass.getName() + ';' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
}
@ -397,7 +398,7 @@ public class FragmentNavigation {
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info.
*/
public void setInitial(@NonNull final Class<? extends Fragment> fragmentClass,
@NonNull final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@NonNull final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
setInitial(fragmentClass, null, transactionSetup);
}
@ -410,7 +411,7 @@ public class FragmentNavigation {
*/
public void setInitial(@NonNull final Class<? extends Fragment> fragmentClass,
@Nullable final Bundle args,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
beforeSetInitialActions();
setAsTop(fragmentClass, args, transactionSetup);
}

View File

@ -27,7 +27,7 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import io.reactivex.functions.Function;
import io.reactivex.functions.BiFunction;
import ru.touchin.roboswag.components.navigation.activities.ViewControllerActivity;
import ru.touchin.roboswag.components.navigation.fragments.SimpleViewControllerFragment;
import ru.touchin.roboswag.components.navigation.fragments.StatelessTargetedViewControllerFragment;
@ -72,7 +72,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
*/
public <TState extends AbstractState> void push(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
@Nullable final TState state,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(fragmentClass, null, true, ViewControllerFragment.createState(state), null, transactionSetup);
}
@ -103,7 +103,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
public <TState extends AbstractState> void pushForResult(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
@NonNull final Fragment targetFragment,
@Nullable final TState state,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment,
FragmentTransaction> transactionSetup) {
addToStack(fragmentClass, targetFragment, true, ViewControllerFragment.createState(state),
fragmentClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
}
@ -131,7 +132,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
*/
public <TState extends AbstractState> void setAsTop(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
@Nullable final TState state,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment,
FragmentTransaction> transactionSetup) {
setAsTop(fragmentClass, ViewControllerFragment.createState(state), transactionSetup);
}
@ -157,7 +159,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
*/
public <TState extends AbstractState> void setInitial(@NonNull final Class<? extends ViewControllerFragment<TState, TActivity>> fragmentClass,
@Nullable final TState state,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment,
FragmentTransaction> transactionSetup) {
setInitial(fragmentClass, ViewControllerFragment.createState(state), transactionSetup);
}
@ -181,7 +184,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
public <TState extends AbstractState> void pushViewController(@NonNull final Class<? extends ViewController<TActivity,
SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
@NonNull final TState state) {
addViewControllerToStack(viewControllerClass, null, state, null, null);
addViewControllerToStack(viewControllerClass, state, null, null);
}
/**
@ -192,7 +195,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
*/
public void pushViewController(
@NonNull final Class<? extends ViewController<TActivity, StatelessViewControllerFragment<TActivity>>> viewControllerClass,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addStatelessViewControllerToStack(viewControllerClass, null, null, transactionSetup);
}
@ -207,8 +210,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
public <TState extends AbstractState> void pushViewController(
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
@NonNull final TState state,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
addViewControllerToStack(viewControllerClass, null, state, null, transactionSetup);
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addViewControllerToStack(viewControllerClass, state, null, transactionSetup);
}
/**
@ -264,7 +267,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
@NonNull final Class<? extends ViewController<TActivity,
StatelessTargetedViewControllerFragment<TTargetState, TActivity>>> viewControllerClass,
@NonNull final TTargetFragment targetFragment,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addTargetedStatelessViewControllerToStack(viewControllerClass, targetFragment,
viewControllerClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
}
@ -310,7 +313,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
TargetedViewControllerFragment<TState, TTargetState, TActivity>>> viewControllerClass,
@NonNull final TTargetFragment targetFragment,
@NonNull final TState state,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addTargetedViewControllerToStack(viewControllerClass, targetFragment, state,
viewControllerClass.getName() + ';' + WITH_TARGET_FRAGMENT_TAG_MARK, transactionSetup);
}
@ -336,7 +339,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
public <TState extends AbstractState> void setViewControllerAsTop(
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
@NonNull final TState state) {
addViewControllerToStack(viewControllerClass, null, state, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, null);
addViewControllerToStack(viewControllerClass, state, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, null);
}
/**
@ -348,7 +351,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
*/
public void setViewControllerAsTop(
@NonNull final Class<? extends ViewController<TActivity, StatelessViewControllerFragment<TActivity>>> viewControllerClass,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addStatelessViewControllerToStack(viewControllerClass, null, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
}
@ -364,8 +367,8 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
public <TState extends AbstractState> void setViewControllerAsTop(
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
@NonNull final TState state,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
addViewControllerToStack(viewControllerClass, null, state, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addViewControllerToStack(viewControllerClass, state, viewControllerClass.getName() + ' ' + TOP_FRAGMENT_TAG_MARK, transactionSetup);
}
/**
@ -401,7 +404,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
*/
public void setInitialViewController(
@NonNull final Class<? extends ViewController<TActivity, StatelessViewControllerFragment<TActivity>>> viewControllerClass,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
beforeSetInitialActions();
setViewControllerAsTop(viewControllerClass, transactionSetup);
}
@ -418,7 +421,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
public <TState extends AbstractState> void setInitialViewController(
@NonNull final Class<? extends ViewController<TActivity, SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
@NonNull final TState state,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
beforeSetInitialActions();
setViewControllerAsTop(viewControllerClass, state, transactionSetup);
}
@ -435,7 +438,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
@NonNull final Class<? extends ViewController<TActivity, ? extends StatelessViewControllerFragment<TActivity>>> viewControllerClass,
@Nullable final Fragment targetFragment,
@Nullable final String backStackTag,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(StatelessViewControllerFragment.class, targetFragment, true,
StatelessViewControllerFragment.createState(viewControllerClass), backStackTag, transactionSetup);
}
@ -457,7 +460,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
@NonNull final Fragment targetFragment,
@NonNull final TState state,
@Nullable final String backStackTag,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(TargetedViewControllerFragment.class, targetFragment, true,
TargetedViewControllerFragment.createState(viewControllerClass, state), backStackTag, transactionSetup);
}
@ -476,7 +479,7 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
? extends StatelessTargetedViewControllerFragment<TState, TActivity>>> viewControllerClass,
@NonNull final Fragment targetFragment,
@Nullable final String backStackTag,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(StatelessTargetedViewControllerFragment.class, targetFragment, true,
StatelessTargetedViewControllerFragment.createState(viewControllerClass), backStackTag, transactionSetup);
}
@ -485,7 +488,6 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
* Base method to push stateful {@link ViewControllerFragment} to stack.
*
* @param viewControllerClass Class of {@link ViewController} to be pushed;
* @param targetFragment {@link ViewControllerFragment} to be set as target;
* @param state {@link AbstractState} of {@link ViewController}'s fragment;
* @param backStackTag Tag of {@link ViewControllerFragment} in back stack;
* @param transactionSetup Function to setup transaction before commit. It is useful to specify transition animations or additional info;
@ -493,11 +495,10 @@ public class ViewControllerNavigation<TActivity extends ViewControllerActivity<?
*/
protected <TState extends AbstractState> void addViewControllerToStack(
@NonNull final Class<? extends ViewController<TActivity, ? extends SimpleViewControllerFragment<TState, TActivity>>> viewControllerClass,
@Nullable final Fragment targetFragment,
@NonNull final TState state,
@Nullable final String backStackTag,
@Nullable final Function<FragmentTransaction, FragmentTransaction> transactionSetup) {
addToStack(SimpleViewControllerFragment.class, targetFragment, true,
@Nullable final BiFunction<FragmentTransaction, Fragment, FragmentTransaction> transactionSetup) {
addToStack(SimpleViewControllerFragment.class, null, true,
SimpleViewControllerFragment.createState(viewControllerClass, state), backStackTag, transactionSetup);
}