diff --git a/src/main/java/ru/touchin/roboswag/components/navigation/ViewControllerFragment.java b/src/main/java/ru/touchin/roboswag/components/navigation/ViewControllerFragment.java index fe3ca12..623f522 100644 --- a/src/main/java/ru/touchin/roboswag/components/navigation/ViewControllerFragment.java +++ b/src/main/java/ru/touchin/roboswag/components/navigation/ViewControllerFragment.java @@ -131,36 +131,41 @@ public abstract class ViewControllerFragment { - if (logicBridge == null || activity == null || viewInfo == null) { - return null; - } - - final ViewController.CreationContext> creationContext - = new ViewController.CreationContext<>(logicBridge, activity, this, viewInfo.first); - if (getViewControllerClass().getConstructors().length != 1) { - throw OnErrorThrowable - .from(new ShouldNotHappenException("There should be single constructor for " + getViewControllerClass())); - } - final Constructor constructor = getViewControllerClass().getConstructors()[0]; - try { - switch (constructor.getParameterTypes().length) { - case 2: - return (ViewController) constructor.newInstance(creationContext, viewInfo.second); - case 3: - return (ViewController) constructor.newInstance(this, creationContext, viewInfo.second); - default: - Lc.assertion("Wrong constructor parameters count: " + constructor.getParameterTypes().length); - return null; - } - } catch (final Exception exception) { - throw OnErrorThrowable.from(exception); - } - }) + this::getViewController) .observeOn(AndroidSchedulers.mainThread()); } + @Nullable + private ViewController getViewController(@Nullable final TLogicBridge logicBridge, + @Nullable final TActivity activity, + @Nullable final Pair viewInfo) { + if (logicBridge == null || activity == null || viewInfo == null) { + return null; + } + + if (getViewControllerClass().getConstructors().length != 1) { + throw OnErrorThrowable + .from(new ShouldNotHappenException("There should be single constructor for " + getViewControllerClass())); + } + final Constructor constructor = getViewControllerClass().getConstructors()[0]; + final ViewController.CreationContext> creationContext + = new ViewController.CreationContext<>(logicBridge, activity, this, viewInfo.first); + try { + switch (constructor.getParameterTypes().length) { + case 2: + return (ViewController) constructor.newInstance(creationContext, viewInfo.second); + case 3: + return (ViewController) constructor.newInstance(this, creationContext, viewInfo.second); + default: + Lc.assertion("Wrong constructor parameters count: " + constructor.getParameterTypes().length); + return null; + } + } catch (final Exception exception) { + throw OnErrorThrowable.from(exception); + } + } + @Deprecated @NonNull @Override