Annotation helpers for PreferenceActivity and PreferenceFragment #1162
Annotation helpers for PreferenceActivity and PreferenceFragment #1162
Conversation
52c28f6
to
b48c0a0
Compare
public JInvocation findPreferenceByKey(JFieldRef idRef) { | ||
JInvocation getString = invoke(_this(), "getString").arg(idRef); | ||
JInvocation findPreferenceByKey = invoke(_this(), "findPreference"); | ||
findPreferenceByKey.arg(getString); |
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.
i would return on this line. not sure how to explain why, but it feels more clean for me.
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.
Indeed.
from a quick read it looks ok so far. |
79fec41
to
11e8d24
Compare
Functionality is done. Tests and javadoc is for the next day... |
|
||
add(new IgnoredWhenDetachedHandler(processingEnvironment)); | ||
/* After injection methods must be after injections */ | ||
add(new AfterInjectHandler(processingEnvironment)); | ||
add(new AfterExtrasHandler(processingEnvironment)); | ||
add(new AfterViewsHandler(processingEnvironment)); | ||
add(new AfterPreferencesHandler(processingEnvironment)); |
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.
just a note that we keep in mind to update the wiki #1157
a57af5e
to
7946a5a
Compare
I updated And another thing: |
if (variableElement.asType().toString().equals(CanonicalNameConstants.PREFERENCE)) { | ||
call.arg(preferenceParam); | ||
} else if (variableElement.asType().toString().equals(CanonicalNameConstants.OBJECT)) { | ||
call.arg(newValueParam); |
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.
I am just trying this PR in a real app. I think we could further help the user, if we not just allow Object
here, but any type which can be a preference. So the client do not have to cast the parameter, we could do that instead of him.
For the built-in Android Preference
classes, these types can be in the newValue
parameter:
String
(EditTextPreference
,ListPreference
,RingtonePreference
)Set
(MultiSelectListPreference
)Boolean
(CheckBoxPreference
,RingtonePreference
)
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.
I implemented this.
1996920
to
0ab7830
Compare
@yDelouis, if you can take a quick look at this, i will start tests and javadoc if you find this ok. |
for (VariableElement variableElement : userParameters) { | ||
if (variableElement.asType().toString().equals(CanonicalNameConstants.PREFERENCE)) { | ||
call.arg(preferenceParam); | ||
} else { |
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.
Why don't you use else if
? It would remove one level of indentation.
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.
Good question.
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.
Fixed.
0ab7830
to
888dfa2
Compare
Rebased onto develop. |
888dfa2
to
2bd6dfe
Compare
I rebased onto develop again. @yDelouis can you just review this quickly? If it is basically OK, i'll write tests and JavaDoc. |
i had some time to read through the changes. i haven't found anything bad. but i had no chance yet to test it in an app. but you started this as you need it in your app, so i think that you are testing it that way. :P |
Thanks! |
What does CR mean? |
Code review. |
ec0559f
to
a33fa99
Compare
I added JavaDocs and tests. |
So now it can be used for other types of listeners then View listeners. For View listeners, a new subclass, AbstractViewListenerHandler is created.
9525b8b
to
2064edf
Compare
Annotation helpers for PreferenceActivity and PreferenceFragment
It's okay. |
duh. i just found that this PR got merged and wanted to update the pref branch in my app and while testing i found a little problem. while this might be working as intended, we may want to reconsider this. case: i have some
i think it would be nice to have both. a callback before and one after. before using these annotations i used i have another feature branch where i need the post change callback even more as i need to do some logic and fire some events. |
@dodgex i used this listener intentionally. This gives a chance to act before the value is persisted. The value will be persisted after it anyway. So why would you need |
in one of my listener i update the summary based on the new value and in another one i even update another preference and fire an event with the new pref value. |
Can you give more detail? I really do not understand why you cannot use current |
currently i do something like this
where |
|
Argh! Damn. :/ @dodgex RTFM! @WonderCsabo Thank you. Nice Work! 👍 |
This PR is a WIP, and related to #7.
I decided to use resource IDs instead of plain string preference keys in the annotations, since this is the suggested way (if you use a string resource as a key, you can use it both in java and xml). Also the implementation is easier, since we can rely on existing concepts.
The implementation is basically the same as View injection/listener. Currently there is some code duplication, but i am not sure we should remove that, because it would really obfuscate the intent of the code. But i gladly accept suggestions on that.
@yDelouis, @DayS, @dodgex i would appreciate your feedback.