X Tutup
Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
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 @@ -54,8 +54,8 @@
import com.helger.jcodemodel.JMod;
import com.helger.jcodemodel.JVar;

public class EActivityHolder extends EComponentWithViewSupportHolder implements HasIntentBuilder, HasExtras, HasInstanceState, HasOptionsMenu, HasOnActivityResult, HasReceiverRegistration,
HasPreferenceHeaders {
public class EActivityHolder extends EComponentWithViewSupportHolder implements HasIntentBuilder, HasExtras, HasInstanceState, HasOptionsMenu, HasOnActivityResult, HasActivityLifecycleMethods,
HasReceiverRegistration, HasPreferenceHeaders {

private ActivityIntentBuilder intentBuilder;
private JMethod onCreate;
Expand Down Expand Up @@ -726,15 +726,14 @@ public JBlock getOnPauseAfterSuperBlock() {
return onPauseAfterSuperBlock;
}


@Override
public JBlock getOnAttachAfterSuperBlock() {
return receiverRegistrationDelegate.getOnAttachAfterSuperBlock();
public JBlock getStartLifecycleAfterSuperBlock() {
return getOnCreateAfterSuperBlock();
}

@Override
public JBlock getOnDetachBeforeSuperBlock() {
return receiverRegistrationDelegate.getOnDetachBeforeSuperBlock();
public JBlock getEndLifecycleBeforeSuperBlock() {
return getOnDestroyAfterSuperBlock();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
import com.helger.jcodemodel.JMod;
import com.helger.jcodemodel.JVar;

public class EFragmentHolder extends EComponentWithViewSupportHolder implements HasInstanceState, HasOptionsMenu, HasOnActivityResult, HasReceiverRegistration, HasPreferences {
public class EFragmentHolder extends EComponentWithViewSupportHolder implements HasInstanceState, HasOptionsMenu, HasOnActivityResult, HasActivityLifecycleMethods,
HasReceiverRegistration, HasPreferences {

private JFieldVar contentView;
private JFieldVar viewDestroyedField;
Expand Down Expand Up @@ -486,6 +487,16 @@ public JFieldVar getIntentFilterField(IntentFilterData intentFilterData) {
return receiverRegistrationDelegate.getIntentFilterField(intentFilterData);
}

@Override
public JBlock getStartLifecycleAfterSuperBlock() {
return getOnCreateAfterSuperBlock();
}

@Override
public JBlock getEndLifecycleBeforeSuperBlock() {
return getOnDestroyBeforeSuperBlock();
}

@Override
public JBlock getOnCreateAfterSuperBlock() {
if (onCreateAfterSuperBlock == null) {
Expand Down Expand Up @@ -534,15 +545,13 @@ public JBlock getOnPauseBeforeSuperBlock() {
return onPauseBeforeSuperBlock;
}

@Override
public JBlock getOnAttachAfterSuperBlock() {
if (onAttachAfterSuperBlock == null) {
setOnAttach();
}
return onAttachAfterSuperBlock;
}

@Override
public JBlock getOnDetachBeforeSuperBlock() {
if (onDetachBeforeSuperBlock == null) {
setOnDetach();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016-2017 the AndroidAnnotations project
*
* 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
Expand Down Expand Up @@ -39,6 +40,7 @@ public class EServiceHolder extends EComponentHolder implements HasIntentBuilder
private ServiceIntentBuilder intentBuilder;
private JDefinedClass intentBuilderClass;
private ReceiverRegistrationDelegate<EServiceHolder> receiverRegistrationDelegate;
private JBlock onCreateAfterSuperBlock;
private JBlock onDestroyBeforeSuperBlock;

public EServiceHolder(AndroidAnnotationsEnvironment environment, TypeElement annotatedElement, AndroidManifest androidManifest) throws Exception {
Expand Down Expand Up @@ -70,6 +72,7 @@ private void setOnCreate() {
JBlock onCreateBody = onCreate.body();
onCreateBody.invoke(getInit());
onCreateBody.invoke(JExpr._super(), onCreate);
onCreateAfterSuperBlock = onCreateBody.blockVirtual();
}

private void setOnDestroy() {
Expand Down Expand Up @@ -101,45 +104,16 @@ public JBlock getIntentFilterInitializationBlock(IntentFilterData intentFilterDa
}

@Override
public JBlock getOnCreateAfterSuperBlock() {
return getInitBody();
public JBlock getStartLifecycleAfterSuperBlock() {
return onCreateAfterSuperBlock;
}

@Override
public JBlock getOnDestroyBeforeSuperBlock() {
public JBlock getEndLifecycleBeforeSuperBlock() {
if (onDestroyBeforeSuperBlock == null) {
setOnDestroy();
}
return onDestroyBeforeSuperBlock;
}

@Override
public JBlock getOnStartAfterSuperBlock() {
return receiverRegistrationDelegate.getOnStartAfterSuperBlock();
}

@Override
public JBlock getOnStopBeforeSuperBlock() {
return receiverRegistrationDelegate.getOnStopBeforeSuperBlock();
}

@Override
public JBlock getOnResumeAfterSuperBlock() {
return receiverRegistrationDelegate.getOnResumeAfterSuperBlock();
}

@Override
public JBlock getOnPauseBeforeSuperBlock() {
return receiverRegistrationDelegate.getOnPauseBeforeSuperBlock();
}

@Override
public JBlock getOnAttachAfterSuperBlock() {
return receiverRegistrationDelegate.getOnAttachAfterSuperBlock();
}

@Override
public JBlock getOnDetachBeforeSuperBlock() {
return receiverRegistrationDelegate.getOnDetachBeforeSuperBlock();
return onDestroyBeforeSuperBlock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,42 +169,12 @@ public JFieldVar getAlreadyInflated() {
}

@Override
public JBlock getOnCreateAfterSuperBlock() {
return receiverRegistrationDelegate.getOnCreateAfterSuperBlock();
}

@Override
public JBlock getOnDestroyBeforeSuperBlock() {
return receiverRegistrationDelegate.getOnDestroyBeforeSuperBlock();
}

@Override
public JBlock getOnStartAfterSuperBlock() {
return receiverRegistrationDelegate.getOnStartAfterSuperBlock();
}

@Override
public JBlock getOnStopBeforeSuperBlock() {
return receiverRegistrationDelegate.getOnStopBeforeSuperBlock();
}

@Override
public JBlock getOnResumeAfterSuperBlock() {
return receiverRegistrationDelegate.getOnResumeAfterSuperBlock();
}

@Override
public JBlock getOnPauseBeforeSuperBlock() {
return receiverRegistrationDelegate.getOnPauseBeforeSuperBlock();
}

@Override
public JBlock getOnAttachAfterSuperBlock() {
public JBlock getStartLifecycleAfterSuperBlock() {
return getOnAttachedToWindowAfterSuperBlock();
}

@Override
public JBlock getOnDetachBeforeSuperBlock() {
public JBlock getEndLifecycleBeforeSuperBlock() {
return getOnDetachedToWindowBeforeSuperBlock();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016-2017 the AndroidAnnotations project
*
* 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
Expand All @@ -17,7 +18,7 @@

import com.helger.jcodemodel.JBlock;

public interface HasLifecycleMethods extends GeneratedClassHolder {
public interface HasActivityLifecycleMethods extends GeneratedClassHolder {

JBlock getOnCreateAfterSuperBlock();
JBlock getOnDestroyBeforeSuperBlock();
Expand All @@ -27,7 +28,4 @@ public interface HasLifecycleMethods extends GeneratedClassHolder {

JBlock getOnResumeAfterSuperBlock();
JBlock getOnPauseBeforeSuperBlock();

JBlock getOnAttachAfterSuperBlock();
JBlock getOnDetachBeforeSuperBlock();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016-2017 the AndroidAnnotations project
*
* 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
Expand All @@ -21,7 +22,7 @@
import com.helger.jcodemodel.JBlock;
import com.helger.jcodemodel.JFieldVar;

public interface HasReceiverRegistration extends HasLifecycleMethods {
public interface HasReceiverRegistration extends HasSimpleLifecycleMethods {

IJExpression getContextRef();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2016-2017 the AndroidAnnotations project
*
* 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;

import com.helger.jcodemodel.JBlock;

public interface HasSimpleLifecycleMethods extends GeneratedClassHolder {

JBlock getStartLifecycleAfterSuperBlock();
JBlock getEndLifecycleBeforeSuperBlock();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016-2017 the AndroidAnnotations project
*
* 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
Expand Down Expand Up @@ -35,7 +36,6 @@
public class ReceiverRegistrationDelegate<T extends EComponentHolder & HasReceiverRegistration> extends GeneratedClassHolderDelegate<T> {

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

public ReceiverRegistrationDelegate(T holder) {
super(holder);
Expand Down Expand Up @@ -66,38 +66,6 @@ private JFieldVar createIntentFilterField(IntentFilterData intentFilterData) {
return intentFilterField;
}

public JBlock getOnStartAfterSuperBlock() {
throw illegalStateException;
}

public JBlock getOnStopBeforeSuperBlock() {
throw illegalStateException;
}

public JBlock getOnPauseBeforeSuperBlock() {
throw illegalStateException;
}

public JBlock getOnAttachAfterSuperBlock() {
throw illegalStateException;
}

public JBlock getOnDetachBeforeSuperBlock() {
throw illegalStateException;
}

public JBlock getOnResumeAfterSuperBlock() {
throw illegalStateException;
}

public JBlock getOnCreateAfterSuperBlock() {
throw illegalStateException;
}

public JBlock getOnDestroyBeforeSuperBlock() {
throw illegalStateException;
}

public static class IntentFilterData {

private final RegisterAt registerAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.androidannotations.handler.AnnotationHandler;
import org.androidannotations.handler.HasParameterHandlers;
import org.androidannotations.helper.CanonicalNameConstants;
import org.androidannotations.holder.EFragmentHolder;
import org.androidannotations.holder.HasActivityLifecycleMethods;
import org.androidannotations.holder.HasReceiverRegistration;
import org.androidannotations.holder.ReceiverRegistrationDelegate.IntentFilterData;

Expand Down Expand Up @@ -138,22 +140,35 @@ private JFieldVar createReceiverField(HasReceiverRegistration holder, String rec
private void registerAndUnregisterReceiver(HasReceiverRegistration holder, Receiver.RegisterAt registerAt, JFieldVar intentFilterField, JFieldVar receiverField, boolean local) {
JBlock registerBlock = null;
JBlock unregisterBlock = null;
switch (registerAt) {
case OnCreateOnDestroy:
registerBlock = holder.getOnCreateAfterSuperBlock();
unregisterBlock = holder.getOnDestroyBeforeSuperBlock();
break;
case OnStartOnStop:
registerBlock = holder.getOnStartAfterSuperBlock();
unregisterBlock = holder.getOnStopBeforeSuperBlock();
break;
case OnResumeOnPause:
registerBlock = holder.getOnResumeAfterSuperBlock();
unregisterBlock = holder.getOnPauseBeforeSuperBlock();
break;
case OnAttachOnDetach:
registerBlock = holder.getOnAttachAfterSuperBlock();
unregisterBlock = holder.getOnDetachBeforeSuperBlock();

Copy link
Member Author

Choose a reason for hiding this comment

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

This code is now rather ugly, but this is the price for removing the invalid abstraction HasLifecycleMethods. Do you have a better idea? @dodgex

Copy link
Member

Choose a reason for hiding this comment

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

Currently i cant think of a better way to solve this. :/

if (holder instanceof HasActivityLifecycleMethods) {
HasActivityLifecycleMethods activityLifecycleMethods = (HasActivityLifecycleMethods) holder;

switch (registerAt) {
case OnCreateOnDestroy:
registerBlock = activityLifecycleMethods.getOnCreateAfterSuperBlock();
unregisterBlock = activityLifecycleMethods.getOnDestroyBeforeSuperBlock();
break;
case OnStartOnStop:
registerBlock = activityLifecycleMethods.getOnStartAfterSuperBlock();
unregisterBlock = activityLifecycleMethods.getOnStopBeforeSuperBlock();
break;
case OnResumeOnPause:
registerBlock = activityLifecycleMethods.getOnResumeAfterSuperBlock();
unregisterBlock = activityLifecycleMethods.getOnPauseBeforeSuperBlock();
break;
}

if (holder instanceof EFragmentHolder && registerAt == Receiver.RegisterAt.OnAttachOnDetach) {
EFragmentHolder fragmentHolder = (EFragmentHolder) holder;

registerBlock = fragmentHolder.getOnAttachAfterSuperBlock();
unregisterBlock = fragmentHolder.getOnDetachBeforeSuperBlock();
}

} else {
registerBlock = holder.getStartLifecycleAfterSuperBlock();
unregisterBlock = holder.getEndLifecycleBeforeSuperBlock();
}

IJExpression broadcastManager;
Expand Down
Loading
X Tutup