This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
Implements @RootFragment annotation support. #2202
Merged
dodgex
merged 1 commit into
androidannotations:develop
from
smaugho:1636_rootfragment_implementation_for_ebean
Feb 22, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...androidannotations-api/src/main/java/org/androidannotations/annotations/RootFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| * @EBean | ||
| * public class MyClass { | ||
| * | ||
| * @RootFragment | ||
| * Fragment fragment; | ||
| * | ||
| * // Only injected if the root fragment implements a given interface | ||
| * @RootFragment | ||
| * MyInterface fragment; | ||
| * } | ||
| * </pre> | ||
| * | ||
| * </blockquote> | ||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER }) | ||
| public @interface RootFragment { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...st/src/main/java/org/androidannotations/test/ebean/ActivityWithBeansWithRootFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| } |
35 changes: 35 additions & 0 deletions
35
...droidannotations-test/src/main/java/org/androidannotations/test/ebean/CustomFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| } |
25 changes: 25 additions & 0 deletions
25
...idannotations-test/src/main/java/org/androidannotations/test/ebean/DifferentFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
|
||
| } |
45 changes: 45 additions & 0 deletions
45
...ations-test/src/main/java/org/androidannotations/test/ebean/SomeBeanWithRootFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| } |
43 changes: 43 additions & 0 deletions
43
...in/java/org/androidannotations/test/ebean/SomeBeanWithRootFragmentWithCustomFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| } |
43 changes: 43 additions & 0 deletions
43
...java/org/androidannotations/test/ebean/SomeBeanWithRootFragmentWithDifferentFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| } |
74 changes: 74 additions & 0 deletions
74
...oidannotations-test/src/test/java/org/androidannotations/test/ebean/RootFragmentTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.