Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle forcing on generation time
  • Loading branch information
Lochnair committed Oct 9, 2014
commit fd66f6a4b274266b421c261187c0e3333ce59209
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ public void process(Element element, EFragmentHolder holder) {
JVar container = holder.getContainer();

JFieldVar contentView = holder.getContentView();
JFieldVar forceLayoutInjection = holder.getForceLayoutInjection();

block._if(contentView.eq(_null()).cor(forceLayoutInjection.eq(JExpr.TRUE))) //
._then() //
.assign(contentView, inflater.invoke("inflate").arg(contentViewId).arg(container).arg(FALSE));
boolean forceInjection = element.getAnnotation(EFragment.class).forceLayoutInjection();

if (!forceInjection) {
block._if(contentView.eq(_null())) //
._then() //
.assign(contentView, inflater.invoke("inflate").arg(contentViewId).arg(container).arg(FALSE));
} else {
block.assign(contentView, inflater.invoke("inflate").arg(contentViewId).arg(container).arg(FALSE));
}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class EFragmentHolder extends EComponentWithViewSupportHolder implements
private JVar container;
private JDefinedClass fragmentBuilderClass;
private JClass narrowBuilderClass;
private JFieldVar forceLayoutInjection;
private JFieldRef fragmentArgumentsBuilderField;
private JMethod injectArgsMethod;
private JBlock injectArgsBlock;
Expand Down Expand Up @@ -230,7 +229,6 @@ protected void setInit() {
public JFieldVar getContentView() {
if (contentView == null) {
setContentView();
setForceLayoutInjection();
setOnCreateView();
setOnDestroyView();
}
Expand All @@ -241,17 +239,6 @@ private void setContentView() {
contentView = generatedClass.field(PRIVATE, classes().VIEW, "contentView_");
}

public JFieldVar getForceLayoutInjection() {
if (forceLayoutInjection == null) {
setForceLayoutInjection();
}
return forceLayoutInjection;
}

private void setForceLayoutInjection() {
forceLayoutInjection = generatedClass.field(PRIVATE, boolean.class, "forceLayoutInjection_");
}

private void setOnCreateView() {
JMethod onCreateView = generatedClass.method(PUBLIC, classes().VIEW, "onCreateView");
onCreateView.annotate(Override.class);
Expand All @@ -261,9 +248,12 @@ private void setOnCreateView() {

JVar savedInstanceState = onCreateView.param(classes().BUNDLE, "savedInstanceState");

boolean forceInjection = getAnnotatedElement().getAnnotation(EFragment.class).forceLayoutInjection();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not really use getAnnotatedElement() for these kind of purposes. But i also do not see other solution to this problem. @yDelouis WDYT?


JBlock body = onCreateView.body();
body.assign(contentView, _super().invoke(onCreateView).arg(inflater).arg(container).arg(savedInstanceState));
body.assign(forceLayoutInjection, JExpr.lit(getAnnotatedElement().getAnnotation(EFragment.class).forceLayoutInjection()));

if (!forceInjection)
body.assign(contentView, _super().invoke(onCreateView).arg(inflater).arg(container).arg(savedInstanceState));

setContentViewBlock = body.block();

Expand Down