Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 055177e

Browse files
authored
Merge pull request #1907 from dodgex/1904_do_not_clear_method_injected_views
Do not clear views when injected via method
2 parents 0e90171 + 3d324e3 commit 055177e

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

  • AndroidAnnotations/androidannotations-core

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/main/java/org/androidannotations/test/efragment/MySupportFragment.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
3+
* Copyright (C) 2016 the AndroidAnnotations project
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
56
* use this file except in compliance with the License. You may obtain a copy of
@@ -73,4 +74,11 @@ void calledAfterViewInjection() {
7374

7475
}
7576

77+
@ViewById(R.id.my_text_view)
78+
void methodView1(TextView methodView1) {
79+
}
80+
81+
void methodView2(@ViewById(R.id.my_text_view) TextView methodView2) {
82+
}
83+
7684
}

‎AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/ViewByIdHandler.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
3+
* Copyright (C) 2016 the AndroidAnnotations project
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
56
* use this file except in compliance with the License. You may obtain a copy of
@@ -19,6 +20,7 @@
1920

2021
import javax.lang.model.element.Element;
2122
import javax.lang.model.element.ElementKind;
23+
import javax.lang.model.element.ExecutableElement;
2224
import javax.lang.model.type.TypeMirror;
2325

2426
import org.androidannotations.AndroidAnnotationsEnvironment;
@@ -67,12 +69,17 @@ public void validate(Element element, ElementValidation validation) {
6769
@Override
6870
public void process(Element element, EComponentWithViewSupportHolder holder) {
6971
injectHelper.process(element, holder);
70-
if (holder instanceof EFragmentHolder) {
72+
if (holder instanceof EFragmentHolder && isFieldInjection(element)) {
7173
String fieldName = element.getSimpleName().toString();
7274
((EFragmentHolder) holder).clearInjectedView(ref(fieldName));
7375
}
7476
}
7577

78+
private boolean isFieldInjection(Element element) {
79+
Element enclosingElement = element.getEnclosingElement();
80+
return !((element instanceof ExecutableElement) || (enclosingElement instanceof ExecutableElement));
81+
}
82+
7683
@Override
7784
public JBlock getInvocationBlock(EComponentWithViewSupportHolder holder) {
7885
return holder.getOnViewChangedBodyInjectionBlock();

0 commit comments

Comments
 (0)