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
@@ -0,0 +1,55 @@
/**
* Copyright (C) 2016-2019 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.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* <p>
* Use it on Fragment fields in an {@link EBean} annotated classes to inject the
* Fragment which originally injected the bean instance.
* </p>
* <p>
* This field may not be injected at runtime if the fragment used to create the
* bean is not of the appropriate type, or if the bean is injected in an
* activity.
* </p>
* <blockquote>
*
* Example :
*
* <pre>
* &#064;EBean
* public class MyClass {
*
* &#064;RootFragment
* Fragment fragment;
*
* // Only injected if the root fragment implements a given interface
* &#064;RootFragment
* MyInterface fragment;
* }
* </pre>
*
* </blockquote>
*/
@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
public @interface RootFragment {
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<activity android:name=".afterextras.AfterExtrasActivity_"/>
<activity android:name=".FullscreenActivity_"/>
<activity android:name=".PageChangeListenerActivity_"/>
<activity android:name=".ebean.ActivityWithBeansWithRootFragment_"/>

<receiver android:name=".ereceiver.MyReceiver_"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (C) 2016-2019 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.test.ebean;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;

import android.app.Activity;

@EActivity
public class ActivityWithBeansWithRootFragment extends Activity {

@Bean
SomeBeanWithRootFragment someBean;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (C) 2016-2019 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.test.ebean;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;

import android.app.Fragment;

@EFragment
public class CustomFragment extends Fragment {

@Bean
SomeBeanWithRootFragment someBean;

@Bean
SomeBeanWithRootFragmentWithCustomFragment someBeanWithCustomFragment;

@Bean
SomeBeanWithRootFragmentWithDifferentFragment someBeanWithDifferentFragment;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (C) 2016-2019 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.test.ebean;

import org.androidannotations.annotations.EFragment;

import android.app.Fragment;

@EFragment
public class DifferentFragment extends Fragment {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (C) 2016-2019 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.test.ebean;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootFragment;

import android.app.Fragment;

@EBean
public class SomeBeanWithRootFragment {

@RootFragment
Fragment fragment;

Fragment fragmentByMethod;

Fragment fragmentByParam1;

Fragment fragmentByParam2;

@RootFragment
void setFragment(Fragment fragment) {
this.fragmentByMethod = fragment;
}

void setFragment2(@RootFragment Fragment fragment1, @RootFragment Fragment fragment2) {
this.fragmentByParam1 = fragment1;
this.fragmentByParam2 = fragment2;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (C) 2016-2019 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.test.ebean;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootFragment;

@EBean
public class SomeBeanWithRootFragmentWithCustomFragment {

@RootFragment
CustomFragment fragment;

CustomFragment fragmentByMethod;

CustomFragment fragmentByParam1;

CustomFragment fragmentByParam2;

@RootFragment
void setFragment(CustomFragment fragment) {
this.fragmentByMethod = fragment;
}

void setFragment2(@RootFragment CustomFragment fragment1, @RootFragment CustomFragment fragment2) {
this.fragmentByParam1 = fragment1;
this.fragmentByParam2 = fragment2;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (C) 2016-2019 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.test.ebean;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootFragment;

@EBean
public class SomeBeanWithRootFragmentWithDifferentFragment {

@RootFragment
DifferentFragment fragment;

DifferentFragment fragmentByMethod;

DifferentFragment fragmentByParam1;

DifferentFragment fragmentByParam2;

@RootFragment
void setFragment(DifferentFragment fragment) {
this.fragmentByMethod = fragment;
}

void setFragment2(@RootFragment DifferentFragment fragment1, @RootFragment DifferentFragment fragment2) {
this.fragmentByParam1 = fragment1;
this.fragmentByParam2 = fragment2;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright (C) 2016-2019 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.test.ebean;

import static org.fest.assertions.api.Assertions.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class RootFragmentTest {

@Test
public void injectFragmentWhichInjectedBean() {
CustomFragment fragment = Robolectric.buildFragment(CustomFragment_.class).create().get();

fragment.onCreate(null);

assertThat(fragment.someBean.fragment).isEqualTo(fragment);
assertThat(fragment.someBean.fragmentByMethod).isEqualTo(fragment);
assertThat(fragment.someBean.fragmentByParam1).isEqualTo(fragment);
assertThat(fragment.someBean.fragmentByParam2).isEqualTo(fragment);
}

@Test
public void injectSomeFragmentWhichInjectedBean() {
CustomFragment fragment = Robolectric.buildFragment(CustomFragment_.class).create().get();

fragment.onCreate(null);

assertThat(fragment.someBeanWithCustomFragment.fragment).isEqualTo(fragment);
assertThat(fragment.someBeanWithCustomFragment.fragmentByMethod).isEqualTo(fragment);
assertThat(fragment.someBeanWithCustomFragment.fragmentByParam1).isEqualTo(fragment);
assertThat(fragment.someBeanWithCustomFragment.fragmentByParam2).isEqualTo(fragment);
}

@Test
public void nothingInjectedIfDifferentFragmentThanInjectingFragmentIsUsedOnBean() {
CustomFragment fragment = Robolectric.buildFragment(CustomFragment_.class).create().get();

fragment.onCreate(null);

assertThat(fragment.someBeanWithDifferentFragment.fragment).isNull();
assertThat(fragment.someBeanWithDifferentFragment.fragmentByMethod).isNull();
assertThat(fragment.someBeanWithDifferentFragment.fragmentByParam1).isNull();
assertThat(fragment.someBeanWithDifferentFragment.fragmentByParam2).isNull();
}

@Test
public void nothingInjectedIfActivityInjectedBean() {
ActivityWithBeansWithRootFragment_ activity = Robolectric.setupActivity(ActivityWithBeansWithRootFragment_.class);

assertThat(activity.someBean.fragment).isNull();
assertThat(activity.someBean.fragmentByMethod).isNull();
assertThat(activity.someBean.fragmentByParam1).isNull();
assertThat(activity.someBean.fragmentByParam2).isNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public String toPath(Class<?> classOfPackagingContainingFile, String filename) {
return classOfPackagingContainingFile.getResource(filename).getPath();
}

public String[] defPath(String... filesName) {
String[] paths = new String[filesName.length];
for (int i = 0; i < filesName.length; i++) {
paths[i] = toPath(this.getClass(), filesName[i]);
}
return paths;
}

/**
* This module cannot depend on androidannotations module, because that would
* introduce a cycle in the dependency graph. That is why we cannot directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ public CompileResult compileFiles(Object... elements) {
addCollection(files, (Type) element);
} else if (element instanceof String) {
files.add(new File((String) element));
} else if (element instanceof String[]) {
Comment thread
WonderCsabo marked this conversation as resolved.
for (String subElement : (String[]) element) {
files.add(new File(subElement));
}
}
}
return compileFiles(files);
Expand Down
Loading