This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
Add name parameter to @SharedPref #1918
Merged
WonderCsabo
merged 2 commits into
androidannotations:develop
from
dodgex:1675_add_name_parameter_to_shared_pref
Dec 11, 2016
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
25 changes: 25 additions & 0 deletions
25
...droidannotations/src/test/java/org/androidannotations/sharedprefs/ActivityInManifest.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 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.sharedprefs; | ||
|
|
||
| import org.androidannotations.annotations.EActivity; | ||
|
|
||
| import android.app.Activity; | ||
|
|
||
| @EActivity | ||
| public class ActivityInManifest extends Activity { | ||
|
|
||
| } |
43 changes: 43 additions & 0 deletions
43
.../androidannotations/src/test/java/org/androidannotations/sharedprefs/PrefsCollection.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 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.sharedprefs; | ||
|
|
||
| import org.androidannotations.annotations.EBean; | ||
| import org.androidannotations.annotations.sharedpreferences.SharedPref; | ||
|
|
||
| @EBean | ||
| public class PrefsCollection { | ||
|
|
||
| @SharedPref(SharedPref.Scope.ACTIVITY) | ||
| public interface ActivityPrefs { | ||
|
|
||
| } | ||
|
|
||
| @SharedPref(value = SharedPref.Scope.ACTIVITY, name = "named_pref_activity") | ||
| public interface NamedActivityPrefs { | ||
|
|
||
| } | ||
|
|
||
| @SharedPref(SharedPref.Scope.UNIQUE) | ||
| public interface UniquePrefs { | ||
|
|
||
| } | ||
|
|
||
| @SharedPref(value = SharedPref.Scope.UNIQUE, name = "named_pref_unique") | ||
| public interface NamedUniquePrefs { | ||
|
|
||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
...nnotations/src/test/java/org/androidannotations/sharedprefs/PrefsCollectionWithError.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,33 @@ | ||
| /** | ||
| * Copyright (C) 2016 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.sharedprefs; | ||
|
|
||
| import org.androidannotations.annotations.EBean; | ||
| import org.androidannotations.annotations.sharedpreferences.SharedPref; | ||
|
|
||
| @EBean | ||
| public class PrefsCollectionWithError { | ||
|
|
||
| @SharedPref(value = SharedPref.Scope.ACTIVITY_DEFAULT, name = "named_pref_activity_default") | ||
| public interface NamedActivityDefaultPrefs { | ||
|
|
||
| } | ||
|
|
||
| @SharedPref(value = SharedPref.Scope.APPLICATION_DEFAULT, name = "named_pref_application_default") | ||
| public interface NamedApplicationDefaultPrefs { | ||
|
|
||
| } | ||
| } |
79 changes: 79 additions & 0 deletions
79
...oidannotations/src/test/java/org/androidannotations/sharedprefs/SharedPrefNamingTest.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,79 @@ | ||
| /** | ||
| * Copyright (C) 2016 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.sharedprefs; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
|
|
||
| import org.androidannotations.internal.AndroidAnnotationProcessor; | ||
| import org.androidannotations.testutils.AAProcessorTestHelper; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| public class SharedPrefNamingTest extends AAProcessorTestHelper { | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| addManifestProcessorParameter(ActivityInManifest.class); | ||
| addProcessor(AndroidAnnotationProcessor.class); | ||
| ensureOutputDirectoryIsEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNamedPrefGeneration() throws IOException { | ||
| CompileResult result = compileFiles(PrefsCollection.class); | ||
| File generatedFile = toGeneratedFile(PrefsCollection.class); | ||
|
|
||
| assertCompilationSuccessful(result); | ||
|
|
||
| // CHECKSTYLE:OFF | ||
| String[] activityPref = { // | ||
| " public ActivityPrefs_(Context context) {", // | ||
| " super(context.getSharedPreferences((getLocalClassName(context)+\"_ActivityPrefs\"), 0));", // | ||
| " }" // | ||
| }; | ||
| String[] namedActivityPref = { // | ||
| " public NamedActivityPrefs_(Context context) {", // | ||
| " super(context.getSharedPreferences((getLocalClassName(context)+\"_named_pref_activity\"), 0));", // | ||
| " }" // | ||
| }; | ||
| String[] uniquePref = { // | ||
| " public UniquePrefs_(Context context) {", // | ||
| " super(context.getSharedPreferences(\"UniquePrefs\", 0));", // | ||
| " }" // | ||
| }; | ||
| String[] namedUniquePref = { // | ||
| " public NamedUniquePrefs_(Context context) {", // | ||
| " super(context.getSharedPreferences(\"named_pref_unique\", 0));", // | ||
| " }" // | ||
| }; | ||
| // CHECKSTYLE:ON | ||
| assertGeneratedClassContains(generatedFile, activityPref); | ||
| assertGeneratedClassContains(generatedFile, namedActivityPref); | ||
| assertGeneratedClassContains(generatedFile, uniquePref); | ||
| assertGeneratedClassContains(generatedFile, namedUniquePref); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNamedPrefGenerationErrors() throws IOException { | ||
| CompileResult result = compileFiles(PrefsCollectionWithError.class); | ||
|
|
||
| assertCompilationError(result); | ||
|
|
||
| assertCompilationErrorOn(PrefsCollectionWithError.class, "@SharedPref(value = SharedPref.Scope.ACTIVITY_DEFAULT, name = \"named_pref_activity_default\")", result); | ||
| assertCompilationErrorOn(PrefsCollectionWithError.class, "@SharedPref(value = SharedPref.Scope.APPLICATION_DEFAULT, name = \"named_pref_application_default\")", result); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...roidannotations/src/test/resources/org/androidannotations/sharedprefs/AndroidManifest.xml
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,28 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
|
|
||
| Copyright (C) 2016 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. | ||
|
|
||
| --> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="org.androidannotations.testprocessor" | ||
| android:versionCode="1" | ||
| android:versionName="1.0" > | ||
|
|
||
| <application> | ||
| <activity android:name="org.androidannotations.sharedprefs.ActivityInManifest_" /> | ||
| </application> | ||
|
|
||
| </manifest> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)