Merge pull request #15 from TouchInstinct/bugs/static

Bugs/static
This commit is contained in:
Gavriil 2016-03-22 19:34:09 +03:00
commit 7ebaed8290
1 changed files with 32 additions and 27 deletions

View File

@ -131,36 +131,41 @@ public abstract class ViewControllerFragment<TState extends Serializable, TLogic
.observeOn(backgroundScheduler),
activitySubject.distinctUntilChanged().observeOn(backgroundScheduler),
viewSubject.distinctUntilChanged().observeOn(backgroundScheduler),
(logicBridge, activity, viewInfo) -> {
if (logicBridge == null || activity == null || viewInfo == null) {
return null;
}
final ViewController.CreationContext<TLogicBridge, TActivity,
? extends ViewControllerFragment<TState, TLogicBridge, TActivity>> 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<ViewGroup, Bundle> 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<TLogicBridge, TActivity,
? extends ViewControllerFragment<TState, TLogicBridge, TActivity>> 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