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

Commit

Permalink
Refactor holders which decorate another holder
Browse files Browse the repository at this point in the history
  • Loading branch information
WonderCsabo committed Mar 24, 2015
1 parent 0f65e00 commit 69002c5
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 27 deletions.
Expand Up @@ -73,7 +73,7 @@ public class EActivityHolder extends EComponentWithViewSupportHolder implements
private JDefinedClass intentBuilderClass;
private InstanceStateHolder instanceStateHolder;
private OnActivityResultHolder onActivityResultHolder;
private ReceiverRegistrationHolder<EActivityHolder> receiverRegistrationHolder;
private ReceiverRegistrationHolder receiverRegistrationHolder;
private RoboGuiceHolder roboGuiceHolder;
private JMethod injectExtrasMethod;
private JBlock injectExtrasBlock;
Expand Down Expand Up @@ -101,7 +101,7 @@ public EActivityHolder(ProcessHolder processHolder, TypeElement annotatedElement
super(processHolder, annotatedElement);
instanceStateHolder = new InstanceStateHolder(this);
onActivityResultHolder = new OnActivityResultHolder(this);
receiverRegistrationHolder = new ReceiverRegistrationHolder<EActivityHolder>(this);
receiverRegistrationHolder = new ReceiverRegistrationHolder(this);
setSetContentView();
intentBuilder = new ActivityIntentBuilder(this, androidManifest);
intentBuilder.build();
Expand Down
Expand Up @@ -65,7 +65,7 @@ public class EFragmentHolder extends EComponentWithViewSupportHolder implements
private JVar injectBundleArgs;
private InstanceStateHolder instanceStateHolder;
private OnActivityResultHolder onActivityResultHolder;
private ReceiverRegistrationHolder<EFragmentHolder> receiverRegistrationHolder;
private ReceiverRegistrationHolder receiverRegistrationHolder;
private JBlock onCreateOptionsMenuMethodBody;
private JVar onCreateOptionsMenuMenuInflaterVar;
private JVar onCreateOptionsMenuMenuParam;
Expand All @@ -85,7 +85,7 @@ public EFragmentHolder(ProcessHolder processHolder, TypeElement annotatedElement
super(processHolder, annotatedElement);
instanceStateHolder = new InstanceStateHolder(this);
onActivityResultHolder = new OnActivityResultHolder(this);
receiverRegistrationHolder = new ReceiverRegistrationHolder<EFragmentHolder>(this);
receiverRegistrationHolder = new ReceiverRegistrationHolder(this);
setOnCreate();
setOnViewCreated();
setFragmentBuilder();
Expand Down
Expand Up @@ -39,12 +39,12 @@ public class EServiceHolder extends EComponentHolder implements HasIntentBuilder

private ServiceIntentBuilder intentBuilder;
private JDefinedClass intentBuilderClass;
private ReceiverRegistrationHolder<EServiceHolder> receiverRegistrationHolder;
private ReceiverRegistrationHolder receiverRegistrationHolder;
private JBlock onDestroyBeforeSuperBlock;

public EServiceHolder(ProcessHolder processHolder, TypeElement annotatedElement, AndroidManifest androidManifest) throws Exception {
super(processHolder, annotatedElement);
receiverRegistrationHolder = new ReceiverRegistrationHolder<EServiceHolder>(this);
receiverRegistrationHolder = new ReceiverRegistrationHolder(this);
intentBuilder = new ServiceIntentBuilder(this, androidManifest);
intentBuilder.build();
}
Expand Down
Expand Up @@ -22,19 +22,18 @@
import com.sun.codemodel.JClass;
import com.sun.codemodel.JExpression;

public class FoundViewHolder {
public class FoundViewHolder extends GeneratedClassHolderDecorator<GeneratedClassHolder> {

private GeneratedClassHolder holder;
private JClass viewClass;
private JExpression view;
private JBlock ifNotNullBlock;
private boolean ifNotNullCreated = false;

public FoundViewHolder(GeneratedClassHolder holder, JClass viewClass, JExpression view, JBlock block) {
this.holder = holder;
super(holder);
this.viewClass = viewClass;
this.view = view;
this.ifNotNullBlock = block;
ifNotNullBlock = block;
}

public JExpression getView() {
Expand Down
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2010-2015 eBusiness Information, Excilys Group
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.holder;

public class GeneratedClassHolderDecorator<T extends GeneratedClassHolder> {

protected T holder;

public GeneratedClassHolderDecorator(T holder) {
this.holder = holder;
}

}
Expand Up @@ -21,9 +21,8 @@
import com.sun.codemodel.JMod;
import com.sun.codemodel.JVar;

public class OnSeekBarChangeListenerHolder {
public class OnSeekBarChangeListenerHolder extends GeneratedClassHolderDecorator<EComponentWithViewSupportHolder> {

private EComponentWithViewSupportHolder holder;
private JDefinedClass listenerClass;
private JBlock onProgressChangedBody;
private JVar onProgressChangedSeekBarParam;
Expand All @@ -35,8 +34,8 @@ public class OnSeekBarChangeListenerHolder {
private JVar onStopTrackingTouchSeekBarParam;

public OnSeekBarChangeListenerHolder(EComponentWithViewSupportHolder holder, JDefinedClass onSeekbarChangeListenerClass) {
this.holder = holder;
this.listenerClass = onSeekbarChangeListenerClass;
super(holder);
listenerClass = onSeekbarChangeListenerClass;
createOnProgressChanged();
createOnStartTrackingTouch();
createOnStopTrackingTouch();
Expand Down
Expand Up @@ -34,14 +34,13 @@
import com.sun.codemodel.JExpression;
import com.sun.codemodel.JFieldVar;

public class ReceiverRegistrationHolder<T extends EComponentHolder & HasReceiverRegistration> {
public class ReceiverRegistrationHolder extends GeneratedClassHolderDecorator<EComponentHolder> {

private T holder;
private Map<IntentFilterData, JFieldVar> intentFilterFields = new HashMap<IntentFilterData, JFieldVar>();
private IllegalStateException illegalStateException = new IllegalStateException("This shouldn't happen unless the validation is bad");

public ReceiverRegistrationHolder(T holder) {
this.holder = holder;
public ReceiverRegistrationHolder(EComponentHolder holder) {
super(holder);
}

public JFieldVar getIntentFilterField(IntentFilterData intentFilterData) {
Expand All @@ -58,7 +57,7 @@ private JFieldVar createIntentFilterField(IntentFilterData intentFilterData) {
JExpression newIntentFilterExpr = _new(classes().INTENT_FILTER);
JFieldVar intentFilterField = getGeneratedClass().field(PRIVATE | FINAL, classes().INTENT_FILTER, intentFilterName, newIntentFilterExpr);

JBlock intentFilterTarget = holder.getIntentFilterInitializationBlock(intentFilterData);
JBlock intentFilterTarget = ((HasReceiverRegistration) holder).getIntentFilterInitializationBlock(intentFilterData);
for (String action : intentFilterData.getActionSet()) {
intentFilterTarget.invoke(intentFilterField, "addAction").arg(action);
}
Expand Down
Expand Up @@ -20,9 +20,8 @@
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JVar;

public class RoboGuiceHolder {
public class RoboGuiceHolder extends GeneratedClassHolderDecorator<EActivityHolder> {

private EActivityHolder holder;

// TODO access for these fields should be refactored

Expand All @@ -44,7 +43,7 @@ public class RoboGuiceHolder {
protected JBlock onContentChangedAfterSuperBlock;

public RoboGuiceHolder(EActivityHolder holder) {
this.holder = holder;
super(holder);
}

public JFieldVar getEventManagerField() {
Expand Down
Expand Up @@ -22,9 +22,8 @@
import com.sun.codemodel.JPrimitiveType;
import com.sun.codemodel.JVar;

public class TextWatcherHolder {
public class TextWatcherHolder extends GeneratedClassHolderDecorator<EComponentWithViewSupportHolder> {

private EComponentWithViewSupportHolder holder;
private JVar textViewVariable;
private JDefinedClass listenerClass;
private JBlock beforeTextChangedBody;
Expand All @@ -41,9 +40,9 @@ public class TextWatcherHolder {
private JVar afterTextChangedEditableParam;

public TextWatcherHolder(EComponentWithViewSupportHolder holder, JVar viewVariable, JDefinedClass onTextChangeListenerClass) {
this.holder = holder;
this.textViewVariable = viewVariable;
this.listenerClass = onTextChangeListenerClass;
super(holder);
textViewVariable = viewVariable;
listenerClass = onTextChangeListenerClass;
createBeforeTextChanged();
createOnTextChanged();
createAfterTextChanged();
Expand Down

0 comments on commit 69002c5

Please sign in to comment.