X Tutup
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 all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ public void process(Element element, EComponentWithViewSupportHolder holder) {
JClass viewClass = refClass(typeQualifiedName);
JFieldRef fieldRef = ref(fieldName);

holder.assignFindViewById(idRef, viewClass, fieldRef);
holder.processViewById(idRef, viewClass, fieldRef);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public JInvocation findViewById(JFieldRef idRef) {
return findViewById;
}

public void processViewById(JFieldRef idRef, JClass viewClass, JFieldRef fieldRef) {
assignFindViewById(idRef, viewClass, fieldRef);
}

public void assignFindViewById(JFieldRef idRef, JClass viewClass, JFieldRef fieldRef) {
String idRefString = codeModelHelper.getIdStringFromIdFieldRef(idRef);
FoundViewHolder foundViewHolder = foundViewsHolders.get(idRefString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class EFragmentHolder extends EComponentWithViewSupportHolder implements
private JBlock onPauseBeforeSuperBlock;
private JBlock onAttachAfterSuperBlock;
private JBlock onDetachBeforeSuperBlock;
private JBlock onDestroyViewAfterSuperBlock;

public EFragmentHolder(ProcessHolder processHolder, TypeElement annotatedElement) throws Exception {
super(processHolder, annotatedElement);
Expand Down Expand Up @@ -217,13 +218,17 @@ protected void setInit() {

public JFieldVar getContentView() {
if (contentView == null) {
setContentView();
setOnCreateView();
setOnDestroyView();
setContentViewRelatedMethods();
}
return contentView;
}

private void setContentViewRelatedMethods() {
setContentView();
setOnCreateView();
setOnDestroyView();
}

private void setContentView() {
contentView = generatedClass.field(PRIVATE, classes().VIEW, "contentView_");
}
Expand All @@ -249,8 +254,27 @@ private void setOnDestroyView() {
JMethod onDestroyView = generatedClass.method(PUBLIC, codeModel().VOID, "onDestroyView");
onDestroyView.annotate(Override.class);
JBlock body = onDestroyView.body();
body.assign(contentView, _null());
body.invoke(_super(), onDestroyView);
body.assign(contentView, _null());
onDestroyViewAfterSuperBlock = body.block();
}

private JBlock getOnDestroyViewAfterSuperBlock() {
if (onDestroyViewAfterSuperBlock == null) {
setContentViewRelatedMethods();
}
return onDestroyViewAfterSuperBlock;
}

@Override
public void processViewById(JFieldRef idRef, JClass viewClass, JFieldRef fieldRef) {
super.processViewById(idRef, viewClass, fieldRef);
clearInjectedView(fieldRef);
}

private void clearInjectedView(JFieldRef fieldRef) {
JBlock block = getOnDestroyViewAfterSuperBlock();
block.assign(fieldRef, _null());
}

private void setOnStart() {
Expand Down
X Tutup